mirror of https://gitlab.com/pamhyr/pamhyr2
Results: Clear db load code.
parent
82b0837d8c
commit
6c4f6e269c
|
|
@ -153,29 +153,9 @@ class Profile(SQLSubModel):
|
|||
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))
|
||||
values = cls._db_load_data_sl_format(values, len_data, timestamps)
|
||||
|
||||
for timestamp, value in zip(timestamps, values):
|
||||
new_data.set(timestamp, key, value)
|
||||
|
|
@ -184,6 +164,35 @@ class Profile(SQLSubModel):
|
|||
|
||||
return list(new.values())
|
||||
|
||||
@classmethod
|
||||
def _db_load_data_sl_format(cls, values, len_data, timestamps):
|
||||
tuple_size = 3
|
||||
|
||||
# HACK: Transforme list of value to list of n-tuple
|
||||
# sediment results: (h, d50, sigma)
|
||||
tmp_values = [[]]
|
||||
for value in values:
|
||||
t = tmp_values[-1]
|
||||
if len(t) < tuple_size:
|
||||
t.append(value)
|
||||
else:
|
||||
tmp_values.append([value])
|
||||
|
||||
tmp_values = list(map(tuple, tmp_values))
|
||||
|
||||
# HACK: Transforme list of n-tuple to list of n-list
|
||||
# of n-tuple, where n is the number of layer.
|
||||
nb_layer = len_data / len(timestamps) / tuple_size
|
||||
values = [[]]
|
||||
for value in tmp_values:
|
||||
t = values[-1]
|
||||
if len(t) < nb_layer:
|
||||
t.append(value)
|
||||
else:
|
||||
values.append([value])
|
||||
|
||||
return list(map(lambda x: [x], values))
|
||||
|
||||
def update_water_limits(self, timestamp, z):
|
||||
limits = self.geometry.get_water_limits(z)
|
||||
self.set(
|
||||
|
|
|
|||
Loading…
Reference in New Issue