2026-07-31 12:44:09 +05:30
|
|
|
|
2026-01-13 13:21:06 +05:30
|
|
|
import matplotlib
|
|
|
|
|
matplotlib.use("Agg")
|
2026-01-10 16:49:46 +05:30
|
|
|
|
2026-03-17 15:35:52 +05:30
|
|
|
from flask import Blueprint, render_template, session, redirect, url_for, jsonify, request
|
2026-01-13 13:21:06 +05:30
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
import io
|
|
|
|
|
import base64
|
2026-01-20 16:33:45 +05:30
|
|
|
from app.utils.plot_utils import plot_to_base64
|
2026-07-30 14:38:37 +05:30
|
|
|
from app.utils.helpers import login_required
|
2026-01-20 16:33:45 +05:30
|
|
|
from app.services.dashboard_service import DashboardService
|
2026-02-25 15:27:59 +05:30
|
|
|
from sqlalchemy import func
|
|
|
|
|
from app import db
|
2026-07-31 12:44:09 +05:30
|
|
|
from sqlalchemy import tuple_
|
2026-07-30 14:38:37 +05:30
|
|
|
|
|
|
|
|
# Subcontractor models import
|
|
|
|
|
from app.models.subcontractor_model import Subcontractor
|
2026-02-25 15:27:59 +05:30
|
|
|
from app.models.trench_excavation_model import TrenchExcavation
|
|
|
|
|
from app.models.manhole_excavation_model import ManholeExcavation
|
2026-07-30 14:38:37 +05:30
|
|
|
from app.models.manhole_domestic_chamber_model import ManholeDomesticChamber
|
2026-02-25 15:27:59 +05:30
|
|
|
from app.models.laying_model import Laying
|
2025-12-11 10:16:43 +05:30
|
|
|
|
2026-07-30 14:38:37 +05:30
|
|
|
# client models import
|
|
|
|
|
from app.models.tr_ex_client_model import TrenchExcavationClient
|
2026-07-31 16:43:38 +05:30
|
|
|
from app.models.mh_ex_client_model import ManholeExcavationClient
|
|
|
|
|
from app.models.mh_dc_client_model import ManholeDomesticChamberClient
|
|
|
|
|
from app.models.laying_client_model import LayingClient
|
2026-07-30 14:38:37 +05:30
|
|
|
|
2026-03-11 13:20:49 +05:30
|
|
|
|
2026-01-10 01:04:21 +05:30
|
|
|
dashboard_bp = Blueprint("dashboard", __name__, url_prefix="/dashboard")
|
2025-12-11 10:16:43 +05:30
|
|
|
|
2026-01-20 16:33:45 +05:30
|
|
|
|
2026-02-26 17:08:49 +05:30
|
|
|
@dashboard_bp.route("/")
|
|
|
|
|
def dashboard():
|
|
|
|
|
if not session.get("user_id"):
|
|
|
|
|
return redirect(url_for("auth.login"))
|
|
|
|
|
return render_template("dashboard.html", title="Business Intelligence Dashboard")
|
2026-01-13 13:21:06 +05:30
|
|
|
|
|
|
|
|
|
2026-02-25 15:27:59 +05:30
|
|
|
@dashboard_bp.route("/api/live-stats")
|
2026-07-30 14:38:37 +05:30
|
|
|
@login_required
|
2026-02-25 15:27:59 +05:30
|
|
|
def live_stats():
|
|
|
|
|
try:
|
|
|
|
|
# 1. Overall Volume
|
|
|
|
|
t_count = TrenchExcavation.query.count()
|
|
|
|
|
m_count = ManholeExcavation.query.count()
|
|
|
|
|
l_count = Laying.query.count()
|
|
|
|
|
|
|
|
|
|
# 2. Location Distribution (Business reach)
|
|
|
|
|
loc_results = db.session.query(
|
|
|
|
|
TrenchExcavation.Location,
|
|
|
|
|
func.count(TrenchExcavation.id)
|
|
|
|
|
).group_by(TrenchExcavation.Location).all()
|
|
|
|
|
|
|
|
|
|
# 3. Work Timeline (Business productivity trend)
|
|
|
|
|
# Assuming your models have a 'created_at' field
|
|
|
|
|
timeline_results = db.session.query(
|
|
|
|
|
func.date(TrenchExcavation.created_at),
|
|
|
|
|
func.count(TrenchExcavation.id)
|
|
|
|
|
).group_by(func.date(TrenchExcavation.created_at)).order_by(func.date(TrenchExcavation.created_at)).all()
|
|
|
|
|
|
|
|
|
|
return jsonify({
|
|
|
|
|
"summary": {
|
|
|
|
|
"trench": t_count,
|
|
|
|
|
"manhole": m_count,
|
|
|
|
|
"laying": l_count,
|
|
|
|
|
"total": t_count + m_count + l_count
|
|
|
|
|
},
|
|
|
|
|
"locations": {row[0]: row[1] for row in loc_results if row[0]},
|
|
|
|
|
"timeline": {str(row[0]): row[1] for row in timeline_results}
|
|
|
|
|
})
|
|
|
|
|
except Exception as e:
|
|
|
|
|
return jsonify({"error": str(e)}), 500
|
2026-01-13 13:21:06 +05:30
|
|
|
|
2026-02-25 15:27:59 +05:30
|
|
|
|
2026-01-10 16:49:46 +05:30
|
|
|
|
2026-01-17 17:39:31 +05:30
|
|
|
# subcontractor dashboard
|
2026-03-11 13:20:49 +05:30
|
|
|
@dashboard_bp.route("/subcontractor_dashboard")
|
2026-07-30 14:38:37 +05:30
|
|
|
@login_required
|
2026-01-17 17:39:31 +05:30
|
|
|
def subcontractor_dashboard():
|
2026-03-11 13:20:49 +05:30
|
|
|
|
2026-01-17 17:39:31 +05:30
|
|
|
if not session.get("user_id"):
|
|
|
|
|
return redirect(url_for("auth.login"))
|
|
|
|
|
|
2026-03-11 13:20:49 +05:30
|
|
|
subcontractors = Subcontractor.query.all()
|
|
|
|
|
|
2026-01-17 17:39:31 +05:30
|
|
|
return render_template(
|
|
|
|
|
"subcontractor_dashboard.html",
|
2026-03-11 13:20:49 +05:30
|
|
|
subcontractors=subcontractors
|
|
|
|
|
)
|
|
|
|
|
|
2026-07-30 14:38:37 +05:30
|
|
|
# API: Get Unique RA Bills
|
2026-03-18 17:18:05 +05:30
|
|
|
@dashboard_bp.route("/api/get-ra-bills")
|
2026-07-30 14:38:37 +05:30
|
|
|
@login_required
|
2026-03-18 17:18:05 +05:30
|
|
|
def get_ra_bills():
|
|
|
|
|
|
|
|
|
|
subcontractor_id = request.args.get("subcontractor")
|
|
|
|
|
category = request.args.get("category")
|
|
|
|
|
|
|
|
|
|
if not subcontractor_id or not category:
|
|
|
|
|
return {"ra_bills": []}
|
|
|
|
|
|
|
|
|
|
match category:
|
|
|
|
|
|
|
|
|
|
case "trench_excavation":
|
|
|
|
|
results = db.session.query(
|
|
|
|
|
TrenchExcavation.RA_Bill_No
|
|
|
|
|
).filter(
|
|
|
|
|
TrenchExcavation.subcontractor_id == subcontractor_id
|
|
|
|
|
).distinct().order_by(TrenchExcavation.RA_Bill_No).all()
|
|
|
|
|
|
|
|
|
|
# (Add others same pattern later)
|
2026-07-30 14:38:37 +05:30
|
|
|
case "manhole_excavation":
|
|
|
|
|
results = db.session.query(
|
|
|
|
|
ManholeExcavation.RA_Bill_No
|
|
|
|
|
).filter(
|
|
|
|
|
ManholeExcavation.subcontractor_id == subcontractor_id
|
|
|
|
|
).distinct().order_by(ManholeExcavation.RA_Bill_No).all()
|
|
|
|
|
|
|
|
|
|
case "Manhole_Domestic_Chamber":
|
|
|
|
|
results = db.session.query(
|
|
|
|
|
ManholeDomesticChamber.RA_Bill_No
|
|
|
|
|
).filter(
|
|
|
|
|
ManholeDomesticChamber.subcontractor_id == subcontractor_id
|
|
|
|
|
).distinct().order_by(ManholeDomesticChamber.RA_Bill_No).all()
|
|
|
|
|
|
|
|
|
|
case "Laying":
|
|
|
|
|
results = db.session.query(
|
|
|
|
|
Laying.RA_Bill_No
|
|
|
|
|
).filter(
|
|
|
|
|
Laying.subcontractor_id == subcontractor_id
|
|
|
|
|
).distinct().order_by(Laying.RA_Bill_No).all()
|
|
|
|
|
|
2026-03-18 17:18:05 +05:30
|
|
|
ra_bills = [r[0] for r in results if r[0]]
|
|
|
|
|
|
|
|
|
|
return {"ra_bills": ra_bills}
|
|
|
|
|
|
2026-03-11 13:20:49 +05:30
|
|
|
|
2026-07-30 14:38:37 +05:30
|
|
|
def total(records, field):
|
|
|
|
|
return float(sum(getattr(r, field) or 0 for r in records))
|
2026-03-18 17:18:05 +05:30
|
|
|
|
2026-07-31 16:43:38 +05:30
|
|
|
# category= trench_excavation
|
|
|
|
|
@dashboard_bp.route("/api/tr-analysis")
|
2026-03-18 17:18:05 +05:30
|
|
|
def trench_analysis():
|
2026-03-11 13:20:49 +05:30
|
|
|
|
2026-07-30 14:38:37 +05:30
|
|
|
subcontractor_id = request.args.get("subcontractor", "").strip()
|
|
|
|
|
ra_bill = request.args.get("ra_bill", "").strip()
|
2026-03-11 13:20:49 +05:30
|
|
|
|
2026-07-30 14:38:37 +05:30
|
|
|
# Convert "1,2,3" -> ["1", "2", "3"]
|
|
|
|
|
ra_bill_list = []
|
2026-03-11 13:20:49 +05:30
|
|
|
if ra_bill:
|
2026-07-30 14:38:37 +05:30
|
|
|
ra_bill_list = [x.strip() for x in ra_bill.split(",") if x.strip()]
|
2026-03-11 13:20:49 +05:30
|
|
|
|
2026-07-30 14:38:37 +05:30
|
|
|
# Subcontractor Query
|
|
|
|
|
sub_query = TrenchExcavation.query
|
|
|
|
|
if subcontractor_id:
|
|
|
|
|
sub_query = sub_query.filter(
|
|
|
|
|
TrenchExcavation.subcontractor_id == int(subcontractor_id)
|
2026-03-18 17:18:05 +05:30
|
|
|
)
|
|
|
|
|
|
2026-07-30 14:38:37 +05:30
|
|
|
if ra_bill_list:
|
|
|
|
|
sub_query = sub_query.filter(
|
|
|
|
|
TrenchExcavation.RA_Bill_No.in_(ra_bill_list)
|
2026-03-18 17:18:05 +05:30
|
|
|
)
|
|
|
|
|
|
2026-07-31 12:44:09 +05:30
|
|
|
sub_records = sub_query.all()
|
|
|
|
|
|
|
|
|
|
sub_keys = [
|
|
|
|
|
(
|
|
|
|
|
(r.MH_NO or "").strip().upper(),
|
|
|
|
|
(r.Location or "").strip().upper()
|
|
|
|
|
)
|
|
|
|
|
for r in sub_records
|
|
|
|
|
]
|
2026-03-18 17:18:05 +05:30
|
|
|
|
2026-07-30 14:38:37 +05:30
|
|
|
client_query = TrenchExcavationClient.query
|
|
|
|
|
|
2026-07-31 12:44:09 +05:30
|
|
|
if sub_keys:
|
|
|
|
|
|
2026-07-30 14:38:37 +05:30
|
|
|
client_query = client_query.filter(
|
2026-07-31 12:44:09 +05:30
|
|
|
tuple_(
|
|
|
|
|
func.upper(func.trim(TrenchExcavationClient.MH_NO)),
|
|
|
|
|
func.upper(func.trim(TrenchExcavationClient.Location))
|
|
|
|
|
).in_(sub_keys)
|
|
|
|
|
|
2026-03-18 17:18:05 +05:30
|
|
|
)
|
|
|
|
|
|
2026-07-31 12:44:09 +05:30
|
|
|
client_records = client_query.all()
|
2026-07-30 14:38:37 +05:30
|
|
|
|
|
|
|
|
chart_data = [
|
2026-07-31 16:43:38 +05:30
|
|
|
{
|
|
|
|
|
"label": "Marshi 0 to 1.5",
|
|
|
|
|
"client": total(client_records, "Marshi_Muddy_Slushy_0_to_1_5_total"),
|
|
|
|
|
"sub": 0
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "Marshi 1.5 to 3.0",
|
|
|
|
|
"client": total(client_records, "Marshi_Muddy_Slushy_1_5_to_3_0_total"),
|
|
|
|
|
"sub": 0
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "Marshi 3.0 to 4.5",
|
|
|
|
|
"client": total(client_records, "Marshi_Muddy_Slushy_3_0_to_4_5_total"),
|
|
|
|
|
"sub": 0
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"label": "Soft Murum 0 to 1.5",
|
|
|
|
|
"client": total(client_records, "Soft_Murum_0_to_1_5_total"),
|
|
|
|
|
"sub": total(sub_records, "Soft_Murum_0_to_1_5_total")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "Soft Murum 1.5 to 3.0",
|
|
|
|
|
"client": total(client_records, "Soft_Murum_1_5_to_3_0_total"),
|
|
|
|
|
"sub": total(sub_records, "Soft_Murum_1_5_to_3_0_total")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "Soft Murum 3.0 to 4.5",
|
|
|
|
|
"client": total(client_records, "Soft_Murum_3_0_to_4_5_total"),
|
|
|
|
|
"sub": total(sub_records, "Soft_Murum_3_0_to_4_5_total")
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"label": "Hard Murum 0 to 1.5",
|
|
|
|
|
"client": total(client_records, "Hard_Murum_0_to_1_5_total"),
|
|
|
|
|
"sub": total(sub_records, "Hard_Murum_0_to_1_5_total")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "Hard Murum 1.5 to 3.0",
|
|
|
|
|
"client": total(client_records, "Hard_Murum_1_5_to_3_0_total"),
|
|
|
|
|
"sub": total(sub_records, "Hard_Murum_1_5_and_above_total")
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"label": "Soft Rock 0 to 1.5",
|
|
|
|
|
"client": total(client_records, "Soft_Rock_0_to_1_5_total"),
|
|
|
|
|
"sub": total(sub_records, "Soft_Rock_0_to_1_5_total")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "Soft Rock 1.5 to 3.0",
|
|
|
|
|
"client": total(client_records, "Soft_Rock_1_5_to_3_0_total"),
|
|
|
|
|
"sub": total(sub_records, "Soft_Rock_1_5_and_above_total")
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"label": "Hard Rock 0 to 1.5",
|
|
|
|
|
"client": total(client_records, "Hard_Rock_0_to_1_5_total"),
|
|
|
|
|
"sub": total(sub_records, "Hard_Rock_0_to_1_5_total")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "Hard Rock 1.5 to 3.0",
|
|
|
|
|
"client": total(client_records, "Hard_Rock_1_5_to_3_0_total"),
|
|
|
|
|
"sub": total(sub_records, "Hard_Rock_1_5_to_3_0_total")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "Hard Rock 3.0 to 4.5",
|
|
|
|
|
"client": total(client_records, "Hard_Rock_3_0_to_4_5_total"),
|
|
|
|
|
"sub": total(sub_records, "Hard_Rock_3_0_to_4_5_total")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "Hard Rock 4.5 to 6.0",
|
|
|
|
|
"client": total(client_records, "Hard_Rock_4_5_to_6_0_total"),
|
|
|
|
|
"sub": total(sub_records, "Hard_Rock_4_5_to_6_0_total")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "Hard Rock 6.0 to 7.5",
|
|
|
|
|
"client": total(client_records, "Hard_Rock_6_0_to_7_5_total"),
|
|
|
|
|
"sub": total(sub_records, "Hard_Rock_6_0_to_7_5_total")
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
return jsonify({
|
|
|
|
|
"title": "Trench Excavation Comparison",
|
|
|
|
|
"y_title": "Excavation Qty (Cum)",
|
|
|
|
|
"labels": [x["label"] for x in chart_data],
|
|
|
|
|
"client_qty": [x["client"] for x in chart_data],
|
|
|
|
|
"sub_qty": [x["sub"] for x in chart_data]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
# category = manhole_excavation
|
|
|
|
|
@dashboard_bp.route("/api/mh-analysis")
|
|
|
|
|
def manhole_analysis():
|
|
|
|
|
|
|
|
|
|
subcontractor_id = request.args.get("subcontractor", "").strip()
|
|
|
|
|
ra_bill = request.args.get("ra_bill", "").strip()
|
|
|
|
|
|
|
|
|
|
# Convert "1,2,3" -> ["1", "2", "3"]
|
|
|
|
|
ra_bill_list = []
|
|
|
|
|
if ra_bill:
|
|
|
|
|
ra_bill_list = [x.strip() for x in ra_bill.split(",") if x.strip()]
|
|
|
|
|
|
|
|
|
|
# Subcontractor Query
|
|
|
|
|
sub_query = ManholeExcavation.query
|
|
|
|
|
if subcontractor_id:
|
|
|
|
|
sub_query = sub_query.filter(
|
|
|
|
|
ManholeExcavation.subcontractor_id == int(subcontractor_id)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if ra_bill_list:
|
|
|
|
|
sub_query = sub_query.filter(
|
|
|
|
|
ManholeExcavation.RA_Bill_No.in_(ra_bill_list)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
sub_records = sub_query.all()
|
|
|
|
|
|
|
|
|
|
sub_keys = [
|
|
|
|
|
(
|
|
|
|
|
(r.MH_NO or "").strip().upper(),
|
|
|
|
|
(r.Location or "").strip().upper()
|
|
|
|
|
)
|
|
|
|
|
for r in sub_records
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
client_query = ManholeExcavationClient.query
|
|
|
|
|
|
|
|
|
|
if sub_keys:
|
|
|
|
|
|
|
|
|
|
client_query = client_query.filter(
|
|
|
|
|
tuple_(
|
|
|
|
|
func.upper(func.trim(ManholeExcavationClient.MH_NO)),
|
|
|
|
|
func.upper(func.trim(ManholeExcavationClient.Location))
|
|
|
|
|
).in_(sub_keys)
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
client_records = client_query.all()
|
|
|
|
|
|
|
|
|
|
chart_data = [
|
2026-07-30 14:38:37 +05:30
|
|
|
{
|
|
|
|
|
"label": "Marshi 0 to 1.5",
|
2026-07-31 12:44:09 +05:30
|
|
|
"client": total(client_records, "Marshi_Muddy_Slushy_0_to_1_5_total"),
|
2026-07-30 14:38:37 +05:30
|
|
|
"sub": 0
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "Marshi 1.5 to 3.0",
|
2026-07-31 12:44:09 +05:30
|
|
|
"client": total(client_records, "Marshi_Muddy_Slushy_1_5_to_3_0_total"),
|
2026-07-30 14:38:37 +05:30
|
|
|
"sub": 0
|
|
|
|
|
},
|
|
|
|
|
{
|
2026-07-31 12:44:09 +05:30
|
|
|
"label": "Marshi 3.0 to 4.5",
|
|
|
|
|
"client": total(client_records, "Marshi_Muddy_Slushy_3_0_to_4_5_total"),
|
2026-07-30 14:38:37 +05:30
|
|
|
"sub": 0
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
2026-07-31 12:44:09 +05:30
|
|
|
"label": "Soft Murum 0 to 1.5",
|
|
|
|
|
"client": total(client_records, "Soft_Murum_0_to_1_5_total"),
|
|
|
|
|
"sub": total(sub_records, "Soft_Murum_0_to_1_5_total")
|
2026-07-30 14:38:37 +05:30
|
|
|
},
|
|
|
|
|
{
|
2026-07-31 12:44:09 +05:30
|
|
|
"label": "Soft Murum 1.5 to 3.0",
|
|
|
|
|
"client": total(client_records, "Soft_Murum_1_5_to_3_0_total"),
|
|
|
|
|
"sub": total(sub_records, "Soft_Murum_1_5_to_3_0_total")
|
2026-07-30 14:38:37 +05:30
|
|
|
},
|
|
|
|
|
{
|
2026-07-31 12:44:09 +05:30
|
|
|
"label": "Soft Murum 3.0 to 4.5",
|
|
|
|
|
"client": total(client_records, "Soft_Murum_3_0_to_4_5_total"),
|
|
|
|
|
"sub": total(sub_records, "Soft_Murum_3_0_to_4_5_total")
|
2026-07-30 14:38:37 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
2026-07-31 12:44:09 +05:30
|
|
|
"label": "Hard Murum 0 to 1.5",
|
|
|
|
|
"client": total(client_records, "Hard_Murum_0_to_1_5_total"),
|
|
|
|
|
"sub": total(sub_records, "Hard_Murum_0_to_1_5_total")
|
2026-07-30 14:38:37 +05:30
|
|
|
},
|
|
|
|
|
{
|
2026-07-31 12:44:09 +05:30
|
|
|
"label": "Hard Murum 1.5 to 3.0",
|
|
|
|
|
"client": total(client_records, "Hard_Murum_1_5_to_3_0_total"),
|
|
|
|
|
"sub": total(sub_records, "Hard_Murum_1_5_and_above_total")
|
2026-07-30 14:38:37 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
2026-07-31 12:44:09 +05:30
|
|
|
"label": "Soft Rock 0 to 1.5",
|
|
|
|
|
"client": total(client_records, "Soft_Rock_0_to_1_5_total"),
|
|
|
|
|
"sub": total(sub_records, "Soft_Rock_0_to_1_5_total")
|
2026-07-30 14:38:37 +05:30
|
|
|
},
|
|
|
|
|
{
|
2026-07-31 12:44:09 +05:30
|
|
|
"label": "Soft Rock 1.5 to 3.0",
|
|
|
|
|
"client": total(client_records, "Soft_Rock_1_5_to_3_0_total"),
|
|
|
|
|
"sub": total(sub_records, "Soft_Rock_1_5_and_above_total")
|
2026-07-30 14:38:37 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
2026-07-31 12:44:09 +05:30
|
|
|
"label": "Hard Rock 0 to 1.5",
|
|
|
|
|
"client": total(client_records, "Hard_Rock_0_to_1_5_total"),
|
|
|
|
|
"sub": total(sub_records, "Hard_Rock_0_to_1_5_total")
|
2026-07-30 14:38:37 +05:30
|
|
|
},
|
|
|
|
|
{
|
2026-07-31 12:44:09 +05:30
|
|
|
"label": "Hard Rock 1.5 to 3.0",
|
|
|
|
|
"client": total(client_records, "Hard_Rock_1_5_to_3_0_total"),
|
|
|
|
|
"sub": total(sub_records, "Hard_Rock_1_5_to_3_0_total")
|
2026-07-30 14:38:37 +05:30
|
|
|
},
|
|
|
|
|
{
|
2026-07-31 12:44:09 +05:30
|
|
|
"label": "Hard Rock 3.0 to 4.5",
|
|
|
|
|
"client": total(client_records, "Hard_Rock_3_0_to_4_5_total"),
|
|
|
|
|
"sub": total(sub_records, "Hard_Rock_3_0_to_4_5_total")
|
2026-07-30 14:38:37 +05:30
|
|
|
},
|
|
|
|
|
{
|
2026-07-31 12:44:09 +05:30
|
|
|
"label": "Hard Rock 4.5 to 6.0",
|
|
|
|
|
"client": total(client_records, "Hard_Rock_4_5_to_6_0_total"),
|
|
|
|
|
"sub": total(sub_records, "Hard_Rock_4_5_to_6_0_total")
|
2026-07-30 14:38:37 +05:30
|
|
|
},
|
|
|
|
|
{
|
2026-07-31 12:44:09 +05:30
|
|
|
"label": "Hard Rock 6.0 to 7.5",
|
|
|
|
|
"client": total(client_records, "Hard_Rock_6_0_to_7_5_total"),
|
|
|
|
|
"sub": total(sub_records, "Hard_Rock_6_0_to_7_5_total")
|
2026-07-30 14:38:37 +05:30
|
|
|
}
|
|
|
|
|
]
|
2026-03-11 13:20:49 +05:30
|
|
|
|
|
|
|
|
return jsonify({
|
2026-07-31 16:43:38 +05:30
|
|
|
"title": "Manhole Excavation Comparison",
|
|
|
|
|
"y_title": "Manhole Qty (Nos)",
|
2026-07-30 14:38:37 +05:30
|
|
|
"labels": [x["label"] for x in chart_data],
|
|
|
|
|
"client_qty": [x["client"] for x in chart_data],
|
|
|
|
|
"sub_qty": [x["sub"] for x in chart_data]
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-31 16:43:38 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
# category = Manhole_Domestic_Chamber
|
|
|
|
|
@dashboard_bp.route("/api/mdc-analysis")
|
|
|
|
|
def Manhole_Domestic_Chamber_analysis():
|
|
|
|
|
|
|
|
|
|
subcontractor_id = request.args.get("subcontractor", "").strip()
|
|
|
|
|
ra_bill = request.args.get("ra_bill", "").strip()
|
|
|
|
|
|
|
|
|
|
# Convert "1,2,3" -> ["1", "2", "3"]
|
|
|
|
|
ra_bill_list = []
|
|
|
|
|
if ra_bill:
|
|
|
|
|
ra_bill_list = [x.strip() for x in ra_bill.split(",") if x.strip()]
|
|
|
|
|
|
|
|
|
|
# Subcontractor Query
|
|
|
|
|
sub_query = ManholeDomesticChamber.query
|
|
|
|
|
if subcontractor_id:
|
|
|
|
|
sub_query = sub_query.filter(
|
|
|
|
|
ManholeDomesticChamber.subcontractor_id == int(subcontractor_id)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if ra_bill_list:
|
|
|
|
|
sub_query = sub_query.filter(
|
|
|
|
|
ManholeDomesticChamber.RA_Bill_No.in_(ra_bill_list)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
sub_records = sub_query.all()
|
|
|
|
|
|
|
|
|
|
sub_keys = [
|
|
|
|
|
(
|
|
|
|
|
(r.MH_NO or "").strip().upper(),
|
|
|
|
|
(r.Location or "").strip().upper()
|
|
|
|
|
)
|
|
|
|
|
for r in sub_records
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
client_query = ManholeDomesticChamberClient.query
|
|
|
|
|
|
|
|
|
|
if sub_keys:
|
|
|
|
|
|
|
|
|
|
client_query = client_query.filter(
|
|
|
|
|
tuple_(
|
|
|
|
|
func.upper(func.trim(ManholeDomesticChamberClient.MH_NO)),
|
|
|
|
|
func.upper(func.trim(ManholeDomesticChamberClient.Location))
|
|
|
|
|
).in_(sub_keys)
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
client_records = client_query.all()
|
|
|
|
|
|
|
|
|
|
chart_data = [
|
|
|
|
|
{
|
|
|
|
|
"label": "Depth of MH",
|
|
|
|
|
"client": total(client_records, "Depth_of_MH"),
|
|
|
|
|
"sub": total(sub_records, "Depth_of_MH")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "Domestic_Chambers Total",
|
|
|
|
|
"client": total(client_records, "Total"),
|
|
|
|
|
"sub": total(sub_records, "Total")
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
return jsonify({
|
|
|
|
|
"title": "Domestic Chamber Comparison",
|
|
|
|
|
"y_title": "Quantity (Nos)",
|
|
|
|
|
"labels": [x["label"] for x in chart_data],
|
|
|
|
|
"client_qty": [x["client"] for x in chart_data],
|
|
|
|
|
"sub_qty": [x["sub"] for x in chart_data]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# category = Laying
|
|
|
|
|
@dashboard_bp.route("/api/laying-analysis")
|
|
|
|
|
def laying_analysis():
|
|
|
|
|
|
|
|
|
|
subcontractor_id = request.args.get("subcontractor", "").strip()
|
|
|
|
|
ra_bill = request.args.get("ra_bill", "").strip()
|
|
|
|
|
|
|
|
|
|
# Convert "1,2,3" -> ["1", "2", "3"]
|
|
|
|
|
ra_bill_list = []
|
|
|
|
|
if ra_bill:
|
|
|
|
|
ra_bill_list = [x.strip() for x in ra_bill.split(",") if x.strip()]
|
|
|
|
|
|
|
|
|
|
# Subcontractor Query
|
|
|
|
|
sub_query = Laying.query
|
|
|
|
|
if subcontractor_id:
|
|
|
|
|
sub_query = sub_query.filter(
|
|
|
|
|
Laying.subcontractor_id == int(subcontractor_id)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if ra_bill_list:
|
|
|
|
|
sub_query = sub_query.filter(
|
|
|
|
|
Laying.RA_Bill_No.in_(ra_bill_list)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
sub_records = sub_query.all()
|
|
|
|
|
|
|
|
|
|
sub_keys = [
|
|
|
|
|
(
|
|
|
|
|
(r.MH_NO or "").strip().upper(),
|
|
|
|
|
(r.Location or "").strip().upper()
|
|
|
|
|
)
|
|
|
|
|
for r in sub_records
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
client_query = LayingClient.query
|
|
|
|
|
|
|
|
|
|
if sub_keys:
|
|
|
|
|
|
|
|
|
|
client_query = client_query.filter(
|
|
|
|
|
tuple_(
|
|
|
|
|
func.upper(func.trim(LayingClient.MH_NO)),
|
|
|
|
|
func.upper(func.trim(LayingClient.Location))
|
|
|
|
|
).in_(sub_keys)
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
client_records = client_query.all()
|
|
|
|
|
|
|
|
|
|
chart_data = [
|
|
|
|
|
{
|
|
|
|
|
"label": "150 mm",
|
|
|
|
|
"client": total(client_records, "pipe_150_mm"),
|
|
|
|
|
"sub": total(sub_records, "pipe_150_mm")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "200 mm",
|
|
|
|
|
"client": total(client_records, "pipe_200_mm"),
|
|
|
|
|
"sub": total(sub_records, "pipe_200_mm")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "250 mm",
|
|
|
|
|
"client": total(client_records, "pipe_250_mm"),
|
|
|
|
|
"sub": total(sub_records, "pipe_250_mm")
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"label": "300 mm",
|
|
|
|
|
"client": total(client_records, "pipe_300_mm"),
|
|
|
|
|
"sub": total(sub_records, "pipe_300_mm")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "350 mm",
|
|
|
|
|
"client": total(client_records, "pipe_350_mm"),
|
|
|
|
|
"sub": total(sub_records, "pipe_350_mm")
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"label": "400 mm",
|
|
|
|
|
"client": total(client_records, "pipe_400_mm"),
|
|
|
|
|
"sub": total(sub_records, "pipe_400_mm")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "450 mm",
|
|
|
|
|
"client": total(client_records, "pipe_450_mm"),
|
|
|
|
|
"sub": total(sub_records, "pipe_450_mm")
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"label": "500 mm",
|
|
|
|
|
"client": total(client_records, "pipe_500_mm"),
|
|
|
|
|
"sub": total(sub_records, "pipe_500_mm")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "600 mm",
|
|
|
|
|
"client": total(client_records, "pipe_600_mm"),
|
|
|
|
|
"sub": total(sub_records, "pipe_600_mm")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "700 mm",
|
|
|
|
|
"client": total(client_records, "pipe_700_mm"),
|
|
|
|
|
"sub": total(sub_records, "pipe_700_mm")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "900 mm",
|
|
|
|
|
"client": total(client_records, "pipe_900_mm"),
|
|
|
|
|
"sub": total(sub_records, "pipe_900_mm")
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"label": "1200 mm",
|
|
|
|
|
"client": total(client_records, "pipe_1200_mm"),
|
|
|
|
|
"sub": total(sub_records, "pipe_1200_mm")
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
return jsonify({
|
|
|
|
|
"title": "Pipe Laying Comparison",
|
|
|
|
|
"y_title": "Pipe Length (Mtr)",
|
|
|
|
|
"labels": [x["label"] for x in chart_data],
|
|
|
|
|
"client_qty": [x["client"] for x in chart_data],
|
|
|
|
|
"sub_qty": [x["sub"] for x in chart_data]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|