mirror of https://gitlab.com/pamhyr/pamhyr2
pollutant characteristics
parent
1945e94190
commit
1e8949067b
|
|
@ -47,6 +47,8 @@ class Pollutants(SQLSubModel):
|
|||
self._name = str(name)
|
||||
self._enabled = True
|
||||
|
||||
self._characteristics = []
|
||||
|
||||
Pollutants._id_cnt = max(
|
||||
Pollutants._id_cnt + 1, self.id)
|
||||
|
||||
|
|
@ -69,6 +71,22 @@ class Pollutants(SQLSubModel):
|
|||
)
|
||||
""")
|
||||
|
||||
execute("""
|
||||
CREATE TABLE Pollutants_characteristics(
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
type INTEGER NOT NULL,
|
||||
diametre REAL NOT NULL,
|
||||
rho REAL NOT NULL,
|
||||
porosity REAL NOT NULL,
|
||||
cdc_riv REAL NOT NULL,
|
||||
cdc_cas REAL NOT NULL,
|
||||
apd REAL NOT NULL,
|
||||
ac REAL NOT NULL,
|
||||
bc REAL NOT NULL,
|
||||
FOREIGN KEY(pollutant) REFERENCES Pollutants(id)
|
||||
)
|
||||
""")
|
||||
|
||||
return cls._create_submodel(execute)
|
||||
|
||||
@classmethod
|
||||
|
|
@ -96,12 +114,28 @@ class Pollutants(SQLSubModel):
|
|||
status=status
|
||||
)
|
||||
|
||||
new_data = []
|
||||
table = execute(
|
||||
"SELECT * " +
|
||||
"FROM Pollutants_characteristics " +
|
||||
f"WHERE pollutant = {id}"
|
||||
)
|
||||
|
||||
if table is not None:
|
||||
for t in table:
|
||||
new_data.append(t)
|
||||
|
||||
new_pollutant._characteristics = new_data
|
||||
|
||||
new.append(new_pollutant)
|
||||
|
||||
return new
|
||||
|
||||
def _db_save(self, execute, data=None):
|
||||
|
||||
execute(f"DELETE FROM Pollutants WHERE id = {self.id}")
|
||||
execute(f"DELETE FROM Pollutants_characteristics WHERE pollutant = {self.id}")
|
||||
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"Pollutants(id, name " +
|
||||
|
|
@ -113,6 +147,16 @@ class Pollutants(SQLSubModel):
|
|||
|
||||
execute(sql)
|
||||
|
||||
for d in self._characteristics:
|
||||
sql = (
|
||||
"INSERT INTO " +
|
||||
"Pollutants_characteristics(type, diametre, rho, porosity, " +
|
||||
"cdc_riv, cdc_cas, apd, ac, bc) " +
|
||||
f"VALUES ({d[1]}, {d[2]}, {d[3]},{d[4]}, {d[5]}, "
|
||||
f"{d[6]}, {d[7]}, {d[8]}, {d[9]}, {self.id})"
|
||||
)
|
||||
execute(sql)
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
|
|
|
|||
Loading…
Reference in New Issue