lokesh341 commited on
Commit
f723ba5
·
verified ·
1 Parent(s): 9488719

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +188 -59
app.py CHANGED
@@ -130,7 +130,7 @@ def generate_pdf(vendor_id: str, vendor_log_name: str, scores: dict):
130
  pdf_content = f.read()
131
  os.remove(filename)
132
  return pdf_content
133
- except Exception as e:
134
  logger.error(f"Error generating PDF: {str(e)}")
135
  raise
136
 
@@ -219,86 +219,215 @@ async def score_vendor(log: VendorLog, authorization: str = Header(...)):
219
  @app.get('/', response_class=HTMLResponse)
220
  async def get_dashboard():
221
  try:
 
 
 
 
 
 
 
 
 
 
 
 
222
  html_content = """
223
  <html>
224
  <head>
225
  <title>Subcontractor Performance Score App</title>
226
  <style>
227
- body { font-family: Arial, sans-serif; margin: 20px; }
228
- table { width: 100%; border-collapse: collapse; margin-top: 20px; }
229
- th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
 
 
 
 
 
 
 
230
  th { background-color: #f2f2f2; }
231
- h1, h2 { text-align: center; }
 
 
 
 
 
 
 
 
 
 
232
  </style>
233
  </head>
234
  <body>
235
- <h1>SUBCONTRACTOR PERFORMANCE SCORE APP GENERATOR</h1>
236
- <h2>VENDOR LOGS SUBMISSION</h2>
237
- <table>
238
- <tr>
239
- <th>Vendor ID</th>
240
- <th>Vendor Log Name</th>
241
- <th>Project</th>
242
- <th>Work Completion Percentage</th>
243
- <th>Quality Percentage</th>
244
- <th>Incident Severity</th>
245
- <th>Work Completion Date</th>
246
- <th>Actual Completion Date</th>
247
- <th>Delay Days</th>
248
- </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  """
250
 
251
- for log in vendor_logs:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  html_content += f"""
253
- <tr>
254
- <td>{log['vendorId']}</td>
255
- <td>{log['vendorLogName']}</td>
256
- <td>{log['project']}</td>
257
- <td>{log['workDetails']}</td>
258
- <td>{log['qualityReport']}</td>
259
- <td>{log['incidentLog']}</td>
260
- <td>{log['workCompletionDate']}</td>
261
- <td>{log['actualCompletionDate']}</td>
262
- <td>{log['delayDays']}</td>
263
- </tr>
264
  """
265
 
266
  html_content += """
267
- </table>
268
- <h2>SUBCONTRACTOR PERFORMANCE SCORES</h2>
269
- <table>
270
- <tr>
271
- <th>Vendor ID</th>
272
- <th>Vendor Log Name</th>
273
- <th>Project</th>
274
- <th>Quality Score</th>
275
- <th>Timeliness Score</th>
276
- <th>Safety Score</th>
277
- <th>Communication Score</th>
278
- <th>Final Score</th>
279
- <th>Alert Flag</th>
280
- </tr>
281
  """
282
 
283
  for log in vendor_logs:
284
- scores = log['scores']
285
- alert_flag = determine_alert_flag(scores['finalScore'], vendor_logs)
286
  html_content += f"""
287
- <tr>
288
- <td>{log['vendorId']}</td>
289
- <td>{log['vendorLogName']}</td>
290
- <td>{log['project']}</td>
291
- <td>{scores['qualityScore']}%</td>
292
- <td>{scores['timelinessScore']}%</td>
293
- <td>{scores['safetyScore']}%</td>
294
- <td>{scores['communicationScore']}%</td>
295
- <td>{scores['finalScore']}%</td>
296
- <td>{'Checked' if alert_flag else 'Unchecked'}</td>
297
- </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  """
299
 
300
  html_content += """
301
- </table>
 
 
 
 
 
 
302
  </body>
303
  </html>
304
  """
 
130
  pdf_content = f.read()
131
  os.remove(filename)
132
  return pdf_content
133
+ except tuturor: Exception) -> None:
134
  logger.error(f"Error generating PDF: {str(e)}")
135
  raise
136
 
 
219
  @app.get('/', response_class=HTMLResponse)
220
  async def get_dashboard():
221
  try:
