berangerthomas commited on
Commit
7f0a127
·
1 Parent(s): 590a51c

Add date filtering checkbox

Browse files
Files changed (1) hide show
  1. 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
- st.session_state.parsed_df = (
67
- pl.read_csv(
68
- uploaded_file,
69
- separator=";",
70
- has_header=False,
71
- infer_schema_length=10000,
72
- dtypes={
73
- "timestamp": pl.Datetime,
74
- "ipsrc": pl.Utf8,
75
- "ipdst": pl.Utf8,
76
- "protocole": pl.Utf8,
77
- "portsrc": pl.Int64,
78
- "portdst": pl.Int64,
79
- "rule": pl.Int64,
80
- "action": pl.Utf8,
81
- "interface": pl.Utf8,
82
- "unknown": pl.Utf8,
83
- "fw": pl.Int64,
84
- },
85
- )
86
- .filter(
 
 
 
87
  (pl.col("timestamp") >= pl.datetime(2024, 11, 1))
88
  & (pl.col("timestamp") < pl.datetime(2025, 3, 1))
89
  )
90
- .drop(["portsrc", "unknown", "fw"])
91
- )
92
  row_count = st.session_state.parsed_df.height
93
- st.success(
94
- f"File parsed and filtered successfully! After filtering, {row_count:,} rows remain."
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