mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
No commits in common. "ecb2544caba17f27c26d2ab505fe7e85e96c115e" and "32e7413aad5359453bc2cb73f0dd7bcc88353681" have entirely different histories.
ecb2544cab
...
32e7413aad
|
|
@ -22,8 +22,6 @@ import numpy as np
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from tools import timer
|
|
||||||
|
|
||||||
from Model.Scenario import Scenario
|
from Model.Scenario import Scenario
|
||||||
from Model.Tools.PamhyrDB import SQLSubModel
|
from Model.Tools.PamhyrDB import SQLSubModel
|
||||||
from Model.Results.River.River import River
|
from Model.Results.River.River import River
|
||||||
|
|
@ -169,7 +167,7 @@ class Results(SQLSubModel):
|
||||||
|
|
||||||
self._name = name
|
self._name = name
|
||||||
self._study = study
|
self._study = study
|
||||||
self._river = River(self._study, self)
|
self._river = River(self._study)
|
||||||
|
|
||||||
self._solver = solver
|
self._solver = solver
|
||||||
self._repertory = repertory
|
self._repertory = repertory
|
||||||
|
|
@ -197,7 +195,6 @@ class Results(SQLSubModel):
|
||||||
def study(self):
|
def study(self):
|
||||||
return self._study
|
return self._study
|
||||||
|
|
||||||
@timer
|
|
||||||
def set(self, key, value):
|
def set(self, key, value):
|
||||||
self._meta_data[key] = value
|
self._meta_data[key] = value
|
||||||
|
|
||||||
|
|
@ -215,12 +212,6 @@ class Results(SQLSubModel):
|
||||||
def get(self, key):
|
def get(self, key):
|
||||||
return self._meta_data[key]
|
return self._meta_data[key]
|
||||||
|
|
||||||
def set_timestamp_index(self, index):
|
|
||||||
self._ts_index = index
|
|
||||||
|
|
||||||
def get_timestamp_id(self, ts):
|
|
||||||
return self._ts_index[ts]
|
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
return self._solver.results(
|
return self._solver.results(
|
||||||
self._study,
|
self._study,
|
||||||
|
|
@ -323,7 +314,6 @@ class Results(SQLSubModel):
|
||||||
new_results.set("timestamps", ts)
|
new_results.set("timestamps", ts)
|
||||||
|
|
||||||
data["timestamps"] = sorted(ts)
|
data["timestamps"] = sorted(ts)
|
||||||
data["parent"] = new_results
|
|
||||||
new_results._river = River._db_load(execute, data)
|
new_results._river = River._db_load(execute, data)
|
||||||
|
|
||||||
new_results.set(
|
new_results.set(
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import logging
|
||||||
import itertools
|
import itertools
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from tools import flatten, timer
|
from tools import flatten
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
@ -31,17 +31,15 @@ logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
class Profile(SQLSubModel):
|
class Profile(SQLSubModel):
|
||||||
def __init__(self, profile, study, parent):
|
def __init__(self, profile, study):
|
||||||
super(Profile, self).__init__(
|
super(Profile, self).__init__(
|
||||||
id=-1, status=study.status,
|
id=-1, status=study.status,
|
||||||
owner_scenario=study.status.scenario.id
|
owner_scenario=study.status.scenario.id
|
||||||
)
|
)
|
||||||
|
|
||||||
self._parent = parent
|
|
||||||
self._study = study
|
self._study = study
|
||||||
self._profile = profile # Source profile in the study
|
self._profile = profile # Source profile in the study
|
||||||
self._data = {} # Dict of dict {<ts>: {<key>: <value>, ...}, ...}
|
self._data = {} # Dict of dict {<ts>: {<key>: <value>, ...}, ...}
|
||||||
self._global_index = -1
|
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self._data)
|
return len(self._data)
|
||||||
|
|
@ -58,26 +56,15 @@ class Profile(SQLSubModel):
|
||||||
def geometry(self):
|
def geometry(self):
|
||||||
return self._profile
|
return self._profile
|
||||||
|
|
||||||
@property
|
|
||||||
def global_index(self):
|
|
||||||
return self._global_index
|
|
||||||
|
|
||||||
@global_index.setter
|
|
||||||
def global_index(self, id):
|
|
||||||
self._global_index = id
|
|
||||||
|
|
||||||
@timer
|
|
||||||
def set(self, timestamp, key, data):
|
def set(self, timestamp, key, data):
|
||||||
if timestamp not in self._data:
|
if timestamp not in self._data:
|
||||||
self._data[timestamp] = {}
|
self._data[timestamp] = {}
|
||||||
|
|
||||||
self._data[timestamp][key] = data
|
self._data[timestamp][key] = data
|
||||||
|
|
||||||
@timer
|
|
||||||
def get_ts(self, timestamp):
|
def get_ts(self, timestamp):
|
||||||
return self._data[timestamp]
|
return self._data[timestamp]
|
||||||
|
|
||||||
@timer
|
|
||||||
def get_key(self, key):
|
def get_key(self, key):
|
||||||
res = list(
|
res = list(
|
||||||
map(lambda ts: self._data[ts][key],
|
map(lambda ts: self._data[ts][key],
|
||||||
|
|
@ -85,7 +72,6 @@ class Profile(SQLSubModel):
|
||||||
)
|
)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@timer
|
|
||||||
def get_ts_key(self, timestamp, key):
|
def get_ts_key(self, timestamp, key):
|
||||||
if timestamp in self._data:
|
if timestamp in self._data:
|
||||||
if key in self._data[timestamp]:
|
if key in self._data[timestamp]:
|
||||||
|
|
@ -140,7 +126,6 @@ class Profile(SQLSubModel):
|
||||||
new = {}
|
new = {}
|
||||||
status = data['status']
|
status = data['status']
|
||||||
|
|
||||||
parent = data['parent']
|
|
||||||
study = data['study']
|
study = data['study']
|
||||||
reach = data['reach']
|
reach = data['reach']
|
||||||
profile = data['profile']
|
profile = data['profile']
|
||||||
|
|
@ -168,7 +153,7 @@ class Profile(SQLSubModel):
|
||||||
owner_scenario = next(it)
|
owner_scenario = next(it)
|
||||||
|
|
||||||
if profile not in new:
|
if profile not in new:
|
||||||
new_data = cls(profile, study, parent)
|
new_data = cls(profile, study)
|
||||||
new[profile] = new_data
|
new[profile] = new_data
|
||||||
else:
|
else:
|
||||||
new_data = new[profile]
|
new_data = new[profile]
|
||||||
|
|
@ -281,20 +266,19 @@ class Profile(SQLSubModel):
|
||||||
class Reach(SQLSubModel):
|
class Reach(SQLSubModel):
|
||||||
_sub_classes = [Profile]
|
_sub_classes = [Profile]
|
||||||
|
|
||||||
def __init__(self, reach, study, parent, with_init=True):
|
def __init__(self, reach, study, with_init=True):
|
||||||
super(Reach, self).__init__(
|
super(Reach, self).__init__(
|
||||||
id=-1, status=study.status,
|
id=-1, status=study.status,
|
||||||
owner_scenario=study.status.scenario.id
|
owner_scenario=study.status.scenario.id
|
||||||
)
|
)
|
||||||
|
|
||||||
self._parent = parent
|
|
||||||
self._study = study
|
self._study = study
|
||||||
self._reach = reach # Source reach in the study
|
self._reach = reach # Source reach in the study
|
||||||
self._profiles = []
|
self._profiles = []
|
||||||
if with_init:
|
if with_init:
|
||||||
self._profiles = list(
|
self._profiles = list(
|
||||||
map(
|
map(
|
||||||
lambda p: Profile(p, self._study, self._parent),
|
lambda p: Profile(p, self._study),
|
||||||
reach.profiles
|
reach.profiles
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
@ -332,11 +316,6 @@ class Reach(SQLSubModel):
|
||||||
def profile(self, id):
|
def profile(self, id):
|
||||||
return self._profiles[id]
|
return self._profiles[id]
|
||||||
|
|
||||||
def set_global_index(self, indexs):
|
|
||||||
for profile, ind in zip(self._profiles, indexs):
|
|
||||||
profile.global_index = ind
|
|
||||||
|
|
||||||
@timer
|
|
||||||
def set(self, profile_id, timestamp, key, data):
|
def set(self, profile_id, timestamp, key, data):
|
||||||
self._profiles[profile_id].set(timestamp, key, data)
|
self._profiles[profile_id].set(timestamp, key, data)
|
||||||
|
|
||||||
|
|
@ -365,8 +344,7 @@ class Reach(SQLSubModel):
|
||||||
reach = data["reach"]
|
reach = data["reach"]
|
||||||
|
|
||||||
new_reach = cls(
|
new_reach = cls(
|
||||||
data["reach"], data["study"], data["parent"],
|
data["reach"], data["study"], with_init=False
|
||||||
with_init=False
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for i, profile in enumerate(reach.profiles):
|
for i, profile in enumerate(reach.profiles):
|
||||||
|
|
@ -385,14 +363,13 @@ class Reach(SQLSubModel):
|
||||||
class River(SQLSubModel):
|
class River(SQLSubModel):
|
||||||
_sub_classes = [Reach]
|
_sub_classes = [Reach]
|
||||||
|
|
||||||
def __init__(self, study, parent):
|
def __init__(self, study):
|
||||||
super(River, self).__init__(
|
super(River, self).__init__(
|
||||||
id=-1, status=study.status,
|
id=-1, status=study.status,
|
||||||
owner_scenario=study.status.scenario.id
|
owner_scenario=study.status.scenario.id
|
||||||
)
|
)
|
||||||
|
|
||||||
self._study = study
|
self._study = study
|
||||||
self._parent = parent
|
|
||||||
|
|
||||||
# Dict with timestamps as key
|
# Dict with timestamps as key
|
||||||
self._reachs = []
|
self._reachs = []
|
||||||
|
|
@ -413,7 +390,7 @@ class River(SQLSubModel):
|
||||||
def add(self, reach_id):
|
def add(self, reach_id):
|
||||||
reachs = self._study.river.enable_edges()
|
reachs = self._study.river.enable_edges()
|
||||||
|
|
||||||
new = Reach(reachs[reach_id].reach, self._study, self._parent)
|
new = Reach(reachs[reach_id].reach, self._study)
|
||||||
|
|
||||||
self._reachs.append(new)
|
self._reachs.append(new)
|
||||||
return new
|
return new
|
||||||
|
|
@ -437,9 +414,7 @@ class River(SQLSubModel):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_load(cls, execute, data=None):
|
def _db_load(cls, execute, data=None):
|
||||||
study = data["study"]
|
study = data["study"]
|
||||||
parent = data["parent"]
|
new_river = cls(study)
|
||||||
|
|
||||||
new_river = cls(study, parent)
|
|
||||||
|
|
||||||
for reach in study.river.reachs():
|
for reach in study.river.reachs():
|
||||||
data["reach"] = reach.reach
|
data["reach"] = reach.reach
|
||||||
|
|
|
||||||
|
|
@ -1098,9 +1098,6 @@ class Mage8(Mage):
|
||||||
i1 = data[2*i] - 1
|
i1 = data[2*i] - 1
|
||||||
i2 = data[2*i+1] - 1
|
i2 = data[2*i+1] - 1
|
||||||
|
|
||||||
# Keep profiles index of all river
|
|
||||||
r.set_global_index(range(i1, i2 + 1))
|
|
||||||
|
|
||||||
# Add profile id correspondance to reach
|
# Add profile id correspondance to reach
|
||||||
for key in range(i1, i2 + 1):
|
for key in range(i1, i2 + 1):
|
||||||
iprofiles.append(i)
|
iprofiles.append(i)
|
||||||
|
|
@ -1174,11 +1171,6 @@ class Mage8(Mage):
|
||||||
endline()
|
endline()
|
||||||
end = newline().size <= 0
|
end = newline().size <= 0
|
||||||
|
|
||||||
ts_index = {}
|
|
||||||
for i, t in enumerate(sorted(ts)):
|
|
||||||
ts_index[t] = i
|
|
||||||
results.set_timestamp_index(ts_index)
|
|
||||||
|
|
||||||
table = {}
|
table = {}
|
||||||
for k in tmp_table:
|
for k in tmp_table:
|
||||||
table[k] = np.array(tmp_table[k])
|
table[k] = np.array(tmp_table[k])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue