mirror of https://gitlab.com/pamhyr/pamhyr2
Ensemble: Create new ensemble scenario.
parent
70dae9ab1b
commit
e64c45b621
|
|
@ -53,6 +53,7 @@ class Scenario(SQLSubModel):
|
||||||
"geometry_pointXYZ", "geometry_profileXYZ",
|
"geometry_pointXYZ", "geometry_profileXYZ",
|
||||||
"river_reach", "river_node",
|
"river_reach", "river_node",
|
||||||
"geotiff", "reservoir", "reservoir_data",
|
"geotiff", "reservoir", "reservoir_data",
|
||||||
|
"ensemble",
|
||||||
]
|
]
|
||||||
|
|
||||||
related_tables = tables_with_deleted_column + [
|
related_tables = tables_with_deleted_column + [
|
||||||
|
|
@ -67,6 +68,7 @@ class Scenario(SQLSubModel):
|
||||||
name: str = "",
|
name: str = "",
|
||||||
description: str = "",
|
description: str = "",
|
||||||
x: int = 1000.0, y: int = 1000.0,
|
x: int = 1000.0, y: int = 1000.0,
|
||||||
|
is_ensemble: bool = False,
|
||||||
revision: int = 0,
|
revision: int = 0,
|
||||||
parent=None):
|
parent=None):
|
||||||
super(Scenario, self).__init__()
|
super(Scenario, self).__init__()
|
||||||
|
|
@ -76,6 +78,7 @@ class Scenario(SQLSubModel):
|
||||||
self._x, self._y = x, y
|
self._x, self._y = x, y
|
||||||
self._name = name
|
self._name = name
|
||||||
self._description = description
|
self._description = description
|
||||||
|
self._is_ensemble = False
|
||||||
self._revision = revision
|
self._revision = revision
|
||||||
self._parent = parent
|
self._parent = parent
|
||||||
|
|
||||||
|
|
@ -98,6 +101,7 @@ class Scenario(SQLSubModel):
|
||||||
y REAL NOT NULL DEFAULT 1000,
|
y REAL NOT NULL DEFAULT 1000,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
description TEXT NOT NULL,
|
description TEXT NOT NULL,
|
||||||
|
is_ensemble BOOL DEFAULT FALSE,
|
||||||
revision INTEGER NOT NULL,
|
revision INTEGER NOT NULL,
|
||||||
parent_id INTEGER REFERENCES scenario(id)
|
parent_id INTEGER REFERENCES scenario(id)
|
||||||
)
|
)
|
||||||
|
|
@ -133,6 +137,13 @@ class Scenario(SQLSubModel):
|
||||||
cls._db_create(execute)
|
cls._db_create(execute)
|
||||||
cls._db_add_default(execute)
|
cls._db_add_default(execute)
|
||||||
|
|
||||||
|
if major == "0" and int(minor) == 2:
|
||||||
|
if int(release) < 8:
|
||||||
|
execute(
|
||||||
|
f"ALTER TABLE scenario " +
|
||||||
|
"ADD COLUMN is_ensemble BOOL DEFAULT FALSE"
|
||||||
|
)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -153,7 +164,8 @@ class Scenario(SQLSubModel):
|
||||||
scenarios = {}
|
scenarios = {}
|
||||||
|
|
||||||
table = execute(
|
table = execute(
|
||||||
"SELECT id, x, y, name, description, revision, parent_id " +
|
"SELECT id, x, y, name, description, " +
|
||||||
|
" is_ensemble, revision, parent_id " +
|
||||||
"FROM scenario " +
|
"FROM scenario " +
|
||||||
"ORDER BY id ASC"
|
"ORDER BY id ASC"
|
||||||
)
|
)
|
||||||
|
|
@ -165,6 +177,7 @@ class Scenario(SQLSubModel):
|
||||||
x, y = next(it), next(it)
|
x, y = next(it), next(it)
|
||||||
name = next(it)
|
name = next(it)
|
||||||
desc = next(it)
|
desc = next(it)
|
||||||
|
is_ens = next(it)
|
||||||
revi = next(it)
|
revi = next(it)
|
||||||
parent = next(it)
|
parent = next(it)
|
||||||
|
|
||||||
|
|
@ -174,7 +187,9 @@ class Scenario(SQLSubModel):
|
||||||
new = cls(
|
new = cls(
|
||||||
id=id, x=x, y=y,
|
id=id, x=x, y=y,
|
||||||
name=name, description=desc,
|
name=name, description=desc,
|
||||||
revision=revi, parent=parent
|
is_ensemble=is_ens,
|
||||||
|
revision=revi,
|
||||||
|
parent=parent
|
||||||
)
|
)
|
||||||
scenarios[id] = new
|
scenarios[id] = new
|
||||||
|
|
||||||
|
|
@ -184,21 +199,18 @@ class Scenario(SQLSubModel):
|
||||||
if self.is_deleted():
|
if self.is_deleted():
|
||||||
return self.drop_all(execute)
|
return self.drop_all(execute)
|
||||||
|
|
||||||
parent = 'NULL'
|
parent = None
|
||||||
if self.parent is not None:
|
if self.parent is not None:
|
||||||
parent = self.parent._id
|
parent = self.parent._id
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
"INSERT OR REPLACE INTO " +
|
"INSERT OR REPLACE INTO " +
|
||||||
"scenario(id, x, y, name, description, revision, parent_id) " +
|
"scenario(id, x, y, name, description, " +
|
||||||
"VALUES (" +
|
" is_ensemble, revision, parent_id) " +
|
||||||
f"{self._id}, " +
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
f"{self.x}, {self.y}, " +
|
self._id, self.x, self.y,
|
||||||
f"'{self._db_format(self.name)}', " +
|
self.name, self.description, self._is_ensemble,
|
||||||
f"'{self._db_format(self.description)}', " +
|
self._revision, parent
|
||||||
f"{self._revision}, " +
|
|
||||||
f"{parent}" +
|
|
||||||
")"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
@ -323,6 +335,9 @@ class Scenario(SQLSubModel):
|
||||||
def parent(self):
|
def parent(self):
|
||||||
return self._parent
|
return self._parent
|
||||||
|
|
||||||
|
def is_ensemble(self):
|
||||||
|
return self._is_ensemble
|
||||||
|
|
||||||
def set_pos(self, x, y):
|
def set_pos(self, x, y):
|
||||||
self._x = x
|
self._x = x
|
||||||
self._y = y
|
self._y = y
|
||||||
|
|
@ -340,6 +355,8 @@ class Scenario(SQLSubModel):
|
||||||
return self.name
|
return self.name
|
||||||
if key == "description":
|
if key == "description":
|
||||||
return self.description
|
return self.description
|
||||||
|
if key == "is_ensemble":
|
||||||
|
return self.is_ensemble()
|
||||||
if key == "parent":
|
if key == "parent":
|
||||||
return self.parent
|
return self.parent
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,11 @@ class Scenarios(PamhyrModelDict):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def new(self, parent):
|
def new(self, parent, is_ensemble=False):
|
||||||
new = Scenario(parent=parent)
|
new = Scenario(
|
||||||
|
parent=parent,
|
||||||
|
is_ensemble=is_ensemble
|
||||||
|
)
|
||||||
self.set(new._id, new)
|
self.set(new._id, new)
|
||||||
return new
|
return new
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -674,6 +674,22 @@ class Study(SQLModel):
|
||||||
self.status.set_as_editable()
|
self.status.set_as_editable()
|
||||||
return new
|
return new
|
||||||
|
|
||||||
|
def create_ensemble_scenario(self, switch=True):
|
||||||
|
new = self.scenarios.new(
|
||||||
|
self.status.scenario,
|
||||||
|
is_ensemble=True
|
||||||
|
)
|
||||||
|
|
||||||
|
new.name = self.status.scenario.name + " (ensemble)"
|
||||||
|
new.set_pos(self.status.scenario.x + 100,
|
||||||
|
self.status.scenario.y + 100)
|
||||||
|
|
||||||
|
if switch:
|
||||||
|
self.status.scenario = new
|
||||||
|
|
||||||
|
self.status.set_as_editable()
|
||||||
|
return new
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def results(self):
|
def results(self):
|
||||||
return self._river.results
|
return self._river.results
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ class SetDataCommand(QUndoCommand):
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._ensembles.get(self._index).target_data = self._new
|
self._ensembles.get(self._index).target_data = self._new
|
||||||
|
|
||||||
|
|
||||||
class SetFunctionCommand(QUndoCommand):
|
class SetFunctionCommand(QUndoCommand):
|
||||||
def __init__(self, ensembles, index, edge):
|
def __init__(self, ensembles, index, edge):
|
||||||
QUndoCommand.__init__(self)
|
QUndoCommand.__init__(self)
|
||||||
|
|
@ -89,6 +90,7 @@ class SetFunctionCommand(QUndoCommand):
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._ensembles.get(self._index).function = self._new
|
self._ensembles.get(self._index).function = self._new
|
||||||
|
|
||||||
|
|
||||||
class AddCommand(QUndoCommand):
|
class AddCommand(QUndoCommand):
|
||||||
def __init__(self, ensembles, index, reach):
|
def __init__(self, ensembles, index, reach):
|
||||||
QUndoCommand.__init__(self)
|
QUndoCommand.__init__(self)
|
||||||
|
|
|
||||||
|
|
@ -59,11 +59,15 @@ class ScenarioMenu(AbstractMenu):
|
||||||
item = self._items[0]
|
item = self._items[0]
|
||||||
scenarios = item.graph._study.scenarios
|
scenarios = item.graph._study.scenarios
|
||||||
|
|
||||||
|
if len(scenarios) == 1:
|
||||||
|
return
|
||||||
|
|
||||||
current_scenario = item.graph._study.status.scenario.id
|
current_scenario = item.graph._study.status.scenario.id
|
||||||
|
|
||||||
select = self._menu.addAction(self._trad["menu_select_scenario"])
|
select = self._menu.addAction(self._trad["menu_select_scenario"])
|
||||||
duplicate = None
|
duplicate = None
|
||||||
delete = None
|
delete = None
|
||||||
|
ensemble = None
|
||||||
|
|
||||||
if item.scenario.id != 0:
|
if item.scenario.id != 0:
|
||||||
if scenarios.is_leaf(item.scenario):
|
if scenarios.is_leaf(item.scenario):
|
||||||
|
|
@ -74,6 +78,11 @@ class ScenarioMenu(AbstractMenu):
|
||||||
self._trad["menu_dup_scenario"]
|
self._trad["menu_dup_scenario"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if item.scenario.id == current_scenario:
|
||||||
|
ensemble = self._menu.addAction(
|
||||||
|
self._trad["menu_ens_scenario"]
|
||||||
|
)
|
||||||
|
|
||||||
action = self._exec()
|
action = self._exec()
|
||||||
if action is None:
|
if action is None:
|
||||||
return
|
return
|
||||||
|
|
@ -83,3 +92,5 @@ class ScenarioMenu(AbstractMenu):
|
||||||
self._parent.delete_scenario(item)
|
self._parent.delete_scenario(item)
|
||||||
elif action == duplicate:
|
elif action == duplicate:
|
||||||
self._parent.duplicate_scenario(item)
|
self._parent.duplicate_scenario(item)
|
||||||
|
elif action == ensemble:
|
||||||
|
self._parent.create_ensemble_scenario(item)
|
||||||
|
|
|
||||||
|
|
@ -526,6 +526,26 @@ class GraphWidget(QGraphicsView):
|
||||||
self.exec_with_waiting_window(fn, "duplicate_scenario")
|
self.exec_with_waiting_window(fn, "duplicate_scenario")
|
||||||
self.changeScenario.emit(self.sender())
|
self.changeScenario.emit(self.sender())
|
||||||
|
|
||||||
|
def create_ensemble_scenario(self, item):
|
||||||
|
must_save = self.dialog_save()
|
||||||
|
if must_save == "Cancel":
|
||||||
|
return
|
||||||
|
|
||||||
|
def fn():
|
||||||
|
self._close_other_window()
|
||||||
|
|
||||||
|
if must_save == "Save":
|
||||||
|
self._study.save()
|
||||||
|
|
||||||
|
self._undo.push(
|
||||||
|
CreateEnsembleScenarioCommand(
|
||||||
|
self._study,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.exec_with_waiting_window(fn, "create_ensemble_scenario")
|
||||||
|
self.changeScenario.emit(self.sender())
|
||||||
|
|
||||||
def _close_other_window(self):
|
def _close_other_window(self):
|
||||||
self.parent\
|
self.parent\
|
||||||
.parent\
|
.parent\
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,25 @@ class DuplicateScenariosCommand(QUndoCommand):
|
||||||
self._study.reload_from_scenario(self._new)
|
self._study.reload_from_scenario(self._new)
|
||||||
|
|
||||||
|
|
||||||
|
class CreateEnsembleScenarioCommand(QUndoCommand):
|
||||||
|
def __init__(self, study):
|
||||||
|
QUndoCommand.__init__(self)
|
||||||
|
|
||||||
|
self._study = study
|
||||||
|
self._new = None
|
||||||
|
|
||||||
|
def undo(self):
|
||||||
|
self._study.scenarios.delete(self._new.id)
|
||||||
|
self._study.reload_from_scenario(self._new.parent)
|
||||||
|
|
||||||
|
def redo(self):
|
||||||
|
if self._new is None:
|
||||||
|
self._new = self._study.create_ensemble_scenario()
|
||||||
|
else:
|
||||||
|
self._new.set_as_not_deleted()
|
||||||
|
self._study.reload_from_scenario(self._new)
|
||||||
|
|
||||||
|
|
||||||
class SetCommand(QUndoCommand):
|
class SetCommand(QUndoCommand):
|
||||||
def __init__(self, scenario, column, new_value):
|
def __init__(self, scenario, column, new_value):
|
||||||
QUndoCommand.__init__(self)
|
QUndoCommand.__init__(self)
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,9 @@ class ScenariosTranslate(MainTranslate):
|
||||||
self._dict["menu_dup_scenario"] = _translate(
|
self._dict["menu_dup_scenario"] = _translate(
|
||||||
"Scenarios", "Duplicate this scenario"
|
"Scenarios", "Duplicate this scenario"
|
||||||
)
|
)
|
||||||
|
self._dict["menu_ens_scenario"] = _translate(
|
||||||
|
"Scenarios", "Create ensemble scenario from this scenario"
|
||||||
|
)
|
||||||
|
|
||||||
self._sub_dict["table_headers_scenarios"] = {
|
self._sub_dict["table_headers_scenarios"] = {
|
||||||
# "id": self._dict['id'],
|
# "id": self._dict['id'],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue