mirror of https://gitlab.com/pamhyr/pamhyr2
Results: Add results model.
parent
0c750ec244
commit
1f0d49bd4d
|
|
@ -0,0 +1,45 @@
|
||||||
|
# Results.py -- Pamhyr
|
||||||
|
# Copyright (C) 2023 INRAE
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
from copy import deepcopy
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from Model.Results.River.River import River
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
class Results(object):
|
||||||
|
def __init__(self, study = None):
|
||||||
|
self._study = study
|
||||||
|
self._river = River(self._study)
|
||||||
|
|
||||||
|
self._meta_data = {
|
||||||
|
# Keep results creation date
|
||||||
|
"creation_date": datetime.now(),
|
||||||
|
}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def river(self):
|
||||||
|
return self._river
|
||||||
|
|
||||||
|
def set(self, key, value):
|
||||||
|
self._meta_data[key] = value
|
||||||
|
|
||||||
|
def get(self, key):
|
||||||
|
return self._meta_data[key]
|
||||||
|
|
@ -0,0 +1,81 @@
|
||||||
|
# River.py -- Pamhyr
|
||||||
|
# Copyright (C) 2023 INRAE
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
class Profile(object):
|
||||||
|
def __init__(self, profile, study):
|
||||||
|
self._study = study
|
||||||
|
self._profile = profile # Source profile in the study
|
||||||
|
self._data = {} # Dict of dict {<ts>: {<key>: <value>, ...}, ...}
|
||||||
|
|
||||||
|
def set(self, timestamp, key, data):
|
||||||
|
if timestamp not in self._data:
|
||||||
|
self._data[timestamp] = {}
|
||||||
|
|
||||||
|
self._data[timestamp][key] = data
|
||||||
|
|
||||||
|
def get_ts(self, timestamp):
|
||||||
|
return self._data[timestamp]
|
||||||
|
|
||||||
|
def get_key(self, timestamp):
|
||||||
|
return list(
|
||||||
|
map(lambda ts: self._data[ts][key], self._data)
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_ts_key(self, timestamp, key):
|
||||||
|
return self._data[timestamp][key]
|
||||||
|
|
||||||
|
class Reach(object):
|
||||||
|
def __init__(self, reach, study):
|
||||||
|
self._study = study
|
||||||
|
self._reach = reach # Source reach in the study
|
||||||
|
self._profiles = list(
|
||||||
|
map(
|
||||||
|
lambda p: Profile(p, self._study),
|
||||||
|
reach.profiles
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def profiles(self):
|
||||||
|
return self._profiles.copy()
|
||||||
|
|
||||||
|
def set(self, profile_id, timestamp, key, data):
|
||||||
|
self._profiles[profile_id].set(timestamp, key, data)
|
||||||
|
|
||||||
|
class River(object):
|
||||||
|
def __init__(self, study):
|
||||||
|
self._study = study
|
||||||
|
|
||||||
|
# Dict with timestamps as key
|
||||||
|
self._reachs = []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def reachs(self):
|
||||||
|
return self.reachs.copy()
|
||||||
|
|
||||||
|
def add(self, reach_id):
|
||||||
|
reachs = self._study.river.enable_edges()
|
||||||
|
|
||||||
|
new = Reach(reachs[reach_id].reach, self._study)
|
||||||
|
|
||||||
|
self._reachs.append(new)
|
||||||
|
return new
|
||||||
Loading…
Reference in New Issue