Create an app that allows me to fill newborn's sleeping times, feeding, and diaper changes, and then I can track these by day, week, and month.
To upload files, please first save the app
import streamlit as st
import pandas as pd
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
from database_setup import CareLog
engine = create_engine("sqlite:///baby_care_tracker.sqlite")
st.title("Baby Care Tracker")
# Input forms
with st.form(key='care_log_form'):
feeding_time = st.text_input('Feeding Time (e.g., 3:00 PM)')
sleeping_time = st.text_input('Sleeping Time (e.g., 5:00 PM)')
diaper_change_time = st.text_input('Diaper Change Time (e.g., 6:00 PM)')
submit_button = st.form_submit_button(label='Submit')
if submit_button:
with Session(engine) as session:
new_log = CareLog(feeding=feeding_time, sleeping=sleeping_time, diaper_change=diaper_change_time)
session.add(new_log)
session.commit()
st.success("Log submitted successfully!")
# Data display
st.header("Logs")
with Session(engine) as session:
logs = pd.read_sql("SELECT * FROM care_logs ORDER BY date DESC", session.bind)
st.table(logs)
# Filter by day, week, and month
st.header("Filter Logs")
filter_option = st.selectbox("Select filter type:", ["Daily", "Weekly", "Monthly"])
if filter_option:
if filter_option == "Daily":
filter_date = st.date_input("Select a date")
filtered_logs = logs[logs['date'].dt.date == pd.to_datetime(filter_date).date()]
elif filter_option == "Weekly":
filter_week = st.date_input("Select a week start date")
filtered_logs = logs[(logs['date'] >= pd.to_datetime(filter_week)) & (logs['date'] < pd.to_datetime(filter_week) + pd.Timedelta(weeks=1))]
else:
filter_month = st.date_input("Select a month start date")
filtered_logs = logs[logs['date'].dt.to_period('M') == pd.to_datetime(filter_month).to_period('M')]
st.table(filtered_logs)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?