spinetoolbox.spine_db_editor.widgets.scenario_generator

Contains a dialog for generating scenarios from selected alternatives.

Module Contents

Classes

_ScenarioNameResolution

Generic enumeration.

ScenarioGenerator

A dialog where users can generate scenarios from given alternatives.

Functions

_ensure_unique(scenario_alternatives)

Removes duplicate scenario alternatives.

_find_base_alternative(names)

Returns the name of a 'base' alternative or empty string if not found.

_suffix(item_count)

Returns a formattable string with enough zero padding to hold item_count digits.

class spinetoolbox.spine_db_editor.widgets.scenario_generator._ScenarioNameResolution[source]

Bases: enum.Enum

Generic enumeration.

Derive from this class to define new enumerations.

NO_CONFLICT[source]
OVERWRITE[source]
LEAVE_AS_IS[source]
CANCEL_OPERATION[source]
class spinetoolbox.spine_db_editor.widgets.scenario_generator.ScenarioGenerator(parent, db_map, alternatives, spine_db_editor)[source]

Bases: PySide6.QtWidgets.QWidget

A dialog where users can generate scenarios from given alternatives.

Parameters
  • parent (QWidget) – parent widget

  • db_map (DiffDatabaseMapping) – database mapping that contains the alternatives

  • alternatives (Iterable of CacheItem) – alternatives from which the scenarios are generated

  • spine_db_editor (SpineDBEditor) – database editor instance

_TYPE_LABELS = ('All combinations', 'Scenario for each alternative')[source]
accept()[source]

Generates scenarios and closes the dialog.

The operation may get cancelled by user if there are conflicts in scenario names.

_generate_scenarios(new_scenarios, scenarios_to_modify, scenario_alternatives)[source]

Generates scenarios with all possible combinations of given alternatives.

Parameters
  • new_scenarios (Iterable of str) – names of new scenarios to create

  • scenarios_to_modify (Iterable of str) – names of scenarios to modify

  • scenario_alternatives (list of list) – alternative items for each scenario

_check_existing_scenarios(proposed_scenario_names, existing_scenario_names)[source]

Checks if proposed scenarios exist, and if so, prompts users what to do.

Parameters
  • proposed_scenario_names (Iterable of str) – proposed scenario names

  • existing_scenario_names (set of str) – existing scenario names

Returns

action to take

Return type

_ScenarioNameResolution

_enable_base_alternative(check_box_state)[source]

Enables and disables base alternative combo box.

Parameters

check_box_state (int) – state of ‘Use base alternative’ check box

_insert_base_alternative(scenario_alternatives)[source]

Prepends base alternative to scenario alternatives if it has been enabled.

If base alternative is already in scenario alternatives, make sure it comes first.

Parameters

scenario_alternatives (list of list) – scenario alternatives

spinetoolbox.spine_db_editor.widgets.scenario_generator._ensure_unique(scenario_alternatives)[source]

Removes duplicate scenario alternatives.

Parameters

scenario_alternatives (list of list) – scenario alternatives

spinetoolbox.spine_db_editor.widgets.scenario_generator._find_base_alternative(names)[source]

Returns the name of a ‘base’ alternative or empty string if not found.

Basically, checks if “Base” is in names, otherwise searches for the first case-insensitive version of “base”.

Parameters

names (list of str) – alternative names

Returns

base alternative name

Return type

str

spinetoolbox.spine_db_editor.widgets.scenario_generator._suffix(item_count)[source]

Returns a formattable string with enough zero padding to hold item_count digits.

Parameters

item_count (int) – maximum number of items

Returns

string in the form ‘{:0n}’ where n is the number of digits in item_count

Return type

str