From 5ddfb1f440212909245443973fcae60b219b9a21 Mon Sep 17 00:00:00 2001 From: pjpatil12 Date: Tue, 17 Mar 2026 18:02:28 +0530 Subject: [PATCH] regular exp updated on model --- app/models/laying_client_model.py | 14 +------- app/models/laying_model.py | 13 ------- app/models/manhole_domestic_chamber_model.py | 15 -------- app/models/manhole_excavation_model.py | 7 ++-- app/models/mh_dc_client_model.py | 28 ++------------- app/models/mh_ex_client_model.py | 11 ++---- app/models/tr_ex_client_model.py | 8 ++--- app/models/trench_excavation_model.py | 37 ++------------------ app/routes/generate_comparison_report.py | 17 ++------- app/templates/{users.htm => users.html} | 0 app/utils/regex_utils.py | 10 +++--- 11 files changed, 25 insertions(+), 135 deletions(-) rename app/templates/{users.htm => users.html} (100%) diff --git a/app/models/laying_client_model.py b/app/models/laying_client_model.py index 1ba73f2..1cfa15b 100644 --- a/app/models/laying_client_model.py +++ b/app/models/laying_client_model.py @@ -50,25 +50,13 @@ class LayingClient(db.Model): def serialize(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns} - - # def sum_laying_fields(): - # return [ - # "pipe_150_mm", "pipe_200_mm", "pipe_250_mm", - # "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 RegularExpression.PIPE_MM_PATTERN.match(column.name): total += getattr(target, column.name) or 0 - target.Total = total event.listen(LayingClient, "before_insert", calculate_laying_total) diff --git a/app/models/laying_model.py b/app/models/laying_model.py index 30de9cf..e159c43 100644 --- a/app/models/laying_model.py +++ b/app/models/laying_model.py @@ -1,7 +1,6 @@ from app import db from datetime import datetime from sqlalchemy import event - from app.utils.regex_utils import RegularExpression class Laying(db.Model): @@ -48,24 +47,12 @@ class Laying(db.Model): return {c.name: getattr(self, c.name) for c in self.__table__.columns} - # def sum_laying_fields(): - # return [ - # "pipe_150_mm", "pipe_200_mm", "pipe_250_mm", - # "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 RegularExpression.PIPE_MM_PATTERN.match(column.name): total += getattr(target, column.name) or 0 - target.Total = total event.listen(Laying, "before_insert", calculate_laying_total) diff --git a/app/models/manhole_domestic_chamber_model.py b/app/models/manhole_domestic_chamber_model.py index 406be00..5303420 100644 --- a/app/models/manhole_domestic_chamber_model.py +++ b/app/models/manhole_domestic_chamber_model.py @@ -53,28 +53,13 @@ class ManholeDomesticChamber(db.Model): return {c.name: getattr(self, c.name) for c in self.__table__.columns} - # def sum_mh_dc_fields(): - # return [ - # "d_0_to_0_75", "d_0_76_to_1_05", "d_1_06_to_1_65", - # "d_1_66_to_2_15", "d_2_16_to_2_65", "d_2_66_to_3_15", - # "d_3_16_to_3_65", "d_3_66_to_4_15", "d_4_16_to_4_65", - # "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"] - -# =============================== # AUTO TOTAL USING REGEX -# =============================== def calculate_mh_dc_total(mapper, connection, target): total = 0 - for column in target.__table__.columns: if RegularExpression.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) \ No newline at end of file diff --git a/app/models/manhole_excavation_model.py b/app/models/manhole_excavation_model.py index d0b008f..15839a2 100644 --- a/app/models/manhole_excavation_model.py +++ b/app/models/manhole_excavation_model.py @@ -1,6 +1,7 @@ from app import db from datetime import datetime from sqlalchemy import event +from app.utils.regex_utils import RegularExpression class ManholeExcavation(db.Model): __tablename__ = "manhole_excavation" @@ -67,13 +68,11 @@ class ManholeExcavation(db.Model): def serialize(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns} -# ========================================== -# AUTO CALCULATE GRAND TOTAL -# ========================================== +# AUTO TOTAL USING REGEX def calculate_Manhole_total(mapper, connection, target): total = 0 for column in target.__table__.columns: - if column.name.endswith("_total"): + if RegularExpression.STR_TOTAL_PATTERN.match(column.name): total += getattr(target, column.name) or 0 target.Total = total diff --git a/app/models/mh_dc_client_model.py b/app/models/mh_dc_client_model.py index 6acaaa6..0fb90ee 100644 --- a/app/models/mh_dc_client_model.py +++ b/app/models/mh_dc_client_model.py @@ -1,19 +1,12 @@ 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+)?$") +from app.utils.regex_utils import RegularExpression class ManholeDomesticChamberClient(db.Model): __tablename__ = "mh_dc_client" id = db.Column(db.Integer, primary_key=True) - # Foreign Key to Subcontractor table - # subcontractor_id = db.Column(db.Integer, db.ForeignKey("subcontractors.id"), nullable=False) - # Relationship for easy access (subcontractor.subcontractor_name) - # subcontractor = db.relationship("Subcontractor", backref="mh_dc_records") # Basic Fields RA_Bill_No=db.Column(db.String(500)) @@ -23,7 +16,6 @@ class ManholeDomesticChamberClient(db.Model): MH_IL_LEVEL = db.Column(db.Float, default=0) Depth_of_MH = db.Column(db.Float, default=0) - # Excavation categories d_0_to_1_5 = db.Column(db.Float, default=0) d_1_5_to_2_0 = db.Column(db.Float, default=0) @@ -49,27 +41,13 @@ class ManholeDomesticChamberClient(db.Model): def serialize(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns} - - def sum_mh_dc_fields(): - return [ - "d_0_to_0_75", "d_0_76_to_1_05", "d_1_06_to_1_65", - "d_1_66_to_2_15", "d_2_16_to_2_65", "d_2_66_to_3_15", - "d_3_16_to_3_65", "d_3_66_to_4_15", "d_4_16_to_4_65", - "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" ] - -# =============================== + # 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): + if RegularExpression.D_RANGE_PATTERN.match(column.name): total += getattr(target, column.name) or 0 - target.Total = total diff --git a/app/models/mh_ex_client_model.py b/app/models/mh_ex_client_model.py index 7ce2657..d7707c7 100644 --- a/app/models/mh_ex_client_model.py +++ b/app/models/mh_ex_client_model.py @@ -1,15 +1,12 @@ from app import db from datetime import datetime from sqlalchemy import event +from app.utils.regex_utils import RegularExpression class ManholeExcavationClient(db.Model): __tablename__ = "mh_ex_client" id = db.Column(db.Integer, primary_key=True) - # Foreign Key to Subcontractor table - # subcontractor_id = db.Column(db.Integer, db.ForeignKey("subcontractors.id"), nullable=False) - # Relationship for easy access (subcontractor.subcontractor_name) - # subcontractor = db.relationship("Subcontractor", backref="mh_ex_records") # Basic Fields RA_Bill_No=db.Column(db.String(500)) @@ -84,13 +81,11 @@ class ManholeExcavationClient(db.Model): return {c.name: getattr(self, c.name) for c in self.__table__.columns} -# ========================================== -# AUTO CALCULATE GRAND TOTAL -# ========================================== +# AUTO TOTAL USING REGEX def calculate_Manhole_total(mapper, connection, target): total = 0 for column in target.__table__.columns: - if column.name.endswith("_total"): + if RegularExpression.STR_TOTAL_PATTERN.match(column.name): total += getattr(target, column.name) or 0 target.Total = total diff --git a/app/models/tr_ex_client_model.py b/app/models/tr_ex_client_model.py index 0ac5bd6..4f943d0 100644 --- a/app/models/tr_ex_client_model.py +++ b/app/models/tr_ex_client_model.py @@ -1,6 +1,7 @@ from app import db from datetime import datetime from sqlalchemy import event +from app.utils.regex_utils import RegularExpression class TrenchExcavationClient(db.Model): __tablename__ = "tr_ex_client" @@ -85,16 +86,13 @@ class TrenchExcavationClient(db.Model): return {c.name: getattr(self, c.name) for c in self.__table__.columns} -# ========================================== -# AUTO CALCULATE GRAND TOTAL -# ========================================== +# AUTO TOTAL USING REGEX def calculate_trench_client_total(mapper, connection, target): total = 0 for column in target.__table__.columns: - if column.name.endswith("_total"): + if RegularExpression.STR_TOTAL_PATTERN.match(column.name): total += getattr(target, column.name) or 0 target.Total = total - event.listen(TrenchExcavationClient, "before_insert", calculate_trench_client_total) event.listen(TrenchExcavationClient, "before_update", calculate_trench_client_total) \ No newline at end of file diff --git a/app/models/trench_excavation_model.py b/app/models/trench_excavation_model.py index c7a19c0..b3959ef 100644 --- a/app/models/trench_excavation_model.py +++ b/app/models/trench_excavation_model.py @@ -1,6 +1,7 @@ from app import db from datetime import datetime from sqlalchemy import event +from app.utils.regex_utils import RegularExpression class TrenchExcavation(db.Model): __tablename__ = "trench_excavation" @@ -79,44 +80,12 @@ class TrenchExcavation(db.Model): def serialize(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns} - def excavation_category_sums(self): - def safe(val): - return val or 0 - - return { - "Soft_Murum_Total": ( - safe(self.Soft_Murum_0_to_1_5) - + safe(self.Soft_Murum_1_5_to_3_0) - + safe(self.Soft_Murum_3_0_to_4_5) - ), - - "Hard_Murum_Total": ( - safe(self.Hard_Murum_0_to_1_5) - + safe(self.Hard_Murum_1_5_to_3_0) - ), - - "Soft_Rock_Total": ( - safe(self.Soft_Rock_0_to_1_5) - + safe(self.Soft_Rock_1_5_to_3_0) - ), - - "Hard_Rock_Total": ( - safe(self.Hard_Rock_0_to_1_5) - + safe(self.Hard_Rock_1_5_to_3_0) - + safe(self.Hard_Rock_3_0_to_4_5) - + safe(self.Hard_Rock_4_5_to_6_0) - + safe(self.Hard_Rock_6_0_to_7_5) - ), - } - -# ========================================== -# AUTO CALCULATE GRAND TOTAL -# ========================================== +# AUTO TOTAL USING REGEX def calculate_trench_total(mapper, connection, target): total = 0 for column in target.__table__.columns: - if column.name.endswith("_total"): + if RegularExpression.STR_TOTAL_PATTERN.match(column.name): total += getattr(target, column.name) or 0 target.Total = total diff --git a/app/routes/generate_comparison_report.py b/app/routes/generate_comparison_report.py index 7c06ece..c48c986 100644 --- a/app/routes/generate_comparison_report.py +++ b/app/routes/generate_comparison_report.py @@ -76,9 +76,7 @@ def build_comparison(client_rows, contractor_rows, key_field): used_index = defaultdict(int) # 🔥 THIS FIXES YOUR ISSUE for c in client_rows: - print("@@@@@@@@@@@@@@@@@@@@@@@") - print("c::::",c) - print("@@@@@@@@@@@@@@@@@@@@@@@") + client_location = normalize_key(c.get("Location")) client_key = normalize_key(c.get(key_field)) @@ -137,18 +135,9 @@ def build_comparison(client_rows, contractor_rows, key_field): output.append(row) df = pd.DataFrame(output) - print("-------------------") - print("df::",df) - print("++++++++++++++++++++++++s+++++") - for col in df.columns: - print("colll::",col) - - + # formatting headers df.columns = [format_header(col) for col in df.columns] - print("-------------------") - print("df.columns::",df.columns) - - + return df diff --git a/app/templates/users.htm b/app/templates/users.html similarity index 100% rename from app/templates/users.htm rename to app/templates/users.html diff --git a/app/utils/regex_utils.py b/app/utils/regex_utils.py index 7ed8757..f6eb7b1 100644 --- a/app/utils/regex_utils.py +++ b/app/utils/regex_utils.py @@ -2,9 +2,11 @@ import re class RegularExpression: - # sum field of pipe laying (pipe_150_mm) + # sum fields of TrEx, MhEx (_total) + STR_TOTAL_PATTERN = re.compile(r".*_total$") + + # sum fields of pipe laying (pipe_150_mm) PIPE_MM_PATTERN = re.compile(r"^pipe_\d+_mm$") - + # sum fields of MH dc (d_0_to_0_75) - D_RANGE_PATTERN = re.compile( r"^d_\d+(?:_\d+)?_to_\d+(?:_\d+)?$") - \ No newline at end of file + D_RANGE_PATTERN = re.compile( r"^d_\d+(?:_\d+)?_to_\d+(?:_\d+)?$") \ No newline at end of file