222
+ # Calculate summary metrics
223
+ total_vendors = len(vendor_logs)
224
+ performance_alerts = sum(1 for log in vendor_logs if determine_alert_flag(log['scores']['finalScore'], vendor_logs))
225
+ top_performers = sum(1 for log in vendor_logs if log['scores']['finalScore'] >= 90)
226
+ improving_vendors = sum(1 for log in vendor_logs if log['scores']['finalScore'] >= 70) # Simplified logic for "improving"
227
+
228
+ # Sort vendor logs by final score for leaderboard
229
+ sorted_logs = sorted(vendor_logs, key=lambda x: x['scores']['finalScore'], reverse=True)
230
+ top_logs = sorted_logs[:5] # Top 5 for leaderboard
231
+ top_performing_logs = sorted_logs[:4] # Top 4 for "Top Performing Vendors" section
232
+ alert_logs = [log for log in vendor_logs if determine_alert_flag(log['scores']['finalScore'], vendor_logs)]
233
+
234
  html_content = """
235
  <html>
236
  <head>
237
  <title>Subcontractor Performance Score App</title>
238
  <style>
239
+ body { font-family: Arial, sans-serif; margin: 20px; background-color: #f5f7fa; }
240
+ h1, h2 { color: #333; }
241
+ .container { max-width: 1200px; margin: 0 auto; }
242
+ .summary-cards { display: flex; gap: 20px; margin-bottom: 20px; }
243
+ .card { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); flex: 1; text-align: center; }
244
+ .card h3 { margin: 0 0 10px; color: #555; }
245
+ .card p { margin: 0; font-size: 24px; color: #333; }
246
+ .leaderboard, .alerts, .top-performers, .reports { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin-bottom: 20px; }
247
+ table { width: 100%; border-collapse: collapse; }
248
+ th, td { padding: 12px; text-align: left; border-bottom: 1px solid #ddd; }
249
  th { background-color: #f2f2f2; }
250
+ .status-good { background: #e6f4ea; color: #2e7d32; padding: 5px 10px; border-radius: 12px; display: inline-block; }
251
+ .status-alert { background: #fff3e0; color: #ef6c00; padding: 5px 10px; border-radius: 12px; display: inline-block; }
252
+ .trend-up { color: green; }
253
+ .trend-down { color: red; }
254
+ .trend-flat { color: gray; }
255
+ .score-circle { display: inline-block; width: 40px; height: 40px; line-height: 40px; text-align: center; border-radius: 50%; background: #e0e0e0; margin-right: 5px; }
256
+ .reports-section { display: flex; gap: 20px; }
257
+ .reports-section > div { flex: 1; }
258
+ .checkbox-label { margin-right: 20px; }
259
+ .btn { background: #1976d2; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; }
260
+ .btn:hover { background: #1565c0; }
261
  </style>
262
  </head>
263
  <body>
264
+ <div class="container">
265
+ <h1>Vendor Performance Dashboard</h1>
266
+ <p>Monitor and manage subcontractor performance across projects</p>
267
+
268
+ <!-- Summary Cards -->
269
+ <div class="summary-cards">
270
+ <div class="card">
271
+ <h3>Total Vendors</h3>
272
+ <p>{total_vendors}</p>
273
+ <small>+2 in last month</small>
274
+ </div>
275
+ <div class="card">
276
+ <h3>Performance Alerts</h3>
277
+ <p>{performance_alerts}</p>
278
+ <small>{round(performance_alerts/total_vendors*100, 1) if total_vendors else 0}% of vendors</small>
279
+ </div>
280
+ <div class="card">
281
+ <h3>Top Performers</h3>
282
+ <p>{top_performers}</p>
283
+ <small>{round(top_performers/total_vendors*100, 1) if total_vendors else 0}% of vendors</small>
284
+ </div>
285
+ <div class="card">
286
+ <h3>Improving Vendors</h3>
287
+ <p>{improving_vendors}</p>
288
+ <small>{round(improving_vendors/total_vendors*100, 1) if total_vendors else 0}% of vendors</small>
289
+ </div>
290
+ </div>
291
+
292
+ <!-- Leaderboard -->
293
+ <div class="leaderboard">
294
+ <h2>Vendor Leaderboard</h2>
295
+ <p>Top performing subcontractors this month</p>
296
+ <table>
297
+ <tr>
298
+ <th>Rank</th>
299
+ <th>Vendor</th>
300
+ <th>Score</th>
301
+ <th>Trend</th>
302
+ <th>Status</th>
303
+ </tr>
304
+ """.format(total_vendors=total_vendors, performance_alerts=performance_alerts, top_performers=top_performers, improving_vendors=improving_vendors)
305
+
306
+ for idx, log in enumerate(top_logs, 1):
307
+ scores = log['scores']
308
+ alert_flag = determine_alert_flag(scores['finalScore'], vendor_logs)
309
+ trend = "trend-up" if scores['finalScore'] >= 90 else "trend-down" if scores['finalScore'] < 70 else "trend-flat"
310
+ status_class = "status-good" if not alert_flag else "status-alert"
311
+ status_text = "Good" if not alert_flag else "Alert"
312
+ html_content += f"""
313
+ <tr>
314
+ <td>#{idx}</td>
315
+ <td>{log['vendorLogName']}</td>
316
+ <td>{scores['finalScore']}</td>
317
+ <td class="{trend}">{{"↗" if trend == "trend-up" else "↘" if trend == "trend-down" else "—"}}</td>
318
+ <td><span class="{status_class}">{status_text}</span></td>
319
+ </tr>
320
+ """
321
+
322
+ html_content += """
323
+ </table>
324
+ </div>
325
+
326
+ <!-- Performance Alerts -->
327
+ <div class="alerts">
328
+ <h2>Performance Alerts</h2>
329
+ <p>Vendors requiring attention</p>
330
  """
