An error occurred while loading the file. Please try again.
-
Theophile Terraz authored143f468c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# TableAdisTS.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 -*-
import logging
import traceback
from tools import timer, trace
from PyQt5.QtGui import (
QKeySequence, QColor
)
from PyQt5.QtCore import (
Qt, QAbstractTableModel, QModelIndex,
QVariant, pyqtSlot, QCoreApplication,
)
from PyQt5.QtWidgets import (
QMessageBox, QUndoCommand, QUndoStack,
QStyledItemDelegate, QLineEdit, QAbstractItemView,
QComboBox,
)
from View.Tools.PamhyrTable import PamhyrTableModel
from View.Results.translate import *
logger = logging.getLogger()
_translate = QCoreApplication.translate
class TableModel(PamhyrTableModel):
def _setup_lst(self):
_river = self._data.river
###print("//////////////////opt_data: ", self._opt_data)
###print("data: ", self._data)
###print("river: ", _river)
###print("reaches: ", _river.reachs)
if self._opt_data == "reach":
self._lst = _river.reachs
###print("optreach: ", self._lst)
elif self._opt_data == "profile":
self._lst = _river.reach(0).profiles
elif self._opt_data == "raw_data":
self._lst = _river.reach(0).profiles
elif self._opt_data == "pollutants":
tmp_list = self._data.pollutants_list.copy()
tmp_list.remove("total_sediment")
###print(type(tmp_list))
#tmp_list.insert(len(tmp_list), "total_sediment")
self._lst = tmp_list
###print("=====table pollutants: ", self._lst)
def __init__(self, **kwargs):
self._timestamp = 0.0
super(TableModel, self).__init__(**kwargs)
def data(self, index, role=Qt.DisplayRole):
if role != Qt.ItemDataRole.DisplayRole:
return QVariant()
row = index.row()
column = index.column()
if self._opt_data == "reach":
if self._headers[column] == "name":
v = self._lst[row].name
return str(v)
elif self._opt_data == "pollutants":
if self._headers[column] == "name":
v = self._lst[row]
return str(v)
elif self._opt_data == "profile":
if self._headers[column] == "name":
v = self._lst[row].name
return str(v)
elif self._headers[column] == "rk":
v = self._lst[row].rk
return f"{v:.4f}"
elif self._opt_data == "raw_data":
p = self._lst[row]
if self._headers[column] == "name":
if p.name == "":
return f"{p.rk:.4f}"
return f"{p.name}"
tmp_list = self._data.pollutants_list.copy()
tmp_list.remove("total_sediment")
tmp_list2 = self._data.pollutants_list.copy()
print("=============================list polutants table raw: ", tmp_list)
print("=============================list polutants table raw: ", tmp_list2)
for pol in tmp_list:
pol_index = tmp_list2.index(pol)
print("=============================pol index: ", pol_index)
header_name = pol + " Concentration"
print("=============================Headers: ", self._headers[column])
print("=============================Headers: ", header_name)
if self._headers[column] == header_name:
print("=============================Headers: ", self._headers[column])
print("=============================Headers: ", header_name)
v = self._lst[row].get_ts_key(self._timestamp, "pols")[pol_index][0]
return f"{v:.4f}"
elif self._headers[column] == pol + " Mass":
m1 = self._lst[row].get_ts_key(self._timestamp, "pols")[pol_index][1]
m2 = self._lst[row].get_ts_key(self._timestamp, "pols")[pol_index][2]
m3 = self._lst[row].get_ts_key(self._timestamp, "pols")[pol_index][3]
v = m1 + m2 + m3
return f"{v:.4f}"
return QVariant()
def update(self, reach):
_river = self._data.river
if self._opt_data == "reach":
self._lst = _river.reachs
elif self._opt_data == "profile" or self._opt_data == "raw_data":
self._lst = _river.reach(reach).profiles
self.layoutChanged.emit()
@property
def timestamp(self):
return self._timestamp
@timestamp.setter
def timestamp(self, timestamp):
self._timestamp = timestamp
self.layoutChanged.emit()