ssb_sirius_dash.modals package¶
ssb_sirius_dash.modals.control module¶
- class Control(ident, qualityreport_path)¶
Bases:
object
Provides a layout and functionality for a modal that offers an overview of data checks and control results.
- Parameters:
ident (str)
qualityreport_path (str)
- ident¶
Name of the identification variable, e.g., ‘orgf’.
- Type:
str
- control_documentation_path¶
Path to the saved quality report in JSON format on Dapla.
- Type:
str
- callbacks()¶
Sets up interactivity for the control modal, including linking table clicks and navigation back to the main view.
- Return type:
None
- layout()¶
Generates the layout for the control modal.
- Returns:
Layout containing the control modal and interactive components.
- Return type:
dash.html.Div
ssb_sirius_dash.modals.hb_method module¶
- class HBMethod(database, hb_get_data_func, selected_state_keys, selected_ident, variable)¶
Bases:
object
Module for detecting outliers using the Hidiroglou-Berthelot (HB) method in a Dash application.
This module applies the HB method to identify potential outliers in time-series data by comparing values in the current period (t) with revised values from the previous period (t-1). It includes methods for preprocessing data, visualizing results, and managing interactions in a Dash app.
- Parameters:
database (object)
hb_get_data_func (Callable[[...], DataFrame])
selected_state_keys (list[str])
selected_ident (str)
variable (str)
- database¶
Database connection or interface for fetching data.
- Type:
object
- hb_get_data¶
Function for retrieving data based on selected parameters.
- Type:
callable
References
More information about the HB method: https://rdrr.io/github/statisticsnorway/Kostra/man/Hb.html
- callbacks(selected_state_keys, selected_ident, variable)¶
Registers callbacks for the HB method Dash app components.
- Parameters:
selected_state_keys (list of str) – List of state keys for dynamic state configuration.
selected_ident (str) – Identifier used for grouping or filtering data.
variable (str) – Name of the value variable for HB method analysis.
- Return type:
None
Notes
This method registers Dash callbacks for handling user interactions, including running the HB method, toggling the modal, and passing results to variabelvelger.
- layout()¶
Generates the layout for the HB method Dash component.
- Returns:
Div containing the modal and interactive elements for the HB method.
- Return type:
dash.html.Div
- make_hb_data(data_df, pc, pu, pa, ident, variable)¶
Processes data using the HB method for outlier detection.
- Parameters:
data_df (pandas.DataFrame) – Input data containing variables for analysis.
pc (int) – Confidence interval control parameter.
pu (float) – Parameter for adjusting the variable’s level.
pa (float) – Parameter for small differences between quartiles and the median.
ident (str) – Identifier field name in the dataset.
variable (str) – Name of the value variable for analysis.
- Returns:
Processed data with outlier results, sorted by “maxX”.
- Return type:
pandas.DataFrame
- make_hb_figure(data, variable)¶
Creates a Plotly figure for visualizing HB method results.
- Parameters:
data (pandas.DataFrame) – Processed data from the HB method, including outlier and limit values.
variable (str) – Name of the value variable for the method.
- Returns:
Plotly figure with scatter plots for observations and limits.
- Return type:
plotly.graph_objects.Figure
ssb_sirius_dash.modals.quality_indicators module¶
- class QualityIndicator(indicators)¶
Bases:
object
A module for setting up the view for selected quality indicators.
- Parameters:
indicators (list[Any])
- indicators¶
A list of quality indicators. Example: [QualityIndicatorEditeringsandel(), QualityIndicatorEffektaveditering()]
- Type:
list
Notes
All indicators assume a long format for the data with a minimum of ident, variabel, and verdi as columns.
- callbacks()¶
Registers callbacks to enable the modal to be opened and closed.
- Return type:
None
- layout()¶
Creates the layout for the quality indicator modal.
- Returns:
A Dash HTML Div element containing the modal and the sidebar button.
- Return type:
html.Div
- class QualityIndicatorEditeringsandel(get_current_data_func, get_change_data_func, var_name, ident_var, grouping_vars=None, key_vars=None)¶
Bases:
object
Quality indicator for editing ratio.
- Parameters:
get_current_data_func (Callable[[...], DataFrame])
get_change_data_func (Callable[[...], DataFrame])
var_name (str)
ident_var (str)
grouping_vars (list[str] | None)
key_vars (list[str] | None)
- get_current_data_func¶
Function to retrieve current data.
- Type:
Callable
- get_change_data_func¶
Function to retrieve rows with changes.
- Type:
Callable
- periode¶
Current period for the data.
- var_name¶
The name of the column in the dataset indicating the variable.
- Type:
str
- ident_var¶
Name of the identification variable. For example, “orgf”.
- Type:
str
- grouping_vars¶
Variables by which the dataset can be grouped, such as “nace” or “kommune”.
- Type:
list[str]
- key_vars¶
Key variables relevant to the quality indicator.
- Type:
list[str]
- callbacks()¶
Sets up callbacks for opening the detail view and selecting grouping for details.
- Return type:
None
- editeringsandel()¶
Calculates the editing ratio.
- Returns:
The editing ratio as a percentage.
- Return type:
float
- editeringsandel_details(group)¶
Calculates the editing ratio for different subsets of the dataset.
- Parameters:
group (list[str] | str) – Variable(s) by which to group the dataset.
- Returns:
A DataFrame with editing ratios for each subset.
- Return type:
pd.DataFrame
- class QualityIndicatorEffektaveditering(get_current_data_func, get_original_data_func, periode, ident_var, key_vars, grouping_vars)¶
Bases:
object
Indicator to display the effect of editing.
- Parameters:
get_current_data_func (Callable[[...], DataFrame])
get_original_data_func (Callable[[...], DataFrame])
periode (str | int)
ident_var (str)
key_vars (list[str])
grouping_vars (str | list[str])
- get_current_data_func¶
Function to fetch the current updated data.
- Type:
Callable
- get_original_data_func¶
Function to fetch the original received data.
- Type:
Callable
- periode¶
The period for the data.
- Type:
str | int
- ident_var¶
Name of the identification variable, e.g., “orgf”.
- Type:
str
- key_vars¶
List of key variables relevant to the indicator.
- Type:
list[str]
- grouping_vars¶
List of grouping variables for stratification.
- Type:
list[str]
- callbacks()¶
Sets up callbacks for opening and closing the detailed view.
- Return type:
None
- get_comparison_data(periode, grouping=None)¶
Calculates the effect of editing using the provided functions.
- Parameters:
periode (str | int) – The period for the data.
grouping (list[str] | None) – Variables for grouping. Defaults to None.
- Returns:
A DataFrame containing the calculated effect of editing.
- Return type:
pd.DataFrame
- class QualityIndicatorKontrollutslagsandel(control_documentation=None, qualityreport_path=None)¶
Bases:
object
Indicator for displaying the percentage of possible control outcomes that trigger a flag.
The control documentation must be a dataset with the following columns: kontroll_id, Enheter kontrollert, Kontrollutslag.
- Parameters:
control_documentation (QualityReport | None)
qualityreport_path (str | None)
- control_documentation¶
The quality report used for calculations.
- Type:
QualityReport | None
- qualityreport_path¶
File path to a saved quality report in JSON format on Dapla.
- Type:
str | None
- callbacks()¶
Sets up callbacks for opening and closing the detailed view.
- Return type:
None
- kontrollutslag()¶
Calculates the proportion of control outcomes that trigger a flag.
- Returns:
The total proportion of control outcomes as a float.
A DataFrame with detailed proportions for each control.
- Return type:
tuple[float, pd.DataFrame]
- class QualityIndicatorTreffsikkerhet(get_edits_list_func, quality_report=None, qualityreport_path=None)¶
Bases:
object
Indicator to display the accuracy of the controls being run.
- Parameters:
get_edits_list_func (Callable[[...], list[tuple[str, str]]])
quality_report (QualityReport | None)
qualityreport_path (str | None)
- get_edits_list_func¶
Function that retrieves a list of changes made to the data. It returns a list of tuples describing the fields changed. Used to check against control outcomes to determine if a control outcome likely resulted in an edit. Example: [(orgnr_1, variabel_1), (orgnr_1, variabel_2), (orgnr_2, variabel_1)].
- Type:
Callable
- quality_report¶
The quality report used for calculations.
- Type:
QualityReport | None
- qualityreport_path¶
File path to a saved quality report in JSON format on Dapla.
- Type:
str | None
- beregn_treffsikkerhet()¶
Calculates the accuracy indicator based on the quality report.
- Returns:
- A dictionary where keys are control names and values are the accuracy percentage.
Includes a “total” key for overall accuracy.
- Return type:
dict
- callbacks()¶
Sets up callbacks for opening and closing the detailed view.
- Return type:
None
ssb_sirius_dash.modals.visualizationbuilder module¶
- class VisualizationBuilder(database)¶
Bases:
object
A module for creating and visualizing data queries and graphs interactively.
- Parameters:
database (object)
- database¶
The database connection or interface for executing queries.
- Type:
object
- callbacks()¶
Registers Dash callbacks for the Visualiseringsbygger module.
- Return type:
None
Notes
sqlmodal_toggle: Toggles the visibility of the query modal.
sql_query: Executes the SQL query and updates the table and dropdown options.
update_graph: Generates graphs based on selected columns and graph type.
- layout()¶
Generates the layout for the Visualiseringsbygger module.
- Returns:
A Div element containing components for querying data and visualizing graphs.
- Return type:
html.Div