IAMTFRMZA commited on
Commit
c959952
ยท
verified ยท
1 Parent(s): 19384fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
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.Date(label="Select Date")
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
- date_obj = pd.to_datetime(report_date)
 
 
 
 
 
 
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())