create regular exp added and change model
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import matplotlib
|
||||
matplotlib.use("Agg")
|
||||
|
||||
from flask import Blueprint, render_template, session, redirect, url_for, jsonify
|
||||
from flask import Blueprint, render_template, session, redirect, url_for, jsonify, request
|
||||
import matplotlib.pyplot as plt
|
||||
import io
|
||||
import base64
|
||||
@@ -93,6 +93,9 @@ def subcontractor_chart():
|
||||
if subcontractor_id:
|
||||
query = query.filter(TrenchExcavation.subcontractor_id == subcontractor_id)
|
||||
|
||||
if category:
|
||||
query = query.filter(TrenchExcavation.subcontractor_id == subcontractor_id)
|
||||
|
||||
if ra_bill:
|
||||
query = query.filter(TrenchExcavation.RA_Bill_No == ra_bill)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ from flask import Blueprint, render_template, request, send_file, flash
|
||||
from collections import defaultdict
|
||||
import pandas as pd
|
||||
import io
|
||||
|
||||
|
||||
from app.models.subcontractor_model import Subcontractor
|
||||
from app.models.trench_excavation_model import TrenchExcavation
|
||||
from app.models.manhole_excavation_model import ManholeExcavation
|
||||
@@ -15,17 +15,13 @@ from app.models.mh_dc_client_model import ManholeDomesticChamberClient
|
||||
from app.models.laying_client_model import LayingClient
|
||||
|
||||
from app.utils.helpers import login_required
|
||||
import re
|
||||
from app.utils.regex_utils import RegularExpression
|
||||
|
||||
|
||||
generate_report_bp = Blueprint("generate_report", __name__, url_prefix="/report")
|
||||
|
||||
|
||||
# sum field 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+)?$")
|
||||
|
||||
|
||||
|
||||
# NORMALIZER
|
||||
def normalize_key(value):
|
||||
@@ -80,6 +76,9 @@ 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))
|
||||
|
||||
@@ -104,16 +103,16 @@ def build_comparison(client_rows, contractor_rows, key_field):
|
||||
float(v or 0)
|
||||
for k, v in c.items()
|
||||
if k.endswith("_total")
|
||||
or D_RANGE_PATTERN.match(k)
|
||||
or PIPE_MM_PATTERN.match(k)
|
||||
or RegularExpression.D_RANGE_PATTERN.match(k)
|
||||
or RegularExpression.PIPE_MM_PATTERN.match(k)
|
||||
)
|
||||
|
||||
sub_total = sum(
|
||||
float(v or 0)
|
||||
for k, v in s.items()
|
||||
if k.endswith("_total")
|
||||
or D_RANGE_PATTERN.match(k)
|
||||
or PIPE_MM_PATTERN.match(k)
|
||||
or RegularExpression.D_RANGE_PATTERN.match(k)
|
||||
or RegularExpression.PIPE_MM_PATTERN.match(k)
|
||||
)
|
||||
|
||||
row = {
|
||||
@@ -138,7 +137,18 @@ 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)
|
||||
|
||||
|
||||
df.columns = [format_header(col) for col in df.columns]
|
||||
print("-------------------")
|
||||
print("df.columns::",df.columns)
|
||||
|
||||
|
||||
return df
|
||||
|
||||
|
||||
@@ -254,106 +264,4 @@ def comparison_report():
|
||||
)
|
||||
|
||||
return render_template("generate_comparison_report.html",subcontractors=subcontractors)
|
||||
|
||||
|
||||
# def build_comparison_mh_dc(client_rows, contractor_rows, key_field):
|
||||
# contractor_lookup = make_lookup(contractor_rows, key_field)
|
||||
# mh_dc_fields = ManholeDomesticChamberClient.sum_mh_dc_fields()
|
||||
|
||||
# output = []
|
||||
|
||||
# for c in client_rows:
|
||||
# loc = normalize_key(c.get("Location"))
|
||||
# key = normalize_key(c.get(key_field))
|
||||
# if not loc or not key:
|
||||
# continue
|
||||
|
||||
# s = contractor_lookup.get((loc, key))
|
||||
# if not s:
|
||||
# continue
|
||||
|
||||
# client_total = sum(float(c.get(f, 0) or 0) for f in mh_dc_fields)
|
||||
# sub_total = sum(float(s.get(f, 0) or 0) for f in mh_dc_fields)
|
||||
|
||||
# row = {
|
||||
# "Location": loc,
|
||||
# key_field.replace("_", " "): key
|
||||
# }
|
||||
|
||||
# # CLIENT – ALL FIELDS
|
||||
# for k, v in c.items():
|
||||
# if k in ["id", "created_at"]:
|
||||
# continue
|
||||
# row[f"Client-{k}"] = v
|
||||
|
||||
# row["Client-Total"] = round(client_total, 2)
|
||||
# row[" "] = ""
|
||||
|
||||
# # SUBCONTRACTOR – ALL FIELDS
|
||||
# for k, v in s.items():
|
||||
# if k in ["id", "created_at", "subcontractor_id"]:
|
||||
# continue
|
||||
# row[f"Subcontractor-{k}"] = v
|
||||
|
||||
# row["Subcontractor-Total"] = round(sub_total, 2)
|
||||
# row["Diff"] = round(client_total - sub_total, 2)
|
||||
|
||||
# output.append(row)
|
||||
|
||||
# df = pd.DataFrame(output)
|
||||
# df.columns = [format_header(col) for col in df.columns]
|
||||
# return df
|
||||
|
||||
|
||||
# def build_comparison_laying(client_rows, contractor_rows, key_field):
|
||||
# contractor_lookup = make_lookup(contractor_rows, key_field)
|
||||
# laying_fields = Laying.sum_laying_fields()
|
||||
|
||||
# output = []
|
||||
|
||||
# for c in client_rows:
|
||||
# loc = normalize_key(c.get("Location"))
|
||||
# key = normalize_key(c.get(key_field))
|
||||
# if not loc or not key:
|
||||
# continue
|
||||
|
||||
# s = contractor_lookup.get((loc, key))
|
||||
# if not s:
|
||||
# continue
|
||||
|
||||
# client_total = sum(float(c.get(f, 0) or 0) for f in laying_fields)
|
||||
# sub_total = sum(float(s.get(f, 0) or 0) for f in laying_fields)
|
||||
|
||||
# print("--------------",key,"----------")
|
||||
# print("sum -client_total ",client_total)
|
||||
# print("sum -sub_total ",sub_total)
|
||||
# print("Diff ---- ",client_total - sub_total)
|
||||
# print("------------------------")
|
||||
# row = {
|
||||
# "Location": loc,
|
||||
# key_field.replace("_", " "): key
|
||||
# }
|
||||
|
||||
# # CLIENT – ALL FIELDS
|
||||
# for k, v in c.items():
|
||||
# if k in ["id", "created_at"]:
|
||||
# continue
|
||||
# row[f"Client-{k}"] = v
|
||||
|
||||
# row["Client-Total"] = round(client_total, 2)
|
||||
# row[" "] = ""
|
||||
|
||||
# # SUBCONTRACTOR – ALL FIELDS
|
||||
# for k, v in s.items():
|
||||
# if k in ["id", "created_at", "subcontractor_id"]:
|
||||
# continue
|
||||
# row[f"Subcontractor-{k}"] = v
|
||||
|
||||
# row["Subcontractor-Total"] = round(sub_total, 2)
|
||||
# row["Diff"] = round(client_total - sub_total, 2)
|
||||
|
||||
# output.append(row)
|
||||
|
||||
# df = pd.DataFrame(output)
|
||||
# df.columns = [format_header(col) for col in df.columns]
|
||||
# return df
|
||||
|
||||
@@ -121,7 +121,7 @@ def update_subcontractor(id):
|
||||
subcontractor.mobile_no = request.form.get("mobile_no")
|
||||
subcontractor.email_id = request.form.get("email_id")
|
||||
subcontractor.gst_no = request.form.get("gst_no")
|
||||
subcontractor.gst_no = request.form.get("pan_no")
|
||||
subcontractor.pan_no = request.form.get("pan_no")
|
||||
subcontractor.status = request.form.get("status")
|
||||
|
||||
db.session.commit()
|
||||
|
||||
Reference in New Issue
Block a user