mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Ensemble: Results: Add seed and number_of_run to DB (0.2.9).
This commit is contained in:
1 parent
290b8918fc
commit
e9c998fec8
2 files changed
+40
-6
No files matched your search
@@ -436,9 +436,11 @@ class Results(SQLSubModel):
|
||||
solver_name TEXT NOT NULL,
|
||||
solver_type TEXT NOT NULL,
|
||||
study_revision INTEGER NOT NULL,
|
||||
creation_data DATE NOT NULL,
|
||||
creation_date DATE NOT NULL,
|
||||
nb_timestamps INTEGER NOT NULL,
|
||||
timestamps BLOB NOT NULL,
|
||||
seed INTEGER,
|
||||
number_of_run INTEGER,
|
||||
{Scenario.create_db_add_scenario()},
|
||||
{Scenario.create_db_add_scenario_fk()},
|
||||
PRIMARY KEY(pamhyr_id, scenario)
|
||||
@@ -464,6 +466,21 @@ class Results(SQLSubModel):
|
||||
cls._db_create(execute)
|
||||
create = True
|
||||
|
||||
if major == "0" and int(minor) <= 2:
|
||||
if int(release) < 9 and not create:
|
||||
execute(
|
||||
"ALTER TABLE results ADD COLUMN " +
|
||||
"seed INTEGER"
|
||||
)
|
||||
execute(
|
||||
"ALTER TABLE results ADD COLUMN " +
|
||||
"number_of_run INTEGER"
|
||||
)
|
||||
execute(
|
||||
"ALTER TABLE results RENAME COLUMN " +
|
||||
"creation_data TO creation_date"
|
||||
)
|
||||
|
||||
return cls._update_submodel(execute, version, data)
|
||||
|
||||
@classmethod
|
||||
@@ -476,7 +493,9 @@ class Results(SQLSubModel):
|
||||
|
||||
table = execute(
|
||||
"SELECT pamhyr_id, solver_name, solver_type, " +
|
||||
"study_revision, creation_data, nb_timestamps, timestamps, " +
|
||||
"study_revision, creation_date, " +
|
||||
"seed, number_of_run, " +
|
||||
"nb_timestamps, timestamps, " +
|
||||
"scenario " +
|
||||
"FROM results " +
|
||||
f"WHERE scenario = {scenario.id}"
|
||||
@@ -496,6 +515,8 @@ class Results(SQLSubModel):
|
||||
solver_type = next(it)
|
||||
revision = next(it)
|
||||
creation_date = next(it)
|
||||
seed = next(it)
|
||||
number_of_run = next(it)
|
||||
nb_timestamps = next(it)
|
||||
timestamps_bytes = next(it)
|
||||
owner_scenario = next(it)
|
||||
@@ -506,6 +527,9 @@ class Results(SQLSubModel):
|
||||
new_results.set("solver_type", solver_type)
|
||||
new_results.set("study_revision", revision)
|
||||
new_results.set("creation_date", creation_date)
|
||||
if seed is not None:
|
||||
new_results.set("seed", seed)
|
||||
new_results.set("number_of_run", number_of_run)
|
||||
|
||||
data["result_pid"] = pid
|
||||
data["result"] = new_results
|
||||
@@ -598,15 +622,25 @@ class Results(SQLSubModel):
|
||||
ts = sorted(self.get("timestamps"))
|
||||
sf = ">" + ''.join(itertools.repeat("d", len(ts)))
|
||||
|
||||
if "seed" in self._meta_data:
|
||||
seed = int(self.get("seed"))
|
||||
number_of_run = int(self.get("number_of_run"))
|
||||
else:
|
||||
seed = None
|
||||
number_of_run = None
|
||||
|
||||
execute(
|
||||
"INSERT INTO " +
|
||||
"results (pamhyr_id, solver_name, solver_type, " +
|
||||
"study_revision, creation_data, " +
|
||||
"study_revision, creation_date, " +
|
||||
"seed, number_of_run, " +
|
||||
"nb_timestamps, timestamps, " +
|
||||
"scenario) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
"scenario) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
self._pamhyr_id, solver_name, solver_type,
|
||||
self._status.version, self.get("creation_date"),
|
||||
len(ts), struct.pack(sf, *ts), self._owner_scenario
|
||||
seed, number_of_run,
|
||||
len(ts), struct.pack(sf, *ts),
|
||||
self._owner_scenario
|
||||
)
|
||||
|
||||
data["result"] = self._pamhyr_id
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ logger = logging.getLogger()
|
||||
|
||||
|
||||
class Study(SQLModel):
|
||||
_version = "0.2.8"
|
||||
_version = "0.2.9"
|
||||
|
||||
_sub_classes = [
|
||||
Scenario,
|
||||
|
||||
Reference in new issue
Block a user