Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Note, that the semantics of metadata imports have changed, see the Changed section below.
- Added missing `export_metadata()`, `export_entity_metadata()` and `export_parameter_value_metadata()` functions
to `export_functions` module.
- A new experimental module `spinedb_api.scenario_recipes` contains functions to support complex scenario generation
from sets of alternatives.

### Changed

Expand Down
12 changes: 10 additions & 2 deletions spinedb_api/filters/alternative_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
from ..exception import SpineDBAPIError
from .query_utils import filter_by_active_elements

__all__ = ("alternative_filter_config",)

ALTERNATIVE_FILTER_TYPE = "alternative_filter"
ALTERNATIVE_FILTER_SHORTHAND_TAG = "alternatives"

Expand All @@ -31,6 +29,8 @@ def apply_alternative_filter_to_parameter_value_sq(db_map, alternatives):
"""
Replaces parameter value subquery properties in ``db_map`` such that they return only values of given alternatives.

:meta private:

Args:
db_map (DatabaseMapping): a database map to alter
alternatives (Iterable of str or int, optional): alternative names or ids;
Expand Down Expand Up @@ -69,6 +69,8 @@ def alternative_filter_from_dict(db_map, config):
"""
Applies alternative filter to given database map.

:meta private:

Args:
db_map (DatabaseMapping): target database map
config (dict): alternative filter configuration
Expand All @@ -80,6 +82,8 @@ def alternative_filter_config_to_shorthand(config):
"""
Makes a shorthand string from alternative filter configuration.

:meta private:

Args:
config (dict): alternative filter configuration

Expand All @@ -96,6 +100,8 @@ def alternative_names_from_dict(config):
"""
Returns alternatives' names from filter config.

:meta private:

Args:
config (dict): alternative filter configuration

Expand All @@ -111,6 +117,8 @@ def alternative_filter_shorthand_to_config(shorthand):
"""
Makes configuration dictionary out of a shorthand string.

:meta private:

Args:
shorthand (str): a shorthand string

Expand Down
18 changes: 16 additions & 2 deletions spinedb_api/filters/renamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
from functools import partial
from sqlalchemy import case

__all__ = ("entity_class_renamer_config", "parameter_renamer_config")

ENTITY_CLASS_RENAMER_TYPE = "entity_class_renamer"
ENTITY_CLASS_RENAMER_SHORTHAND_TAG = "entity_class_rename"
PARAMETER_RENAMER_TYPE = "parameter_renamer"
Expand All @@ -29,6 +27,8 @@ def apply_renaming_to_entity_class_sq(db_map, name_map):
"""
Applies renaming to entity class subquery.

:meta private:

Args:
db_map (DatabaseMapping): a database map
name_map (dict): a map from old name to new name
Expand All @@ -55,6 +55,8 @@ def entity_class_renamer_from_dict(db_map, config):
"""
Applies entity class renamer manipulator to given database map.

:meta private:

Args:
db_map (DatabaseMapping): target database map
config (dict): renamer configuration
Expand All @@ -66,6 +68,8 @@ def entity_class_renamer_config_to_shorthand(config):
"""
Makes a shorthand string from renamer configuration.

:meta private:

Args:
config (dict): renamer configuration

Expand All @@ -82,6 +86,8 @@ def entity_class_renamer_shorthand_to_config(shorthand):
"""
Makes configuration dictionary out of a shorthand string.

:meta private:

Args:
shorthand (str): a shorthand string

Expand All @@ -99,6 +105,8 @@ def apply_renaming_to_parameter_definition_sq(db_map, name_map):
"""
Applies renaming to parameter definition subquery.

:meta private:

Args:
db_map (DatabaseMapping): a database map
name_map (dict): a map from old name to new name
Expand All @@ -124,6 +132,8 @@ def parameter_renamer_from_dict(db_map, config):
"""
Applies parameter renamer manipulator to given database map.

:meta private:

Args:
db_map (DatabaseMapping): target database map
config (dict): renamer configuration
Expand All @@ -135,6 +145,8 @@ def parameter_renamer_config_to_shorthand(config):
"""
Makes a shorthand string from renamer configuration.

:meta private:

Args:
config (dict): renamer configuration

Expand All @@ -152,6 +164,8 @@ def parameter_renamer_shorthand_to_config(shorthand):
"""
Makes configuration dictionary out of a shorthand string.

:meta private:

Args:
shorthand (str): a shorthand string

Expand Down
14 changes: 11 additions & 3 deletions spinedb_api/filters/scenario_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
# Public License for more details. You should have received a copy of the GNU Lesser General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
######################################################################################################################
""" This module provides the scenario filter. """
"""This module provides the scenario filter."""

from functools import partial
from sqlalchemy import and_, case, desc, func, or_
from sqlalchemy.sql.expression import label
from ..exception import SpineDBAPIError
from .query_utils import filter_by_active_elements

__all__ = ("scenario_filter_config",)

SCENARIO_FILTER_TYPE = "scenario_filter"
SCENARIO_SHORTHAND_TAG = "scenario"

Expand All @@ -27,6 +25,8 @@ def apply_scenario_filter_to_subqueries(db_map, scenario):
"""
Replaces affected subqueries in ``db_map`` such that they return only values of given scenario.

:meta private:

Args:
db_map (DatabaseMapping): a database map to alter
scenario (str or int): scenario name or id
Expand Down Expand Up @@ -65,6 +65,8 @@ def scenario_filter_from_dict(db_map, config):
"""
Applies scenario filter to given database map.

:meta private:

Args:
db_map (DatabaseMapping): target database map
config (dict): scenario filter configuration
Expand All @@ -76,6 +78,8 @@ def scenario_name_from_dict(config):
"""
Returns scenario's name from filter config.

:meta private:

Args:
config (dict): scenario filter configuration

Expand All @@ -91,6 +95,8 @@ def scenario_filter_config_to_shorthand(config):
"""
Makes a shorthand string from scenario filter configuration.

:meta private:

Args:
config (dict): scenario filter configuration

Expand All @@ -104,6 +110,8 @@ def scenario_filter_shorthand_to_config(shorthand):
"""
Makes configuration dictionary out of a shorthand string.

:meta private:

Args:
shorthand (str): a shorthand string

Expand Down
10 changes: 8 additions & 2 deletions spinedb_api/filters/value_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
VALUE_TRANSFORMER_TYPE = "value_transformer"
VALUE_TRANSFORMER_SHORTHAND_TAG = "value_transform"

__all__ = ("value_transformer_config",)


def apply_value_transform_to_parameter_value_sq(db_map, instructions):
"""
Applies renaming to parameter definition subquery.

:meta private:

Args:
db_map (DatabaseMapping): a database map
instructions (dict): mapping from entity class name to mapping from parameter name to list of
Expand Down Expand Up @@ -73,6 +73,8 @@ def value_transformer_from_dict(db_map, config):
"""
Applies value transformer manipulator to given database map.

:meta private:

Args:
db_map (DatabaseMapping): target database map
config (dict): transformer configuration
Expand All @@ -84,6 +86,8 @@ def value_transformer_config_to_shorthand(config):
"""
Makes a shorthand string from transformer configuration.

:meta private:

Args:
config (dict): transformer configuration

Expand Down Expand Up @@ -113,6 +117,8 @@ def value_transformer_shorthand_to_config(shorthand):
Args:
shorthand (str): a shorthand string

:meta private:

Returns:
dict: value transformer configuration
"""
Expand Down
Loading