Resource Assessments Losses Types¶
ResourceAssessmentLossesTypes(perfdb)
¶
Class used for handling resource assessment losses types. Can be accessed via perfdb.resourceassessments.losses.types.
Parameters:
Source code in echo_postgres/perfdb_root.py
Python
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 entries with detailed information.
Parameters:
-
(output_type¶Literal['dict', 'DataFrame', 'pl.DataFrame'], default:'dict') –Output type of the data. Can be one of ["dict", "DataFrame", "pl.DataFrame"] By default "dict"
Returns:
-
dict[str, dict[str, Any]]–In case output_type is "dict", returns a dictionary in the format {name: {attribute: value, ...}, ...}
-
DataFrame–In case output_type is "DataFrame", returns a pandas DataFrame with index = name.
-
DataFrame–In case output_type is "pl.DataFrame", returns a Polars DataFrame
Source code in echo_postgres/base_lookup.py
Python
@validate_call
def get(
self,
output_type: Literal["dict", "DataFrame", "pl.DataFrame"] = "dict",
) -> dict[str, dict[str, Any]] | pd.DataFrame | pl.DataFrame:
"""Gets all entries with detailed information.
Parameters
----------
output_type : Literal["dict", "DataFrame", "pl.DataFrame"], optional
Output type of the data. Can be one of ["dict", "DataFrame", "pl.DataFrame"]
By default "dict"
Returns
-------
dict[str, dict[str, Any]]
In case output_type is "dict", returns a dictionary in the format {name: {attribute: value, ...}, ...}
pd.DataFrame
In case output_type is "DataFrame", returns a pandas DataFrame with index = name.
pl.DataFrame
In case output_type is "pl.DataFrame", returns a Polars DataFrame
"""
query = sql.SQL("SELECT * FROM {schema}.{table} ORDER BY {index_col}").format(
schema=sql.Identifier(self._schema_name),
table=sql.Identifier(self._table_name),
index_col=sql.Identifier(self._index_col),
)
df = self._perfdb.conn.read_to_polars(query, schema_overrides=self._cols_schema)
return convert_output(df, output_type, index_col=self._index_col)
get_ids()
¶
Gets all entries and their respective ids.
Returns:
-
dict[str, int]–Dictionary in the format {name: id, ...}.
Source code in echo_postgres/base_lookup.py
Python
def get_ids(self) -> dict[str, int]:
"""Gets all entries and their respective ids.
Returns
-------
dict[str, int]
Dictionary in the format {name: id, ...}.
"""
query = sql.SQL("SELECT {index_col}, {id_col} FROM {schema}.{table} ORDER BY {index_col}").format(
index_col=sql.Identifier(self._index_col),
id_col=sql.Identifier(self._id_col),
schema=sql.Identifier(self._schema_name),
table=sql.Identifier(self._table_name),
)
df = self._perfdb.conn.read_to_polars(query)
return dict(zip(df[self._index_col].to_list(), df[self._id_col].to_list(), strict=False))