mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Fix pep8
This commit is contained in:
1 parent
d4c596a6fe
commit
89c6e8bb29
10 files changed
+89
-34
No files matched your search
+1
-1
@@ -201,7 +201,7 @@ class Study(SQLModel):
|
||||
self.status.modified()
|
||||
|
||||
def change_start_date(self, date, preserve_dates=False):
|
||||
"""Change the origin, optionally preserving calendar dates of all series."""
|
||||
"""Change the origin, optionally preserving series calendar dates."""
|
||||
new_date = parse_datetime(date)
|
||||
offset = (parse_datetime(self.date) - new_date).total_seconds()
|
||||
if preserve_dates and offset:
|
||||
|
||||
+37
-15
@@ -2,9 +2,15 @@
|
||||
from Model.BoundaryCondition.BoundaryCondition import BoundaryCondition
|
||||
from Model.LateralContribution.LateralContribution import LateralContribution
|
||||
from Model.WeatherParameters.WeatherParameters import WeatherParameters
|
||||
from Model.BoundaryConditionsAdisTS.BoundaryConditionAdisTS import BoundaryConditionAdisTS
|
||||
from Model.LateralContributionsAdisTS.LateralContributionAdisTS import LateralContributionAdisTS
|
||||
from Model.BoundaryConditionsTemperature.BoundaryConditionTemperature import BoundaryConditionTemperature
|
||||
from Model.BoundaryConditionsAdisTS.BoundaryConditionAdisTS import (
|
||||
BoundaryConditionAdisTS
|
||||
)
|
||||
from Model.LateralContributionsAdisTS.LateralContributionAdisTS import (
|
||||
LateralContributionAdisTS
|
||||
)
|
||||
from Model.BoundaryConditionsTemperature.BoundaryConditionTemperature import (
|
||||
BoundaryConditionTemperature
|
||||
)
|
||||
|
||||
|
||||
def shift_river_times(river, offset):
|
||||
@@ -12,10 +18,14 @@ def shift_river_times(river, offset):
|
||||
seen = set()
|
||||
|
||||
def collect(obj, data):
|
||||
temporal = isinstance(obj, (BoundaryConditionAdisTS,
|
||||
LateralContributionAdisTS,
|
||||
BoundaryConditionTemperature))
|
||||
if isinstance(obj, (BoundaryCondition, LateralContribution, WeatherParameters)):
|
||||
temporal = isinstance(obj, (
|
||||
BoundaryConditionAdisTS,
|
||||
LateralContributionAdisTS,
|
||||
BoundaryConditionTemperature
|
||||
))
|
||||
if isinstance(obj, (
|
||||
BoundaryCondition, LateralContribution, WeatherParameters
|
||||
)):
|
||||
temporal = bool(obj.header) and obj.header[0] == 'time'
|
||||
if temporal:
|
||||
for point in obj._data:
|
||||
@@ -24,34 +34,46 @@ def shift_river_times(river, offset):
|
||||
seen.add(id(point))
|
||||
|
||||
river._data_traversal(modifier=collect)
|
||||
print(f"Shifting {len(changes)} temporal points by {offset} seconds.")
|
||||
for point, value in changes:
|
||||
print(f" {point[0]} -> {value}")
|
||||
# This is a global change of origin, not a scenario-specific edit.
|
||||
point[0] = value
|
||||
|
||||
|
||||
def shift_database_times(connection, offset):
|
||||
tables = [
|
||||
('boundary_condition_data', 'boundary_condition', 'bc', BoundaryCondition),
|
||||
('lateral_contribution_data', 'lateral_contribution', 'lc', LateralContribution),
|
||||
('weather_parameters_data', 'weather_parameters', 'wp', WeatherParameters),
|
||||
(
|
||||
'boundary_condition_data', 'boundary_condition',
|
||||
'bc', BoundaryCondition
|
||||
),
|
||||
(
|
||||
'lateral_contribution_data', 'lateral_contribution',
|
||||
'lc', LateralContribution
|
||||
),
|
||||
(
|
||||
'weather_parameters_data', 'weather_parameters',
|
||||
'wp', WeatherParameters
|
||||
),
|
||||
('boundary_condition_data_adists', None, None, None),
|
||||
('lateral_contribution_data_adists', None, None, None),
|
||||
('boundary_condition_data_temperature', None, None, None),
|
||||
]
|
||||
for table, parent, fk, model in tables:
|
||||
if model is None:
|
||||
rows = connection.execute(f'SELECT rowid, data0 FROM {table}').fetchall()
|
||||
rows = connection.execute(
|
||||
f'SELECT rowid, data0 FROM {table}'
|
||||
).fetchall()
|
||||
else:
|
||||
rows = []
|
||||
for kind, in connection.execute(f'SELECT DISTINCT type FROM {parent}'):
|
||||
for kind, in connection.execute(
|
||||
f'SELECT DISTINCT type FROM {parent}'
|
||||
):
|
||||
headers = model._get_ctor_from_type(kind)().header
|
||||
if not headers or headers[0] != 'time':
|
||||
continue
|
||||
rows.extend(connection.execute(
|
||||
f'SELECT d.rowid, d.data0 FROM {table} d JOIN {parent} p '
|
||||
f'ON p.pamhyr_id=d.{fk} AND p.scenario=d.scenario WHERE p.type=?',
|
||||
f'ON p.pamhyr_id=d.{fk} AND p.scenario=d.scenario '
|
||||
f'WHERE p.type=?',
|
||||
(kind,)
|
||||
).fetchall())
|
||||
connection.executemany(
|
||||
|
||||
@@ -98,7 +98,8 @@ class TableModel(PamhyrTableModel):
|
||||
value = timestamp_to_old_pamhyr_date(int(v))
|
||||
else:
|
||||
value = format_datetime(
|
||||
parse_datetime(self.start_date) + timedelta(seconds=float(v))
|
||||
parse_datetime(self.start_date)
|
||||
+ timedelta(seconds=float(v))
|
||||
)
|
||||
else:
|
||||
value = f"{v}"
|
||||
|
||||
@@ -89,7 +89,8 @@ class TableModel(PamhyrTableModel):
|
||||
value = timestamp_to_old_pamhyr_date(int(v))
|
||||
else:
|
||||
value = format_datetime(
|
||||
parse_datetime(self.start_date) + timedelta(seconds=float(v))
|
||||
parse_datetime(self.start_date)
|
||||
+ timedelta(seconds=float(v))
|
||||
)
|
||||
else:
|
||||
value = f"{v}"
|
||||
|
||||
@@ -89,7 +89,8 @@ class TableModel(PamhyrTableModel):
|
||||
value = timestamp_to_old_pamhyr_date(int(v))
|
||||
else:
|
||||
value = format_datetime(
|
||||
parse_datetime(self.start_date) + timedelta(seconds=float(v))
|
||||
parse_datetime(self.start_date)
|
||||
+ timedelta(seconds=float(v))
|
||||
)
|
||||
else:
|
||||
value = f"{v}"
|
||||
|
||||
@@ -78,7 +78,8 @@ class TableModel(PamhyrTableModel):
|
||||
value = timestamp_to_old_pamhyr_date(int(v))
|
||||
else:
|
||||
value = format_datetime(
|
||||
parse_datetime(self.start_date) + timedelta(seconds=float(v))
|
||||
parse_datetime(self.start_date)
|
||||
+ timedelta(seconds=float(v))
|
||||
)
|
||||
else:
|
||||
value = f"{v}"
|
||||
|
||||
@@ -92,7 +92,8 @@ class TableModel(PamhyrTableModel):
|
||||
value = timestamp_to_old_pamhyr_date_adists(int(v))
|
||||
else:
|
||||
value = format_datetime(
|
||||
parse_datetime(self.start_date) + timedelta(seconds=float(v))
|
||||
parse_datetime(self.start_date)
|
||||
+ timedelta(seconds=float(v))
|
||||
)
|
||||
else:
|
||||
value = f"{v}"
|
||||
|
||||
+31
-10
@@ -174,14 +174,20 @@ All right reserved.
|
||||
|
||||
def accept(self):
|
||||
preserve_dates = False
|
||||
if (self._study is not None
|
||||
if (
|
||||
self._study is not None
|
||||
and self._study.time_system == "date"
|
||||
and self.get_radio_button("radioButton_date")):
|
||||
and self.get_radio_button("radioButton_date")
|
||||
):
|
||||
old_date = parse_datetime(self._study.date)
|
||||
new_date = parse_datetime(self.get_datetime_edit("dateTimeEdit_date"))
|
||||
new_date = parse_datetime(
|
||||
self.get_datetime_edit("dateTimeEdit_date")
|
||||
)
|
||||
if new_date != old_date:
|
||||
dialog = QMessageBox(self)
|
||||
dialog.setWindowTitle(_translate("Study", "Change simulation start date?"))
|
||||
dialog.setWindowTitle(_translate(
|
||||
"Study", "Change simulation start date?"
|
||||
))
|
||||
dialog.setText(_translate(
|
||||
"Study", "How should the data dates change?"
|
||||
))
|
||||
@@ -189,10 +195,20 @@ All right reserved.
|
||||
"Study",
|
||||
"Previous start: {old}\nNew start: {new}\n\n"
|
||||
"Shift dates: keep elapsed simulation times unchanged.\n"
|
||||
"Keep dates: adjust elapsed times so calendar dates stay unchanged."
|
||||
).format(old=format_datetime(old_date), new=format_datetime(new_date)))
|
||||
shift = dialog.addButton(_translate("Study", "Shift dates"), QMessageBox.AcceptRole)
|
||||
keep = dialog.addButton(_translate("Study", "Keep dates"), QMessageBox.ActionRole)
|
||||
"Keep dates: adjust elapsed times so calendar dates "
|
||||
"stay unchanged."
|
||||
).format(
|
||||
old=format_datetime(old_date),
|
||||
new=format_datetime(new_date)
|
||||
))
|
||||
shift = dialog.addButton(
|
||||
_translate("Study", "Shift dates"),
|
||||
QMessageBox.AcceptRole
|
||||
)
|
||||
keep = dialog.addButton(
|
||||
_translate("Study", "Keep dates"),
|
||||
QMessageBox.ActionRole
|
||||
)
|
||||
cancel = dialog.addButton(QMessageBox.Cancel)
|
||||
dialog.setDefaultButton(cancel)
|
||||
dialog.exec()
|
||||
@@ -207,7 +223,10 @@ All right reserved.
|
||||
parse_datetime(self.get_datetime_edit("dateTimeEdit_date"))
|
||||
!= parse_datetime(self._study.date)
|
||||
)
|
||||
if (mode_changed or date_changed) and not self._close_study_editors():
|
||||
if (
|
||||
(mode_changed or date_changed)
|
||||
and not self._close_study_editors()
|
||||
):
|
||||
return
|
||||
|
||||
name = self.get_line_edit_text("lineEdit_name")
|
||||
@@ -226,7 +245,9 @@ All right reserved.
|
||||
self._study.description = description
|
||||
if self.get_radio_button("radioButton_date"):
|
||||
date = self.get_datetime_edit("dateTimeEdit_date")
|
||||
self._study.change_start_date(date, preserve_dates=preserve_dates)
|
||||
self._study.change_start_date(
|
||||
date, preserve_dates=preserve_dates
|
||||
)
|
||||
else:
|
||||
self._study.use_time()
|
||||
|
||||
|
||||
@@ -64,11 +64,17 @@ class PamhyrTextDelegate(QStyledItemDelegate):
|
||||
class PamhyrTableModel(QAbstractTableModel):
|
||||
@property
|
||||
def time_system(self):
|
||||
return self._study.time_system if self._study is not None else self._opt_data
|
||||
return (
|
||||
self._study.time_system
|
||||
if self._study is not None else self._opt_data
|
||||
)
|
||||
|
||||
@property
|
||||
def start_date(self):
|
||||
return self._study.date if self._study is not None else self._start_date
|
||||
return (
|
||||
self._study.date
|
||||
if self._study is not None else self._start_date
|
||||
)
|
||||
|
||||
def date_to_elapsed_seconds(self, value):
|
||||
"""Convert an accepted calendar date to elapsed simulation seconds."""
|
||||
|
||||
@@ -79,7 +79,8 @@ class TableModel(PamhyrTableModel):
|
||||
value = timestamp_to_old_pamhyr_date(int(v))
|
||||
else:
|
||||
value = format_datetime(
|
||||
parse_datetime(self.start_date) + timedelta(seconds=float(v))
|
||||
parse_datetime(self.start_date)
|
||||
+ timedelta(seconds=float(v))
|
||||
)
|
||||
else:
|
||||
value = f"{v}"
|
||||
|
||||
Reference in new issue
Block a user