Skip to content

Data Source Types

DataSourceTypes(perfdb)

Class used for handling data source types. Can be accessed via perfdb.datasources.types.

Parameters:

  • perfdb

    (PerfDB) –

    Top level object carrying all functionality and the connection handler.

Source code in echo_postgres/perfdb_root.py
def __init__(self, perfdb: e_pg.PerfDB) -> None:
    """Base class that all subclasses should inherit from.

    Parameters
    ----------
    perfdb : PerfDB
        Top level object carrying all functionality and the connection handler.

    """
    self._perfdb: e_pg.PerfDB = perfdb

get(output_type='dict')

Gets all datasource types definitions with detailed information.

The most useful keys/columns returned are:

  • id
  • display_name
  • description

Parameters:

  • output_type

    (Literal['dict', 'DataFrame'], default: 'dict' ) –

    Output type of the data. Can be one of ["dict", "DataFrame"] By default "dict"

Returns:

  • dict[str, dict[str, str | int]]

    In case output_type is "dict", returns a dictionary in the format {name: {attribute: value, ...}, ...}

  • DataFrame

    In case output_type is "DataFrame", returns a DataFrame with the following format: index = name, columns = [attribute, ...]

Source code in echo_postgres/datasource_types.py
@validate_call
def get(self, output_type: Literal["dict", "DataFrame"] = "dict") -> dict[str, dict[str, str | int]] | DataFrame:
    """Gets all datasource types definitions with detailed information.

    The most useful keys/columns returned are:

    - id
    - display_name
    - description

    Parameters
    ----------
    output_type : Literal["dict", "DataFrame"], optional
        Output type of the data. Can be one of ["dict", "DataFrame"]
        By default "dict"

    Returns
    -------
    dict[str, dict[str, str | int]]
        In case output_type is "dict", returns a dictionary in the format {name: {attribute: value, ...}, ...}
    DataFrame
        In case output_type is "DataFrame", returns a DataFrame with the following format: index = name, columns = [attribute, ...]
    """
    query = sql.SQL("SELECT * FROM performance.data_source_types ORDER BY name")

    with self._perfdb.conn.reconnect() as conn:
        df = conn.read_to_pandas(query)
    df = df.set_index("name")

    return df.to_dict(orient="index") if output_type == "dict" else df

get_ids()

Gets all data source types and their respective ids.

Returns:

  • dict[str, int]

    Dictionary with all datasource types and their respective ids in the format {datasource_type: id, ...}.

Source code in echo_postgres/datasource_types.py
def get_ids(self) -> dict[str, int]:
    """Gets all data source types and their respective ids.

    Returns
    -------
    dict[str, int]
        Dictionary with all datasource types and their respective ids in the format {datasource_type: id, ...}.
    """
    query = sql.SQL("SELECT name, id FROM performance.data_source_types ORDER BY name")

    with self._perfdb.conn.reconnect() as conn:
        df = conn.read_to_pandas(query)

    return df.set_index("name").to_dict()["id"]