mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
2 Commits
002ebc5928
...
bc08d06bb1
| Author | SHA1 | Date |
|---|---|---|
|
|
bc08d06bb1 | |
|
|
05e039011a |
|
|
@ -276,7 +276,7 @@ class Scenario(SQLSubModel):
|
|||
if self.id != 0:
|
||||
srep = os.path.join(
|
||||
self.parent.workdir(),
|
||||
"senario_" + str(self.id)
|
||||
"scenario_" + str(self.id)
|
||||
)
|
||||
|
||||
return srep
|
||||
|
|
|
|||
|
|
@ -44,7 +44,10 @@ class Study(SQLModel):
|
|||
River,
|
||||
]
|
||||
|
||||
def __init__(self, filename=None, init_new=True):
|
||||
def __init__(self, filename=None, init_new=True, copy=False):
|
||||
if copy:
|
||||
return
|
||||
|
||||
# Metadata
|
||||
self.creation_date = datetime.now()
|
||||
self.last_modification_date = datetime.now()
|
||||
|
|
@ -476,30 +479,7 @@ class Study(SQLModel):
|
|||
return new
|
||||
|
||||
def reload_from_scenario(self, scenario):
|
||||
if scenario in self._river_scenario_cache:
|
||||
self._river = self._river_scenario_cache[scenario]
|
||||
self.status.scenario = scenario
|
||||
else:
|
||||
def sql_exec(sql):
|
||||
return self.execute(
|
||||
sql, fetch_one=False, commit=True
|
||||
)
|
||||
|
||||
self.status.scenario = scenario
|
||||
data = {
|
||||
"status": self.status,
|
||||
"loaded_pid": set(),
|
||||
"scenario": scenario
|
||||
}
|
||||
|
||||
# Reload river data
|
||||
river = River._db_load(
|
||||
sql_exec, data=data
|
||||
)
|
||||
data["study"] = self
|
||||
river._db_load_results(sql_exec, data=data)
|
||||
|
||||
self._river_scenario_cache[scenario] = river
|
||||
river = self.load_scenario(scenario)
|
||||
self._river = river
|
||||
|
||||
if reduce(
|
||||
|
|
@ -511,6 +491,80 @@ class Study(SQLModel):
|
|||
else:
|
||||
self.status.set_as_editable()
|
||||
|
||||
def load_scenario(self, scenario):
|
||||
if scenario in self._river_scenario_cache:
|
||||
return self._river_scenario_cache[scenario]
|
||||
|
||||
def sql_exec(sql):
|
||||
return self.execute(
|
||||
sql, fetch_one=False, commit=True
|
||||
)
|
||||
|
||||
old_scenario = self.status.scenario
|
||||
self.status.scenario = scenario
|
||||
|
||||
data = {
|
||||
"status": self.status,
|
||||
"loaded_pid": set(),
|
||||
"scenario": scenario
|
||||
}
|
||||
|
||||
# Load river data
|
||||
river = River._db_load(
|
||||
sql_exec, data=data
|
||||
)
|
||||
data["study"] = self
|
||||
river._db_load_results(sql_exec, data=data)
|
||||
|
||||
self._river_scenario_cache[scenario] = river
|
||||
self.status.scenario = old_scenario
|
||||
|
||||
return river
|
||||
|
||||
def copy_from_scenario(self, scenario):
|
||||
new = self._copy()
|
||||
|
||||
new._river = self.load_scenario(scenario)
|
||||
|
||||
def set_status(obj):
|
||||
obj._status = new.status
|
||||
|
||||
new.river._data_traversal(
|
||||
modifier=lambda obj, data: set_status(obj),
|
||||
)
|
||||
|
||||
return new
|
||||
|
||||
def _copy(self):
|
||||
"""
|
||||
This method make a copy of current study. This copy is like an
|
||||
empty shell, it's not fully functional. Study object use
|
||||
SQLite connection to file, this copy as no valid connection.
|
||||
|
||||
/!\ Please use this copy as read only object!
|
||||
"""
|
||||
new = Study(copy=True)
|
||||
|
||||
new._filename = ""
|
||||
new.creation_date = self.creation_date
|
||||
new.last_modification_date = self.last_modification_date
|
||||
new.last_save_date = self.last_save_date
|
||||
|
||||
new._name = self._name
|
||||
new.description = self.description
|
||||
|
||||
new._time_system = self._time_system
|
||||
new._date = self._date
|
||||
|
||||
new.status = StudyStatus()
|
||||
new.scenarios = self.scenarios
|
||||
new.status.scenario = self.status.scenario
|
||||
|
||||
new._river = self._river
|
||||
new._river_scenario_cache = self._river_scenario_cache
|
||||
|
||||
return new
|
||||
|
||||
def duplicate_current_scenario(self):
|
||||
source = self.status.scenario_id
|
||||
new = self.scenarios.new(
|
||||
|
|
|
|||
|
|
@ -1375,6 +1375,7 @@ class Mage8(Mage):
|
|||
results = super(Mage8, self).results(study, repertory, qlog, name=name)
|
||||
if results is None:
|
||||
return None
|
||||
|
||||
if with_gra:
|
||||
self.read_gra(study, repertory, results, qlog, name=name)
|
||||
|
||||
|
|
|
|||
|
|
@ -1511,7 +1511,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
return False
|
||||
|
||||
def open_solver_results(self, solver, results=None):
|
||||
logger.info(f"{solver} {results}")
|
||||
logger.info(f"Open results for '{solver}' ({results})")
|
||||
|
||||
def reading_fn():
|
||||
self._tmp_results = results
|
||||
|
|
@ -1647,6 +1647,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
"_PAMHYR_",
|
||||
self._study.name.replace(" ", "_"),
|
||||
solver.name.replace(" ", "_"),
|
||||
self._study.status.scenario.workdir(),
|
||||
)
|
||||
|
||||
return workdir
|
||||
|
|
@ -1870,6 +1871,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
solver_results_adists = solver_results.results(
|
||||
self._study,
|
||||
repertory=dir_path, qlog=None) # self._output)
|
||||
|
||||
logger.info(f"Select results: {dir_path}")
|
||||
if len(bin_list) >= 2 and ("total_sediment.bin" in bin_list):
|
||||
self.open_solver_results_adists(
|
||||
|
|
|
|||
Loading…
Reference in New Issue