nspek_controls module

class NspekControls(time_units=None, applies_to_subset=None)

Bases: ControlFrameworkBase

Control framework som bruker nspek_core-tabellene som datakilde

get_current_kontroller()

Leser kontroll-definisjoner fra database.

Return type:

DataFrame

Returns:

DataFrame med kontrollmetadata

get_current_kontrollutslag(aar=None, sekvensnummer=None, specific_control=None)

Leser kontrollutslag fra database.

Parameters:
  • aar (int | None) – filtrer på årgang (valgfritt)

  • sekvensnummer (int | None) – filtrer på sekvensnummer (valgfritt)

  • specific_control (str | None) – filtrer på kontrollid (valgfritt)

Return type:

DataFrame

Returns:

DataFrame med utslag

insert_new_records(control_results)

Inserts new records that are not found in the current contents of the ‘kontrollutslag’ table.

run_all_controls()

Runs all controls found in the class.

Return type:

dict[str, DataFrame]

run_control(kontrollid)

Runs a single control.

Parameters:
  • control – Name of a control method to run implemented in the supplied control class built upon ControlFrameworkBase.

  • kontrollid (str)

Returns:

Dataframe containing results from the control.

Return type:

DataFrame

Raises:
  • TypeError – If the control method does not return a pd.DataFrame.

  • ValueError – If a required column from _required_kontrollutslag_columns is missing. Or if the result contains extra columns that are not allowed. Or if the control is not registered in self.controls. Or if any key in applies_to_subset has too many unique values. Or if any value in applies_to_subset does not match the expected period. Or if the results contain more than one unique kontrollid. Or if the kontrollid in the results does not match the registered _control_meta. Or if there are duplicated rows in the results based on time_units, ident, and refnr.

update_existing_records(control_results)

Updates the ‘kontrollutslag’ table based on results from new run of the method.