mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
BC AdisTS View1
This commit is contained in:
1 parent
6067ba601e
commit
d154ac96c2
16 files changed
+1854
-25
No files matched your search
@@ -36,7 +36,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||
_id_cnt = 0
|
||||
|
||||
def __init__(self, id: int = -1,
|
||||
status=None):
|
||||
pollutant: int = -1, status=None):
|
||||
super(BoundaryConditionAdisTS, self).__init__()
|
||||
|
||||
self._status = status
|
||||
@@ -48,7 +48,7 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||
|
||||
self._type = ""
|
||||
self._node = None
|
||||
self._pollutant = None
|
||||
self._pollutant = pollutant
|
||||
self._data = []
|
||||
self._header = []
|
||||
self._types = [self.time_convert, float]
|
||||
@@ -87,37 +87,39 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = []
|
||||
pollutant_id = data["pollutant_id"]
|
||||
|
||||
table = execute(
|
||||
"SELECT id, pollutant, type, node " +
|
||||
"FROM boundary_condition_adists " +
|
||||
f"WHERE tab = '{pollutant_id}'"
|
||||
"FROM boundary_condition_adists"
|
||||
)
|
||||
|
||||
for row in table:
|
||||
bc = cls(
|
||||
id=row[0],
|
||||
status=data['status']
|
||||
)
|
||||
if table is not None:
|
||||
for row in table:
|
||||
bc = cls(
|
||||
id=row[0],
|
||||
pollutant=row[1],
|
||||
status=data['status']
|
||||
)
|
||||
|
||||
bc.node = None
|
||||
if row[3] != -1:
|
||||
bc.node = next(filter(lambda n: n.id == row[3], data["nodes"]))
|
||||
bc.type = row[2]
|
||||
|
||||
values = execute(
|
||||
"SELECT data0, data1 FROM boundary_condition_data_adists " +
|
||||
f"WHERE bc = '{bc.id}'"
|
||||
)
|
||||
bc.node = None
|
||||
if row[3] != -1:
|
||||
bc.node = next(filter(lambda n: n.id == row[3], data["nodes"]))
|
||||
|
||||
# Write data
|
||||
for v in values:
|
||||
data0 = bc._types[0](v[1])
|
||||
data1 = bc._types[1](v[2])
|
||||
# Replace data at pos ind
|
||||
bc._data.append((data0, data1))
|
||||
values = execute(
|
||||
"SELECT data0, data1 FROM boundary_condition_data_adists " +
|
||||
f"WHERE bc = '{bc.id}'"
|
||||
)
|
||||
|
||||
new.append(bc)
|
||||
# Write data
|
||||
for v in values:
|
||||
data0 = bc._types[0](v[1])
|
||||
data1 = bc._types[1](v[2])
|
||||
# Replace data at pos ind
|
||||
bc._data.append((data0, data1))
|
||||
|
||||
new.append(bc)
|
||||
|
||||
return new
|
||||
|
||||
@@ -194,6 +196,11 @@ class BoundaryConditionAdisTS(SQLSubModel):
|
||||
def type(self):
|
||||
return self._type
|
||||
|
||||
@type.setter
|
||||
def type(self, type):
|
||||
self._type = type
|
||||
self._status.modified()
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return self._data.copy()
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
# BoundaryConditionsAdisTSList.py -- Pamhyr
|
||||
# Copyright (C) 2023-2024 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/>.
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from copy import copy
|
||||
from tools import trace, timer
|
||||
|
||||
from Model.Tools.PamhyrList import PamhyrModelList
|
||||
from Model.Except import NotImplementedMethodeError
|
||||
|
||||
from Model.BoundaryConditionsAdisTS.BoundaryConditionAdisTS import BoundaryConditionAdisTS
|
||||
|
||||
class BoundaryConditionsAdisTSList(PamhyrModelList):
|
||||
_sub_classes = [
|
||||
BoundaryConditionAdisTS,
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def _db_load(cls, execute, data=None):
|
||||
new = cls(status=data['status'])
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
new._lst = BoundaryConditionAdisTS._db_load(
|
||||
execute, data
|
||||
)
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
execute("DELETE FROM boundary_condition_adists")
|
||||
|
||||
if data is None:
|
||||
data = {}
|
||||
|
||||
for bc in self._lst:
|
||||
bc._db_save(execute, data=data)
|
||||
|
||||
return True
|
||||
|
||||
def new(self, index, pollutant):
|
||||
n = BoundaryConditionAdisTS(pollutant=pollutant, status=self._status)
|
||||
self._lst.insert(index, n)
|
||||
self._status.modified()
|
||||
return n
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user