Spaces:
Runtime error
Runtime error
Zack
commited on
Commit
·
df3beea
1
Parent(s):
85e7307
chore: Add debugging
Browse files
app.py
CHANGED
@@ -109,27 +109,21 @@ def clean_data(df):
|
|
109 |
raise ValueError("Dataframe does not contain necessary columns.")
|
110 |
|
111 |
def master(file):
|
112 |
-
# read file
|
113 |
data = pd.read_csv(file.name)
|
114 |
-
|
115 |
-
# clean data
|
116 |
data = clean_data(data)
|
117 |
-
|
118 |
-
# Convert timestamp to datetime after cleaning
|
119 |
data['timestamp'] = pd.to_datetime(data['timestamp'])
|
120 |
-
|
121 |
data.set_index("timestamp", inplace=True)
|
122 |
-
|
123 |
-
# Check if data has enough records to create sequences
|
124 |
if len(data) < TIME_STEPS:
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
127 |
df_test_value = normalize_data(data)
|
128 |
-
# plot input test data
|
129 |
plot1 = plot_test_data(df_test_value)
|
130 |
-
# predict
|
131 |
anomalies = get_anomalies(df_test_value)
|
132 |
-
#plot anomalous data points
|
133 |
plot2 = plot_anomalies(df_test_value, data, anomalies)
|
134 |
return plot2
|
135 |
|
|
|
109 |
raise ValueError("Dataframe does not contain necessary columns.")
|
110 |
|
111 |
def master(file):
|
|
|
112 |
data = pd.read_csv(file.name)
|
113 |
+
print(f"Original data shape: {data.shape}") # Debug statement
|
|
|
114 |
data = clean_data(data)
|
115 |
+
print(f"Cleaned data shape: {data.shape}") # Debug statement
|
|
|
116 |
data['timestamp'] = pd.to_datetime(data['timestamp'])
|
|
|
117 |
data.set_index("timestamp", inplace=True)
|
|
|
|
|
118 |
if len(data) < TIME_STEPS:
|
119 |
+
fig, ax = plt.subplots(figsize=(8, 5))
|
120 |
+
ax.text(0.5, 0.5, "Not enough data to create sequences. Need at least {} records.".format(TIME_STEPS),
|
121 |
+
horizontalalignment='center', verticalalignment='center', fontsize=14)
|
122 |
+
plt.axis('off')
|
123 |
+
return fig
|
124 |
df_test_value = normalize_data(data)
|
|
|
125 |
plot1 = plot_test_data(df_test_value)
|
|
|
126 |
anomalies = get_anomalies(df_test_value)
|
|
|
127 |
plot2 = plot_anomalies(df_test_value, data, anomalies)
|
128 |
return plot2
|
129 |
|