mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Status: Rename SavedStatus to StudyStatus and add scenario to StudyStatus.
This commit is contained in:
1 parent
7274ff5e2d
commit
71b631fbe4
8 files changed
+56
-28
No files matched your search
@@ -0,0 +1,81 @@
|
||||
# Status.py -- Pamhyr model status class
|
||||
# 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
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class StudyStatus(object):
|
||||
def __init__(self, scenario=None):
|
||||
super(StudyStatus, self).__init__()
|
||||
self._scenario = scenario
|
||||
self._saved = True
|
||||
|
||||
@property
|
||||
def scenario_id(self):
|
||||
if self._scenario is None:
|
||||
return -1
|
||||
|
||||
return self._scenario.id
|
||||
|
||||
@property
|
||||
def scenario(self):
|
||||
return self._scenario
|
||||
|
||||
@scenario.setter
|
||||
def scenario(self, scenario):
|
||||
self._scenario = scenario
|
||||
|
||||
@property
|
||||
def version(self):
|
||||
if self._scenario is None:
|
||||
return 0
|
||||
|
||||
return self._scenario.revision
|
||||
|
||||
@version.setter
|
||||
def version(self, version):
|
||||
if self._scenario is None:
|
||||
return
|
||||
|
||||
self._scenario.revision = version
|
||||
|
||||
def str_display(self):
|
||||
if self._scenario is None:
|
||||
return ""
|
||||
|
||||
return f"{self._scenario.name}"
|
||||
|
||||
def is_saved(self):
|
||||
return self._saved
|
||||
|
||||
def save(self):
|
||||
logger.debug("model status set as saved")
|
||||
self._saved = True
|
||||
|
||||
def modified(self):
|
||||
if self._saved:
|
||||
self.version += 1
|
||||
|
||||
logger.debug(
|
||||
"STATUS: Model status set as modified " +
|
||||
f"at version {self.version}"
|
||||
)
|
||||
|
||||
self._saved = False
|
||||
Reference in new issue
Block a user