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"
|
||||
@@ -56,3 +60,18 @@ class LayingClient(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(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):
|
||||
@@ -55,3 +59,19 @@ class ManholeDomesticChamberClient(db.Model):
|
||||
"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" ]
|
||||
|
||||
# ===============================
|
||||
# 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)
|
||||
@@ -143,21 +143,29 @@ def build_comparison(client_rows, contractor_rows, key_field):
|
||||
|
||||
|
||||
|
||||
|
||||
# EXCEL SHEET WRITER
|
||||
def write_sheet(writer, df, sheet_name, subcontractor_name):
|
||||
workbook = writer.book
|
||||
|
||||
# write dataframe (data already correct)
|
||||
df.to_excel(writer, sheet_name=sheet_name, index=False, startrow=3)
|
||||
ws = writer.sheets[sheet_name]
|
||||
|
||||
# formats
|
||||
title_fmt = workbook.add_format({"bold": True, "font_size": 14})
|
||||
client_fmt = workbook.add_format({"bold": True, "border": 1, "bg_color": "#B6DAED"})
|
||||
sub_fmt = workbook.add_format({"bold": True, "border": 1, "bg_color": "#F3A081"})
|
||||
total_fmt = workbook.add_format({"bold": True, "border": 1, "bg_color": "#F7D261"})
|
||||
diff_fmt = workbook.add_format({"bold": True, "border": 1, "bg_color": "#82DD49"})
|
||||
default_header_fmt = workbook.add_format({"bold": True,"border": 1,"bg_color": "#E7E6E6","align": "center","valign": "vcenter"})
|
||||
|
||||
client_fmt = workbook.add_format({"bold": True, "border": 1, "bg_color": "#D9EDF7"})
|
||||
sub_fmt = workbook.add_format({"bold": True, "border": 1, "bg_color": "#F7E1D9"})
|
||||
total_fmt = workbook.add_format({"bold": True, "border": 1, "bg_color": "#FFF2CC"})
|
||||
diff_fmt = workbook.add_format({"bold": True, "border": 1, "bg_color": "#E2EFDA"})
|
||||
default_header_fmt = workbook.add_format({
|
||||
"bold": True,
|
||||
"border": 1,
|
||||
"bg_color": "#E7E6E6",
|
||||
"align": "center",
|
||||
"valign": "vcenter"
|
||||
})
|
||||
|
||||
# titles
|
||||
ws.merge_range(
|
||||
0, 0, 0, len(df.columns) - 1,
|
||||
"CLIENT vs SUBCONTRACTOR",
|
||||
@@ -169,13 +177,13 @@ def write_sheet(writer, df, sheet_name, subcontractor_name):
|
||||
title_fmt
|
||||
)
|
||||
|
||||
|
||||
# header formatting
|
||||
for col_num, col_name in enumerate(df.columns):
|
||||
if col_name.startswith("Client-"):
|
||||
ws.write(3, col_num, col_name, client_fmt)
|
||||
elif col_name.startswith("Subcontractor-"):
|
||||
ws.write(3, col_num, col_name, sub_fmt)
|
||||
elif col_name.endswith("_total") or col_name.endswith("_total") :
|
||||
elif col_name.endswith("Total"):
|
||||
ws.write(3, col_num, col_name, total_fmt)
|
||||
elif col_name == "Diff":
|
||||
ws.write(3, col_num, col_name, diff_fmt)
|
||||
@@ -234,8 +242,8 @@ def comparison_report():
|
||||
with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
|
||||
write_sheet(writer, df_tr, "Tr.Ex", subcontractor.subcontractor_name)
|
||||
write_sheet(writer, df_mh, "Mh.Ex", subcontractor.subcontractor_name)
|
||||
# write_sheet(writer, df_dc, "MH & DC", subcontractor.subcontractor_name)
|
||||
# write_sheet(writer, df_lay, "Laying", subcontractor.subcontractor_name)
|
||||
write_sheet(writer, df_dc, "MH & DC", subcontractor.subcontractor_name)
|
||||
write_sheet(writer, df_lay, "Laying", subcontractor.subcontractor_name)
|
||||
|
||||
output.seek(0)
|
||||
return send_file(
|
||||
|
||||
Reference in New Issue
Block a user