ssb_sirius_dash.control package¶
ssb_sirius_dash.control.framework module¶
- class ControlType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
Enum
Enum class representing the types of quality control checks.
- ABSOLUTT_FEIL = 3¶
- AUTOMATISK_OPPRETTING = 0¶
- MISSING = 1¶
- MULIG_FEIL = 2¶
- class ErrorReport(sub_control_id, result_type, context_id, error_description=None, important_variables=None)¶
Bases:
object
A class to detail errors found during quality control checks.
- Parameters:
sub_control_id (str)
result_type (ControlType)
context_id (str)
error_description (str | None)
important_variables (list[str] | None)
- sub_control_id¶
Identifier for the sub control check.
- Type:
str
- result_type¶
The result type of the quality control check.
- Type:
- context_id¶
Identifier for the context within which the error was detected.
- Type:
str
- error_description¶
A description of the error, if applicable.
- Type:
str, optional
- important_variables¶
A list of important variables related to the error.
- Type:
list[str], optional
- to_dict()¶
Converts the quality control result into a dictionary format.
- Returns:
A dictionary representing the quality control result.
- Return type:
dict
- class QualityReport(statistics_name, quality_control_id, data_location, data_period, quality_control_datetime, quality_control_results, quality_control_errors, quality_control_documentation=None)¶
Bases:
object
A class representing the result of a quality control check.
- Parameters:
statistics_name (str)
quality_control_id (str)
data_location (list[str])
data_period (str)
quality_control_datetime (datetime)
quality_control_results (list[ControlType])
quality_control_errors (list[ErrorReport])
quality_control_documentation (dict[str, str] | None)
- statistics_name¶
The name of the statistics being checked.
- Type:
str
- quality_control_id¶
The unique identifier for the quality control.
- Type:
str
- data_location¶
Locations of the data checked.
- Type:
list[str]
- data_period¶
The period for which the data was checked.
- Type:
str
- quality_control_datetime¶
The datetime when the quality control was performed.
- Type:
datetime.datetime
- quality_control_results¶
The results of the quality control.
- Type:
list[ControlType]
- quality_control_errors¶
Detailed errors found during the quality control.
- Type:
list[ErrorReport]
- quality_control_documentation¶
Documentation of the quality control process.
- Type:
dict[str, str], optional
- classmethod from_dict(kvalitetsrapport_dict)¶
Initialize a QualityReport from a dictionary.
- Parameters:
kvalitetsrapport_dict (dict[str, Any]) – A dictionary representing the quality control report.
- Returns:
An instance of the quality control report.
- Return type:
- classmethod from_json(path)¶
Initialize a QualityReport from a saved JSON file.
- Parameters:
path (str) – Path to the JSON file.
- Returns:
An instance of the quality control report.
- Return type:
- save_report(path)¶
Save the quality control report to the specified path.
- Parameters:
path (str) – The file path where the report will be saved.
- Return type:
None
- to_dict()¶
Converts the quality control report into a dictionary format.
- Returns:
A dictionary representing the quality control report.
- Return type:
dict
- control(result_type, error_description, id_column, filter_for_relevant_data=None, important_variables=None)¶
Decorator to define a quality control function.
- Parameters:
result_type (ControlType) – The type of quality control being performed.
error_description (str) – Description of the error being checked for.
id_column (str) – The column used to uniquely identify rows in the dataset.
filter_for_relevant_data (Callable, optional) – A function to filter relevant rows from the dataset.
important_variables (list[str], optional) – List of variables deemed important for the control check.
- Returns:
A decorated function that processes the dataset and logs errors.
- Return type:
Callable
Notes
Assumes all data given to the function is data that should be checked.
- create_control_documentation(quality_report)¶
Create control documentation.
- Parameters:
quality_report (QualityReport | dict) – The quality control report or its dictionary representation.
- Returns:
A DataFrame containing control documentation.
- Return type:
pd.DataFrame
- create_quality_report(statistics_name, data_location, data_period, also_return_control_docs=False)¶
Create a quality control report.
- Parameters:
statistics_name (str) – The name of the statistics being checked.
data_location (str) – The location of the data being checked.
data_period (str) – The period for which the data is being checked.
also_return_control_docs (bool) – Whether to return control documentation as part of the result.
- Returns:
The quality control report or a tuple containing the report and control documentation.
- Return type:
QualityReport | tuple[QualityReport, pd.DataFrame]
- Raises:
AssertionError – If statistics_name, data_location, or data_period is not provided.
- eimerdb_template(control_documentation)¶
Create a template for the EimerDB control table.
- Parameters:
control_documentation (pd.DataFrame) – The control documentation as a DataFrame.
- Returns:
A list of lists representing the template for the control table.
- Return type:
list[list[Any]]
Notes
Each entry in the resulting list represents a control, including its period, ID, type, and description.