accept xlsx or csv file
Browse files
apps/kpi_analysis/anomalie.py
CHANGED
|
@@ -8,7 +8,7 @@ import streamlit as st
|
|
| 8 |
|
| 9 |
st.title("KPIsAnomaly Detection")
|
| 10 |
|
| 11 |
-
uploaded_file = st.file_uploader("Upload KPI
|
| 12 |
penalty = st.number_input("Penalty", min_value=1.0, max_value=100.0, value=2.5)
|
| 13 |
|
| 14 |
|
|
@@ -45,7 +45,9 @@ def detect_anomalies(df: pd.DataFrame, penalty: int):
|
|
| 45 |
if len(df_kpi) < 30:
|
| 46 |
return None
|
| 47 |
|
| 48 |
-
series = df_kpi[kpi].values
|
|
|
|
|
|
|
| 49 |
try:
|
| 50 |
change_indices = detect_change_points(series)
|
| 51 |
if not change_indices:
|
|
@@ -95,7 +97,13 @@ def detect_anomalies(df: pd.DataFrame, penalty: int):
|
|
| 95 |
|
| 96 |
|
| 97 |
if uploaded_file:
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
anomaly_dict, anomaly_data, all_kpis = detect_anomalies(df, penalty)
|
| 100 |
|
| 101 |
if not anomaly_dict:
|
|
|
|
| 8 |
|
| 9 |
st.title("KPIsAnomaly Detection")
|
| 10 |
|
| 11 |
+
uploaded_file = st.file_uploader("Upload KPI file", type=["csv", "xlsx"])
|
| 12 |
penalty = st.number_input("Penalty", min_value=1.0, max_value=100.0, value=2.5)
|
| 13 |
|
| 14 |
|
|
|
|
| 45 |
if len(df_kpi) < 30:
|
| 46 |
return None
|
| 47 |
|
| 48 |
+
series = df_kpi[kpi].values.copy()
|
| 49 |
+
# if len(series) > 0:
|
| 50 |
+
# series[-1] *= 10 # Boost last value to give it more weight
|
| 51 |
try:
|
| 52 |
change_indices = detect_change_points(series)
|
| 53 |
if not change_indices:
|
|
|
|
| 97 |
|
| 98 |
|
| 99 |
if uploaded_file:
|
| 100 |
+
|
| 101 |
+
# Detect if file is csv or excel
|
| 102 |
+
if uploaded_file.name.endswith(".csv"):
|
| 103 |
+
df = pd.read_csv(uploaded_file, delimiter=";")
|
| 104 |
+
else:
|
| 105 |
+
df = pd.read_excel(uploaded_file, sheet_name=0, skiprows=[1])
|
| 106 |
+
|
| 107 |
anomaly_dict, anomaly_data, all_kpis = detect_anomalies(df, penalty)
|
| 108 |
|
| 109 |
if not anomaly_dict:
|