Commit 1e894906 authored by Youcef Aouad's avatar Youcef Aouad
Browse files

pollutant characteristics

No related merge requests found
Pipeline #55740 passed with stages
in 58 seconds
Showing with 44 additions and 0 deletions
+44 -0
...@@ -47,6 +47,8 @@ class Pollutants(SQLSubModel): ...@@ -47,6 +47,8 @@ class Pollutants(SQLSubModel):
self._name = str(name) self._name = str(name)
self._enabled = True self._enabled = True
self._characteristics = []
Pollutants._id_cnt = max( Pollutants._id_cnt = max(
Pollutants._id_cnt + 1, self.id) Pollutants._id_cnt + 1, self.id)
...@@ -69,6 +71,22 @@ class Pollutants(SQLSubModel): ...@@ -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) return cls._create_submodel(execute)
@classmethod @classmethod
...@@ -96,12 +114,28 @@ class Pollutants(SQLSubModel): ...@@ -96,12 +114,28 @@ class Pollutants(SQLSubModel):
status=status 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) new.append(new_pollutant)
return new return new
def _db_save(self, execute, data=None): 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 = ( sql = (
"INSERT INTO " + "INSERT INTO " +
"Pollutants(id, name " + "Pollutants(id, name " +
...@@ -113,6 +147,16 @@ class Pollutants(SQLSubModel): ...@@ -113,6 +147,16 @@ class Pollutants(SQLSubModel):
execute(sql) 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 return True
@property @property
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment