DataTableProfileManager

class profiles.datatableprofilemanager.DataTableProfileManager(data_table_profile: DataTableProfile | None = None, source_profile=None)

DataTableProfileManager: manages profile data that can be loaded from and saved to Postgres or InfluxDB. DataTableProfileManager is a subclass of ProfileManager, so it also provides functionality to convert from/to different ESDL profiles and to load/save to CSV

metadata: List[DataTableMetaData | None]
data_table_profile: DataTableProfile
set_data_table_profile(data_table_profile: DataTableProfile)
static close_db_connections() None

Closes all database connections in the cache. Should be called when the application is shutting down to properly close resources.

load_from_database(configuration: DatabaseConfiguration | None = None, close_connection_after_load: bool = True)

Loads profile data from a database configuration into profile_header and profile_data_list.

Parameters:
  • configuration – the database configuration, optional, otherwise the one provided in the constructor is used

  • close_connection_after_load – if True (default), close DB connection after loading data. If False, callers must close connections manually via close_db_connections().

Returns:

None

get_profile_with_multiplier(column_based: bool = False) List[List[float]]

Return the loaded profile data with the configured multiplier applied to a column or all columns (if columnName is not set). The datetime column is returned unchanged as the first column.

Parameters:

column_based – If True, return data grouped by column instead of row. If False, return row-based data.

Returns:

A list of columns, where the first column is the datetime values and subsequent columns are scaled numeric data columns.

Raises:

NoProfileLoadedExecption – If no profile data has been loaded.

static load(data_table_profile: DataTableProfile) DataTableProfileManager

Static method to create an instance of DataTableProfileManager using an esdl.DataTableProfile. The data referenced to in the profile is loaded from the associated DataConfiguration (e.g. DatabaseConfiguration or FileConfiguration)

Parameters:

data_table_profile – esdl.DataTableProfile that is used as an input profile

Note: - for FileConfigurations: uri without extension is used as tableName for CSV files if no tableName is given

static query(data_table_profile: DataTableProfile, table_name: str, column_name: str, schema: str | None = None, datetime_column_name: str | None = None, start_date: datetime | None = None, end_date: datetime | None = None, additional_filters: Dict[str, Any] | None = None, multiplier: float | None = None, downsample_bucket_sec: int | None = None, column_based: bool = False) Tuple[List[List[float]], List[str], List[QuantityAndUnitType]]

Query and return data from a database using the associated DatabaseConfiguration. This method acts as the high-level API for retrieving profile data, applying optional filtering, scaling, and downsampling.

Data is NOT stored inside this class, but passed directly to the caller.

Parameters:
  • data_table_profile – The esdl.DataTableProfile describing the data source and default query parameters.

  • table_name – Name of the database table to query.

  • column_name – Name of the single value column to retrieve.

  • schema – Optional schema name. If None, the default schema is used.

  • datetime_column_name – Optional override for the datetime column name. If None, the profile’s datetime column is used.

  • start_date – Optional start datetime for filtering.

  • end_date – Optional end datetime for filtering.

  • additional_filters – Optional (key, value) set of additional filters applied in the SQL WHERE clause.

  • multiplier – Optional scaling factor applied to the value column. If None, the profile’s default multiplier is used.

  • downsample_bucket_sec – Optional bucket size (in seconds) for time-based downsampling using AVG().

  • column_based – If True, results are returned column-based instead of row-based.

Returns:

Tuple with: List of data (column-based if configured), header names, QuantityAndUnit if available for each header

get_data_table_profile(profile_name: str | None = None, table_name: str | None = None, schema_name: str | None = None) DataTableProfile | list[DataTableProfile]

Creates an esdl.DataTableProfile instance that refers to the data loaded in this ProfileManager

Parameters:
  • profile_name – name of the profile (one of the columns retrieved from the database), if None all will be returned

  • table_name – name of the table, if None the value of self.data_table_profile.tableName will be used

  • schema_name – name of the schema, if required. Defaults to None

save(drop=True)

Saves the current datatable profile to the database

Parameters:

drop – Drop data in the referenced table before writing data (default=True)

exception profiles.datatableprofilemanager.NoDataException

Thrown when no profile data can be written to Postgres

exception profiles.datatableprofilemanager.WrongFilterFormatException

Thrown when filter specification in ESDL profile cannot be parsed

exception profiles.datatableprofilemanager.InvalidDataConfiguration

Thrown when there is no or invalid DataConfiguration

exception profiles.datatableprofilemanager.InfluxDBProfileLoadError

Thrown when failing to load profile from InfluxDB.

exception profiles.datatableprofilemanager.UnsupportedDataConfiguration

Thrown when this DataConfiguration is not supported