repository¶
common¶
- class EntityDataProcessor(session: AsyncSession, all_data: SQLAlchemyRepository, selector: EntityDataSelector)¶
Bases:
objectLogic for storing and retrieving entity data from the database. This can be used for both Dataset data and Update data
- async get(id: UUID) Dict[str, Dict[str, UniformAttributeData | CSRAttributeData]]¶
- async store(id: UUID, data: Dict[str, Dict[str, UniformAttributeData | CSRAttributeData]])¶
- Parameters:
id – dataset UUID
data – dataset data section in numpy format
- class EntityDataSelector(*args, **kwargs)¶
Bases:
ProtocolEntityDataSelector is a Protocol that EntityDataProcessor uses to retrieve SQLAlchemy queries for the resource it is operating on, ie Dataset or Update.
- insert_linked_attribute(id: UUID, attribute_id: UUID) sqlalchemy.Insert¶
- select_linked_attribute(id: UUID) sqlalchemy.Select.tuple[movici_data_core.database.model.Attribute]¶
- class GenericResourceRepository(session: AsyncSession, options: Options, all_data: SQLAlchemyRepository)¶
Bases:
SQLResourceRepository,Generic[T_dom]A GenericResourceRepository is the simplest CRUD repository. Resources are globally unique by name and do not have a parent (such as a Workspace). Resources that are managed through a GenericResourceRepository are:
Workspaces
DatasetTypes
EntityTypes
AttributeTypes
ModelTypes
To implement a GenericResourceRepository, subclass it and set the
__resource__and__resource_type_name__class fields. Then, implement thecreateandupdatemethods it is recommended to wrap theupdatemethod in an@ensure_valid_iddecorator- async create(obj: T_dom) UUID¶
- async delete(id: UUID)¶
- async exists(name: str) bool¶
- async get_by_id(id: UUID) T_dom | None¶
- async get_by_name(name: str) T_dom | None¶
- async list() list[T_dom]¶
- async update(id: UUID, obj: T_dom) None¶
- class RawDataProcessor(session: sqlalchemy.ext.asyncio.AsyncSession)¶
Bases:
objectLogic for storing dataset data as raw bytes in the database. Used for
BINARYandUNSTRUCTUREDdatasets- RAW_DATA_CHUNK_SIZE = 100000000¶
- async get_dict(id: UUID) dict¶
- class SQLResourceRepository(session: AsyncSession, options: Options, all_data: SQLAlchemyRepository)¶
Bases:
objectBase class for the various resource repositories
- all_data: SQLAlchemyRepository¶
- session: AsyncSession¶
- ensure_valid_id(method)¶
Decorator to ensure that a resource id exists, raises ResourceDoesNotExist if a non-existing id is given :param method: a method from a GenericResourceRepository that takes in
idas its first argument
dataset¶
- class DatasetDataRepository(session: AsyncSession, options: Options, all_data: SQLAlchemyRepository)¶
Bases:
SQLResourceRepository- async create(id: UUID, data: dict | bytes | BinaryIO | Path, format: DatasetFormat, chunk_size=0)¶
Store dataset data for a dataset. The dataset must currently not contain any data
- Parameters:
id – A dataset id
data – The dataset data as dict, bytes, BytesIO or pathlib.Path
format – The dataset’s
DatasetFormatchunk_size – The maximum chunk size in bytes to store data. By default set to the value of DatasetRepository.RAW_DATA_CHUNK_SIZE. This parameter is ignore when the dataset format is DatasetFormat.ENTITY_BASED
- async delete(id: UUID, prune_dataset=True)¶
- async exists_for(id: UUID)¶
- Parameters:
id – a dataset id
- Returns:
a boolean wether the dataset has data (either entity data or raw data)
- async get_entity_data(id: UUID)¶
return the dataset data for an
ENTITY_BASEDdataset- Parameters:
id – the dataset
UUID- Returns:
The entity based dataset data section
- async get_unstructured_data(id: UUID) dict¶
return the dataset data for an
UNSTRUCTUREDdataset- Parameters:
id – the dataset
UUID- Returns:
The unstructured dataset data section
- async stream_binary_data(id: UUID, yield_per=1) AsyncGenerator[bytes, None]¶
- Parameters:
id – the dataset
UUIDyield_per – an optimzation parameter for the database to request n chunks at a time. Default: 1
- Returns:
An async generator that can be iterated over (async for loop) to produce chunks of binary data. The chunk size is determined by the data stored in the database and is
RawDataProcessor.RAW_DATA_CHUNK_SIZEby default
- class DatasetDataSelector(*args, **kwargs)¶
Bases:
EntityDataSelector- insert_linked_attribute(id: UUID, attribute_id: UUID) sqlalchemy.Insert¶
- select_linked_attribute(id: UUID) sqlalchemy.Select.tuple[movici_data_core.database.model.Attribute]¶
- class DatasetRepository(session: 'AsyncSession', options: 'Options', all_data: 'SQLAlchemyRepository', workspace_id: 'UUID | None' = None)¶
Bases:
SQLResourceRepository- async delete(id: UUID)¶
- async ensure_scenario_datasets(datasets: Sequence[ScenarioDataset]) List[ScenarioDataset]¶
Ensure that the
Datasets of a sequences ofScenarioDatasets exist in the database or raise an error. If one or more of theDataset``s do not exist and the database option ``STRICT_SCENARIO_DATASETSis unset, the non-existing datasets will be created as a stub. If any of the newly created datasets has a dataset type that does not yet exist, then theSTRICT_DATASET_TYPESdatabase option must also be unset. Otherwise an error will be raise. An error is also raised if aDatasetalready exists but with a different dataset type.- Parameters:
datasets – The
ScenarioDatasets to ensure- Returns:
The datasets as they exist in the database, as
ScenarioDatasetobjects, in the same order as the input sequence
- async exists(name: str)¶
return whether the dataset (by name) already exists in the database for the acitve workspace.
- Parameters:
name – dataset name
- Returns:
a boolean indicating the dataset exists for the active workspace
- async get_summary(id: UUID)¶
Request a DatasetSummary for the dataset id
- Parameters:
id – the dataset id
- Returns:
A
DatasetSummary
- property selector¶
- property selector_with_has_data¶
- async update(id: UUID, obj: Dataset, chunk_size=0)¶
Update a dataset. When not given
obj.data, only thenameanddisplay_nameare updated. Otherwise this method als processes the data and updates thegeneral,epsg_codeandbounding_boxfield.- Parameters:
id – the UUID of the stored
Datasetobj – the
Datasetobject with the changeschunk_size – the chunk size in bytes when storing unstructured or binary data. When set to 0, the default, the chunk size is set to
RawDataProcessor.RAW_DATA_CHUNK_SIZE
- workspace_id: UUID | None = None¶
general¶
- class AttributeTypeRepository(session: AsyncSession, options: Options, all_data: SQLAlchemyRepository)¶
Bases:
GenericResourceRepository[AttributeType]- async create(obj: AttributeType) UUID¶
Store a :class:
AttributeTypein the database- Parameters:
obj – the
AttributeTypeobject- Returns:
the UUID of the stored
AttributeType
- async ensure_attribute_type(attribute_type: AttributeType) AttributeType¶
Ensure that an attribute type exists in the database or raise an error. If the attribute type does not exist and the database option
STRICT_ATTRIBUTE_TYPESis unset, the attribute type will be created. If theSTRICT_ATTRIBUTE_TYPESoptions is set, an error is raised instead. An error will also be raised if anAttributeTypewith a different data_type already exists.- Parameters:
attribute_type – the
AttributeTypeobject to ensure.- Returns:
the
AttributeTypeobject as it exists in the database
- async update(id: UUID, obj: AttributeType)¶
Update a :class:
AttributeTypein the databaseValid fields to update are:
name,data_type,unit,description,enum_name- Parameters:
id – the UUID of the stored
EntityTypeobj – the
EntityTypeobject with the changes
- class DatasetTypeRepository(session: AsyncSession, options: Options, all_data: SQLAlchemyRepository)¶
Bases:
GenericResourceRepository[DatasetType]- async create(obj: DatasetType) UUID¶
Store a :class:
DatasetTypein the database. When storing aDatasetType, itsformatfield may not be set toNone.- Parameters:
obj – the
DatasetTypeobject- Returns:
the UUID of the stored
DatasetType
- async ensure_dataset_type(dataset_type: DatasetType) DatasetType¶
Ensure that a dataset type exists in the database or raise an error. If the dataset type does not exist and the database option
STRICT_DATASET_TYPESis unset, the dataset type will be created. If theSTRICT_DATASET_TYPESoptions is set, an error is raised instead. An error will also be raised if an attempt is made to create a DatasetType with itsformatfield set toNone- Parameters:
dataset_type – the
DatasetTypeobject to ensure.- Returns:
the
DatasetTypeobject as it exists in the database
- async update(id: UUID, obj: DatasetType)¶
Update a :class:
DatasetTypein the databaseValid fields to update are:
name,mimetype- Parameters:
id – the UUID of the stored
DatasetTypeobj – the
DatasetTypeobject
- class EntityTypeRepository(session: AsyncSession, options: Options, all_data: SQLAlchemyRepository)¶
Bases:
GenericResourceRepository[EntityType]- async create(obj: EntityType) UUID¶
Store a :class:
EntityTypein the database- Parameters:
obj – the
EntityTypeobject- Returns:
the UUID of the stored
EntityType
- async ensure_entity_type(entity_type: EntityType) EntityType¶
- async update(id: UUID, obj: EntityType)¶
Update a :class:
EntityTypein the databaseValid fields to update are:
name- Parameters:
id – the UUID of the stored
EntityTypeobj – the
EntityTypeobject with the changes
- class ModelTypeRepository(session: AsyncSession, options: Options, all_data: SQLAlchemyRepository)¶
Bases:
GenericResourceRepository[ModelType]- async create(obj: ModelType) UUID¶
Store a :class:
ModelTypein the database- Parameters:
obj – the
ModelTypeobject- Returns:
the UUID of the stored
ModelType
- async ensure_model_types(model_types: Sequence[ModelType]) list[ModelType]¶
Ensure that a sequence of model types exist in the database or raise an error. If one or more of the model types does not exist and the database option
STRICT_MODEL_TYPESis unset, the non-existing model types will be created. If theSTRICT_MODEL_TYPESoptions is set, an error is raised instead.- Parameters:
model_types – The model types to ensure, as a sequence of model type names
- Returns:
the
ModelTypeobjects as they exist in the database, in the same order as the input sequence
scenario¶
- class ScenarioRepository(session: 'AsyncSession', options: 'Options', all_data: 'SQLAlchemyRepository', workspace_id: 'UUID | None' = None, scenario_id: 'UUID | None' = None)¶
Bases:
SQLResourceRepository- async create(obj: Scenario, validator: ModelConfigValidator) UUID¶
Store a new Scenario in the database. This method can only be invoked if there is no currently active Scenario, to prevent creating scenarios when in a
SINGLE_SCENARIOmode- Parameters:
obj – The scenario to create
validator – A ModelConfigValidator that is instantiated with all available models in the dataset
- Returns:
the newly created Scenario UUID
- async delete()¶
Delete de active scenario, if it exists
- async exists()¶
- async exists_by_name(name: str)¶
checks whether a scenario with a specific name exists in the active workspace :return: bool
- for_id(scenario_id: UUID)¶
Bind the ScenarioRepository to a specific scenario
- async get() Scenario | None¶
Get the active scenario from the database
- Returns:
The Scenario, or None if it does not exist
- scenario_id: UUID | None = None¶
- property selector¶
- async set_status(status: ScenarioStatus)¶
Set the ScenarioStatus for the active scenario
- async update(obj: Scenario, validator: ModelConfigValidator)¶
Update a scenario in the database. The scenario to update must be the active scenario
- Parameters:
obj – The sc
validator – A ModelConfigValidator that is instantiated with all available models in the dataset
- workspace_id: UUID | None = None¶
updates¶
- class UpdateDataSelector(*args, **kwargs)¶
Bases:
EntityDataSelectorSubclass of EntityDataSelector to be use for Updates
- insert_linked_attribute(id: UUID, attribute_id: UUID)¶
- select_linked_attribute(id: UUID)¶
- class UpdateRepository(session: AsyncSession, options: Options, all_data: SQLAlchemyRepository, scenario_id: UUID | None)¶
Bases:
SQLResourceRepositoryA Repository for managing Updates. In contrast to other resources, Updates are immutable and can only be created (added to a scenario). The only way to delete an update is by deleting all updates for a Scenario, thereby effectively resetting the Scenario
- Parameters:
scenario_id – A Scenario UUID to bind this UpdateRepository to. Most methods require the repository to be bound, with the exception of
UpdateRepository.get_by_id(). Binding generally is performed by theSQLAlchemyRepositorythat manages thisUpdateRepository
- async create(obj: Update) UUID¶
Store an Update to the active scenario.
- Parameters:
obj – the Update to add, including data
- Returns:
the newly created Update UUID
- async delete_all()¶
Delete all updates for the active scenario. Should be combined with a separate call, to the Scenario, resetting the ScenarioStatus
- async exists() bool¶
Does the active scenario have any updates?
- async list() list[Update]¶
List all updates in the active scenario.
- Returns:
a list of Updates, these Updates do not contain any data
- scenario_id: UUID | None¶
- property selector¶
workspace¶
- class WorkspaceRepository(session: AsyncSession, options: Options, all_data: SQLAlchemyRepository)¶
Bases:
GenericResourceRepository[Workspace]- async create(obj: Workspace) UUID¶
Store a :class:
Workspacein the database- Parameters:
obj – the
Workspaceobject- Returns:
the UUID of the stored
ModelType