Failed to fetch fork details. Try again later.
-
Delaigue Olivier authoredc3cb2324
Forked from
HYCAR-Hydro / airGR
Source project has a limited visibility.
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# OutputKpAdists.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
from tools import (
trace, timer,
old_pamhyr_date_to_timestamp,
date_iso_to_timestamp,
date_dmy_to_timestamp,
)
from Model.Tools.PamhyrDB import SQLSubModel
from Model.Except import NotImplementedMethodeError
logger = logging.getLogger()
class OutputKpAdists(SQLSubModel):
_sub_classes = []
_id_cnt = 0
def __init__(self, id: int = -1, reach = None, kp = None, title: str = "", status=None):
super(OutputKpAdists, self).__init__()
self._status = status
if id == -1:
self.id = OutputKpAdists._id_cnt
else:
self.id = id
self._reach = reach
self._kp = kp
self._title = str(title)
self._enabled = True
OutputKpAdists._id_cnt = max(
OutputKpAdists._id_cnt + 1, self.id)
@property
def reach(self):
return self._reach
@reach.setter
def reach(self, reach_id):
self._reach = reach_id
self._status.modified()
@property
def kp(self):
return self._kp
@kp.setter
def kp(self, profile_id):
self._kp = profile_id
self._status.modified()
@property
def title(self):
return self._title
@title.setter
def title(self, title):
self._title = title
self._status.modified()
@classmethod
def _db_create(cls, execute):
sql = (
"CREATE TABLE OutputKpAdists(" +
"id INTEGER NOT NULL PRIMARY KEY, " +
"reach INTEGER NOT NULL, " +
"kp REAL NOT NULL, " +
"title TEXT NOT NULL, " +
"FOREIGN KEY(reach) REFERENCES river_reach(id)" +
")"
)
execute(sql)
return cls._create_submodel(execute)
@classmethod
def _db_update(cls, execute, version):
return True
@classmethod
def _db_load(cls, execute, data=None):
new = []
#reach = data["reach"]
#profile = data["profile"]
status = data["status"]
table = execute(
"SELECT id, reach, kp, title " +
f"FROM OutputKpAdists"
)
if table is not None:
for row in table:
id = row[0]
id_reach = row[1]
id_kp = row[2]
title = row[3]
new_output = cls(
id=id, reach=id_reach,
kp=id_kp, title=title,
status=status
)
new.append(new_output)
return new
def _db_save(self, execute, data=None):
execute(f"DELETE FROM OutputKpAdists WHERE id = {self.id}")
sql = (
"INSERT INTO " +
"OutputKpAdists(id, reach, kp, title) " +
"VALUES (" +
f"{self.id}, {self._reach}, {self._kp}, " +
f"'{self._db_format(self._title)}'" +
")"
)
execute(sql)
return True
@property
def enabled(self):
return self._enabled
@enabled.setter
def enabled(self, enabled):
self._enabled = enabled
self._status.modified()