Skip to content

KPI Resource Types

KpiResourceTypes(perfdb)

Class used for handling resource types (wind speed, solar irradiance, etc).

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 the possible resource types.

The most useful keys/columns returned are:

  • id
  • bazefield_point

Parameters:

  • output_type

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

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

Returns:

  • DataFrame

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

  • dict[str, dict[str, str]]

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

Source code in echo_postgres/kpi_resource_types.py
@validate_call
def get(
    self,
    output_type: Literal["dict", "DataFrame"] = "dict",
) -> DataFrame | dict[str, dict[str, str]]:
    """Gets the possible resource types.

    The most useful keys/columns returned are:

    - id
    - bazefield_point

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

    Returns
    -------
    DataFrame
        In case output_type is "DataFrame", returns a DataFrame with the following format: index = name, columns = [description, id]
    dict[str, dict[str, str]]
        In case output_type is "dict", returns a dictionary in the format {name: {attribute: value, ...}, ...}
    """
    # validate the input
    if output_type not in ["dict", "DataFrame"]:
        raise ValueError(f"output_type must be one of ['dict', 'DataFrame'], got {output_type}")

    # build the query
    query = sql.SQL("SELECT * FROM performance.resource_types")

    with self._perfdb.conn.reconnect() as conn:
        df = conn.read_to_pandas(query, post_convert="pyarrow")

    df = df.set_index("name")

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

get_ids()

Gets the possible resource types.

Returns:

  • dict[str, int]

    A dictionary in the format {name: id, ...}

Source code in echo_postgres/kpi_resource_types.py
def get_ids(self) -> dict[str, int]:
    """Gets the possible resource types.

    Returns
    -------
    dict[str, int]
        A dictionary in the format {name: id, ...}
    """
    query = sql.SQL("SELECT name, id FROM performance.resource_types")

    with self._perfdb.conn.reconnect() as conn:
        data = conn.read_to_pandas(query, post_convert="pyarrow")

    data = data.set_index("name")

    return data["id"].to_dict()