Skip to content

ts_shape.loader.metadata.metadata_api_loader ¤

Classes:

  • DatapointAPI

    Class for accessing datapoints for multiple devices via an API.

DatapointAPI ¤

DatapointAPI(device_names: List[str], base_url: str, api_token: str, output_path: str = 'data', required_uuid_list: List[str] = None, filter_enabled: bool = True)

Class for accessing datapoints for multiple devices via an API.

:param device_names: List of device names to retrieve metadata for. :param base_url: Base URL of the API. :param api_token: API token for authentication. :param output_path: Directory to save the data points JSON files. :param required_uuid_list: Mixed list of UUIDs to filter the metadata across devices (optional). :param filter_enabled: Whether to filter metadata by "enabled == True" (default is True).

Methods:

Source code in src/ts_shape/loader/metadata/metadata_api_loader.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def __init__(self, device_names: List[str], base_url: str, api_token: str, output_path: str = "data", required_uuid_list: List[str] = None, filter_enabled: bool = True):
    """
    Initialize the DatapointAPI class.

    :param device_names: List of device names to retrieve metadata for.
    :param base_url: Base URL of the API.
    :param api_token: API token for authentication.
    :param output_path: Directory to save the data points JSON files.
    :param required_uuid_list: Mixed list of UUIDs to filter the metadata across devices (optional).
    :param filter_enabled: Whether to filter metadata by "enabled == True" (default is True).
    """
    self.device_names = device_names
    self.base_url = base_url
    self.api_token = api_token
    self.output_path = output_path
    self.required_uuid_list = required_uuid_list or []  # Defaults to an empty list if None
    self.filter_enabled = filter_enabled
    self.device_metadata: Dict[str, pd.DataFrame] = {}  # Store metadata for each device
    self.device_uuids: Dict[str, List[str]] = {}  # Store UUIDs for each device
    self._api_access()

display_dataframe ¤

display_dataframe(device_name: str = None) -> None

Print the metadata DataFrame for a specific device or all devices.

:param device_name: Name of the device to display metadata for (optional). If None, displays metadata for all devices.

Source code in src/ts_shape/loader/metadata/metadata_api_loader.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
def display_dataframe(self, device_name: str = None) -> None:
    """
    Print the metadata DataFrame for a specific device or all devices.

    :param device_name: Name of the device to display metadata for (optional).
                        If None, displays metadata for all devices.
    """
    if device_name:
        # Display metadata for a specific device
        if device_name in self.device_metadata:
            print(f"Metadata for device: {device_name}")
            print(self.device_metadata[device_name])
        else:
            print(f"No metadata found for device: {device_name}")
    else:
        # Display metadata for all devices
        for device, metadata in self.device_metadata.items():
            print(f"\nMetadata for device: {device}")
            print(metadata)

get_all_metadata ¤

get_all_metadata() -> Dict[str, List[Dict[str, str]]]

Return a dictionary of metadata for each device.

Source code in src/ts_shape/loader/metadata/metadata_api_loader.py
87
88
89
def get_all_metadata(self) -> Dict[str, List[Dict[str, str]]]:
    """Return a dictionary of metadata for each device."""
    return {device: metadata.to_dict(orient="records") for device, metadata in self.device_metadata.items()}

get_all_uuids ¤

get_all_uuids() -> Dict[str, List[str]]

Return a dictionary of UUIDs for each device.

Source code in src/ts_shape/loader/metadata/metadata_api_loader.py
83
84
85
def get_all_uuids(self) -> Dict[str, List[str]]:
    """Return a dictionary of UUIDs for each device."""
    return self.device_uuids