mirror of https://gitlab.com/pamhyr/pamhyr2
INI table db
parent
7df0750c58
commit
6f3e1e31f0
|
|
@ -62,7 +62,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||
@classmethod
|
||||
def _db_create(cls, execute):
|
||||
execute("""
|
||||
CREATE TABLE initial_conditions(
|
||||
CREATE TABLE initial_conditions_adists(
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
pollutant INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
|
|
@ -93,9 +93,11 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||
table = execute(
|
||||
"SELECT id, pollutant, name, concentration, eg, em, ed, " +
|
||||
"enabled " +
|
||||
"FROM initial_conditions"
|
||||
"FROM initial_conditions_adists"
|
||||
)
|
||||
|
||||
print("db load ic adists : ", table)
|
||||
|
||||
if table is not None:
|
||||
for row in table:
|
||||
IC_id = row[0]
|
||||
|
|
@ -113,6 +115,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||
status=data['status']
|
||||
)
|
||||
|
||||
IC.pollutant = pollutant
|
||||
IC.concentration = concentration
|
||||
IC.eg = eg
|
||||
IC.em = em
|
||||
|
|
@ -127,31 +130,31 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
execute(f"DELETE FROM initial_conditions WHERE id = {self.id}")
|
||||
execute(f"DELETE FROM initial_conditions_adists WHERE id = {self.id}")
|
||||
|
||||
pollutant = -1
|
||||
if self.pollutant is not None:
|
||||
pollutant = self.pollutant
|
||||
|
||||
concentration = -1
|
||||
concentration = -1.
|
||||
if self.concentration is not None:
|
||||
concentration = self.concentration
|
||||
|
||||
eg = -1
|
||||
eg = -1.
|
||||
if self.eg is not None:
|
||||
eg = self.eg
|
||||
|
||||
em = -1
|
||||
em = -1.
|
||||
if self.em is not None:
|
||||
em = self.em
|
||||
|
||||
ed = -1
|
||||
ed = -1.
|
||||
if self.ed is not None:
|
||||
ed = self.ed
|
||||
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"initial_conditions(" +
|
||||
"initial_conditions_adists(" +
|
||||
"id, pollutant, name, concentration, " +
|
||||
"eg, em, ed, enabled" +
|
||||
") " +
|
||||
|
|
@ -160,6 +163,7 @@ class InitialConditionsAdisTS(SQLSubModel):
|
|||
f"{concentration}, {eg}, {em}, {ed}, {self._enabled}" +
|
||||
")"
|
||||
)
|
||||
|
||||
execute(sql)
|
||||
|
||||
data['ic_default_id'] = self.id
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ class InitialConditionsAdisTSList(PamhyrModelList):
|
|||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
print("db save ic adists")
|
||||
execute("DELETE FROM initial_conditions")
|
||||
|
||||
if data is None:
|
||||
|
|
|
|||
|
|
@ -234,6 +234,7 @@ class River(Graph, SQLSubModel):
|
|||
REPLineList,
|
||||
OutputKpAdistsList,
|
||||
PollutantsList,
|
||||
InitialConditionsAdisTSList,
|
||||
]
|
||||
|
||||
def __init__(self, status=None):
|
||||
|
|
|
|||
|
|
@ -138,7 +138,6 @@ class MoveCommand(QUndoCommand):
|
|||
else:
|
||||
self._ics.move_down(self._i)
|
||||
|
||||
|
||||
class InsertCommand(QUndoCommand):
|
||||
def __init__(self, ics, row, ic):
|
||||
QUndoCommand.__init__(self)
|
||||
|
|
@ -155,7 +154,6 @@ class InsertCommand(QUndoCommand):
|
|||
for ic in self._ic:
|
||||
self._ics.insert(self._row, ic)
|
||||
|
||||
|
||||
class DuplicateCommand(QUndoCommand):
|
||||
def __init__(self, ics, rows, ic):
|
||||
QUndoCommand.__init__(self)
|
||||
|
|
|
|||
|
|
@ -36,9 +36,7 @@ from PyQt5.QtWidgets import (
|
|||
from View.Tools.PamhyrTable import PamhyrTableModel
|
||||
|
||||
from View.InitialConditionsAdisTS.UndoCommand import (
|
||||
SetCommand, AddCommand, DelCommand,
|
||||
SortCommand, MoveCommand, InsertCommand,
|
||||
DuplicateCommand, GenerateCommand,
|
||||
SetCommand,
|
||||
)
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
|
@ -92,7 +90,7 @@ class InitialConditionTableDefaultModel(PamhyrTableModel):
|
|||
if self._headers[column] is not None:
|
||||
self._undo.push(
|
||||
SetCommand(
|
||||
self._lst, row, self._headers[column], value
|
||||
self._data, row, self._headers[column], value
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
|
|
@ -102,36 +100,6 @@ class InitialConditionTableDefaultModel(PamhyrTableModel):
|
|||
self.dataChanged.emit(index, index)
|
||||
return True
|
||||
|
||||
def paste(self, index, header, data):
|
||||
if len(header) != 0:
|
||||
logger.error("Unexpected header in IC past data")
|
||||
return
|
||||
|
||||
if len(data) == 0:
|
||||
logger.error("Empty data")
|
||||
return
|
||||
|
||||
if len(data[0]) != 3:
|
||||
logger.error(f"Unexpected data size: [{data[0]}, ...]")
|
||||
return
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
self._undo.push(
|
||||
InsertCommand(
|
||||
self._lst, index,
|
||||
list(
|
||||
map(
|
||||
lambda d: self._lst.new_from_data(*d),
|
||||
data
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def undo(self):
|
||||
self._undo.undo()
|
||||
self.layoutChanged.emit()
|
||||
|
|
@ -140,10 +108,3 @@ class InitialConditionTableDefaultModel(PamhyrTableModel):
|
|||
self._undo.redo()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def generate(self, generator, param):
|
||||
self._undo.push(
|
||||
GenerateCommand(
|
||||
self._lst, generator, param
|
||||
)
|
||||
)
|
||||
self.layoutChanged.emit()
|
||||
|
|
|
|||
|
|
@ -23,170 +23,57 @@ from PyQt5.QtWidgets import (
|
|||
QMessageBox, QUndoCommand, QUndoStack,
|
||||
)
|
||||
|
||||
from Model.InitialConditions.InitialConditions import InitialConditions
|
||||
from Model.InitialConditions.InitialConditionsDict import InitialConditionsDict
|
||||
from Model.InitialConditionsAdisTS.InitialConditionsAdisTS import InitialConditionsAdisTS
|
||||
from Model.InitialConditionsAdisTS.InitialConditionsAdisTSList import InitialConditionsAdisTSList
|
||||
|
||||
|
||||
class SetCommand(QUndoCommand):
|
||||
def __init__(self, ics, row, column, new_value):
|
||||
def __init__(self, data, row, column, new_value):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._ics = ics
|
||||
self._data = data
|
||||
self._row = row
|
||||
self._column = column
|
||||
self._old = self._ics.get(self._row)[column]
|
||||
|
||||
if self._column == "name":
|
||||
self._old = self._data[self._row].name
|
||||
elif self._column == "concentration":
|
||||
print(self._column, self._data[self._row].concentration, new_value)
|
||||
self._old = self._data[self._row].concentration
|
||||
elif self._column == "eg":
|
||||
self._old = self._data[self._row].eg
|
||||
elif self._column == "em":
|
||||
self._old = self._data[self._row].em
|
||||
elif self._column == "ed":
|
||||
self._old = self._data[self._row].ed
|
||||
|
||||
_type = float
|
||||
if column == "name" or column == "comment":
|
||||
if column == "name":
|
||||
_type = str
|
||||
|
||||
self._new = _type(new_value)
|
||||
|
||||
def undo(self):
|
||||
self._ics.get(self._row)[self._column] = self._old
|
||||
if self._column == "name":
|
||||
self._data[self._row].name = self._old
|
||||
elif self._column == "concentration":
|
||||
self._data[self._row].concentration = self._old
|
||||
elif self._column == "eg":
|
||||
self._data[self._row].eg = self._old
|
||||
elif self._column == "em":
|
||||
self._data[self._row].em = self._old
|
||||
elif self._column == "ed":
|
||||
self._data[self._row].ed = self._old
|
||||
|
||||
def redo(self):
|
||||
self._ics.get(self._row)[self._column] = self._new
|
||||
if self._column == "name":
|
||||
self._data[self._row].name = self._new
|
||||
elif self._column == "concentration":
|
||||
self._data[self._row].concentration = self._new
|
||||
elif self._column == "eg":
|
||||
self._data[self._row].eg = self._new
|
||||
elif self._column == "em":
|
||||
self._data[self._row].em = self._new
|
||||
elif self._column == "ed":
|
||||
self._data[self._row].ed = self._new
|
||||
|
||||
|
||||
class AddCommand(QUndoCommand):
|
||||
def __init__(self, ics, index):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._ics = ics
|
||||
self._index = index
|
||||
self._new = None
|
||||
|
||||
def undo(self):
|
||||
self._ics.delete_i([self._index])
|
||||
|
||||
def redo(self):
|
||||
if self._new is None:
|
||||
self._new = self._ics.new(self._index)
|
||||
else:
|
||||
self._ics.insert(self._index, self._new)
|
||||
|
||||
|
||||
class DelCommand(QUndoCommand):
|
||||
def __init__(self, ics, rows):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._ics = ics
|
||||
self._rows = rows
|
||||
|
||||
self._ic = []
|
||||
for row in rows:
|
||||
self._ic.append((row, self._ics.get(row)))
|
||||
self._ic.sort()
|
||||
|
||||
def undo(self):
|
||||
for row, el in self._ic:
|
||||
self._ics.insert(row, el)
|
||||
|
||||
def redo(self):
|
||||
self._ics.delete_i(self._rows)
|
||||
|
||||
|
||||
class SortCommand(QUndoCommand):
|
||||
def __init__(self, ics, _reverse):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._ics = ics
|
||||
self._reverse = _reverse
|
||||
|
||||
self._old = self._ics.data
|
||||
self._indexes = None
|
||||
|
||||
def undo(self):
|
||||
ll = self._ics.data
|
||||
self._ics.sort(
|
||||
key=lambda x: self._indexes[ll.index(x)]
|
||||
)
|
||||
|
||||
def redo(self):
|
||||
self._ics.sort(
|
||||
reverse=self._reverse,
|
||||
key=lambda x: x["kp"]
|
||||
)
|
||||
if self._indexes is None:
|
||||
self._indexes = list(
|
||||
map(
|
||||
lambda p: self._old.index(p),
|
||||
self._ics.data
|
||||
)
|
||||
)
|
||||
self._old = None
|
||||
|
||||
|
||||
class MoveCommand(QUndoCommand):
|
||||
def __init__(self, ics, up, i):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._ics = ics
|
||||
self._up = up == "up"
|
||||
self._i = i
|
||||
|
||||
def undo(self):
|
||||
if self._up:
|
||||
self._ics.move_up(self._i)
|
||||
else:
|
||||
self._ics.move_down(self._i)
|
||||
|
||||
def redo(self):
|
||||
if self._up:
|
||||
self._ics.move_up(self._i)
|
||||
else:
|
||||
self._ics.move_down(self._i)
|
||||
|
||||
|
||||
class InsertCommand(QUndoCommand):
|
||||
def __init__(self, ics, row, ic):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._ics = ics
|
||||
self._row = row
|
||||
self._ic = deepcopy(ic)
|
||||
self._ic.reverse()
|
||||
|
||||
def undo(self):
|
||||
self._ics.delete(self._ic)
|
||||
|
||||
def redo(self):
|
||||
for ic in self._ic:
|
||||
self._ics.insert(self._row, ic)
|
||||
|
||||
|
||||
class DuplicateCommand(QUndoCommand):
|
||||
def __init__(self, ics, rows, ic):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._ics = ics
|
||||
self._rows = rows
|
||||
self._ic = deepcopy(ic)
|
||||
self._ic.reverse()
|
||||
|
||||
def undo(self):
|
||||
self._ics.delete(self._ic)
|
||||
|
||||
def redo(self):
|
||||
for ic in self._ics:
|
||||
self._ics.insert(self._rows[0], ic)
|
||||
|
||||
|
||||
class GenerateCommand(QUndoCommand):
|
||||
def __init__(self, ics, generator, param):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._ics = ics
|
||||
self._param = param
|
||||
self._copy = self._ics.data
|
||||
self._generator = generator
|
||||
|
||||
def undo(self):
|
||||
self._ics.data = self._copy
|
||||
|
||||
def redo(self):
|
||||
if self._generator == "growing":
|
||||
self._ics.generate_growing_constante_height(self._param)
|
||||
elif self._generator == "discharge":
|
||||
self._ics.generate_discharge(self._param)
|
||||
|
|
|
|||
|
|
@ -43,9 +43,7 @@ from PyQt5.QtWidgets import (
|
|||
from Modules import Modules
|
||||
|
||||
from View.InitialConditionsAdisTS.UndoCommand import (
|
||||
SetCommand, AddCommand, DelCommand,
|
||||
SortCommand, MoveCommand, InsertCommand,
|
||||
DuplicateCommand,
|
||||
SetCommand,
|
||||
)
|
||||
|
||||
from View.InitialConditionsAdisTS.TableDefault import (
|
||||
|
|
@ -68,7 +66,6 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
|
|||
def __init__(self, data=None, study=None, config=None, parent=None):
|
||||
self._data = []
|
||||
self._data.append(data)
|
||||
#print(self._data.name, self._data.concentration, self._data.eg, self._data.em, self._data.ed)
|
||||
trad = IcAdisTSTranslate()
|
||||
|
||||
name = (
|
||||
|
|
@ -108,7 +105,6 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
|
|||
table.setModel(self._table)
|
||||
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||
#table.verticalHeader()
|
||||
table.setAlternatingRowColors(True)
|
||||
|
||||
def index_selected_row(self):
|
||||
|
|
|
|||
|
|
@ -194,6 +194,7 @@ class PollutantsWindow(PamhyrWindow):
|
|||
|
||||
for row in rows:
|
||||
pollutant_id = self._pollutants_lst.get(row).id
|
||||
|
||||
ics_adists = next(filter(lambda x: x.pollutant == pollutant_id,
|
||||
self._study.river.initial_conditions_adists.lst))
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue