Spaces:
Running
Running
Commit
·
7f0a127
1
Parent(s):
590a51c
Add date filtering checkbox
Browse files- sections/upload.py +36 -26
sections/upload.py
CHANGED
|
@@ -55,6 +55,11 @@ st.write(
|
|
| 55 |
unsafe_allow_html=True,
|
| 56 |
)
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
uploaded_file = st.file_uploader("Choose a log file")
|
| 59 |
|
| 60 |
if "parsed_df" not in st.session_state:
|
|
@@ -63,36 +68,41 @@ if "parsed_df" not in st.session_state:
|
|
| 63 |
if uploaded_file is not None:
|
| 64 |
with st.spinner("Parsing and filtering the file..."):
|
| 65 |
try:
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
| 87 |
(pl.col("timestamp") >= pl.datetime(2024, 11, 1))
|
| 88 |
& (pl.col("timestamp") < pl.datetime(2025, 3, 1))
|
| 89 |
)
|
| 90 |
-
|
| 91 |
-
)
|
| 92 |
row_count = st.session_state.parsed_df.height
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
| 96 |
except Exception as e:
|
| 97 |
st.error(f"Error parsing the file: {e}")
|
| 98 |
|
|
|
|
| 55 |
unsafe_allow_html=True,
|
| 56 |
)
|
| 57 |
|
| 58 |
+
# Add checkbox for date filtering
|
| 59 |
+
apply_date_filter = st.checkbox(
|
| 60 |
+
"Apply date filtering (Nov 1, 2024 - Mar 1, 2025)", value=True
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
uploaded_file = st.file_uploader("Choose a log file")
|
| 64 |
|
| 65 |
if "parsed_df" not in st.session_state:
|
|
|
|
| 68 |
if uploaded_file is not None:
|
| 69 |
with st.spinner("Parsing and filtering the file..."):
|
| 70 |
try:
|
| 71 |
+
# Read the CSV
|
| 72 |
+
st.session_state.parsed_df = pl.read_csv(
|
| 73 |
+
uploaded_file,
|
| 74 |
+
separator=";",
|
| 75 |
+
has_header=False,
|
| 76 |
+
infer_schema_length=10000,
|
| 77 |
+
dtypes={
|
| 78 |
+
"timestamp": pl.Datetime,
|
| 79 |
+
"ipsrc": pl.Utf8,
|
| 80 |
+
"ipdst": pl.Utf8,
|
| 81 |
+
"protocole": pl.Utf8,
|
| 82 |
+
"portsrc": pl.Int64,
|
| 83 |
+
"portdst": pl.Int64,
|
| 84 |
+
"rule": pl.Int64,
|
| 85 |
+
"action": pl.Utf8,
|
| 86 |
+
"interface": pl.Utf8,
|
| 87 |
+
"unknown": pl.Utf8,
|
| 88 |
+
"fw": pl.Int64,
|
| 89 |
+
},
|
| 90 |
+
).drop(["portsrc", "unknown", "fw"])
|
| 91 |
+
|
| 92 |
+
# Apply date filter only if checkbox is checked
|
| 93 |
+
if apply_date_filter:
|
| 94 |
+
st.session_state.parsed_df = st.session_state.parsed_df.filter(
|
| 95 |
(pl.col("timestamp") >= pl.datetime(2024, 11, 1))
|
| 96 |
& (pl.col("timestamp") < pl.datetime(2025, 3, 1))
|
| 97 |
)
|
| 98 |
+
|
|
|
|
| 99 |
row_count = st.session_state.parsed_df.height
|
| 100 |
+
if row_count == 0:
|
| 101 |
+
st.error("No data found in the file.")
|
| 102 |
+
else:
|
| 103 |
+
st.success(
|
| 104 |
+
f"File parsed and filtered successfully! After filtering, {row_count:,} rows remain."
|
| 105 |
+
)
|
| 106 |
except Exception as e:
|
| 107 |
st.error(f"Error parsing the file: {e}")
|
| 108 |
|