Update app.py
Browse files
app.py
CHANGED
|
@@ -187,6 +187,9 @@ def generate_daily_report():
|
|
| 187 |
try:
|
| 188 |
logs_df = pd.read_csv(LOG_FILE)
|
| 189 |
daily_logs = logs_df[pd.to_datetime(logs_df['timestamp']).dt.strftime('%Y-%m-%d') == today_str]
|
|
|
|
|
|
|
|
|
|
| 190 |
total_workers = len(daily_logs['worker_id'].unique())
|
| 191 |
verified_workers = len(daily_logs[daily_logs['verification_status'] == 'Verified']['worker_id'].unique())
|
| 192 |
unverified_workers = len(daily_logs[daily_logs['verification_status'] == 'Pending']['worker_id'].unique())
|
|
@@ -230,7 +233,7 @@ Worker ID | Name | In-Time | Verification Status
|
|
| 230 |
report_filename = f"daily_report_{today_str}_{uuid.uuid4().hex[:12]}.txt"
|
| 231 |
report_filepath = os.path.join(REPORT_DIR, report_filename)
|
| 232 |
try:
|
| 233 |
-
with open(report_filepath, "w") as f:
|
| 234 |
f.write(report)
|
| 235 |
logger.info(f"Report saved to {report_filepath}")
|
| 236 |
return report, report_filepath # Return file path for Gradio download
|
|
@@ -420,11 +423,14 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 420 |
if os.path.exists(LOG_FILE):
|
| 421 |
try:
|
| 422 |
df = pd.read_csv(LOG_FILE)
|
| 423 |
-
|
| 424 |
-
|
|
|
|
|
|
|
|
|
|
| 425 |
except pd.errors.EmptyDataError:
|
| 426 |
-
return pd.DataFrame()
|
| 427 |
-
return pd.DataFrame()
|
| 428 |
|
| 429 |
refresh_button = gr.Button("Refresh Log")
|
| 430 |
refresh_button.click(update_log_display, None, log_display)
|
|
|
|
| 187 |
try:
|
| 188 |
logs_df = pd.read_csv(LOG_FILE)
|
| 189 |
daily_logs = logs_df[pd.to_datetime(logs_df['timestamp']).dt.strftime('%Y-%m-%d') == today_str]
|
| 190 |
+
if daily_logs.empty:
|
| 191 |
+
return "No attendance data available for today.", None
|
| 192 |
+
|
| 193 |
total_workers = len(daily_logs['worker_id'].unique())
|
| 194 |
verified_workers = len(daily_logs[daily_logs['verification_status'] == 'Verified']['worker_id'].unique())
|
| 195 |
unverified_workers = len(daily_logs[daily_logs['verification_status'] == 'Pending']['worker_id'].unique())
|
|
|
|
| 233 |
report_filename = f"daily_report_{today_str}_{uuid.uuid4().hex[:12]}.txt"
|
| 234 |
report_filepath = os.path.join(REPORT_DIR, report_filename)
|
| 235 |
try:
|
| 236 |
+
with open(report_filepath, "w", encoding='utf-8') as f:
|
| 237 |
f.write(report)
|
| 238 |
logger.info(f"Report saved to {report_filepath}")
|
| 239 |
return report, report_filepath # Return file path for Gradio download
|
|
|
|
| 423 |
if os.path.exists(LOG_FILE):
|
| 424 |
try:
|
| 425 |
df = pd.read_csv(LOG_FILE)
|
| 426 |
+
if not df.empty:
|
| 427 |
+
df['timestamp'] = pd.to_datetime(df['timestamp'], errors='coerce')
|
| 428 |
+
df = df.sort_values(by="timestamp", ascending=False).fillna('')
|
| 429 |
+
return df[["worker_id", "first_name", "last_name", "timestamp", "camera_id", "verification_status"]]
|
| 430 |
+
return pd.DataFrame(columns=["worker_id", "first_name", "last_name", "timestamp", "camera_id", "verification_status"])
|
| 431 |
except pd.errors.EmptyDataError:
|
| 432 |
+
return pd.DataFrame(columns=["worker_id", "first_name", "last_name", "timestamp", "camera_id", "verification_status"])
|
| 433 |
+
return pd.DataFrame(columns=["worker_id", "first_name", "last_name", "timestamp", "camera_id", "verification_status"])
|
| 434 |
|
| 435 |
refresh_button = gr.Button("Refresh Log")
|
| 436 |
refresh_button.click(update_log_display, None, log_display)
|