mirror of https://gitlab.com/pamhyr/pamhyr2
Results: Save sediment layers to db save.
parent
dbcdace348
commit
ae15311471
|
|
@ -18,6 +18,7 @@ import struct
|
||||||
import logging
|
import logging
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
|
from tools import flatten
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
@ -64,7 +65,7 @@ class Profile(SQLSubModel):
|
||||||
|
|
||||||
def get_key(self, key):
|
def get_key(self, key):
|
||||||
res = list(
|
res = list(
|
||||||
map(lambda ts: self._data[ts][key], self._data)
|
map(lambda ts: self._data[ts][key], sorted(self._data))
|
||||||
)
|
)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
@ -146,8 +147,34 @@ class Profile(SQLSubModel):
|
||||||
else:
|
else:
|
||||||
new_data = new[profile]
|
new_data = new[profile]
|
||||||
|
|
||||||
sf = ">" + ''.join(itertools.repeat("f", len_data))
|
if key in ["Z", "Q", "V"]:
|
||||||
values = struct.unpack(sf, data)
|
sf = ">" + ''.join(itertools.repeat("f", len_data))
|
||||||
|
len_values = len(values)
|
||||||
|
values = struct.unpack(sf, data)
|
||||||
|
elif key in ["sl"]:
|
||||||
|
nb_layer = len_data / len(timestamps) / 3
|
||||||
|
sf = ">" + ''.join(itertools.repeat("f", len_data))
|
||||||
|
values = struct.unpack(sf, data)
|
||||||
|
|
||||||
|
tmp_values = [[]]
|
||||||
|
for value in values:
|
||||||
|
t = tmp_values[-1]
|
||||||
|
if len(t) < 3:
|
||||||
|
t.append(value)
|
||||||
|
else:
|
||||||
|
tmp_values.append([value])
|
||||||
|
|
||||||
|
tmp_values = list(map(tuple, tmp_values))
|
||||||
|
|
||||||
|
values = [[]]
|
||||||
|
for value in tmp_values:
|
||||||
|
t = values[-1]
|
||||||
|
if len(t) < nb_layer:
|
||||||
|
t.append(value)
|
||||||
|
else:
|
||||||
|
values.append([value])
|
||||||
|
|
||||||
|
values = list(map(lambda x: [x], values))
|
||||||
|
|
||||||
for timestamp, value in zip(timestamps, values):
|
for timestamp, value in zip(timestamps, values):
|
||||||
new_data.set(timestamp, key, value)
|
new_data.set(timestamp, key, value)
|
||||||
|
|
@ -177,13 +204,24 @@ class Profile(SQLSubModel):
|
||||||
logger.debug(f"{keys}...")
|
logger.debug(f"{keys}...")
|
||||||
for key in keys:
|
for key in keys:
|
||||||
values = self.get_key(key)
|
values = self.get_key(key)
|
||||||
if any(filter(lambda x: type(x) in [tuple, list], values)):
|
|
||||||
logger.debug(f"{key} : {len(values)} {values[0]}")
|
if key in ["Z", "Q", "V"]:
|
||||||
|
values = list(map(float, values))
|
||||||
|
|
||||||
|
sf = ">" + ''.join(itertools.repeat("f", len(values)))
|
||||||
|
len_values = len(values)
|
||||||
|
elif key is "sl":
|
||||||
|
values = flatten(
|
||||||
|
flatten(
|
||||||
|
map(lambda v: list(
|
||||||
|
map(lambda t: list(
|
||||||
|
map(float, t)), v[0])),
|
||||||
|
values)))
|
||||||
|
len_values = len(values)
|
||||||
|
sf = ">" + ''.join(itertools.repeat("f", len_values))
|
||||||
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
values = list(map(float, values))
|
|
||||||
|
|
||||||
sf = ">" + ''.join(itertools.repeat("f", len(values)))
|
|
||||||
data_bytes = struct.pack(sf, *values)
|
data_bytes = struct.pack(sf, *values)
|
||||||
|
|
||||||
execute(
|
execute(
|
||||||
|
|
@ -195,7 +233,7 @@ class Profile(SQLSubModel):
|
||||||
pid, result,
|
pid, result,
|
||||||
data["reach"].pamhyr_id,
|
data["reach"].pamhyr_id,
|
||||||
self._profile.pamhyr_id,
|
self._profile.pamhyr_id,
|
||||||
key, len(values), data_bytes,
|
key, len_values, data_bytes,
|
||||||
self._owner_scenario
|
self._owner_scenario
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,6 @@ class PlotAC(PamhyrPlot):
|
||||||
)
|
)
|
||||||
|
|
||||||
def draw_gl(self):
|
def draw_gl(self):
|
||||||
|
|
||||||
results = self.results[self._current_res_id]
|
results = self.results[self._current_res_id]
|
||||||
reach = results.river.reach(self._current_reach_id)
|
reach = results.river.reach(self._current_reach_id)
|
||||||
profile = reach.profile(self._current_profile_id)
|
profile = reach.profile(self._current_profile_id)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue