regular exp updated on model
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user