Root Causes¶
RootCauses(perfdb)
¶
Class used for handling RootCauses. Can be accessed via perfdb.rootcauses.
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 all root causes with detailed information.
The most useful keys/columns returned are:
- id
- 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/rootcauses.py
@validate_call
def get(self, output_type: Literal["dict", "DataFrame"] = "dict") -> dict[str, dict[str, str | int]] | DataFrame:
"""Gets all root causes with detailed information.
The most useful keys/columns returned are:
- id
- 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.root_causes 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 root causes and their respective ids.
Returns:
-
dict[str, int]–Dictionary with all root causes and their respective ids in the format {data_type: id, ...}.
Source code in echo_postgres/rootcauses.py
def get_ids(self) -> dict[str, int]:
"""Gets all root causes and their respective ids.
Returns
-------
dict[str, int]
Dictionary with all root causes and their respective ids in the format {data_type: id, ...}.
"""
query = sql.SQL("SELECT name, id FROM performance.root_causes ORDER BY name")
with self._perfdb.conn.reconnect() as conn:
df = conn.read_to_pandas(query)
return df.set_index("name").to_dict()["id"]