spinetoolbox.mvcmodels.parameter_mixins

Miscelaneous mixins for parameter models

authors:
  1. Marin (KTH)
date:

4.10.2019

Module Contents

spinetoolbox.mvcmodels.parameter_mixins._parse_csv_list(csv_list)[source]
class spinetoolbox.mvcmodels.parameter_mixins.ConvertToDBMixin[source]

Base class for all mixins that convert model items (name-based) into database items (id-based).

build_lookup_dictionary(self, db_map_data)[source]

Begins an operation to convert items.

_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters:
  • item (dict) – the model item
  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs
Returns:

the db item list: error log

Return type:

dict

class spinetoolbox.mvcmodels.parameter_mixins.FillInParameterNameMixin[source]

Bases: spinetoolbox.mvcmodels.parameter_mixins.ConvertToDBMixin

Fills in parameter names.

_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters:
  • item (dict) – the model item
  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs
Returns:

the db item list: error log

Return type:

dict

class spinetoolbox.mvcmodels.parameter_mixins.FillInValueListIdMixin(*args, **kwargs)[source]

Bases: spinetoolbox.mvcmodels.parameter_mixins.ConvertToDBMixin

Fills in value list ids.

Initializes lookup dicts.

build_lookup_dictionary(self, db_map_data)[source]

Builds a name lookup dictionary for the given data.

Parameters:db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping
_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters:
  • item (dict) – the model item
  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs
Returns:

the db item list: error log

Return type:

dict

_fill_in_value_list_id(self, item, db_map)[source]

Fills in the value list id in the given db item.

Parameters:
  • item (dict) – the db item
  • db_map (DiffDatabaseMapping) – the database where the given item belongs
Returns:

error log

Return type:

list

class spinetoolbox.mvcmodels.parameter_mixins.MakeParameterTagMixin(*args, **kwargs)[source]

Bases: spinetoolbox.mvcmodels.parameter_mixins.ConvertToDBMixin

Makes parameter tag items.

Initializes lookup dicts.

build_lookup_dictionary(self, db_map_data)[source]

Builds a name lookup dictionary for the given data.

Parameters:db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping
_make_parameter_definition_tag(self, item, db_map)[source]

Returns a db parameter definition tag item (id-based) from the given model parameter definition item (name-based).

Parameters:
  • item (dict) – the model parameter definition item
  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs
Returns:

the db parameter definition tag item list: error log

Return type:

dict

class spinetoolbox.mvcmodels.parameter_mixins.FillInEntityClassIdMixin(*args, **kwargs)[source]

Bases: spinetoolbox.mvcmodels.parameter_mixins.ConvertToDBMixin

Fills in entity class ids.

Initializes lookup dicts.

build_lookup_dictionary(self, db_map_data)[source]

Builds a name lookup dictionary for the given data.

Parameters:db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping
_fill_in_entity_class_id(self, item, db_map)[source]

Fills in the entity class id in the given db item.

Parameters:
  • item (dict) – the db item
  • db_map (DiffDatabaseMapping) – the database where the given item belongs
Returns:

error log

Return type:

list

_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters:
  • item (dict) – the model item
  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs
Returns:

the db item list: error log

Return type:

dict

class spinetoolbox.mvcmodels.parameter_mixins.FillInEntityIdsMixin(*args, **kwargs)[source]

Bases: spinetoolbox.mvcmodels.parameter_mixins.ConvertToDBMixin

Fills in entity ids.

Initializes lookup dicts.

_add_entities_on_the_fly = False[source]
build_lookup_dictionary(self, db_map_data)[source]

Builds a name lookup dictionary for the given data.

Parameters:db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping
_fill_in_entity_ids(self, item, db_map)[source]

Fills in all possible entity ids keyed by entity class id in the given db item (as there can be more than one entity for the same name).

Parameters:
  • item (dict) – the db item
  • db_map (DiffDatabaseMapping) – the database where the given item belongs
Returns:

error log

Return type:

list

_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters:
  • item (dict) – the model item
  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs
Returns:

the db item list: error log

Return type:

dict

class spinetoolbox.mvcmodels.parameter_mixins.FillInParameterDefinitionIdsMixin(*args, **kwargs)[source]

Bases: spinetoolbox.mvcmodels.parameter_mixins.ConvertToDBMixin

Fills in parameter definition ids.

Initializes lookup dicts.

build_lookup_dictionary(self, db_map_data)[source]

Builds a name lookup dictionary for the given data.

Parameters:db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping
_fill_in_parameter_ids(self, item, db_map)[source]

Fills in all possible parameter definition ids keyed by entity class id in the given db item (as there can be more than one parameter definition for the same name).

Parameters:
  • item (dict) – the db item
  • db_map (DiffDatabaseMapping) – the database where the given item belongs
Returns:

error log

Return type:

list

_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters:
  • item (dict) – the model item
  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs
Returns:

the db item list: error log

Return type:

dict

class spinetoolbox.mvcmodels.parameter_mixins.InferEntityClassIdMixin[source]

Bases: spinetoolbox.mvcmodels.parameter_mixins.ConvertToDBMixin

Infers object class ids.

_convert_to_db(self, item, db_map)[source]

Returns a db item (id-based) from the given model item (name-based).

Parameters:
  • item (dict) – the model item
  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs
Returns:

the db item list: error log

Return type:

dict

_infer_and_fill_in_entity_class_id(self, item, db_map)[source]

Fills the entity class id in the given db item, by intersecting entity ids and parameter ids. Then picks the correct entity id and parameter definition id. Also sets the inferred entity class name in the model.

Parameters:
  • item (dict) – the db item
  • db_map (DiffDatabaseMapping) – the database where the given item belongs
Returns:

error log

Return type:

list

class spinetoolbox.mvcmodels.parameter_mixins.MakeRelationshipOnTheFlyMixin(*args, **kwargs)[source]

Makes relationships on the fly.

Initializes lookup dicts.

static _make_unique_relationship_id(item)[source]

Returns a unique name-based identifier for db relationships.

build_lookup_dictionaries(self, db_map_data)[source]

Builds a name lookup dictionary for the given data.

Parameters:db_map_data (dict) – lists of model items keyed by DiffDatabaseMapping.
_make_relationship_on_the_fly(self, item, db_map)[source]

Returns a database relationship item (id-based) from the given model parameter value item (name-based).

Parameters:
  • item (dict) – the model parameter value item
  • db_map (DiffDatabaseMapping) – the database where the resulting item belongs
Returns:

the db relationship item list: error log

Return type:

dict