import streamlit as st import pandas as pd import matplotlib.pyplot as plt from datetime import date # Configure Streamlit page st.set_page_config(page_title="Productivity Tracker", layout="centered") st.markdown("
Track your tasks, working hours, and daily notes with clean summaries and visuals
", unsafe_allow_html=True) # Initialize session data if "data" not in st.session_state: st.session_state.data = [] # --- Input Form --- st.markdown("### โ Add New Entry") with st.form("entry_form", clear_on_submit=True): col1, col2 = st.columns(2) with col1: task = st.text_input("๐ Task Description") with col2: hours = st.number_input("โฑ๏ธ Hours Worked", min_value=0.0, step=0.5) notes = st.text_area("๐งพ Short Notes", height=100) submitted = st.form_submit_button("Add Task", use_container_width=True) # Save data if submitted and task: today = date.today().strftime("%Y-%m-%d") st.session_state.data.append({ "Date": today, "Task": task, "Hours": hours, "Notes": notes }) st.success("โ Task added successfully!") # Convert to DataFrame df = pd.DataFrame(st.session_state.data) # --- Show Data --- if not df.empty: st.markdown("---") st.markdown("### ๐ All Logged Entries") st.dataframe(df, use_container_width=True) st.markdown("### ๐ Productivity Overview") daily_summary = df.groupby("Date")["Hours"].sum().reset_index() fig, ax = plt.subplots(figsize=(8, 4)) ax.plot(daily_summary["Date"], daily_summary["Hours"], marker='o', color="#3498DB", linewidth=2) ax.set_title("Hours Worked Per Day", fontsize=14) ax.set_xlabel("Date", fontsize=12) ax.set_ylabel("Total Hours", fontsize=12) ax.grid(True) plt.xticks(rotation=45) st.pyplot(fig) st.markdown("### ๐ Summary Statistics") col1, col2, col3 = st.columns(3) with col1: st.metric("Total Tasks", len(df)) with col2: st.metric("Total Hours", f"{df['Hours'].sum():.1f}") with col3: avg = df.groupby("Date")["Hours"].sum().mean() st.metric("Avg Hours/Day", f"{avg:.2f}") else: st.warning("No entries yet. Start by adding a task above.") # --- Footer --- st.markdown("---") st.markdown("ยฉ 2025 Productivity Tracker | Built with โค๏ธ in Streamlit
", unsafe_allow_html=True)