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 @classmethod
def time_convert(cls, data): 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 old_pamhyr_date_to_timestamp(data)
return int(data) return int(data)
@ -302,10 +302,10 @@ class BoundaryCondition(SQLSubModel):
return self.data[index] return self.data[index]
def get_range(self, _range): def get_range(self, _range):
l = [] lst = []
for r in _range: for r in _range:
l.append(r) lst.append(r)
return l return lst
def _set_i_c_v(self, index, column, value): def _set_i_c_v(self, index, column, value):
v = list(self._data[index]) v = list(self._data[index])

View File

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

View File

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

View File

@ -92,7 +92,8 @@ class Friction(SQLSubModel):
ind = data["ind"] ind = data["ind"]
execute( execute(
"INSERT INTO " + "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 (" + "VALUES (" +
f"{ind}, {self._begin_kp}, {self._end_kp}, " + f"{ind}, {self._begin_kp}, {self._end_kp}, " +
f"{self._edge.id}, " + f"{self._edge.id}, " +

View File

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

View File

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

View File

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

View File

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

View File

@ -154,7 +154,8 @@ class LateralContribution(SQLSubModel):
sql = ( sql = (
"INSERT INTO " + "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 (" + "VALUES (" +
f"{self.id}, '{self._sql_format(self._name)}', " + f"{self.id}, '{self._sql_format(self._name)}', " +
f"'{self._sql_format(self._type)}', '{tab}', {edge}, " + f"'{self._sql_format(self._type)}', '{tab}', {edge}, " +
@ -187,7 +188,7 @@ class LateralContribution(SQLSubModel):
@classmethod @classmethod
def time_convert(cls, data): 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 old_pamhyr_date_to_timestamp(data)
return int(data) return int(data)
@ -338,10 +339,10 @@ class LateralContribution(SQLSubModel):
return self.data[index] return self.data[index]
def get_range(self, _range): def get_range(self, _range):
l = [] lst = []
for r in _range: for r in _range:
l.append(r) lst.append(r)
return l return lst
def _set_i_c_v(self, index, column, value): def _set_i_c_v(self, index, column, value):
v = list(self._data[index]) v = list(self._data[index])

View File

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

View File

@ -75,7 +75,10 @@ class Edge(object):
@property @property
def name(self): 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): def is_enable(self):
return self._enable return self._enable

View File

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

View File

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

View File

@ -99,9 +99,13 @@ class SolverParametersList(PamhyrModelList):
if major == minor == "0": if major == minor == "0":
if int(release) < 3: if int(release) < 3:
execute( 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( 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: if int(release) < 4:
solvers = execute( solvers = execute(
@ -229,7 +233,7 @@ class SolverParametersList(PamhyrModelList):
self._lst self._lst
) )
)["value"] )["value"]
except: except Exception:
return None return None
def set(self, index, new): def set(self, index, new):

View File

@ -182,7 +182,8 @@ class Study(SQLModel):
self.execute( self.execute(
"CREATE TABLE info(key TEXT NOT NULL UNIQUE, value TEXT NOT NULL)") "CREATE TABLE info(key TEXT NOT NULL UNIQUE, value TEXT NOT NULL)")
self.execute( 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 commit=True
) )
self.execute("INSERT INTO info VALUES ('name', '')") self.execute("INSERT INTO info VALUES ('name', '')")
@ -260,17 +261,32 @@ class Study(SQLModel):
def _save(self): def _save(self):
self.execute( 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( 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( 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( 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( 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( 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._save_submodel([self._river])
self.commit() self.commit()

View File

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

View File

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