datahelper module¶
These classes can be used to create a functioning database instance for your Altinn3 statistic.
It is intended to be a shortcut for quickly getting an editing application up and running, and serve as an example for those making their own setup.
If you’d rather make your own setup, you are free to do so.
It also contains a utility to fill your database with demo-data.
- class Base(**kwargs)¶
Bases:
DeclarativeBaseSets up the Base class for the SQLAlchemy ORM.
- Parameters:
kwargs (Any)
- metadata: ClassVar[MetaData] = MetaData()¶
Refers to the
_schema.MetaDatacollection that will be used for new_schema.Tableobjects.See also
orm_declarative_metadata
- registry: ClassVar[registry] = <sqlalchemy.orm.decl_api.registry object>¶
Refers to the
_orm.registryin use where new_orm.Mapperobjects will be associated.
- class Datatyper(**kwargs)¶
Bases:
BaseSQLAlchemy ORM model for the ‘datatyper’ table.
- aar¶
- datatype¶
- radnr¶
- tabell¶
- variabel¶
- class DemoDataCreator(engine)¶
Bases:
objectClass for creating demo data to test the editing framework.
Assumes your database is set up according to the template with only ‘aar’ as period columns.
- Parameters:
engine (Engine)
- build_demo_database()¶
Builds the demo database by inserting data into each table in order using the engine connection.
- Return type:
None
- get_data()¶
Gathers open data to be used for creating the demo database.
- Return type:
None
- get_enheter()¶
Builds the content for the ‘enheter’ table.
- Return type:
None
- get_enhetsinfo()¶
Builds the content for the ‘enhetsinfo’ table.
- Return type:
None
- get_kontaktinfo()¶
Builds the content for the ‘kontaktinfo’ table.
- Return type:
None
- get_skjemadata_hoved()¶
Builds the content for the ‘skjemadata_hoved’ table.
- Return type:
None
- get_skjemamottak()¶
Builds the content for the ‘skjemamottak’ table.
- Return type:
None
- insert_to_db(table_name, dataframe)¶
Uses self.engine to insert data.
- Return type:
None- Parameters:
table_name (str)
dataframe (DataFrame)
- random_date()¶
Assigns a random date.
- Return type:
str
- class Enheter(**kwargs)¶
Bases:
BaseSQLAlchemy ORM model for the ‘enheter’ table.
- aar¶
- ident¶
- skjema¶
- class Enhetsinfo(**kwargs)¶
Bases:
BaseSQLAlchemy ORM model for the ‘enhetsinfo’ table.
- aar¶
- ident¶
- variabel¶
- verdi¶
- class Kontaktinfo(**kwargs)¶
Bases:
BaseSQLAlchemy ORM model for the ‘kontaktinfo’ table.
- aar¶
- bekreftet_kontaktinfo¶
- epost¶
- ident¶
- kommentar_kontaktinfo¶
- kommentar_krevende¶
- kontaktperson¶
- refnr¶
- skjema¶
- telefon¶
- class Kontroller(**kwargs)¶
Bases:
BaseSQLAlchemy ORM model for the ‘kontroller’ table.
- aar¶
- beskrivelse¶
- kontrollid¶
- kontrolltype¶
- kontrollvarsiabel¶
- skjema¶
- sorteringsvariabel¶
- class Kontrollutslag(**kwargs)¶
Bases:
BaseSQLAlchemy ORM model for the ‘kontrollutslag’ table.
- aar¶
- ident¶
- kontrollid¶
- refnr¶
- skjema¶
- utslag¶
- verdi¶
- class Skjemadata_hoved(**kwargs)¶
Bases:
BaseSQLAlchemy ORM model for the ‘skjemadata_hoved’ table.
- aar¶
- ident¶
- refnr¶
- skjema¶
- variabel¶
- verdi¶
- class Skjemamottak(**kwargs)¶
Bases:
BaseSQLAlchemy ORM model for the ‘skjemamottak’ table.
- aar¶
- aktiv¶
- dato_mottatt¶
- editert¶
- ident¶
- kommentar¶
- refnr¶
- skjema¶
- create_database(engine)¶
Uses engine to create the database.
This is only a simple wrapper to make it easier to run ‘Base.metadata.create_all(engine)’
- Parameters:
engine (
Engine) – An SQLAlchemy Engine to be used for creating the database.- Return type:
None
- create_database_engine(database_type, *args, **kwargs)¶
Wrapper for creating an sqlalchemy engine.
For sqlite requires the argument ‘sqlite_path’ to complete the path after ‘sqlite:///’
- Return type:
Engine- Parameters:
database_type (str)
args (Any)
kwargs (Any)
- For postgres requires the environment variables:
DB_USER
DB_PASSWORD
DB_HOST
DB_PORT
DB_NAME
- period_columns()¶
Generate Column definitions for period dimensions based on the value of ‘PERIOD_COUMNS’.
- Return type:
dict[str,Column[Any]]