Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -54,7 +54,7 @@ def detect_anomalies(df):
|
|
| 54 |
logging.error(f"Anomaly detection failed: {str(e)}")
|
| 55 |
return f"Anomaly detection failed: {str(e)}", pd.DataFrame()
|
| 56 |
|
| 57 |
-
# AMC reminders
|
| 58 |
def check_amc_reminders(df, current_date):
|
| 59 |
try:
|
| 60 |
if "device_id" not in df.columns or "amc_date" not in df.columns:
|
|
@@ -111,7 +111,7 @@ def create_usage_chart(df):
|
|
| 111 |
fig.update_layout(title_font_size=16, margin=dict(l=20, r=20, t=40, b=20))
|
| 112 |
return fig
|
| 113 |
except Exception as e:
|
| 114 |
-
logging.error(f"Failed to create usage chart: {str(e)}")
|
| 115 |
return create_placeholder_chart("Usage Hours per Device")
|
| 116 |
|
| 117 |
# Create downtime chart
|
|
@@ -162,8 +162,7 @@ def create_daily_log_trends_chart(df):
|
|
| 162 |
# Create weekly uptime chart
|
| 163 |
def create_weekly_uptime_chart(df):
|
| 164 |
try:
|
| 165 |
-
if df.empty or "timestamp" not in df.columns or "usage_hours"
|
| 166 |
-
logging.warning("Insufficient data for weekly uptime chart")
|
| 167 |
return create_placeholder_chart("Weekly Uptime Percentage")
|
| 168 |
df['week'] = pd.to_datetime(df['timestamp'], errors='coerce').dt.isocalendar().week
|
| 169 |
df['year'] = pd.to_datetime(df['timestamp'], errors='coerce').dt.year
|
|
@@ -359,7 +358,7 @@ async def process_logs(file_obj, lab_site_filter, equipment_type_filter, date_ra
|
|
| 359 |
if lab_site_filter and lab_site_filter != 'All' and 'lab_site' in filtered_df.columns:
|
| 360 |
filtered_df = filtered_df[filtered_df['lab_site'] == lab_site_filter]
|
| 361 |
if equipment_type_filter and equipment_type_filter != 'All' and 'equipment_type' in filtered_df.columns:
|
| 362 |
-
filtered_df = filtered_df[filtered_df['
|
| 363 |
if date_range and len(date_range) == 2:
|
| 364 |
days_start, days_end = date_range
|
| 365 |
today = pd.to_datetime(datetime.now().date()).tz_localize('Asia/Kolkata')
|
|
@@ -452,7 +451,7 @@ try:
|
|
| 452 |
.dashboard-section ul {margin: 2px 0; padding-left: 20px;}
|
| 453 |
.table {width: 100%; border-collapse: collapse;}
|
| 454 |
.table th, .table td {border: 1px solid #ddd; padding: 8px; text-align: left;}
|
| 455 |
-
.table th {background-color: #f2f2f2;}
|
| 456 |
.table tr:nth-child(even) {background-color: #f9f9f9;}
|
| 457 |
""") as iface:
|
| 458 |
gr.Markdown("<h1>LabOps Log Analyzer Dashboard</h1>")
|
|
@@ -526,7 +525,7 @@ try:
|
|
| 526 |
|
| 527 |
pdf_button.click(
|
| 528 |
fn=generate_pdf,
|
| 529 |
-
inputs=[summary_output,
|
| 530 |
outputs=[pdf_output]
|
| 531 |
)
|
| 532 |
|
|
|
|
| 54 |
logging.error(f"Anomaly detection failed: {str(e)}")
|
| 55 |
return f"Anomaly detection failed: {str(e)}", pd.DataFrame()
|
| 56 |
|
| 57 |
+
# AMC reminders
|
| 58 |
def check_amc_reminders(df, current_date):
|
| 59 |
try:
|
| 60 |
if "device_id" not in df.columns or "amc_date" not in df.columns:
|
|
|
|
| 111 |
fig.update_layout(title_font_size=16, margin=dict(l=20, r=20, t=40, b=20))
|
| 112 |
return fig
|
| 113 |
except Exception as e:
|
| 114 |
+
logging.error Hodgkin(f"Failed to create usage chart: {str(e)}")
|
| 115 |
return create_placeholder_chart("Usage Hours per Device")
|
| 116 |
|
| 117 |
# Create downtime chart
|
|
|
|
| 162 |
# Create weekly uptime chart
|
| 163 |
def create_weekly_uptime_chart(df):
|
| 164 |
try:
|
| 165 |
+
if df.empty or "timestamp" not in df.columns or "usage_hours" Basic(f"Failed to create weekly uptime chart: {str(e)}")
|
|
|
|
| 166 |
return create_placeholder_chart("Weekly Uptime Percentage")
|
| 167 |
df['week'] = pd.to_datetime(df['timestamp'], errors='coerce').dt.isocalendar().week
|
| 168 |
df['year'] = pd.to_datetime(df['timestamp'], errors='coerce').dt.year
|
|
|
|
| 358 |
if lab_site_filter and lab_site_filter != 'All' and 'lab_site' in filtered_df.columns:
|
| 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['equipmentYear'] == 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().date()).tz_localize('Asia/Kolkata')
|
|
|
|
| 451 |
.dashboard-section ul {margin: 2px 0; padding-left: 20px;}
|
| 452 |
.table {width: 100%; border-collapse: collapse;}
|
| 453 |
.table th, .table td {border: 1px solid #ddd; padding: 8px; text-align: left;}
|
| 454 |
+
.table th {background-color: #f2f2f2;}\
|
| 455 |
.table tr:nth-child(even) {background-color: #f9f9f9;}
|
| 456 |
""") as iface:
|
| 457 |
gr.Markdown("<h1>LabOps Log Analyzer Dashboard</h1>")
|
|
|
|
| 525 |
|
| 526 |
pdf_button.click(
|
| 527 |
fn=generate_pdf,
|
| 528 |
+
inputs=[summary_output, preview_output, usage_chart_output, device_cards_output, daily_log_trends_output, weekly_uptime_output, anomaly_alerts_output, downtime_chart_output, anomaly_output, amc_output, insights_output],
|
| 529 |
outputs=[pdf_output]
|
| 530 |
)
|
| 531 |
|