RathodHarish commited on
Commit
d9e8630
·
verified ·
1 Parent(s): f97c6f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -573,9 +573,9 @@ async def process_logs(file_obj, lab_site_filter, equipment_type_filter, date_ra
573
  days = int(date_range)
574
  date_range = [days, days]
575
  logging.info(f"Converted single value {days} to range {date_range}")
576
- if len(date_range) != 2 or not all(isinstance(x, (int, float)) for x in date_range):
577
- logging.error(f"Invalid date range format: {date_range}. Expected [start, end] or single integer.")
578
- return "Invalid date range format. Please use [start, end] (e.g., [-7, 0]) or a single integer (e.g., -1).", "<p>Error processing data.</p>", None, '<p>Error processing data.</p>', None, None, None, None, "", "", "", None, df, current_modified_time
579
  days_start, days_end = date_range
580
  today = pd.to_datetime(datetime.now()).tz_localize('Asia/Kolkata')
581
  start_date = today + pd.Timedelta(days=days_start)
@@ -674,7 +674,7 @@ try:
674
  .table tr:nth-child(even) {background-color: #f9f9f9;}
675
  """) as iface:
676
  gr.Markdown("<h1>LabOps Log Analyzer Dashboard</h1>")
677
- gr.Markdown("Upload a CSV file to analyze. Click 'Analyze' to refresh the dashboard. Use 'Export PDF' for report download. Date Range can be [start, end] (e.g., [-7, 0] for June 11 to June 18) or a single integer (e.g., -1 for June 17).")
678
 
679
  last_modified_state = gr.State(value=None)
680
  current_file_state = gr.State(value=None)
@@ -687,7 +687,7 @@ try:
687
  gr.Markdown("### Filters")
688
  lab_site_filter = gr.Dropdown(label="Lab Site", choices=['All'], value='All', interactive=True)
689
  equipment_type_filter = gr.Dropdown(label="Equipment Type", choices=['All'], value='All', interactive=True)
690
- date_range_filter = gr.Slider(label="Date Range (Days from Today)", minimum=-365, maximum=0, step=1, value=[-7, 0], interactive=True)
691
  submit_button = gr.Button("Analyze", variant="primary")
692
  pdf_button = gr.Button("Export PDF", variant="secondary")
693
 
@@ -707,14 +707,24 @@ try:
707
  gr.Markdown("### Charts")
708
  with gr.Tab("Usage Hours per Device"):
709
  usage_chart_output = gr.Plot()
 
 
710
  with gr.Tab("Downtime per Device"):
711
  downtime_chart_output = gr.Plot()
 
 
712
  with gr.Tab("Daily Log Trends"):
713
  daily_log_trends_output = gr.Plot()
 
 
714
  with gr.Tab("Weekly Uptime Percentage"):
715
  weekly_uptime_output = gr.Plot()
 
 
716
  with gr.Tab("Anomaly Alerts"):
717
  anomaly_alerts_output = gr.Plot()
 
 
718
  with gr.Group(elem_classes="dashboard-section"):
719
  gr.Markdown("### Step 4: Anomaly Detection")
720
  anomaly_output = gr.Markdown()
 
573
  days = int(date_range)
574
  date_range = [days, days]
575
  logging.info(f"Converted single value {days} to range {date_range}")
576
+ if len(date_range) != 2 or not all(isinstance(x, (int, float)) for x in date_range) or date_range[0] > date_range[1]:
577
+ logging.error(f"Invalid date range format: {date_range}. Expected [start, end] with start <= end (e.g., [-45, -28]).")
578
+ return "Invalid date range. Please use [start, end] where start <= end (e.g., [-45, -28]) or a single integer (e.g., -30).", "<p>Error processing data.</p>", None, '<p>Error processing data.</p>', None, None, None, None, "", "", "", None, df, current_modified_time
579
  days_start, days_end = date_range
580
  today = pd.to_datetime(datetime.now()).tz_localize('Asia/Kolkata')
581
  start_date = today + pd.Timedelta(days=days_start)
 
674
  .table tr:nth-child(even) {background-color: #f9f9f9;}
675
  """) as iface:
676
  gr.Markdown("<h1>LabOps Log Analyzer Dashboard</h1>")
677
+ gr.Markdown("Upload a CSV file to analyze. Click 'Analyze' to refresh the dashboard. Use 'Export PDF' for report download. Date Range can be [start, end] (e.g., [-45, -28] for June 1 to June 18) or a single integer (e.g., -30 for June 15).")
678
 
679
  last_modified_state = gr.State(value=None)
680
  current_file_state = gr.State(value=None)
 
687
  gr.Markdown("### Filters")
688
  lab_site_filter = gr.Dropdown(label="Lab Site", choices=['All'], value='All', interactive=True)
689
  equipment_type_filter = gr.Dropdown(label="Equipment Type", choices=['All'], value='All', interactive=True)
690
+ date_range_filter = gr.Slider(label="Date Range (Days from Today)", minimum=-365, maximum=0, step=1, value=[-45, -28], interactive=True)
691
  submit_button = gr.Button("Analyze", variant="primary")
692
  pdf_button = gr.Button("Export PDF", variant="secondary")
693
 
 
707
  gr.Markdown("### Charts")
708
  with gr.Tab("Usage Hours per Device"):
709
  usage_chart_output = gr.Plot()
710
+ if not plotly_available:
711
+ gr.Markdown("**Note:** Charts are unavailable because the 'plotly' library is not installed.")
712
  with gr.Tab("Downtime per Device"):
713
  downtime_chart_output = gr.Plot()
714
+ if not plotly_available:
715
+ gr.Markdown("**Note:** Charts are unavailable because the 'plotly' library is not installed.")
716
  with gr.Tab("Daily Log Trends"):
717
  daily_log_trends_output = gr.Plot()
718
+ if not plotly_available:
719
+ gr.Markdown("**Note:** Charts are unavailable because the 'plotly' library is not installed.")
720
  with gr.Tab("Weekly Uptime Percentage"):
721
  weekly_uptime_output = gr.Plot()
722
+ if not plotly_available:
723
+ gr.Markdown("**Note:** Charts are unavailable because the 'plotly' library is not installed.")
724
  with gr.Tab("Anomaly Alerts"):
725
  anomaly_alerts_output = gr.Plot()
726
+ if not plotly_available:
727
+ gr.Markdown("**Note:** Charts are unavailable because the 'plotly' library is not installed.")
728
  with gr.Group(elem_classes="dashboard-section"):
729
  gr.Markdown("### Step 4: Anomaly Detection")
730
  anomaly_output = gr.Markdown()