pep8: Fix code format for model.

setup.py
Pierre-Antoine Rouby 2023-10-11 11:47:09 +02:00
parent 2c592b25b9
commit 9f2b81d385
17 changed files with 106 additions and 68 deletions

View File

@ -188,7 +188,7 @@ class BoundaryCondition(SQLSubModel):
@classmethod
def time_convert(cls, data):
if type(data) == str and data.count(":") == 3:
if data is str and data.count(":") == 3:
return old_pamhyr_date_to_timestamp(data)
return int(data)
@ -302,10 +302,10 @@ class BoundaryCondition(SQLSubModel):
return self.data[index]
def get_range(self, _range):
l = []
lst = []
for r in _range:
l.append(r)
return l
lst.append(r)
return lst
def _set_i_c_v(self, index, column, value):
v = list(self._data[index])

View File

@ -74,16 +74,16 @@ class BoundaryConditionList(PamhyrModelListWithTab):
def __copy__(self):
new = BoundaryConditionList()
for l in self._tabs:
new.tabs[l] = self._tabs[l].copy()
for lst in self._tabs:
new.tabs[lst] = self._tabs[lst].copy()
return new
def __deepcopy__(self):
new = BoundaryConditionList()
for l in self._tabs:
new.tabs[l] = self._tabs[l].deepcopy()
for lst in self._tabs:
new.tabs[lst] = self._tabs[lst].deepcopy()
return new

View File

@ -82,12 +82,16 @@ class NotImplementedMethodeError(ExeceptionWithMessageBox):
self.alert()
def __str__(self):
class_type = self.obj
if self.obj.__class__ != type:
class_type = self.obj.__class__
return (
_translate("Exception", "Method") +
f" '{self.func.__name__}' " +
_translate("Exception", "not implemented") +
_translate("Exception", "for class") +
f" '{self.obj.__class__ if self.obj.__class__ != type else self.obj}'"
f" '{class_type}'"
)
def header(self):

View File

