Service Order Status¶
ServiceOrderStatus(perfdb)
¶
Class used for handling Service Order Status data. Can be accessed via perfdb.service_orders.status.
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(names=None, sap_names=None, filter_type='and', output_type='dict')
¶
Retrieves Service Order information from the database.
The most useful keys/columns returned are:
- id
- name (index if output_type is DataFrame)
- display_name
- sap_name
Parameters:
-
(names¶list[str] | None, default:None) –List of names to retrieve information for.
If None, retrieves information for all available.
-
(sap_names¶list[str] | None, default:None) –List of SAP names to retrieve information for.
If None, retrieves information for all available.
-
(filter_type¶Literal['and', 'or'], default:'and') –How to treat multiple filters. Can be one of ["and", "or"]. By default "and".
-
(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 DataFrame with the following format: index = name, columns = [attribute, ...]
-
DataFrame–In case output_type is "pl.DataFrame", returns a Polars DataFrame
Source code in echo_postgres/service_order_status.py
@validate_call
def get(
self,
names: list[str] | None = None,
sap_names: list[str] | None = None,
filter_type: Literal["and", "or"] = "and",
output_type: Literal["dict", "DataFrame", "pl.DataFrame"] = "dict",
) -> dict[str, dict[str, Any]] | pd.DataFrame | pl.DataFrame:
"""Retrieves Service Order information from the database.
The most useful keys/columns returned are:
- id
- name (index if output_type is DataFrame)
- display_name
- sap_name
Parameters
----------
names : list[str] | None, optional
List of names to retrieve information for.
If None, retrieves information for all available.
sap_names : list[str] | None, optional
List of SAP names to retrieve information for.
If None, retrieves information for all available.
filter_type : Literal["and", "or"], optional
How to treat multiple filters. Can be one of ["and", "or"]. By default "and".
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, ...}, ...}
DataFrame
In case output_type is "DataFrame", returns a DataFrame with the following format: index = name, columns = [attribute, ...]
pl.DataFrame
In case output_type is "pl.DataFrame", returns a Polars DataFrame
"""
where_query = self._check_get_args(
names=names,
sap_names=sap_names,
filter_type=filter_type,
)
query = sql.SQL(
"SELECT * FROM performance.service_order_status {where_query} ORDER BY name",
).format(
where_query=where_query,
)
with self._perfdb.conn.reconnect() as conn:
df = conn.read_to_polars(query)
if output_type == "pl.DataFrame":
return df
df = df.to_pandas(use_pyarrow_extension_array=True)
df = df.set_index("name")
if output_type == "DataFrame":
return df
return df.to_dict(orient="index")
get_ids(names=None, sap_names=None, filter_type='and')
¶
Retrieves service order ids from the database.
Parameters:
-
(names¶list[str] | None, default:None) –List of names to retrieve information for.
If None, retrieves information for all available.
-
(sap_names¶list[str] | None, default:None) –List of SAP names to retrieve information for.
If None, retrieves information for all available.
-
(filter_type¶Literal['and', 'or'], default:'and') –How to treat multiple filters. Can be one of ["and", "or"]. By default "and".
Returns:
-
dict[str, int]–A dictionary in the format {name: id, ...}
Source code in echo_postgres/service_order_status.py
@validate_call
def get_ids(
self,
names: list[str] | None = None,
sap_names: list[str] | None = None,
filter_type: Literal["and", "or"] = "and",
) -> dict[str, int]:
"""Retrieves service order ids from the database.
Parameters
----------
names : list[str] | None, optional
List of names to retrieve information for.
If None, retrieves information for all available.
sap_names : list[str] | None, optional
List of SAP names to retrieve information for.
If None, retrieves information for all available.
filter_type : Literal["and", "or"], optional
How to treat multiple filters. Can be one of ["and", "or"]. By default "and".
Returns
-------
dict[str, int]
A dictionary in the format {name: id, ...}
"""
where_query = self._check_get_args(
names=names,
sap_names=sap_names,
filter_type=filter_type,
)
query = sql.SQL(
"SELECT name, id FROM performance.service_order_status {where_query} ORDER BY name",
).format(
where_query=where_query,
)
with self._perfdb.conn.reconnect() as conn:
df = conn.read_to_polars(query)
return dict(zip(df["name"].to_list(), df["id"].to_list(), strict=False))