Spaces:
Sleeping
Sleeping
File size: 3,570 Bytes
f83e458 f81a39c 3c8c6ec f81a39c 32691e9 f83e458 f81a39c 7d02576 f81a39c 7d02576 f81a39c 7d02576 3c8c6ec 7d02576 f81a39c 7d02576 f81a39c 7d02576 f81a39c 7d02576 f81a39c f83e458 3c8c6ec f83e458 dfe052f f81a39c dfe052f f81a39c 4bef520 3931be8 4bef520 3c8c6ec f83e458 be00862 f81a39c 3c8c6ec f83e458 3c8c6ec f83e458 3c8c6ec f83e458 f81a39c dfe052f f81a39c dfe052f f83e458 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
import gradio as gr
import pandas as pd
import sqlite3
from datetime import datetime
# Database Setup
db_file = "outputs/attendance_records.db"
# Helper Functions
def get_db_connection():
"""Create a new database connection."""
conn = sqlite3.connect(db_file)
return conn
def log_attendance(name, day, date, status):
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS attendance (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
day TEXT,
date TEXT,
status TEXT
)
""")
conn.commit()
cursor.execute("""
INSERT INTO attendance (name, day, date, status)
VALUES (?, ?, ?, ?)
""", (name, day, date, status))
conn.commit()
conn.close()
return "Attendance logged successfully!"
def calculate_fees():
conn = get_db_connection()
cursor = conn.cursor()
# Calculate attendance fees
cursor.execute("""
SELECT name, COUNT(*) * (1000 / 12) AS fees
FROM attendance
WHERE status = 'Present'
GROUP BY name
""")
fees_data = cursor.fetchall()
fees_dict = {row[0]: row[1] for row in fees_data}
conn.close()
return fees_dict
def create_end_of_month_table():
today = datetime.now()
if today.day != pd.Period(today.strftime("%Y-%m")).days_in_month:
return "It's not the end of the month yet."
conn = get_db_connection()
cursor = conn.cursor()
# Create end-of-month table
month = today.strftime("%Y-%m")
table_name = f"fees_{month.replace('-', '_')}"
cursor.execute(f"""
CREATE TABLE IF NOT EXISTS {table_name} (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
email TEXT,
fees REAL
)
""")
# Load participant data
participant_file = "participants_form.xlsx"
participants = pd.read_excel(participant_file)
# Calculate fees
fees_dict = calculate_fees()
# Populate table
for _, row in participants.iterrows():
name = row["Name"]
email = row["Email"]
fees = fees_dict.get(name, 0)
cursor.execute(f"""
INSERT INTO {table_name} (name, email, fees)
VALUES (?, ?, ?)
""", (name, email, fees))
conn.commit()
conn.close()
return f"End-of-month table '{table_name}' created successfully!"
def submit_attendance(name, day, date, status):
return log_attendance(name, day, date, status)
def is_month_end():
today = datetime.now()
return today.day == pd.Period(today.strftime("%Y-%m")).days_in_month
# Gradio Interface
def get_dropdown_options(file_path, column_name):
df = pd.read_excel(file_path)
options = df["Name"].dropna().unique().tolist()
options.sort()
return options
with gr.Blocks() as app:
gr.Markdown("# Attendance Tracker")
with gr.Row():
file_path = "participants_form.xlsx"
column_name = "Name"
options = get_dropdown_options(file_path, column_name)
name = gr.Dropdown(choices=options, label="Select an Option")
day = gr.Textbox(label="Day")
date = gr.Textbox(label="Date (YYYY-MM-DD)")
status = gr.Radio(["Present", "Absent"], label="Status")
submit_button = gr.Button("Submit Attendance")
submit_message = gr.Textbox(label="Message", interactive=False)
submit_button.click(submit_attendance, inputs=[name, day, date, status], outputs=[submit_message])
def update_end_of_month():
return create_end_of_month_table()
app.load(update_end_of_month)
app.launch()
|