Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from typing import List
import pandas as pd
from vortexasdk.api import Product
from vortexasdk.api.entity_flattening import flatten_dictionary
from vortexasdk.api.search_result import Result
from vortexasdk.logger import get_logger
from vortexasdk.result_conversions import create_dataframe, create_list
logger = get_logger(__name__)
class ProductResult(Result):
"""Container class that holds the result obtained from calling the `Product` endpoint."""
def to_list(self) -> List[Product]:
"""Represent products as a list."""
# noinspection PyTypeChecker
return create_list(super().to_list(), Product)
def to_df(self, columns=None) -> pd.DataFrame:
"""
Represent products as a `pd.DataFrame`.
# Arguments
columns: The product features we want in the dataframe. Enter `columns='all'` to include all features.
Defaults to `columns = ['id', 'name', 'layer.0', 'parent.0.name']`.
from typing import List
import pandas as pd
from vortexasdk.api.search_result import Result
from vortexasdk.api.timeseries_item import TimeSeriesItem
from vortexasdk.logger import get_logger
from vortexasdk.result_conversions import create_dataframe, create_list
logger = get_logger(__name__)
class TimeSeriesResult(Result):
"""Container class that holds the result obtained from calling a time series endpoint."""
def to_list(self) -> List[TimeSeriesItem]:
"""Represents time series as a list."""
# noinspection PyTypeChecker
return create_list(super().to_list(), TimeSeriesItem)
def to_df(self, columns=None) -> pd.DataFrame:
"""Represents the timeseries as a dataframe.
Returns a `pd.DataFrame`, of time series items with columns:
key: The time series key
value: The value of the time series for a given key
count: The number of records contributing to this time series record.
# Example:
from typing import List
import pandas as pd
from vortexasdk.api import VesselMovement
from vortexasdk.api.entity_flattening import (
convert_vessel_movement_to_flat_dict,
)
from vortexasdk.api.search_result import Result
from vortexasdk.result_conversions import create_dataframe, create_list
from vortexasdk.logger import get_logger
logger = get_logger(__name__)
class VesselMovementsResult(Result):
"""
Container class holdings search results returns from the vessel movements endpoint.
This class has two methods, `to_list()`, and `to_df()`, allowing search results to be represented as a list of `VesselMovement`s,
or as a `pd.DataFrame` , respectively.
"""
def to_list(self) -> List[VesselMovement]:
"""Represent vessel movements as a list of `VesselMovementEntity`s."""
# noinspection PyTypeChecker
return create_list(super().to_list(), VesselMovement)
def to_df(self, columns=None) -> pd.DataFrame:
"""
Represent vessel movements as a `pd.DataFrame`.
from typing import List
import pandas as pd
from vortexasdk.logger import get_logger
from vortexasdk.api import Vessel
from vortexasdk.api.search_result import Result
from vortexasdk.result_conversions import create_dataframe, create_list
logger = get_logger(__name__)
class VesselsResult(Result):
"""Container class that holds the result obtained from calling the `Vessels` endpoint."""
def to_list(self) -> List[Vessel]:
"""Represent vessels as a list."""
# noinspection PyTypeChecker
return create_list(super().to_list(), Vessel)
def to_df(self, columns=None) -> pd.DataFrame:
"""
Represent vessels as a `pd.DataFrame`.
# Arguments
columns: The vessel features we want in the dataframe. Enter `columns='all'` to include all features.
Defaults to `columns = ['id', 'name', 'imo', 'vessel_class']`.
from typing import List
import pandas as pd
from vortexasdk.api import Attribute
from vortexasdk.api.search_result import Result
from vortexasdk.result_conversions import create_dataframe, create_list
from vortexasdk.logger import get_logger
logger = get_logger(__name__)
class AttributeResult(Result):
"""Container class that holds the result obtained from calling the `Attributes` endpoint."""
def to_list(self) -> List[Attribute]:
"""Represent attributes as a list."""
# noinspection PyTypeChecker
return create_list(super().to_list(), Attribute)
def to_df(self, columns=None) -> pd.DataFrame:
"""
Represent attributes as a `pd.DataFrame`.
# Arguments
columns: The attributes features we want in the dataframe. Enter `columns='all'` to include all features.
Defaults to `columns = ['id', 'name', 'type']`.
from typing import List
import pandas as pd
from vortexasdk.api import Corporation
from vortexasdk.api.search_result import Result
from vortexasdk.logger import get_logger
from vortexasdk.result_conversions import create_dataframe, create_list
logger = get_logger(__name__)
class CorporationsResult(Result):
"""Container class that holds the result obtained from calling the `Vessels` endpoint."""
def to_list(self) -> List[Corporation]:
"""Represent vessels as a list."""
# noinspection PyTypeChecker
return create_list(super().to_list(), Corporation)
def to_df(self, columns=None) -> pd.DataFrame:
"""
Represent corporations as a `pd.DataFrame`.
# Arguments
columns: The corporation features we want in the dataframe. Enter `columns='all'` to include all features.
Defaults to `columns = ['id', 'name', 'corporate_entity_type']`.
from typing import List
import pandas as pd
from vortexasdk.api import Geography
from vortexasdk.api.search_result import Result
class GeographyResult(Result):
"""Container class that holds the result obtained from calling the `Geography` endpoint."""
def __init__(self, records):
super().__init__(records=records, return_type=Geography)
def to_list(self) -> List[Geography]:
"""Represent geographies as a list."""
return super().to_list()
def to_df(self, columns=None) -> pd.DataFrame:
"""
Represent geographies as a `pd.DataFrame`.
# Arguments
columns: The geography features we want in the dataframe. Enter `columns='all'` to include all features.
Defaults to `columns = ['id', 'name', 'layer']`.
from typing import List
import pandas as pd
from vortexasdk.api import CargoMovement
from vortexasdk.api.entity_flattening import (
convert_cargo_movement_to_flat_dict,
)
from vortexasdk.api.search_result import Result
from vortexasdk.result_conversions import create_dataframe, create_list
from vortexasdk.logger import get_logger
logger = get_logger(__name__)
class CargoMovementsResult(Result):
"""
Container class holdings search results returns from the cargo movements endpoint.
This class has two methods, `to_list()`, and `to_df()`, allowing search results to be represented as a list of `CargoMovements`,
or as a `pd.DataFrame` , respectively.
"""
def to_list(self) -> List[CargoMovement]:
"""Represent cargo movements as a list of `CargoMovementEntity`s."""
# noinspection PyTypeChecker
return create_list(super().to_list(), CargoMovement)
def to_df(self, columns=None) -> pd.DataFrame:
"""
Represent cargo movements as a `pd.DataFrame`.