Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -26,7 +26,7 @@ def refresh_data():
|
|
26 |
|
27 |
df['Timestamp'] = pd.to_datetime(df['Date'].astype(str) + " " + df['Time'].astype(str), errors='coerce')
|
28 |
df['Date'] = pd.to_datetime(df['Date'], errors='coerce').dt.date.astype(str)
|
29 |
-
df['Time'] = pd.to_datetime(df['Time'], errors='coerce').dt.time
|
30 |
|
31 |
gps_split = df['GPS'].astype(str).str.split(',', expand=True)
|
32 |
df['Latitude'] = pd.to_numeric(gps_split[0], errors='coerce')
|
@@ -160,7 +160,7 @@ with gr.Blocks() as app:
|
|
160 |
with gr.Tab("๐ Reports"):
|
161 |
with gr.Row():
|
162 |
report_type = gr.Radio(choices=["Daily", "Weekly", "Monthly"], label="Report Type", value="Daily")
|
163 |
-
report_date = gr.
|
164 |
download_btn = gr.Button("๐ฅ Download CSV")
|
165 |
|
166 |
report_table = gr.Dataframe(label="๐ Report Summary")
|
@@ -169,7 +169,13 @@ with gr.Blocks() as app:
|
|
169 |
|
170 |
def generate_report(report_type, report_date):
|
171 |
df = refresh_data()
|
172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
|
174 |
if report_type == "Daily":
|
175 |
mask = df['Date'] == str(date_obj.date())
|
|
|
26 |
|
27 |
df['Timestamp'] = pd.to_datetime(df['Date'].astype(str) + " " + df['Time'].astype(str), errors='coerce')
|
28 |
df['Date'] = pd.to_datetime(df['Date'], errors='coerce').dt.date.astype(str)
|
29 |
+
df['Time'] = pd.to_datetime(df['Time'], format='%H:%M:%S', errors='coerce').dt.time
|
30 |
|
31 |
gps_split = df['GPS'].astype(str).str.split(',', expand=True)
|
32 |
df['Latitude'] = pd.to_numeric(gps_split[0], errors='coerce')
|
|
|
160 |
with gr.Tab("๐ Reports"):
|
161 |
with gr.Row():
|
162 |
report_type = gr.Radio(choices=["Daily", "Weekly", "Monthly"], label="Report Type", value="Daily")
|
163 |
+
report_date = gr.Textbox(label="Select Date (YYYY-MM-DD)", placeholder="2025-05-27", type="text")
|
164 |
download_btn = gr.Button("๐ฅ Download CSV")
|
165 |
|
166 |
report_table = gr.Dataframe(label="๐ Report Summary")
|
|
|
169 |
|
170 |
def generate_report(report_type, report_date):
|
171 |
df = refresh_data()
|
172 |
+
try:
|
173 |
+
date_obj = pd.to_datetime(report_date, errors='coerce')
|
174 |
+
except:
|
175 |
+
return pd.DataFrame(), "โ ๏ธ Invalid date format.", None
|
176 |
+
|
177 |
+
if pd.isnull(date_obj):
|
178 |
+
return pd.DataFrame(), "โ ๏ธ Date could not be parsed.", None
|
179 |
|
180 |
if report_type == "Daily":
|
181 |
mask = df['Date'] == str(date_obj.date())
|