scenarios.ScenarioCollection
Collection-like access to scenarios in the database.
Usage
scenarios.ScenarioCollection(scenario_manager)Attributes
active: Scenario-
Currently active scenario
base: Scenario- Base scenario
Examples
>>> # Create a new scenario
>>> new_scenario = db.scenarios.create("Future Development")
>>>
>>> # Access by ID
>>> scenario = db.scenarios[new_scenario.id]
>>>
>>> # Get the active scenario
>>> active = db.scenarios.activeAttributes
| Name | Description |
|---|---|
| active | Currently active scenario. |
| base | Base scenario. |
active
Currently active scenario.
active: Scenario
base
Base scenario.
base: Scenario
Methods
| Name | Description |
|---|---|
| __getitem__() | Access scenario by its ID. |
| __init__() | ScenarioCollection constructor. |
| __iter__() | Iterate through all scenarios, parents before their children. |
| __repr__() | Get string representation of the ScenarioCollection object. |
| by_name() | Find a scenario by name (returns the first match if multiple exist). |
| create() | Create a new scenario, optionally as a child of another. |
| delete() | Delete a scenario by object or id. |
| find_by_id() | Find a scenario by its exact ID (returns single item or None). |
| find_by_name() | Find all scenarios with the given name; MIKE+ allows duplicates. |
__getitem__()
Access scenario by its ID.
Usage
__getitem__(id)Returns
Scenario- The scenario with the given ID.
Raises
KeyError- If no scenario matches the given ID
__init__()
ScenarioCollection constructor.
Usage
__init__(scenario_manager)Parameters
scenario_manager: IScenarioManager- The underlying .NET scenario manager object
__iter__()
Iterate through all scenarios, parents before their children.
Usage
__iter__()__repr__()
Get string representation of the ScenarioCollection object.
Usage
__repr__()Returns
str- The class name and the number of scenarios.
by_name()
Find a scenario by name (returns the first match if multiple exist).
Usage
by_name(name)Parameters
name: str- The name of the scenario to find
Returns
Scenario or None- The first scenario that matches the given name, or None if no match is found
create()
Create a new scenario, optionally as a child of another.
Usage
create(name, parent=None)Parameters
name: str-
Name for the new scenario
parent: Scenario = None- Parent scenario (defaults to base scenario if None)
Returns
Scenario- The new scenario.
Raises
ValueError- If the scenario could not be created
delete()
Delete a scenario by object or id.
Usage
delete(scenario)Parameters
scenario: Scenario or str- The scenario to delete (can be a Scenario object or its ID). Its child scenarios are deleted with it.
Raises
ValueError-
If the scenario could not be deleted
KeyError- If the scenario does not exist
find_by_id()
Find a scenario by its exact ID (returns single item or None).
Usage
find_by_id(id)Parameters
id: str- The ID of the scenario to find
Returns
Scenario or None- The scenario with the given ID, or None if no scenario with that ID exists
find_by_name()
Find all scenarios with the given name; MIKE+ allows duplicates.
Usage
find_by_name(name)Parameters
name: str- The name of the scenario to find
Returns
list[Scenario]- The scenarios with the given name, or an empty list if none match