KPI Energy Losses - Types¶
For more details on energy losses data and waterfall calculation see this dedicated page in the reference section.
KpiEnergyLossesTypes(perfdb)
¶
Class used for handling energy losses types (where energy is measured).
Parameters:
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 energy losses types.
The main attributes are: - name - display_name - description - loss_order - source - bazefield_point - resource_assessment_loss_type_id - resource_assessment_loss_type_name - target_source - considered_in_waterfall - waterfall_group - applicable_to
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_energy_losses_types.py
@validate_call
def get(
self,
output_type: Literal["dict", "DataFrame"] = "dict",
) -> DataFrame | dict[str, dict[str, str]]:
"""Gets the possible energy losses types.
The main attributes are:
- name
- display_name
- description
- loss_order
- source
- bazefield_point
- resource_assessment_loss_type_id
- resource_assessment_loss_type_name
- target_source
- considered_in_waterfall
- waterfall_group
- applicable_to
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.v_energyloss_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 energy losses types.
Returns:
-
dict[str, int]–A dictionary in the format {name: id, ...}
Source code in echo_postgres/kpi_energy_losses_types.py
def get_ids(self) -> dict[str, int]:
"""Gets the possible energy losses types.
Returns
-------
dict[str, int]
A dictionary in the format {name: id, ...}
"""
query = sql.SQL("SELECT name, id FROM performance.v_energyloss_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()