diff --git a/app/routes/dashboard.py b/app/routes/dashboard.py index c66c79a..148ba97 100644 --- a/app/routes/dashboard.py +++ b/app/routes/dashboard.py @@ -73,11 +73,10 @@ def index(): ).scalar() # Recent inspections - recent_inspections_query = Inspection.query.order_by(Inspection.inspection_date.desc()).limit(5) + recent_inspections_query = Inspection.query.order_by(Inspection.inspection_date.desc()) if current_user.role == 'inspector': recent_inspections_query = recent_inspections_query.filter(Inspection.inspector_id == current_user.id) - - recent_inspections = recent_inspections_query.all() + recent_inspections = recent_inspections_query.limit(5).all() # System statistics (admin/supervisor only) total_facilities = Facility.query.filter_by(active=True).count() if current_user.role in ['admin', 'supervisor'] else 0 diff --git a/app/routes/reports.py b/app/routes/reports.py index 090712a..38e9fa4 100644 --- a/app/routes/reports.py +++ b/app/routes/reports.py @@ -126,11 +126,11 @@ def index(): completed=completed, flagged=flagged, avg_score=round(float(avg_score), 2) if avg_score else None, - facility_scores=facility_scores, - daily_scores=daily_scores, - issue_severity=issue_severity, - issue_status=issue_status, - top_inspectors=top_inspectors, + facility_scores=[{'name': r.name, 'avg_score': round(float(r.avg_score), 2), 'count': r.count} for r in facility_scores], + daily_scores=[{'day': str(r.day), 'avg': round(float(r.avg), 2), 'count': r.count} for r in daily_scores], + issue_severity=[{'severity': r.severity, 'count': r.count} for r in issue_severity], + issue_status=[{'status': r.status, 'count': r.count} for r in issue_status], + top_inspectors=[{'username': r.username, 'count': r.count, 'avg_score': round(float(r.avg_score), 2) if r.avg_score else None} for r in top_inspectors], critical_issues=critical_issues, ) @@ -276,4 +276,4 @@ def export_issues(): stream_with_context(generate()), mimetype='text/csv', headers={'Content-Disposition': f'attachment; filename="{filename}"'} - ) + ) \ No newline at end of file diff --git a/app/templates/reports/index.html b/app/templates/reports/index.html index 9042dde..77e4057 100644 --- a/app/templates/reports/index.html +++ b/app/templates/reports/index.html @@ -170,7 +170,6 @@ const BLUE = '#0d6efd', GREEN = '#198754', RED = '#dc3545', AMBER = '#ffc107', TEAL = '#0dcaf0', GRAY = '#adb5bd'; // ── Trend chart ────────────────────────────────────────────────────────────── -const trendData = {{ daily_scores | map(attribute=0) | list | tojson }}; {# dates #} new Chart(document.getElementById('trendChart'), { type: 'line', data: { @@ -239,4 +238,4 @@ new Chart(document.getElementById('statusChart'), { plugins: { legend: { position: 'bottom' } } } }); -{% endblock %} +{% endblock %} \ No newline at end of file