Update app.py
Browse files
app.py
CHANGED
@@ -45,20 +45,31 @@ def process_files(uploaded_files):
|
|
45 |
log_table = df.head().to_dict(orient="records")
|
46 |
|
47 |
# Usage chart
|
|
|
48 |
fig = plot_usage(df)
|
|
|
49 |
|
50 |
# Anomalies
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
53 |
|
54 |
# AMC expiries
|
55 |
amc_table = None
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
return log_table, fig, anomaly_table, amc_table, df
|
64 |
except Exception as e:
|
|
|
45 |
log_table = df.head().to_dict(orient="records")
|
46 |
|
47 |
# Usage chart
|
48 |
+
logger.info("Generating usage plot...")
|
49 |
fig = plot_usage(df)
|
50 |
+
logger.info("Usage plot generated successfully.")
|
51 |
|
52 |
# Anomalies
|
53 |
+
anomaly_table = "Anomaly detection failed."
|
54 |
+
try:
|
55 |
+
anomalies = detect_anomalies(df)
|
56 |
+
anomaly_table = anomalies.to_dict(orient="records") if not anomalies.empty else "No anomalies detected."
|
57 |
+
except Exception as e:
|
58 |
+
logger.error(f"Anomaly detection failed: {e}")
|
59 |
|
60 |
# AMC expiries
|
61 |
amc_table = None
|
62 |
+
try:
|
63 |
+
if "amc_expiry" in df.columns:
|
64 |
+
logger.info("Processing AMC expiries...")
|
65 |
+
amc_df = upcoming_amc_devices(df)
|
66 |
+
amc_table = amc_df.to_dict(orient="records") if not amc_df.empty else "No upcoming AMC expiries."
|
67 |
+
else:
|
68 |
+
amc_table = "Column `amc_expiry` not found in uploaded data."
|
69 |
+
logger.warning("Missing `amc_expiry` column in data.")
|
70 |
+
except Exception as e:
|
71 |
+
logger.error(f"AMC processing failed: {e}")
|
72 |
+
amc_table = f"Error processing AMC expiries: {e}"
|
73 |
|
74 |
return log_table, fig, anomaly_table, amc_table, df
|
75 |
except Exception as e:
|