From a73d8e5ed158c050d1b911a06d6c9b44757eb212 Mon Sep 17 00:00:00 2001 From: pjpatil12 Date: Tue, 13 Jan 2026 13:21:06 +0530 Subject: [PATCH] changes of manu bar add report and dashboard --- .env | 2 +- app/models/manhole_domestic_chamber_model.py | 1 + app/routes/dashboard.py | 58 +++++++++++++++- app/services/file_service.py | 66 +++++++++--------- app/templates/base.html | 36 +++++++--- app/templates/dashboard.html | 72 +++++++++++++++++++- app/templates/login.html | 2 +- app/templates/subcontractor/list.html | 8 +-- requirements.txt | 3 +- 9 files changed, 194 insertions(+), 54 deletions(-) diff --git a/.env b/.env index 9a857ca..6396d39 100644 --- a/.env +++ b/.env @@ -3,7 +3,7 @@ # ----------------------------- FLASK_ENV=development FLASK_DEBUG=True -FLASK_HOST=127.0.0.1 +FLASK_HOST='0.0.0.0' FLASK_PORT=5001 # ----------------------------- diff --git a/app/models/manhole_domestic_chamber_model.py b/app/models/manhole_domestic_chamber_model.py index 98d4881..0902f0d 100644 --- a/app/models/manhole_domestic_chamber_model.py +++ b/app/models/manhole_domestic_chamber_model.py @@ -49,3 +49,4 @@ class ManholeDomesticChamber(db.Model): def serialize(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns} + diff --git a/app/routes/dashboard.py b/app/routes/dashboard.py index 04a4544..ad8b047 100644 --- a/app/routes/dashboard.py +++ b/app/routes/dashboard.py @@ -1,11 +1,67 @@ +import matplotlib +matplotlib.use("Agg") from flask import Blueprint, render_template, session, redirect, url_for +import matplotlib.pyplot as plt +import io +import base64 dashboard_bp = Blueprint("dashboard", __name__, url_prefix="/dashboard") + +def plot_to_base64(): + img = io.BytesIO() + plt.savefig(img, format="png", bbox_inches="tight") + plt.close() + img.seek(0) + return base64.b64encode(img.getvalue()).decode() + + +def bar_chart(): + categories = ["Trench", "Manhole", "Pipe Laying", "Restoration"] + values = [120, 80, 150, 60] + + plt.figure() + plt.bar(categories, values) + plt.title("Work Category Report") + plt.xlabel("Category") + plt.ylabel("Count") + + return plot_to_base64() + + +def pie_chart(): + labels = ["Completed", "In Progress", "Pending"] + sizes = [65, 20, 15] + + plt.figure() + plt.pie(sizes, labels=labels, autopct="%1.1f%%", startangle=140) + plt.title("Project Status") + + return plot_to_base64() + + +def histogram_chart(): + daily_work = [5, 10, 15, 20, 20, 25, 30, 35, 40, 45, 50] + + plt.figure() + plt.hist(daily_work, bins=5) + plt.title("Daily Work Distribution") + plt.xlabel("Work Units") + plt.ylabel("Frequency") + + return plot_to_base64() + + @dashboard_bp.route("/") def dashboard(): if not session.get("user_id"): return redirect(url_for("auth.login")) - return render_template("dashboard.html", title="Dashboard") + return render_template( + "dashboard.html", + title="Dashboard", + bar_chart=bar_chart(), + pie_chart=pie_chart(), + histogram=histogram_chart() + ) diff --git a/app/services/file_service.py b/app/services/file_service.py index e98e3f7..82d3819 100644 --- a/app/services/file_service.py +++ b/app/services/file_service.py @@ -96,18 +96,18 @@ class FileService: if not location or not mh_no: continue - exists = TrenchExcavation.query.filter_by( - subcontractor_id=subcontractor_id, - RA_Bill_No=RA_Bill_No, - Location=location, - MH_NO=mh_no, - ).first() + # exists = TrenchExcavation.query.filter_by( + # subcontractor_id=subcontractor_id, + # RA_Bill_No=RA_Bill_No, + # Location=location, + # MH_NO=mh_no, + # ).first() - if exists: - errors.append( - f"Model-Tr.Ex. (Row {idx+1}): Duplicate → Location={location}, MH_NO={mh_no}" - ) - continue + # if exists: + # errors.append( + # f"Model-Tr.Ex. (Row {idx+1}): Duplicate → Location={location}, MH_NO={mh_no}" + # ) + # continue record_data = {} for col in df.columns: @@ -154,18 +154,18 @@ class FileService: if not location or not mh_no: continue - exists = ManholeExcavation.query.filter_by( - subcontractor_id=subcontractor_id, - RA_Bill_No=RA_Bill_No, - Location=location, - MH_NO=mh_no, - ).first() + # exists = ManholeExcavation.query.filter_by( + # subcontractor_id=subcontractor_id, + # RA_Bill_No=RA_Bill_No, + # Location=location, + # MH_NO=mh_no, + # ).first() - if exists: - errors.append( - f"Model-MH Ex. (Row {idx+1}): Duplicate → Location={location}, MH_NO={mh_no}" - ) - continue + # if exists: + # errors.append( + # f"Model-MH Ex. (Row {idx+1}): Duplicate → Location={location}, MH_NO={mh_no}" + # ) + # continue record_data = {} for col in df.columns: @@ -212,18 +212,18 @@ class FileService: if not location or not mh_no: continue - exists = ManholeDomesticChamber.query.filter_by( - subcontractor_id=subcontractor_id, - RA_Bill_No=RA_Bill_No, - Location=location, - MH_NO=mh_no, - ).first() + # exists = ManholeDomesticChamber.query.filter_by( + # subcontractor_id=subcontractor_id, + # RA_Bill_No=RA_Bill_No, + # Location=location, + # MH_NO=mh_no, + # ).first() - if exists: - errors.append( - f"Model-MH & DC (Row {idx+1}): Duplicate → Location={location}, MH_NO={mh_no}" - ) - continue + # if exists: + # errors.append( + # f"Model-MH & DC (Row {idx+1}): Duplicate → Location={location}, MH_NO={mh_no}" + # ) + # continue record_data = {} for col in df.columns: diff --git a/app/templates/base.html b/app/templates/base.html index 3ea90da..affe12d 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -40,10 +40,10 @@ - + - +