comaparison code optimization and cal sum/total mh dc and laying
This commit is contained in:
@@ -5,16 +5,20 @@ from flask import Blueprint, render_template, session, redirect, url_for
|
||||
import matplotlib.pyplot as plt
|
||||
import io
|
||||
import base64
|
||||
from app.utils.plot_utils import plot_to_base64
|
||||
from app.services.dashboard_service import DashboardService
|
||||
|
||||
dashboard_bp = Blueprint("dashboard", __name__, url_prefix="/dashboard")
|
||||
|
||||
# dashboard_bp = Blueprint("dashboard", __name__)
|
||||
|
||||
# charts
|
||||
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 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()
|
||||
|
||||
# bar chart
|
||||
def bar_chart():
|
||||
@@ -28,7 +32,7 @@ def bar_chart():
|
||||
plt.ylabel("Count")
|
||||
|
||||
|
||||
return plot_to_base64()
|
||||
return plot_to_base64(plt)
|
||||
|
||||
# Pie chart
|
||||
def pie_chart():
|
||||
@@ -39,7 +43,7 @@ def pie_chart():
|
||||
plt.pie(sizes, labels=labels, autopct="%1.1f%%", startangle=140)
|
||||
plt.title("Project Status")
|
||||
|
||||
return plot_to_base64()
|
||||
return plot_to_base64(plt)
|
||||
|
||||
# Histogram chart
|
||||
def histogram_chart():
|
||||
@@ -51,7 +55,7 @@ def histogram_chart():
|
||||
plt.xlabel("Work Units")
|
||||
plt.ylabel("Frequency")
|
||||
|
||||
return plot_to_base64()
|
||||
return plot_to_base64(plt)
|
||||
|
||||
# Dashboaed page
|
||||
@dashboard_bp.route("/")
|
||||
@@ -68,15 +72,16 @@ def dashboard():
|
||||
)
|
||||
|
||||
# subcontractor dashboard
|
||||
@dashboard_bp.route("/subcontractor_dashboard")
|
||||
@dashboard_bp.route("/subcontractor_dashboard", methods=["GET", "POST"])
|
||||
def subcontractor_dashboard():
|
||||
if not session.get("user_id"):
|
||||
return redirect(url_for("auth.login"))
|
||||
|
||||
tr_dash = DashboardService().bar_chart_of_tr_ex
|
||||
|
||||
|
||||
return render_template(
|
||||
"subcontractor_dashboard.html",
|
||||
title="Dashboard",
|
||||
bar_chart=bar_chart(),
|
||||
pie_chart=pie_chart(),
|
||||
histogram=histogram_chart()
|
||||
)
|
||||
bar_chart=tr_dash
|
||||
)
|
||||
Reference in New Issue
Block a user