create regular exp added and change model
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
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$")
|
||||
from app.utils.regex_utils import RegularExpression
|
||||
|
||||
class LayingClient(db.Model):
|
||||
__tablename__ = "laying_client"
|
||||
@@ -53,13 +51,13 @@ class LayingClient(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"
|
||||
]
|
||||
# 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
|
||||
@@ -68,7 +66,7 @@ def calculate_laying_total(mapper, connection, target):
|
||||
total = 0
|
||||
|
||||
for column in target.__table__.columns:
|
||||
if PIPE_MM_PATTERN.match(column.name):
|
||||
if RegularExpression.PIPE_MM_PATTERN.match(column.name):
|
||||
total += getattr(target, column.name) or 0
|
||||
|
||||
target.Total = total
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
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$")
|
||||
|
||||
from app.utils.regex_utils import RegularExpression
|
||||
|
||||
class Laying(db.Model):
|
||||
__tablename__ = "laying"
|
||||
@@ -49,13 +48,13 @@ 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"
|
||||
]
|
||||
# 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
|
||||
@@ -64,7 +63,7 @@ def calculate_laying_total(mapper, connection, target):
|
||||
total = 0
|
||||
|
||||
for column in target.__table__.columns:
|
||||
if PIPE_MM_PATTERN.match(column.name):
|
||||
if RegularExpression.PIPE_MM_PATTERN.match(column.name):
|
||||
total += getattr(target, column.name) or 0
|
||||
|
||||
target.Total = total
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
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 ManholeDomesticChamber(db.Model):
|
||||
__tablename__ = "manhole_domestic_chamber"
|
||||
@@ -56,15 +53,15 @@ 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"]
|
||||
# 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
|
||||
@@ -73,7 +70,7 @@ 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
|
||||
|
||||
@@ -88,7 +88,6 @@ class TrenchExcavationClient(db.Model):
|
||||
# ==========================================
|
||||
# AUTO CALCULATE GRAND TOTAL
|
||||
# ==========================================
|
||||
|
||||
def calculate_trench_client_total(mapper, connection, target):
|
||||
total = 0
|
||||
for column in target.__table__.columns:
|
||||
|
||||
Reference in New Issue
Block a user