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