lavanya121 commited on
Commit
c6855ff
·
verified ·
1 Parent(s): ecaef26

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -359,7 +359,13 @@ async def process_logs(file_obj, lab_site_filter, equipment_type_filter, date_ra
359
  filtered_df = filtered_df[filtered_df['lab_site'] == lab_site_filter]
360
  if equipment_type_filter and equipment_type_filter != 'All' and 'equipment_type' in filtered_df.columns:
361
  filtered_df = filtered_df[filtered_df['equipment_type'] == equipment_type_filter]
362
- if date_range and len(date_range) == 2:
 
 
 
 
 
 
363
  days_start, days_end = date_range
364
  today = pd.to_datetime(datetime.now()).tz_localize('Asia/Kolkata')
365
  start_date = today + pd.Timedelta(days=days_start)
@@ -405,7 +411,7 @@ async def process_logs(file_obj, lab_site_filter, equipment_type_filter, date_ra
405
  if elapsed_time > 3:
406
  logging.warning(f"Processing time exceeded 3 seconds: {elapsed_time:.2f} seconds")
407
 
408
- return (summary, preview_html, usage_chart, device_cards, daily_log_chart, weekly_uptime_output, anomaly_alerts_output, downtime_chart, anomalies, amc_reminders, insights, None, df, current_modified_time)
409
  except Exception as e:
410
  logging.error(f"Failed to process file: {str(e)}")
411
  return f"Error: {str(e)}", "<p>Error processing data.</p>", None, '<p>Error processing data.</p>', None, None, None, None, "", "", "", None, cached_df_state, last_modified_state
@@ -454,7 +460,7 @@ try:
454
  .table tr:nth-child(even) {background-color: #f9f9f9;}
455
  """) as iface:
456
  gr.Markdown("<h1>LabOps Log Analyzer Dashboard</h1>")
457
- gr.Markdown("Upload a CSV file to analyze. Click 'Analyze' to refresh the dashboard. Use 'Export PDF' for report download. Date Range accepts [start, end] days (e.g., [-7, -3] for last 7 to 3 days ago).")
458
 
459
  last_modified_state = gr.State(value=None)
460
  current_file_state = gr.State(value=None)
 
359
  filtered_df = filtered_df[filtered_df['lab_site'] == lab_site_filter]
360
  if equipment_type_filter and equipment_type_filter != 'All' and 'equipment_type' in filtered_df.columns:
361
  filtered_df = filtered_df[filtered_df['equipment_type'] == equipment_type_filter]
362
+ if date_range is not None:
363
+ if isinstance(date_range, (int, float)):
364
+ logging.warning(f"Date range received as single value {date_range}. Using default range [-7, 0].")
365
+ date_range = [-7, 0] # Fallback to default range
366
+ if len(date_range) != 2 or not all(isinstance(x, (int, float)) for x in date_range):
367
+ logging.error(f"Invalid date range format: {date_range}. Expected [start, end] list of two numbers.")
368
+ return "Invalid date range format. Please use [start, end] (e.g., [-7, -3]).", "<p>Error processing data.</p>", None, '<p>Error processing data.</p>', None, None, None, None, "", "", "", None, df, current_modified_time
369
  days_start, days_end = date_range
370
  today = pd.to_datetime(datetime.now()).tz_localize('Asia/Kolkata')
371
  start_date = today + pd.Timedelta(days=days_start)
 
411
  if elapsed_time > 3:
412
  logging.warning(f"Processing time exceeded 3 seconds: {elapsed_time:.2f} seconds")
413
 
414
+ return (summary, preview_html, usage_chart, device_cards, daily_log_chart, weekly_uptime_chart, anomaly_alerts_chart, downtime_chart, anomalies, amc_reminders, insights, None, df, current_modified_time)
415
  except Exception as e:
416
  logging.error(f"Failed to process file: {str(e)}")
417
  return f"Error: {str(e)}", "<p>Error processing data.</p>", None, '<p>Error processing data.</p>', None, None, None, None, "", "", "", None, cached_df_state, last_modified_state
 
460
  .table tr:nth-child(even) {background-color: #f9f9f9;}
461
  """) as iface:
462
  gr.Markdown("<h1>LabOps Log Analyzer Dashboard</h1>")
463
+ gr.Markdown("Upload a CSV file to analyze. Click 'Analyze' to refresh the dashboard. Use 'Export PDF' for report download. Date Range must be a range [start, end] (e.g., [-7, -3] for 7 to 3 days ago).")
464
 
465
  last_modified_state = gr.State(value=None)
466
  current_file_state = gr.State(value=None)