@ -92,7 +92,8 @@ class Friction(SQLSubModel):
ind = data["ind"]
execute(
"INSERT INTO " +
"friction(ind, begin_kp, end_kp, reach, begin_strickler, end_strickler) " +
"friction(ind, begin_kp, end_kp, " +
"reach, begin_strickler, end_strickler) " +
"VALUES (" +
f"{ind}, {self._begin_kp}, {self._end_kp}, " +
f"{self._edge.id}, " +

View File

@ -97,7 +97,7 @@ class PointXYZ(Point, SQLSubModel):
status=status
)
if sl == -1 or sl == None:
if sl == -1 or sl is None:
new._sl = None
else:
new._sl = next(

View File

@ -136,7 +136,7 @@ class ProfileXYZ(Profile, SQLSubModel):
status=status
)
if sl == -1 or sl == None:
if sl == -1 or sl is None:
new._sl = None
else:
new._sl = next(
@ -163,7 +163,8 @@ class ProfileXYZ(Profile, SQLSubModel):
sql = (
"INSERT OR REPLACE INTO " +
"geometry_profileXYZ(id, ind, name, reach, kp, num, code1, code2, sl) " +
"geometry_profileXYZ(id, ind, name, reach, " +
"kp, num, code1, code2, sl) " +
"VALUES (" +
f"{self.id}, {ind}, '{self._sql_format(self._name)}', " +
f"{self.reach.id}, {self.kp}, {self.num}, " +
@ -378,28 +379,28 @@ class ProfileXYZ(Profile, SQLSubModel):
if (first_named_point != last_named_point and
first_named_point.x != last_named_point.x):
vector = Vector1d(first_named_point, last_named_point)
normalized_direction_vec = vector.normalized_direction_vector()
norm_dir_vec = vector.normalized_direction_vector()
else:
vector = Vector1d(first_point_not_nan, last_point_not_nan)
normalized_direction_vec = vector.normalized_direction_vector()
norm_dir_vec = vector.normalized_direction_vector()
for point in self.points:
xi = point.x - first_named_point.x
yi = point.y - first_named_point.y
station_i = (normalized_direction_vec[0] * xi +
normalized_direction_vec[1] * yi)
station_i = (norm_dir_vec[0] * xi +
norm_dir_vec[1] * yi)
station.append(station_i)
constant = station[index_first_named_point]
elif first_named_point is None:
vector = Vector1d(first_point_not_nan, last_point_not_nan)
normalized_direction_vec = vector.normalized_direction_vector()
norm_dir_vec = vector.normalized_direction_vector()
for point in self.points:
xi = point.x - first_point_not_nan.x
yi = point.y - first_point_not_nan.y
station_i = (normalized_direction_vec[0] * xi +
normalized_direction_vec[1] * yi)
station_i = (norm_dir_vec[0] * xi +
norm_dir_vec[1] * yi)
station.append(station_i)
z_min = self.z_min()

View File

@ -102,7 +102,7 @@ class Reach(SQLSubModel):
@property
def name(self):
if self._parent == None:
if self._parent is None:
return ""
return self._parent.name
@ -345,12 +345,12 @@ class Reach(SQLSubModel):
for guide in guide_set:
self._guidelines[guide] = flatten(
map(
lambda l: list(
lambda lst: list(
# Filter point with name (we assume we have
# only one point by profile)
filter(
lambda p: p.name == guide,
l
lst
)
),
named_points
@ -385,7 +385,9 @@ class Reach(SQLSubModel):
reduce(
lambda acc, h: acc + h,
map(
lambda l: list(set(l).symmetric_difference(guide_set)),
lambda lst: list(
set(lst).symmetric_difference(guide_set)
),
points_name
),
[]
@ -469,7 +471,8 @@ class Reach(SQLSubModel):
"""Import a geometry from file (.ST or .st)
Args:
file_path_name: The absolute path of geometry file (.ST or .st) to import.
file_path_name: The absolute path of geometry file (.ST or .st)
to import.
Returns:
Nothing.

View File

@ -114,7 +114,8 @@ class Data(SQLSubModel):
execute(
"INSERT INTO " +
"initial_conditions(ind, name, comment, kp, discharge, height, reach) " +
"initial_conditions(ind, name, comment, kp, " +
"discharge, height, reach) " +
"VALUES (" +
f"{ind}, '{self._sql_format(self.name)}', " +
f"'{self._sql_format(self._comment)}', " +

View File

@ -154,7 +154,8 @@ class LateralContribution(SQLSubModel):
sql = (
"INSERT INTO " +
"lateral_contribution(id, name, type, tab, edge, begin_kp, end_kp) " +
"lateral_contribution(id, name, type, tab, " +
"edge, begin_kp, end_kp) " +
"VALUES (" +
f"{self.id}, '{self._sql_format(self._name)}', " +
f"'{self._sql_format(self._type)}', '{tab}', {edge}, " +
@ -187,7 +188,7 @@ class LateralContribution(SQLSubModel):
@classmethod
def time_convert(cls, data):
if type(data) == str and data.count(":") == 3:
if data is str and data.count(":") == 3:
return old_pamhyr_date_to_timestamp(data)
return int(data)
@ -338,10 +339,10 @@ class LateralContribution(SQLSubModel):
return self.data[index]
def get_range(self, _range):
l = []
lst = []
for r in _range:
l.append(r)
return l
lst.append(r)
return lst
def _set_i_c_v(self, index, column, value):
v = list(self._data[index])

View File

@ -71,16 +71,16 @@ class LateralContributionList(PamhyrModelListWithTab):
def __copy__(self):
new = LateralContributionList()
for l in self._tabs:
new.tabs[l] = self._tabs[l].copy()
for lst in self._tabs:
new.tabs[lst] = self._tabs[lst].copy()
return new
def __deepcopy__(self):
new = LateralContributionList()
for l in self._tabs:
new.tabs[l] = self._tabs[l].deepcopy()
for lst in self._tabs:
new.tabs[lst] = self._tabs[lst].deepcopy()
return new

View File

@ -75,7 +75,10 @@ class Edge(object):
@property
def name(self):
return self._name if self._name != "" else f"{self.node1.name} -> {self.node2.name}"
name = self._name
if self._name == "":
name = f"{self.node1.name} -> {self.node2.name}"
return name
def is_enable(self):
return self._enable

View File

@ -28,7 +28,9 @@ from Model.Geometry.Profile import Profile
from Model.Geometry.Reach import Reach
from Model.BoundaryCondition.BoundaryConditionList import BoundaryConditionList
from Model.LateralContribution.LateralContributionList import LateralContributionList
from Model.LateralContribution.LateralContributionList import (
LateralContributionList
)
from Model.InitialConditions.InitialConditionsDict import InitialConditionsDict
from Model.Stricklers.StricklersList import StricklersList
from Model.Friction.FrictionList import FrictionList
@ -383,7 +385,7 @@ class River(Graph, SQLSubModel):
has = len(self._sediment_layers) != 0
has &= any(
filter(
lambda p: p.sl != None,
lambda p: p.sl is not None,
flatten(
map(lambda e: e.reach.profiles, self.edges())
)

View File

@ -117,7 +117,8 @@ class Layer(SQLSubModel):
sl = data["sl"]
table = execute(
"SELECT id, ind, name, type, height, d50, sigma, critical_constraint " +
"SELECT id, ind, name, type, height, " +
"d50, sigma, critical_constraint " +
"FROM sedimentary_layer_layer " +
f"WHERE sl = {sl}"
)
@ -146,7 +147,8 @@ class Layer(SQLSubModel):
sql = (
"INSERT INTO " +
"sedimentary_layer_layer(id, ind, name, type, height, d50, sigma, critical_constraint, sl) " +
"sedimentary_layer_layer(id, ind, name, type, height, " +
"d50, sigma, critical_constraint, sl) " +
"VALUES (" +
f"{self.id}, {ind}, '{self._sql_format(self._name)}', " +
f"'{self._sql_format(self._type)}', {self._height}, " +
@ -197,7 +199,7 @@ class SedimentLayer(SQLSubModel):
def height(self):
return list(
map(lambda l: l.height, self._layers)
map(lambda layer: layer.height, self._layers)
)
@property
@ -210,7 +212,7 @@ class SedimentLayer(SQLSubModel):
def names(self):
return list(
map(lambda l: l.name, self._layers)
map(lambda layer: layer.name, self._layers)
)
@property
@ -280,9 +282,9 @@ class SedimentLayer(SQLSubModel):
data["sl"] = self
ind = 0
for l in self._layers:
for layer in self._layers:
data["ind"] = ind
l._sql_save(execute, data)
layer._sql_save(execute, data)
ind += 1
return True
@ -325,8 +327,8 @@ class SedimentLayer(SQLSubModel):
if index >= 0:
next = index - 1
l = self._layers
l[index], l[next] = l[next], l[index]
lst = self._layers
lst[index], lst[next] = lst[next], lst[index]
self._status.modified()
@ -334,7 +336,7 @@ class SedimentLayer(SQLSubModel):
if index + 1 < len(self._layers):
prev = index + 1
l = self._layers
l[index], l[prev] = l[prev], l[index]
lst = self._layers
lst[index], lst[prev] = lst[prev], lst[index]
self._status.modified()

View File

@ -99,9 +99,13 @@ class SolverParametersList(PamhyrModelList):
if major == minor == "0":
if int(release) < 3:
execute(
f"UPDATE solver_parameter SET name='mage_implicitation' WHERE name='mage_implication'")
"UPDATE solver_parameter SET name='mage_implicitation' " +
"WHERE name='mage_implication'"
)
execute(
f"UPDATE solver_parameter SET name='mage_iteration_type' WHERE name='mage_iter_type'")
"UPDATE solver_parameter SET name='mage_iteration_type' " +
"WHERE name='mage_iter_type'"
)
if int(release) < 4:
solvers = execute(
@ -229,7 +233,7 @@ class SolverParametersList(PamhyrModelList):
self._lst
)
)["value"]
except:
except Exception:
return None
def set(self, index, new):

View File

@ -182,7 +182,8 @@ class Study(SQLModel):
self.execute(
"CREATE TABLE info(key TEXT NOT NULL UNIQUE, value TEXT NOT NULL)")
self.execute(
f"INSERT INTO info VALUES ('version', '{self._sql_format(self._version)}')",
"INSERT INTO info VALUES ('version', " +
f"'{self._sql_format(self._version)}')",
commit=True
)
self.execute("INSERT INTO info VALUES ('name', '')")
@ -260,17 +261,32 @@ class Study(SQLModel):
def _save(self):
self.execute(
f"UPDATE info SET value='{self._sql_format(self.name)}' WHERE key='name'")
f"UPDATE info SET " +
f"value='{self._sql_format(self.name)}' WHERE key='name'"
)
self.execute(
f"UPDATE info SET value='{self._sql_format(self.description)}' WHERE key='description'")
f"UPDATE info SET " +
f"value='{self._sql_format(self.description)}' " +
"WHERE key='description'"
)
self.execute(
f"UPDATE info SET value='{self._time_system}' WHERE key='time_system'")
f"UPDATE info SET " +
f"value='{self._time_system}' WHERE key='time_system'"
)
self.execute(
f"UPDATE info SET value='{timestamp(self._date)}' WHERE key='date'")
f"UPDATE info SET " +
f"value='{timestamp(self._date)}' WHERE key='date'"
)
self.execute(
f"UPDATE info SET value='{timestamp(self.creation_date)}' WHERE key='creation_date'")
f"UPDATE info SET " +
f"value='{timestamp(self.creation_date)}' " +
"WHERE key='creation_date'"
)
self.execute(
f"UPDATE info SET value='{timestamp(self.last_save_date)}' WHERE key='last_save_date'")
f"UPDATE info SET " +
f"value='{timestamp(self.last_save_date)}' " +
"WHERE key='last_save_date'"
)
self._save_submodel([self._river])
self.commit()

View File

@ -115,9 +115,9 @@ class SQLSubModel(object):
def _sql_format(self, value):
# Replace ''' by '&#39;' to preserve SQL injection
if type(value) == str:
if value is str:
value = value.replace("'", "&#39;")
elif type(value) == bool:
elif value is bool:
value = 'TRUE' if value else 'FALSE'
return value

View File

@ -121,8 +121,8 @@ class PamhyrModelList(SQLSubModel):
if index < len(self._lst):
next = index - 1
l = self._lst
l[index], l[next] = l[next], l[index]
lst = self._lst
lst[index], lst[next] = lst[next], lst[index]
if self._status is not None:
self._status.modified()
@ -131,8 +131,8 @@ class PamhyrModelList(SQLSubModel):
if index >= 0:
prev = index + 1
l = self._lst
l[index], l[prev] = l[prev], l[index]
lst = self._lst
lst[index], lst[prev] = lst[prev], lst[index]
if self._status is not None:
self._status.modified()
@ -228,14 +228,14 @@ class PamhyrModelListWithTab(SQLSubModel):
if index < len(self._tabs[lst]):
next = index - 1
l = self._tabs[lst]
l[index], l[next] = l[next], l[index]
lst = self._tabs[lst]
lst[index], lst[next] = lst[next], lst[index]
self._status.modified()
def move_down(self, lst, index):
if index >= 0:
prev = index + 1
l = self._tabs[lst]
l[index], l[prev] = l[prev], l[index]
lst = self._tabs[lst]
lst[index], lst[prev] = lst[prev], lst[index]
self._status.modified()