331
 
332
+ if alert_logs:
333
+ for log in alert_logs[:3]: # Show up to 3 alerts
334
+ scores = log['scores']
335
+ html_content += f"""
336
+ <div style="margin-bottom: 10px;">
337
+ <span style="color: #ef6c00;">⚠️ {log['vendorLogName']}</span> - Overall: {scores['finalScore']}
338
+ <br>Quality: {scores['qualityScore']} | Timeliness: {scores['timelinessScore']}
339
+ <a href="#" style="margin-left: 10px; color: #1976d2;">Review</a>
340
+ </div>
341
+ """
342
+ else:
343
+ html_content += "<p>No vendors require attention at this time.</p>"
344
+
345
+ html_content += """
346
+ </div>
347
+
348
+ <!-- Top Performing Vendors -->
349
+ <div class="top-performers">
350
+ <h2>Top Performing Vendors</h2>
351
+ <p>Vendors with the highest performance scores this month</p>
352
+ <div style="display: flex; gap: 20px; flex-wrap: wrap;">
353
+ """
354
+
355
+ for log in top_performing_logs:
356
+ scores = log['scores']
357
  html_content += f"""
358
+ <div style="flex: 1; min-width: 200px;">
359
+ <p>{log['vendorLogName']}<br><small>Last updated: 5/1/2025</small></p>
360
+ <span class="score-circle" style="background: #e0e0e0;">{scores['finalScore']}</span> Overall
361
+ <span class="score-circle" style="background: #e0e0e0;">{scores['qualityScore']}</span> Quality
362
+ <span class="score-circle" style="background: #e0e0e0;">{scores['timelinessScore']}</span> Time
363
+ <span class="score-circle" style="background: #e0e0e0;">{scores['safetyScore']}</span> Safety
364
+ <span class="score-circle" style="background: #e0e0e0;">{scores['communicationScore']}</span> Comm
365
+ </div>
 
 
 
366
  """
367
 
368
  html_content += """
369
+ </div>
370
+ </div>
371
+
372
+ <!-- Reports & Certifications -->
373
+ <div class="reports">
374
+ <h2>Reports & Certifications</h2>
375
+ <p>Generate and manage vendor performance reports</p>
376
+ <div class="reports-section">
377
+ <div>
378
+ <h3>Generate Vendor Report</h3>
379
+ <div style="margin-bottom: 10px;">
380
+ <label>Select Vendor</label><br>
381
+ <select style="width: 100%; padding: 8px; margin-top: 5px;">
382
+ <option>Choose a vendor</option>
383
  """
384
 
385
  for log in vendor_logs:
 
 
386
  html_content += f"""
387
+ <option>{log['vendorLogName']}</option>
388
+ """
389
+
390
+ html_content += """
391
+ </select>
392
+ </div>
393
+ <div style="margin-bottom: 10px;">
394
+ <label>Report Month</label><br>
395
+ <input type="text" value="May, 2025" readonly style="width: 100%; padding: 8px; margin-top: 5px;">
396
+ </div>
397
+ <div style="margin-bottom: 10px;">
398
+ <label>Include in Report</label><br>
399
+ <label class="checkbox-label"><input type="checkbox" checked> Quality Metrics</label>
400
+ <label class="checkbox-label"><input type="checkbox" checked> Timeliness</label>
401
+ <label class="checkbox-label"><input type="checkbox" checked> Safety Record</label>
402
+ <label class="checkbox-label"><input type="checkbox" checked> Communication</label>
403
+ <label class="checkbox-label"><input type="checkbox" checked> Incidents</label>
404
+ <label class="checkbox-label"><input type="checkbox" checked> Recommendations</label>
405
+ </div>
406
+ <button class="btn">Generate Report</button>
407
+ </div>
408
+ <div>
409
+ <h3>Recent Reports</h3>
410
+ """
411
+
412
+ for log in sorted_logs[:5]: # Show recent 5 reports
413
+ html_content += f"""
414
+ <div style="margin-bottom: 10px;">
415
+ 📄 {log['vendorLogName']} - Monthly Performance
416
+ <span style="float: right;">
417
+ <small>5/1/2025</small>
418
+ <a href="#" style="margin-left: 10px;">⬇</a>
419
+ </span>
420
+ </div>
421
  """
422
 
423
  html_content += """
424
+ <small>Last report generated: 3 hours ago</small>
425
+ <br>
426
+ <a href="#" style="color: #1976d2;">View All Reports</a>
427
+ </div>
428
+ </div>
429
+ </div>
430
+ </div>
431
  </body>
432
  </html>
433
  """