KJ commited on
Commit ·
51f306c
1
Parent(s): 26c816f
adding custom dates
Browse files
app.py
CHANGED
|
@@ -151,9 +151,21 @@ group_by_domain = st.checkbox(T[LANG]["group_by_domain"])
|
|
| 151 |
group_by_score_type = st.checkbox(T[LANG]["all_scores"])
|
| 152 |
|
| 153 |
# --- Timeframe selection ---
|
| 154 |
-
timeframes = ["All", "Last 7 Days", "Last 30 Days", "Last Year"]
|
| 155 |
selected_timeframe = st.selectbox("Select Timeframe", timeframes)
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
# --- Filters ---
|
| 158 |
filtered_df = df.copy()
|
| 159 |
if entities:
|
|
@@ -165,11 +177,18 @@ if selected_timeframe != "All":
|
|
| 165 |
now = pd.Timestamp.now()
|
| 166 |
if selected_timeframe == "Last 7 Days":
|
| 167 |
start_date = now - pd.Timedelta(days=7)
|
|
|
|
| 168 |
elif selected_timeframe == "Last 30 Days":
|
| 169 |
start_date = now - pd.Timedelta(days=30)
|
|
|
|
| 170 |
elif selected_timeframe == "Last Year":
|
| 171 |
start_date = now - pd.Timedelta(days=365)
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
# --- Stop early if no entity selected ---
|
| 175 |
if not entities:
|
|
|
|
| 151 |
group_by_score_type = st.checkbox(T[LANG]["all_scores"])
|
| 152 |
|
| 153 |
# --- Timeframe selection ---
|
| 154 |
+
timeframes = ["All", "Last 7 Days", "Last 30 Days", "Last Year", "Custom"]
|
| 155 |
selected_timeframe = st.selectbox("Select Timeframe", timeframes)
|
| 156 |
|
| 157 |
+
# --- Custom date range selection ---
|
| 158 |
+
start_date, end_date = None, None
|
| 159 |
+
if selected_timeframe == "Custom":
|
| 160 |
+
col1, col2 = st.columns(2)
|
| 161 |
+
with col1:
|
| 162 |
+
start_date = st.date_input("Start Date")
|
| 163 |
+
with col2:
|
| 164 |
+
end_date = st.date_input("End Date")
|
| 165 |
+
if start_date > end_date:
|
| 166 |
+
st.error("Start date must be before or equal to the end date.")
|
| 167 |
+
st.stop()
|
| 168 |
+
|
| 169 |
# --- Filters ---
|
| 170 |
filtered_df = df.copy()
|
| 171 |
if entities:
|
|
|
|
| 177 |
now = pd.Timestamp.now()
|
| 178 |
if selected_timeframe == "Last 7 Days":
|
| 179 |
start_date = now - pd.Timedelta(days=7)
|
| 180 |
+
end_date = now
|
| 181 |
elif selected_timeframe == "Last 30 Days":
|
| 182 |
start_date = now - pd.Timedelta(days=30)
|
| 183 |
+
end_date = now
|
| 184 |
elif selected_timeframe == "Last Year":
|
| 185 |
start_date = now - pd.Timedelta(days=365)
|
| 186 |
+
end_date = now
|
| 187 |
+
if start_date and end_date:
|
| 188 |
+
filtered_df = filtered_df[
|
| 189 |
+
(filtered_df["created_at"] >= pd.Timestamp(start_date)) &
|
| 190 |
+
(filtered_df["created_at"] <= pd.Timestamp(end_date))
|
| 191 |
+
]
|
| 192 |
|
| 193 |
# --- Stop early if no entity selected ---
|
| 194 |
if not entities:
|