regular exp updated on model
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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+)?$")
|
||||
|
||||
D_RANGE_PATTERN = re.compile( r"^d_\d+(?:_\d+)?_to_\d+(?:_\d+)?$")
|
||||
Reference in New Issue
Block a user