change of comparison report of 4 model update
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
from app import db
|
||||
from datetime import datetime
|
||||
from sqlalchemy import event
|
||||
import re
|
||||
# REGEX PATTERN
|
||||
PIPE_MM_PATTERN = re.compile(r"^pipe_\d+_mm$")
|
||||
|
||||
class LayingClient(db.Model):
|
||||
__tablename__ = "laying_client"
|
||||
@@ -55,4 +59,19 @@ class LayingClient(db.Model):
|
||||
"pipe_300_mm", "pipe_350_mm", "pipe_400_mm",
|
||||
"pipe_450_mm", "pipe_500_mm", "pipe_600_mm",
|
||||
"pipe_700_mm", "pipe_900_mm", "pipe_1200_mm"
|
||||
]
|
||||
]
|
||||
|
||||
# ===============================
|
||||
# AUTO TOTAL USING REGEX
|
||||
# ===============================
|
||||
def calculate_laying_total(mapper, connection, target):
|
||||
total = 0
|
||||
|
||||
for column in target.__table__.columns:
|
||||
if PIPE_MM_PATTERN.match(column.name):
|
||||
total += getattr(target, column.name) or 0
|
||||
|
||||
target.Total = total
|
||||
|
||||
event.listen(LayingClient, "before_insert", calculate_laying_total)
|
||||
event.listen(LayingClient, "before_update", calculate_laying_total)
|
||||
@@ -1,5 +1,9 @@
|
||||
from app import db
|
||||
from datetime import datetime
|
||||
from sqlalchemy import event
|
||||
import re
|
||||
# REGEX PATTERN
|
||||
PIPE_MM_PATTERN = re.compile(r"^pipe_\d+_mm$")
|
||||
|
||||
class Laying(db.Model):
|
||||
__tablename__ = "laying"
|
||||
@@ -52,3 +56,18 @@ class Laying(db.Model):
|
||||
"pipe_450_mm", "pipe_500_mm", "pipe_600_mm",
|
||||
"pipe_700_mm", "pipe_900_mm", "pipe_1200_mm"
|
||||
]
|
||||
|
||||
# ===============================
|
||||
# AUTO TOTAL USING REGEX
|
||||
# ===============================
|
||||
def calculate_laying_total(mapper, connection, target):
|
||||
total = 0
|
||||
|
||||
for column in target.__table__.columns:
|
||||
if PIPE_MM_PATTERN.match(column.name):
|
||||
total += getattr(target, column.name) or 0
|
||||
|
||||
target.Total = total
|
||||
|
||||
event.listen(Laying, "before_insert", calculate_laying_total)
|
||||
event.listen(Laying, "before_update", calculate_laying_total)
|
||||
@@ -1,5 +1,10 @@
|
||||
from app import db
|
||||
from datetime import datetime
|
||||
from sqlalchemy import event
|
||||
import re
|
||||
|
||||
# REGEX PATTERN
|
||||
D_RANGE_PATTERN = re.compile(r"^d_\d+(?:_\d+)?_to_\d+(?:_\d+)?$")
|
||||
|
||||
class ManholeDomesticChamber(db.Model):
|
||||
__tablename__ = "manhole_domestic_chamber"
|
||||
@@ -27,7 +32,6 @@ class ManholeDomesticChamber(db.Model):
|
||||
d_4_16_to_4_65 = db.Column(db.Float)
|
||||
d_4_66_to_5_15 = db.Column(db.Float)
|
||||
d_5_16_to_5_65 = db.Column(db.Float)
|
||||
|
||||
d_5_66_to_6_15 = db.Column(db.Float)
|
||||
d_6_16_to_6_65 = db.Column(db.Float)
|
||||
d_6_66_to_7_15 = db.Column(db.Float)
|
||||
@@ -42,6 +46,7 @@ class ManholeDomesticChamber(db.Model):
|
||||
UPVC_Pipe_Length = db.Column(db.Float)
|
||||
RA_Bill_No=db.Column(db.String(500))
|
||||
|
||||
Total = db.Column(db.Float)
|
||||
created_at = db.Column(db.DateTime, default=datetime.today)
|
||||
|
||||
def __repr__(self):
|
||||
@@ -61,3 +66,18 @@ class ManholeDomesticChamber(db.Model):
|
||||
"d_7_66_to_8_15", "d_8_16_to_8_65", "d_8_66_to_9_15",
|
||||
"d_9_16_to_9_65"]
|
||||
|
||||
# ===============================
|
||||
# AUTO TOTAL USING REGEX
|
||||
# ===============================
|
||||
def calculate_mh_dc_total(mapper, connection, target):
|
||||
total = 0
|
||||
|
||||
for column in target.__table__.columns:
|
||||
if D_RANGE_PATTERN.match(column.name):
|
||||
total += getattr(target, column.name) or 0
|
||||
|
||||
target.Total = total
|
||||
|
||||
|
||||
event.listen(ManholeDomesticChamber, "before_insert", calculate_mh_dc_total)
|
||||
event.listen(ManholeDomesticChamber, "before_update", calculate_mh_dc_total)
|
||||
@@ -70,7 +70,7 @@ class ManholeExcavation(db.Model):
|
||||
# ==========================================
|
||||
# AUTO CALCULATE GRAND TOTAL
|
||||
# ==========================================
|
||||
def calculate_trench_total(mapper, connection, target):
|
||||
def calculate_Manhole_total(mapper, connection, target):
|
||||
total = 0
|
||||
for column in target.__table__.columns:
|
||||
if column.name.endswith("_total"):
|
||||
@@ -78,5 +78,5 @@ def calculate_trench_total(mapper, connection, target):
|
||||
target.Total = total
|
||||
|
||||
|
||||
event.listen(TrenchExcavation, "before_insert", calculate_trench_total)
|
||||
event.listen(TrenchExcavation, "before_update", calculate_trench_total)
|
||||
event.listen(ManholeExcavation, "before_insert", calculate_Manhole_total)
|
||||
event.listen(ManholeExcavation, "before_update", calculate_Manhole_total)
|
||||
@@ -1,5 +1,10 @@
|
||||
from app import db
|
||||
from datetime import datetime
|
||||
from sqlalchemy import event
|
||||
import re
|
||||
|
||||
# REGEX PATTERN
|
||||
D_RANGE_PATTERN = re.compile(r"^d_\d+(?:_\d+)?_to_\d+(?:_\d+)?$")
|
||||
|
||||
class ManholeDomesticChamberClient(db.Model):
|
||||
__tablename__ = "mh_dc_client"
|
||||
@@ -24,18 +29,17 @@ class ManholeDomesticChamberClient(db.Model):
|
||||
d_1_5_to_2_0 = db.Column(db.Float)
|
||||
d_2_0_to_2_5 = db.Column(db.Float)
|
||||
d_2_5_to_3_0 = db.Column(db.Float)
|
||||
|
||||
d_3_0_to_3_5 = db.Column(db.Float)
|
||||
d_3_5_to_4_0 = db.Column(db.Float)
|
||||
d_4_0_to_4_5= db.Column(db.Float)
|
||||
d_4_5_to_5_0 = db.Column(db.Float)
|
||||
|
||||
d_5_0_to_5_5 = db.Column(db.Float)
|
||||
d_5_5_to_6_0 = db.Column(db.Float)
|
||||
d_6_0_to_6_5 = db.Column(db.Float)
|
||||
|
||||
Domestic_Chambers = db.Column(db.Float)
|
||||
|
||||
Total = db.Column(db.Float)
|
||||
created_at = db.Column(db.DateTime, default=datetime.today)
|
||||
|
||||
def __repr__(self):
|
||||
@@ -54,4 +58,20 @@ class ManholeDomesticChamberClient(db.Model):
|
||||
"d_4_66_to_5_15", "d_5_16_to_5_65", "d_5_66_to_6_15",
|
||||
"d_6_16_to_6_65", "d_6_66_to_7_15", "d_7_16_to_7_65",
|
||||
"d_7_66_to_8_15", "d_8_16_to_8_65", "d_8_66_to_9_15",
|
||||
"d_9_16_to_9_65" ]
|
||||
"d_9_16_to_9_65" ]
|
||||
|
||||
# ===============================
|
||||
# AUTO TOTAL USING REGEX
|
||||
# ===============================
|
||||
def calculate_mh_dc_total(mapper, connection, target):
|
||||
total = 0
|
||||
|
||||
for column in target.__table__.columns:
|
||||
if D_RANGE_PATTERN.match(column.name):
|
||||
total += getattr(target, column.name) or 0
|
||||
|
||||
target.Total = total
|
||||
|
||||
|
||||
event.listen(ManholeDomesticChamberClient, "before_insert", calculate_mh_dc_total)
|
||||
event.listen(ManholeDomesticChamberClient, "before_update", calculate_mh_dc_total)
|
||||
@@ -87,7 +87,7 @@ class ManholeExcavationClient(db.Model):
|
||||
# ==========================================
|
||||
# AUTO CALCULATE GRAND TOTAL
|
||||
# ==========================================
|
||||
def calculate_trench_total(mapper, connection, target):
|
||||
def calculate_Manhole_total(mapper, connection, target):
|
||||
total = 0
|
||||
for column in target.__table__.columns:
|
||||
if column.name.endswith("_total"):
|
||||
@@ -95,5 +95,5 @@ def calculate_trench_total(mapper, connection, target):
|
||||
target.Total = total
|
||||
|
||||
|
||||
event.listen(TrenchExcavation, "before_insert", calculate_trench_total)
|
||||
event.listen(TrenchExcavation, "before_update", calculate_trench_total)
|
||||
event.listen(ManholeExcavationClient, "before_insert", calculate_Manhole_total)
|
||||
event.listen(ManholeExcavationClient, "before_update", calculate_Manhole_total)
|
||||
Reference in New Issue
Block a user