mirror of https://gitlab.com/pamhyr/pamhyr2
output table
parent
1b3ce91582
commit
f53289ef1b
|
|
@ -0,0 +1,103 @@
|
||||||
|
# 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(LateralContribution, self).__init__()
|
||||||
|
|
||||||
|
self._status = status
|
||||||
|
|
||||||
|
if id == -1:
|
||||||
|
self.id = LateralContribution._id_cnt
|
||||||
|
else:
|
||||||
|
self.id = id
|
||||||
|
|
||||||
|
self._reach = reach
|
||||||
|
self._kp = kp
|
||||||
|
self._title = str(title)
|
||||||
|
|
||||||
|
LateralContribution._id_cnt = max(
|
||||||
|
LateralContribution._id_cnt + 1, self.id)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _db_create(cls, execute):
|
||||||
|
execute("""
|
||||||
|
CREATE TABLE OutputKpAdists(
|
||||||
|
id INTEGER NOT NULL PRIMARY KEY,
|
||||||
|
reach INTEGER NOT NULL,
|
||||||
|
kp INTEGER NOT NULL,
|
||||||
|
title TEXT NOT NULL,
|
||||||
|
FOREIGN KEY(edge) REFERENCES river_reach(id)
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue