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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import sqlite3
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from datetime import datetime, time, timedelta, date
|
| 5 |
+
import plotly.express as px
|
| 6 |
+
import plotly.graph_objects as go
|
| 7 |
+
from plotly.subplots import make_subplots
|
| 8 |
+
import calendar
|
| 9 |
+
import random
|
| 10 |
+
import json
|
| 11 |
+
|
| 12 |
+
DB_FILE = "life_tracker.db"
|
| 13 |
+
|
| 14 |
+
def create_connection():
|
| 15 |
+
return sqlite3.connect(DB_FILE)
|
| 16 |
+
|
| 17 |
+
def create_tables():
|
| 18 |
+
conn = create_connection()
|
| 19 |
+
cursor = conn.cursor()
|
| 20 |
+
|
| 21 |
+
cursor.execute('''
|
| 22 |
+
CREATE TABLE IF NOT EXISTS users (
|
| 23 |
+
id INTEGER PRIMARY KEY,
|
| 24 |
+
name TEXT NOT NULL
|
| 25 |
+
)
|
| 26 |
+
''')
|
| 27 |
+
|
| 28 |
+
cursor.execute('''
|
| 29 |
+
CREATE TABLE IF NOT EXISTS user_settings (
|
| 30 |
+
user_id INTEGER PRIMARY KEY,
|
| 31 |
+
default_wake_time TIME DEFAULT '04:00',
|
| 32 |
+
work_weight REAL DEFAULT 5.0,
|
| 33 |
+
life_weight REAL DEFAULT 5.0,
|
| 34 |
+
health_weight REAL DEFAULT 5.0,
|
| 35 |
+
FOREIGN KEY (user_id) REFERENCES users (id)
|
| 36 |
+
)
|
| 37 |
+
''')
|
| 38 |
+
|
| 39 |
+
cursor.execute('''
|
| 40 |
+
CREATE TABLE IF NOT EXISTS qualitative_metrics (
|
| 41 |
+
id INTEGER PRIMARY KEY,
|
| 42 |
+
user_id INTEGER,
|
| 43 |
+
date DATE,
|
| 44 |
+
life_score INTEGER,
|
| 45 |
+
work_score INTEGER,
|
| 46 |
+
health_score INTEGER,
|
| 47 |
+
FOREIGN KEY (user_id) REFERENCES users (id)
|
| 48 |
+
)
|
| 49 |
+
''')
|
| 50 |
+
|
| 51 |
+
cursor.execute('''
|
| 52 |
+
CREATE TABLE IF NOT EXISTS quantitative_metrics (
|
| 53 |
+
id INTEGER PRIMARY KEY,
|
| 54 |
+
user_id INTEGER,
|
| 55 |
+
date DATE,
|
| 56 |
+
wake_up_time TIME,
|
| 57 |
+
workouts INTEGER,
|
| 58 |
+
meditation_minutes INTEGER,
|
| 59 |
+
brain_training_minutes INTEGER,
|
| 60 |
+
FOREIGN KEY (user_id) REFERENCES users (id)
|
| 61 |
+
)
|
| 62 |
+
''')
|
| 63 |
+
|
| 64 |
+
cursor.execute('''
|
| 65 |
+
CREATE TABLE IF NOT EXISTS goals (
|
| 66 |
+
id INTEGER PRIMARY KEY,
|
| 67 |
+
user_id INTEGER,
|
| 68 |
+
category TEXT,
|
| 69 |
+
description TEXT,
|
| 70 |
+
target_value REAL,
|
| 71 |
+
current_value REAL,
|
| 72 |
+
start_date DATE,
|
| 73 |
+
end_date DATE,
|
| 74 |
+
FOREIGN KEY (user_id) REFERENCES users (id)
|
| 75 |
+
)
|
| 76 |
+
''')
|
| 77 |
+
|
| 78 |
+
cursor.execute('''
|
| 79 |
+
CREATE TABLE IF NOT EXISTS user_settings (
|
| 80 |
+
user_id INTEGER PRIMARY KEY,
|
| 81 |
+
default_wake_time TIME,
|
| 82 |
+
work_weight REAL,
|
| 83 |
+
life_weight REAL,
|
| 84 |
+
health_weight REAL,
|
| 85 |
+
FOREIGN KEY (user_id) REFERENCES users (id)
|
| 86 |
+
)
|
| 87 |
+
''')
|
| 88 |
+
|
| 89 |
+
cursor.execute('''
|
| 90 |
+
CREATE TABLE IF NOT EXISTS custom_categories (
|
| 91 |
+
id INTEGER PRIMARY KEY,
|
| 92 |
+
user_id INTEGER,
|
| 93 |
+
category_name TEXT,
|
| 94 |
+
subcategories TEXT,
|
| 95 |
+
FOREIGN KEY (user_id) REFERENCES users (id)
|
| 96 |
+
)
|
| 97 |
+
''')
|
| 98 |
+
|
| 99 |
+
cursor.execute('''
|
| 100 |
+
CREATE TABLE IF NOT EXISTS daily_checklist (
|
| 101 |
+
id INTEGER PRIMARY KEY,
|
| 102 |
+
user_id INTEGER,
|
| 103 |
+
date DATE,
|
| 104 |
+
checklist_data TEXT,
|
| 105 |
+
notes TEXT,
|
| 106 |
+
FOREIGN KEY (user_id) REFERENCES users (id)
|
| 107 |
+
)
|
| 108 |
+
''')
|
| 109 |
+
|
| 110 |
+
conn.commit()
|
| 111 |
+
conn.close()
|
| 112 |
+
|
| 113 |
+
def add_user_profile(name):
|
| 114 |
+
conn = create_connection()
|
| 115 |
+
cursor = conn.cursor()
|
| 116 |
+
cursor.execute("INSERT INTO users (name) VALUES (?)", (name,))
|
| 117 |
+
conn.commit()
|
| 118 |
+
conn.close()
|
| 119 |
+
|
| 120 |
+
def delete_user_profile(name):
|
| 121 |
+
conn = create_connection()
|
| 122 |
+
cursor = conn.cursor()
|
| 123 |
+
cursor.execute("DELETE FROM users WHERE name = ?", (name,))
|
| 124 |
+
conn.commit()
|
| 125 |
+
conn.close()
|
| 126 |
+
|
| 127 |
+
def generate_placeholder_data(user_name):
|
| 128 |
+
conn = create_connection()
|
| 129 |
+
cursor = conn.cursor()
|
| 130 |
+
|
| 131 |
+
# Get user ID
|
| 132 |
+
cursor.execute("SELECT id FROM users WHERE name = ?", (user_name,))
|
| 133 |
+
user_id = cursor.fetchone()[0]
|
| 134 |
+
|
| 135 |
+
# Generate placeholder data for the last 30 days
|
| 136 |
+
end_date = datetime.now().date()
|
| 137 |
+
start_date = end_date - timedelta(days=30)
|
| 138 |
+
|
| 139 |
+
categories = ["Work", "Life", "Health", "Sleep"]
|
| 140 |
+
subcategories = {
|
| 141 |
+
"Work": ["Meetings", "Project A", "Project B"],
|
| 142 |
+
"Life": ["Family", "Friends", "Hobbies"],
|
| 143 |
+
"Health": ["Exercise", "Meditation", "Personal Care"],
|
| 144 |
+
"Sleep": ["Night Sleep"]
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
for day in range(31):
|
| 148 |
+
current_date = start_date + timedelta(days=day)
|
| 149 |
+
|
| 150 |
+
# Daily activities
|
| 151 |
+
for category in categories:
|
| 152 |
+
for _ in range(random.randint(1, 3)):
|
| 153 |
+
subcategory = random.choice(subcategories[category])
|
| 154 |
+
start_time = time(hour=random.randint(0, 23), minute=random.randint(0, 59))
|
| 155 |
+
duration = timedelta(hours=random.randint(1, 4))
|
| 156 |
+
end_time = (datetime.combine(current_date, start_time) + duration).time()
|
| 157 |
+
|
| 158 |
+
cursor.execute('''
|
| 159 |
+
INSERT INTO daily_activities (user_id, date, category, subcategory, start_time, end_time)
|
| 160 |
+
VALUES (?, ?, ?, ?, ?, ?)
|
| 161 |
+
''', (user_id, current_date.isoformat(), category, subcategory, start_time.isoformat(), end_time.isoformat()))
|
| 162 |
+
|
| 163 |
+
# Qualitative metrics
|
| 164 |
+
cursor.execute('''
|
| 165 |
+
INSERT INTO qualitative_metrics (user_id, date, life_score, work_score, health_score)
|
| 166 |
+
VALUES (?, ?, ?, ?, ?)
|
| 167 |
+
''', (user_id, current_date.isoformat(), random.randint(1, 10), random.randint(1, 10), random.randint(1, 10)))
|
| 168 |
+
|
| 169 |
+
# Quantitative metrics
|
| 170 |
+
wake_up_time = time(hour=random.randint(5, 9), minute=random.randint(0, 59))
|
| 171 |
+
cursor.execute('''
|
| 172 |
+
INSERT INTO quantitative_metrics (user_id, date, wake_up_time, workouts, meditation_minutes, brain_training_minutes)
|
| 173 |
+
VALUES (?, ?, ?, ?, ?, ?)
|
| 174 |
+
''', (user_id, current_date.isoformat(), wake_up_time.isoformat(),
|
| 175 |
+
random.randint(0, 2), random.randint(0, 60), random.randint(0, 60)))
|
| 176 |
+
|
| 177 |
+
# Generate some goals
|
| 178 |
+
goal_categories = ["Work", "Life", "Health"]
|
| 179 |
+
for category in goal_categories:
|
| 180 |
+
cursor.execute('''
|
| 181 |
+
INSERT INTO goals (user_id, category, description, target_value, current_value, start_date, end_date)
|
| 182 |
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
| 183 |
+
''', (user_id, category, f"Improve {category.lower()} balance", random.randint(50, 100),
|
| 184 |
+
random.randint(0, 50), start_date.isoformat(), end_date.isoformat()))
|
| 185 |
+
|
| 186 |
+
# Set user settings
|
| 187 |
+
default_wake_time = time(hour=6, minute=0)
|
| 188 |
+
cursor.execute('''
|
| 189 |
+
INSERT OR REPLACE INTO user_settings (user_id, default_wake_time, work_weight, life_weight, health_weight)
|
| 190 |
+
VALUES (?, ?, ?, ?, ?)
|
| 191 |
+
''', (user_id, default_wake_time.isoformat(), 1.0, 1.0, 1.0))
|
| 192 |
+
|
| 193 |
+
conn.commit()
|
| 194 |
+
conn.close()
|
| 195 |
+
|
| 196 |
+
# Create tables when the script runs
|
| 197 |
+
create_tables()
|
| 198 |
+
|
| 199 |
+
def get_weekly_data(user_name):
|
| 200 |
+
conn = create_connection()
|
| 201 |
+
end_date = datetime.now().date()
|
| 202 |
+
start_date = end_date - timedelta(days=7)
|
| 203 |
+
|
| 204 |
+
query = '''
|
| 205 |
+
SELECT date, category, subcategory, start_time, end_time
|
| 206 |
+
FROM daily_activities
|
| 207 |
+
WHERE user_id = (SELECT id FROM users WHERE name = ?) AND date BETWEEN ? AND ?
|
| 208 |
+
ORDER BY date, start_time
|
| 209 |
+
'''
|
| 210 |
+
df = pd.read_sql_query(query, conn, params=(user_name, start_date, end_date))
|
| 211 |
+
conn.close()
|
| 212 |
+
|
| 213 |
+
# Convert date column to datetime
|
| 214 |
+
df['date'] = pd.to_datetime(df['date'])
|
| 215 |
+
|
| 216 |
+
# Convert start_time and end_time to datetime
|
| 217 |
+
df['start_time'] = pd.to_datetime(df['date'].dt.strftime('%Y-%m-%d') + ' ' + df['start_time'])
|
| 218 |
+
df['end_time'] = pd.to_datetime(df['date'].dt.strftime('%Y-%m-%d') + ' ' + df['end_time'])
|
| 219 |
+
|
| 220 |
+
return df
|
| 221 |
+
|
| 222 |
+
def get_monthly_data(user_name, year=None, month=None):
|
| 223 |
+
if year is None or month is None:
|
| 224 |
+
current_date = datetime.now()
|
| 225 |
+
year = year or current_date.year
|
| 226 |
+
month = month or current_date.month
|
| 227 |
+
|
| 228 |
+
conn = create_connection()
|
| 229 |
+
start_date = f"{year}-{month:02d}-01"
|
| 230 |
+
end_date = f"{year}-{month:02d}-{calendar.monthrange(year, month)[1]}"
|
| 231 |
+
query = '''
|
| 232 |
+
SELECT date, category, subcategory, start_time, end_time
|
| 233 |
+
FROM daily_activities
|
| 234 |
+
WHERE user_id = (SELECT id FROM users WHERE name = ?) AND date BETWEEN ? AND ?
|
| 235 |
+
ORDER BY date, start_time
|
| 236 |
+
'''
|
| 237 |
+
df = pd.read_sql_query(query, conn, params=(user_name, start_date, end_date))
|
| 238 |
+
conn.close()
|
| 239 |
+
|
| 240 |
+
# Convert date column to datetime
|
| 241 |
+
df['date'] = pd.to_datetime(df['date'])
|
| 242 |
+
|
| 243 |
+
# Convert start_time and end_time to datetime
|
| 244 |
+
df['start_time'] = pd.to_datetime(df['date'].dt.strftime('%Y-%m-%d') + ' ' + df['start_time'])
|
| 245 |
+
df['end_time'] = pd.to_datetime(df['date'].dt.strftime('%Y-%m-%d') + ' ' + df['end_time'])
|
| 246 |
+
|
| 247 |
+
return df
|
| 248 |
+
|
| 249 |
+
def format_monthly_data(df, year, month):
|
| 250 |
+
# Create a DataFrame with all days of the month
|
| 251 |
+
all_days = pd.date_range(start=f"{year}-{month:02d}-01", end=f"{year}-{month:02d}-{calendar.monthrange(year, month)[1]}", freq='D')
|
| 252 |
+
calendar_df = pd.DataFrame({'date': all_days})
|
| 253 |
+
|
| 254 |
+
# Calculate total hours for each category
|
| 255 |
+
df['duration'] = (df['end_time'] - df['start_time']).dt.total_seconds() / 3600
|
| 256 |
+
category_hours = df.groupby(['date', 'category'])['duration'].sum().unstack(fill_value=0)
|
| 257 |
+
|
| 258 |
+
# Merge with the calendar DataFrame
|
| 259 |
+
calendar_df = calendar_df.merge(category_hours, left_on='date', right_index=True, how='left')
|
| 260 |
+
calendar_df = calendar_df.fillna(0)
|
| 261 |
+
|
| 262 |
+
return calendar_df
|
| 263 |
+
|
| 264 |
+
def save_day_activities(user_name, date, work, life, health, sleep):
|
| 265 |
+
conn = create_connection()
|
| 266 |
+
cursor = conn.cursor()
|
| 267 |
+
|
| 268 |
+
# Delete existing activities for the day
|
| 269 |
+
cursor.execute('''
|
| 270 |
+
DELETE FROM daily_activities
|
| 271 |
+
WHERE user_id = (SELECT id FROM users WHERE name = ?) AND date = ?
|
| 272 |
+
''', (user_name, date))
|
| 273 |
+
|
| 274 |
+
# Insert new activities
|
| 275 |
+
activities = [
|
| 276 |
+
('Work', work),
|
| 277 |
+
('Life', life),
|
| 278 |
+
('Health', health),
|
| 279 |
+
('Sleep', sleep)
|
| 280 |
+
]
|
| 281 |
+
|
| 282 |
+
for category, hours in activities:
|
| 283 |
+
if hours > 0:
|
| 284 |
+
start_time = '00:00'
|
| 285 |
+
end_time = f'{int(hours):02d}:{int((hours % 1) * 60):02d}'
|
| 286 |
+
cursor.execute('''
|
| 287 |
+
INSERT INTO daily_activities (user_id, date, category, subcategory, start_time, end_time)
|
| 288 |
+
VALUES ((SELECT id FROM users WHERE name = ?), ?, ?, 'Default', ?, ?)
|
| 289 |
+
''', (user_name, date, category, start_time, end_time))
|
| 290 |
+
|
| 291 |
+
conn.commit()
|
| 292 |
+
conn.close()
|
| 293 |
+
|
| 294 |
+
def log_activity(user_name, date, category, subcategory, start_time, end_time):
|
| 295 |
+
conn = create_connection()
|
| 296 |
+
cursor = conn.cursor()
|
| 297 |
+
cursor.execute('''
|
| 298 |
+
INSERT INTO daily_activities (user_id, date, category, subcategory, start_time, end_time)
|
| 299 |
+
VALUES ((SELECT id FROM users WHERE name = ?), ?, ?, ?, ?, ?)
|
| 300 |
+
''', (user_name, date, category, subcategory, start_time, end_time))
|
| 301 |
+
conn.commit()
|
| 302 |
+
conn.close()
|
| 303 |
+
|
| 304 |
+
def get_activities(user_name, date):
|
| 305 |
+
conn = create_connection()
|
| 306 |
+
categories, _ = get_custom_categories(user_name)
|
| 307 |
+
category_list = ', '.join([f"'{cat}'" for cat in categories])
|
| 308 |
+
|
| 309 |
+
query = f'''
|
| 310 |
+
SELECT category, subcategory, start_time, end_time
|
| 311 |
+
FROM daily_activities
|
| 312 |
+
WHERE user_id = (SELECT id FROM users WHERE name = ?) AND date = ? AND category IN ({category_list})
|
| 313 |
+
ORDER BY start_time
|
| 314 |
+
'''
|
| 315 |
+
df = pd.read_sql_query(query, conn, params=(user_name, date))
|
| 316 |
+
conn.close()
|
| 317 |
+
return df
|
| 318 |
+
|
| 319 |
+
def log_qualitative_metrics(user_name, date, life_score, work_score, health_score):
|
| 320 |
+
conn = create_connection()
|
| 321 |
+
cursor = conn.cursor()
|
| 322 |
+
cursor.execute('''
|
| 323 |
+
INSERT INTO qualitative_metrics (user_id, date, life_score, work_score, health_score)
|
| 324 |
+
VALUES ((SELECT id FROM users WHERE name = ?), ?, ?, ?, ?)
|
| 325 |
+
''', (user_name, date, life_score, work_score, health_score))
|
| 326 |
+
conn.commit()
|
| 327 |
+
conn.close()
|
| 328 |
+
|
| 329 |
+
def log_quantitative_metrics(user_name, date, wake_up_time, workouts, meditation_minutes, brain_training_minutes):
|
| 330 |
+
conn = create_connection()
|
| 331 |
+
cursor = conn.cursor()
|
| 332 |
+
cursor.execute('''
|
| 333 |
+
INSERT INTO quantitative_metrics (user_id, date, wake_up_time, workouts, meditation_minutes, brain_training_minutes)
|
| 334 |
+
VALUES ((SELECT id FROM users WHERE name = ?), ?, ?, ?, ?, ?)
|
| 335 |
+
''', (user_name, date, wake_up_time, workouts, meditation_minutes, brain_training_minutes))
|
| 336 |
+
conn.commit()
|
| 337 |
+
conn.close()
|
| 338 |
+
|
| 339 |
+
def get_metrics(user_name, date):
|
| 340 |
+
conn = create_connection()
|
| 341 |
+
qual_query = '''
|
| 342 |
+
SELECT life_score, work_score, health_score
|
| 343 |
+
FROM qualitative_metrics
|
| 344 |
+
WHERE user_id = (SELECT id FROM users WHERE name = ?) AND date = ?
|
| 345 |
+
'''
|
| 346 |
+
quant_query = '''
|
| 347 |
+
SELECT wake_up_time, workouts, meditation_minutes, brain_training_minutes
|
| 348 |
+
FROM quantitative_metrics
|
| 349 |
+
WHERE user_id = (SELECT id FROM users WHERE name = ?) AND date = ?
|
| 350 |
+
'''
|
| 351 |
+
qual_df = pd.read_sql_query(qual_query, conn, params=(user_name, date))
|
| 352 |
+
quant_df = pd.read_sql_query(quant_query, conn, params=(user_name, date))
|
| 353 |
+
conn.close()
|
| 354 |
+
return pd.concat([qual_df, quant_df], axis=1)
|
| 355 |
+
|
| 356 |
+
def analyze_weekly_data(user_name):
|
| 357 |
+
df = get_weekly_data(user_name)
|
| 358 |
+
df['duration'] = (df['end_time'] - df['start_time']).dt.total_seconds() / 3600
|
| 359 |
+
|
| 360 |
+
category_summary = df.groupby('category')['duration'].sum().sort_values(ascending=False)
|
| 361 |
+
total_hours = category_summary.sum()
|
| 362 |
+
|
| 363 |
+
category_percentages = (category_summary / total_hours * 100).round(2)
|
| 364 |
+
|
| 365 |
+
# Create a more detailed pie chart
|
| 366 |
+
pie_chart = go.Figure(data=[go.Pie(
|
| 367 |
+
labels=category_percentages.index,
|
| 368 |
+
values=category_percentages.values,
|
| 369 |
+
hole=.3,
|
| 370 |
+
textinfo='label+percent',
|
| 371 |
+
insidetextorientation='radial'
|
| 372 |
+
)])
|
| 373 |
+
pie_chart.update_layout(title="Weekly Activity Distribution")
|
| 374 |
+
|
| 375 |
+
daily_scores = get_weekly_scores(user_name)
|
| 376 |
+
|
| 377 |
+
# Create a more detailed line chart
|
| 378 |
+
line_chart = go.Figure()
|
| 379 |
+
for column in ['life_score', 'work_score', 'health_score']:
|
| 380 |
+
line_chart.add_trace(go.Scatter(
|
| 381 |
+
x=daily_scores['date'],
|
| 382 |
+
y=daily_scores[column],
|
| 383 |
+
mode='lines+markers',
|
| 384 |
+
name=column.replace('_', ' ').title()
|
| 385 |
+
))
|
| 386 |
+
line_chart.update_layout(title="Weekly Score Trends", xaxis_title="Date", yaxis_title="Score")
|
| 387 |
+
|
| 388 |
+
return pie_chart, line_chart, total_hours
|
| 389 |
+
|
| 390 |
+
def analyze_monthly_data(user_name):
|
| 391 |
+
year, month = datetime.now().year, datetime.now().month
|
| 392 |
+
df = get_monthly_data(user_name, year, month)
|
| 393 |
+
df['duration'] = (df['end_time'] - df['start_time']).dt.total_seconds() / 3600
|
| 394 |
+
|
| 395 |
+
category_summary = df.groupby('category')['duration'].sum().sort_values(ascending=False)
|
| 396 |
+
total_hours = category_summary.sum()
|
| 397 |
+
|
| 398 |
+
category_percentages = (category_summary / total_hours * 100).round(2)
|
| 399 |
+
|
| 400 |
+
pie_chart = px.pie(values=category_percentages.values, names=category_percentages.index, title="Monthly Activity Distribution")
|
| 401 |
+
|
| 402 |
+
weekly_scores = get_monthly_scores(user_name)
|
| 403 |
+
|
| 404 |
+
# Use 'date' instead of 'week' for the x-axis
|
| 405 |
+
line_chart = px.line(weekly_scores, x='date', y=['life_score', 'work_score', 'health_score'], title="Monthly Score Trends")
|
| 406 |
+
|
| 407 |
+
return pie_chart, line_chart, total_hours
|
| 408 |
+
|
| 409 |
+
def get_monthly_scores(user_name):
|
| 410 |
+
conn = create_connection()
|
| 411 |
+
end_date = datetime.now().date()
|
| 412 |
+
start_date = end_date.replace(day=1)
|
| 413 |
+
|
| 414 |
+
query = '''
|
| 415 |
+
SELECT
|
| 416 |
+
date,
|
| 417 |
+
AVG(life_score) as life_score,
|
| 418 |
+
AVG(work_score) as work_score,
|
| 419 |
+
AVG(health_score) as health_score
|
| 420 |
+
FROM qualitative_metrics
|
| 421 |
+
WHERE user_id = (SELECT id FROM users WHERE name = ?) AND date BETWEEN ? AND ?
|
| 422 |
+
GROUP BY date
|
| 423 |
+
ORDER BY date
|
| 424 |
+
'''
|
| 425 |
+
|
| 426 |
+
df = pd.read_sql_query(query, conn, params=(user_name, start_date, end_date))
|
| 427 |
+
conn.close()
|
| 428 |
+
return df
|
| 429 |
+
|
| 430 |
+
def get_weekly_scores(user_name):
|
| 431 |
+
conn = create_connection()
|
| 432 |
+
end_date = datetime.now().date()
|
| 433 |
+
start_date = end_date - timedelta(days=7)
|
| 434 |
+
|
| 435 |
+
query = '''
|
| 436 |
+
SELECT
|
| 437 |
+
date,
|
| 438 |
+
life_score,
|
| 439 |
+
work_score,
|
| 440 |
+
health_score
|
| 441 |
+
FROM qualitative_metrics
|
| 442 |
+
WHERE user_id = (SELECT id FROM users WHERE name = ?) AND date BETWEEN ? AND ?
|
| 443 |
+
ORDER BY date
|
| 444 |
+
'''
|
| 445 |
+
|
| 446 |
+
df = pd.read_sql_query(query, conn, params=(user_name, start_date, end_date))
|
| 447 |
+
conn.close()
|
| 448 |
+
return df
|
| 449 |
+
|
| 450 |
+
def set_goal(user_name, category, description, target_value, start_date, end_date):
|
| 451 |
+
conn = create_connection()
|
| 452 |
+
cursor = conn.cursor()
|
| 453 |
+
cursor.execute('''
|
| 454 |
+
INSERT INTO goals (user_id, category, description, target_value, current_value, start_date, end_date)
|
| 455 |
+
VALUES ((SELECT id FROM users WHERE name = ?), ?, ?, ?, 0, ?, ?)
|
| 456 |
+
''', (user_name, category, description, float(target_value), start_date, end_date))
|
| 457 |
+
conn.commit()
|
| 458 |
+
conn.close()
|
| 459 |
+
|
| 460 |
+
def get_goals(user_name):
|
| 461 |
+
conn = create_connection()
|
| 462 |
+
query = '''
|
| 463 |
+
SELECT category, description, target_value, current_value, start_date, end_date
|
| 464 |
+
FROM goals
|
| 465 |
+
WHERE user_id = (SELECT id FROM users WHERE name = ?)
|
| 466 |
+
'''
|
| 467 |
+
df = pd.read_sql_query(query, conn, params=(user_name,))
|
| 468 |
+
conn.close()
|
| 469 |
+
return df
|
| 470 |
+
|
| 471 |
+
def update_goal_progress(user_name, goal_id, current_value):
|
| 472 |
+
conn = create_connection()
|
| 473 |
+
cursor = conn.cursor()
|
| 474 |
+
cursor.execute('''
|
| 475 |
+
UPDATE goals
|
| 476 |
+
SET current_value = ?
|
| 477 |
+
WHERE id = ? AND user_id = (SELECT id FROM users WHERE name = ?)
|
| 478 |
+
''', (current_value, goal_id, user_name))
|
| 479 |
+
conn.commit()
|
| 480 |
+
conn.close()
|
| 481 |
+
|
| 482 |
+
def get_user_settings(user_name):
|
| 483 |
+
conn = create_connection()
|
| 484 |
+
cursor = conn.cursor()
|
| 485 |
+
cursor.execute('''
|
| 486 |
+
SELECT default_wake_time, work_weight, life_weight, health_weight
|
| 487 |
+
FROM user_settings
|
| 488 |
+
WHERE user_id = (SELECT id FROM users WHERE name = ?)
|
| 489 |
+
''', (user_name,))
|
| 490 |
+
settings = cursor.fetchone()
|
| 491 |
+
conn.close()
|
| 492 |
+
return settings if settings else (None, 1.0, 1.0, 1.0)
|
| 493 |
+
|
| 494 |
+
def update_user_settings(user_name, default_wake_time, work_weight, life_weight, health_weight):
|
| 495 |
+
conn = create_connection()
|
| 496 |
+
cursor = conn.cursor()
|
| 497 |
+
cursor.execute('''
|
| 498 |
+
INSERT OR REPLACE INTO user_settings (user_id, default_wake_time, work_weight, life_weight, health_weight)
|
| 499 |
+
VALUES ((SELECT id FROM users WHERE name = ?), ?, ?, ?, ?)
|
| 500 |
+
''', (user_name, default_wake_time, work_weight, life_weight, health_weight))
|
| 501 |
+
conn.commit()
|
| 502 |
+
conn.close()
|
| 503 |
+
|
| 504 |
+
def parse_date(date_str):
|
| 505 |
+
if date_str.lower() == 'today':
|
| 506 |
+
return datetime.now().date()
|
| 507 |
+
else:
|
| 508 |
+
return datetime.strptime(date_str, "%Y-%m-%d").date()
|
| 509 |
+
|
| 510 |
+
# Define a custom theme with a more modern look
|
| 511 |
+
custom_theme = gr.themes.Soft(
|
| 512 |
+
primary_hue="blue",
|
| 513 |
+
secondary_hue="gray",
|
| 514 |
+
neutral_hue="slate",
|
| 515 |
+
font=("Inter", "sans-serif")
|
| 516 |
+
)
|
| 517 |
+
|
| 518 |
+
# Custom CSS for full-screen layout
|
| 519 |
+
custom_css = """
|
| 520 |
+
html, body {
|
| 521 |
+
margin: 0;
|
| 522 |
+
padding: 0;
|
| 523 |
+
height: 100%;
|
| 524 |
+
font-size: 16px; /* Base font size */
|
| 525 |
+
}
|
| 526 |
+
.gradio-container {
|
| 527 |
+
width: 100vw !important;
|
| 528 |
+
max-width: 100vw !important;
|
| 529 |
+
padding: 0 !important;
|
| 530 |
+
margin: 0 !important;
|
| 531 |
+
font-size: 1rem; /* Use relative units */
|
| 532 |
+
}
|
| 533 |
+
#component-0 {
|
| 534 |
+
max-height: none !important;
|
| 535 |
+
overflow: visible;
|
| 536 |
+
}
|
| 537 |
+
.main {
|
| 538 |
+
height: auto !important;
|
| 539 |
+
max-height: none !important;
|
| 540 |
+
display: flex;
|
| 541 |
+
flex-direction: row;
|
| 542 |
+
}
|
| 543 |
+
.contain {
|
| 544 |
+
max-width: 100% !important;
|
| 545 |
+
height: auto !important;
|
| 546 |
+
flex-grow: 1;
|
| 547 |
+
display: flex;
|
| 548 |
+
flex-direction: column;
|
| 549 |
+
}
|
| 550 |
+
.tabs {
|
| 551 |
+
flex-grow: 1;
|
| 552 |
+
display: flex;
|
| 553 |
+
flex-direction: column;
|
| 554 |
+
}
|
| 555 |
+
.tab-content {
|
| 556 |
+
flex-grow: 1;
|
| 557 |
+
overflow-y: visible;
|
| 558 |
+
}
|
| 559 |
+
.main-content {
|
| 560 |
+
height: auto;
|
| 561 |
+
display: flex;
|
| 562 |
+
flex-direction: column;
|
| 563 |
+
}
|
| 564 |
+
footer {
|
| 565 |
+
display: none !important;
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
/* Increase text size for various elements */
|
| 569 |
+
.gradio-container, .gradio-container *, .gradio-container .form, .gradio-container input, .gradio-container select, .gradio-container textarea {
|
| 570 |
+
font-size: 1.1rem !important;
|
| 571 |
+
}
|
| 572 |
+
|
| 573 |
+
/* Increase text size for headers */
|
| 574 |
+
.gradio-container h1 { font-size: 2.5rem !important; }
|
| 575 |
+
.gradio-container h2 { font-size: 2rem !important; }
|
| 576 |
+
.gradio-container h3 { font-size: 1.75rem !important; }
|
| 577 |
+
.gradio-container h4 { font-size: 1.5rem !important; }
|
| 578 |
+
|
| 579 |
+
/* Increase text size for buttons */
|
| 580 |
+
.gradio-container button {
|
| 581 |
+
font-size: 1.1rem !important;
|
| 582 |
+
padding: 0.5rem 1rem !important;
|
| 583 |
+
}
|
| 584 |
+
|
| 585 |
+
/* Increase text size for dropdown options */
|
| 586 |
+
.gradio-container select option {
|
| 587 |
+
font-size: 1.1rem !important;
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
/* Adjust padding and margins for better spacing */
|
| 591 |
+
.gradio-container .form > *, .gradio-container .form > div > * {
|
| 592 |
+
margin-bottom: 1rem !important;
|
| 593 |
+
}
|
| 594 |
+
|
| 595 |
+
<script>
|
| 596 |
+
function edit_day(date) {
|
| 597 |
+
document.querySelector('input[data-testid="textbox"]').value = date;
|
| 598 |
+
document.querySelector('button[data-testid="button"]').click();
|
| 599 |
+
}
|
| 600 |
+
</script>
|
| 601 |
+
"""
|
| 602 |
+
|
| 603 |
+
# Create the main Gradio interface with the custom theme and CSS
|
| 604 |
+
with gr.Blocks(theme=custom_theme, css=custom_css) as demo:
|
| 605 |
+
with gr.Row(equal_height=True):
|
| 606 |
+
# Left sidebar
|
| 607 |
+
with gr.Column(scale=1, min_width=200):
|
| 608 |
+
gr.Markdown("## Life Tracking System")
|
| 609 |
+
user_name = gr.Dropdown(label="User Name", choices=["John Doe"], value="John Doe")
|
| 610 |
+
date = gr.Textbox(label="Date", value="today", placeholder="YYYY-MM-DD")
|
| 611 |
+
|
| 612 |
+
with gr.Group():
|
| 613 |
+
gr.Markdown("### Quick Glance")
|
| 614 |
+
today_life_score = gr.Number(label="Today's Life Score", value=0)
|
| 615 |
+
today_work_score = gr.Number(label="Today's Work Score", value=0)
|
| 616 |
+
today_health_score = gr.Number(label="Today's Health Score", value=0)
|
| 617 |
+
wake_up_time = gr.Textbox(label="Wake-up Time", value="")
|
| 618 |
+
total_activities = gr.Number(label="Total Activities", value=0)
|
| 619 |
+
|
| 620 |
+
quick_log_btn = gr.Button("Quick Log")
|
| 621 |
+
|
| 622 |
+
# Add buttons for adding and deleting user profiles
|
| 623 |
+
new_user_name = gr.Textbox(label="New User Name")
|
| 624 |
+
add_user_btn = gr.Button("Add User")
|
| 625 |
+
delete_user_btn = gr.Button("Delete User")
|
| 626 |
+
|
| 627 |
+
# Main content area
|
| 628 |
+
with gr.Column(scale=4):
|
| 629 |
+
with gr.Tabs() as tabs:
|
| 630 |
+
# Dashboard Tab
|
| 631 |
+
with gr.TabItem("Dashboard"):
|
| 632 |
+
with gr.Row():
|
| 633 |
+
with gr.Column(scale=2):
|
| 634 |
+
gr.Markdown("### Log Daily Metrics")
|
| 635 |
+
life_score = gr.Slider(label="Life Score", minimum=1, maximum=10, step=1)
|
| 636 |
+
work_score = gr.Slider(label="Work Score", minimum=1, maximum=10, step=1)
|
| 637 |
+
health_score = gr.Slider(label="Health Score", minimum=1, maximum=10, step=1)
|
| 638 |
+
workouts = gr.Number(label="Workouts", minimum=0, step=1)
|
| 639 |
+
meditation_minutes = gr.Number(label="Meditation (minutes)", minimum=0)
|
| 640 |
+
brain_training_minutes = gr.Number(label="Brain Training (minutes)", minimum=0)
|
| 641 |
+
log_metrics_btn = gr.Button("Log Metrics")
|
| 642 |
+
|
| 643 |
+
with gr.Column(scale=2):
|
| 644 |
+
gr.Markdown("### Log Activity")
|
| 645 |
+
category = gr.Dropdown(label="Category", choices=["Work", "Life", "Health", "Sleep"])
|
| 646 |
+
subcategory = gr.Textbox(label="Subcategory")
|
| 647 |
+
start_time = gr.Textbox(label="Start Time (HH:MM)")
|
| 648 |
+
end_time = gr.Textbox(label="End Time (HH:MM)")
|
| 649 |
+
log_activity_btn = gr.Button("Log Activity")
|
| 650 |
+
|
| 651 |
+
gr.Markdown("### Today's Overview")
|
| 652 |
+
with gr.Row():
|
| 653 |
+
today_activities = gr.DataFrame(label="Today's Activities")
|
| 654 |
+
today_metrics = gr.DataFrame(label="Today's Metrics")
|
| 655 |
+
|
| 656 |
+
gr.Markdown("### Weekly Summary")
|
| 657 |
+
with gr.Row():
|
| 658 |
+
weekly_pie_chart = gr.Plot(label="Activity Distribution")
|
| 659 |
+
weekly_line_chart = gr.Plot(label="Score Trends")
|
| 660 |
+
|
| 661 |
+
update_dashboard_btn = gr.Button("Refresh Dashboard")
|
| 662 |
+
|
| 663 |
+
# Analysis Tab
|
| 664 |
+
with gr.TabItem("Analysis"):
|
| 665 |
+
analysis_period = gr.Radio(["Weekly", "Monthly"], label="Analysis Period", value="Weekly")
|
| 666 |
+
update_analysis_btn = gr.Button("Update Analysis")
|
| 667 |
+
with gr.Row():
|
| 668 |
+
analysis_pie_chart = gr.Plot(label="Activity Distribution")
|
| 669 |
+
analysis_line_chart = gr.Plot(label="Score Trends")
|
| 670 |
+
analysis_total_hours = gr.Number(label="Total Hours", precision=2)
|
| 671 |
+
|
| 672 |
+
# Add a detailed breakdown table
|
| 673 |
+
analysis_breakdown = gr.DataFrame(label="Detailed Breakdown")
|
| 674 |
+
|
| 675 |
+
def update_analysis(user_name, period):
|
| 676 |
+
if period == "Weekly":
|
| 677 |
+
pie_chart, line_chart, total_hours = analyze_weekly_data(user_name)
|
| 678 |
+
breakdown_data = get_weekly_data(user_name)
|
| 679 |
+
else:
|
| 680 |
+
pie_chart, line_chart, total_hours = analyze_monthly_data(user_name)
|
| 681 |
+
breakdown_data = get_monthly_data(user_name)
|
| 682 |
+
|
| 683 |
+
breakdown_data['duration'] = breakdown_data['end_time'] - breakdown_data['start_time']
|
| 684 |
+
breakdown_data['duration_hours'] = breakdown_data['duration'].dt.total_seconds() / 3600
|
| 685 |
+
breakdown_summary = breakdown_data.groupby(['category', 'subcategory'])['duration_hours'].sum().reset_index()
|
| 686 |
+
breakdown_summary = breakdown_summary.sort_values('duration_hours', ascending=False)
|
| 687 |
+
|
| 688 |
+
return pie_chart, line_chart, total_hours, breakdown_summary
|
| 689 |
+
|
| 690 |
+
update_analysis_btn.click(update_analysis, inputs=[user_name, analysis_period], outputs=[analysis_pie_chart, analysis_line_chart, analysis_total_hours, analysis_breakdown])
|
| 691 |
+
|
| 692 |
+
# Goals Tab
|
| 693 |
+
with gr.TabItem("Goals"):
|
| 694 |
+
with gr.Row():
|
| 695 |
+
goal_category = gr.Dropdown(label="Category", choices=["Work", "Life", "Health"])
|
| 696 |
+
goal_description = gr.Textbox(label="Goal Description")
|
| 697 |
+
goal_target = gr.Number(label="Target Value")
|
| 698 |
+
with gr.Row():
|
| 699 |
+
goal_start_date = gr.Textbox(label="Start Date", placeholder="YYYY-MM-DD")
|
| 700 |
+
goal_end_date = gr.Textbox(label="End Date", placeholder="YYYY-MM-DD")
|
| 701 |
+
set_goal_btn = gr.Button("Set Goal")
|
| 702 |
+
goals_table = gr.DataFrame(label="Current Goals")
|
| 703 |
+
|
| 704 |
+
# Settings Tab
|
| 705 |
+
with gr.TabItem("Settings"):
|
| 706 |
+
preset_dropdown = gr.Dropdown(label="Preset Templates", choices=["Custom", "Rob Dyrdek", "Student"])
|
| 707 |
+
default_wake_time = gr.Textbox(label="Default Wake-up Time (HH:MM)")
|
| 708 |
+
with gr.Row():
|
| 709 |
+
work_weight = gr.Slider(label="Work Weight", minimum=0, maximum=2, step=0.1, value=1.0)
|
| 710 |
+
life_weight = gr.Slider(label="Life Weight", minimum=0, maximum=2, step=0.1, value=1.0)
|
| 711 |
+
health_weight = gr.Slider(label="Health Weight", minimum=0, maximum=2, step=0.1, value=1.0)
|
| 712 |
+
update_settings_btn = gr.Button("Update Settings")
|
| 713 |
+
|
| 714 |
+
# New: Documentation Tab
|
| 715 |
+
with gr.TabItem("Documentation"):
|
| 716 |
+
gr.Markdown("""
|
| 717 |
+
# Life Tracking System Documentation
|
| 718 |
+
|
| 719 |
+
Welcome to the Life Tracking System, inspired by Rob Dyrdek's philosophy of maintaining a "Rhythm of Existence". This system is designed to help you monitor and optimize various aspects of your life, including work, health, personal life, and sleep.
|
| 720 |
+
|
| 721 |
+
## Getting Started
|
| 722 |
+
|
| 723 |
+
1. Use the Setup tab to configure your profile and preferences.
|
| 724 |
+
2. Choose a preset template or customize your own categories and subcategories.
|
| 725 |
+
3. Set your default wake-up time and adjust weights for work, life, and health.
|
| 726 |
+
4. Use the Dashboard to log your daily activities and metrics.
|
| 727 |
+
5. Review your progress in the Analysis tab.
|
| 728 |
+
6. Set and track your goals in the Goals tab.
|
| 729 |
+
|
| 730 |
+
## Key Features
|
| 731 |
+
|
| 732 |
+
- Guided setup process
|
| 733 |
+
- Daily activity tracking
|
| 734 |
+
- Qualitative and quantitative metric logging
|
| 735 |
+
- Weekly and monthly analysis
|
| 736 |
+
- Visualization and reporting
|
| 737 |
+
- Goal setting and progress monitoring
|
| 738 |
+
- Customizable categories and subcategories
|
| 739 |
+
|
| 740 |
+
## Tips for Success
|
| 741 |
+
|
| 742 |
+
- Be consistent in logging your activities and metrics.
|
| 743 |
+
- Review your weekly and monthly analyses regularly.
|
| 744 |
+
- Adjust your goals as needed based on your progress.
|
| 745 |
+
- Use the preset templates to get started quickly.
|
| 746 |
+
- Customize your categories and subcategories to fit your lifestyle.
|
| 747 |
+
|
| 748 |
+
## Rob Dyrdek's Philosophy
|
| 749 |
+
|
| 750 |
+
Rob Dyrdek's approach to life and success emphasizes:
|
| 751 |
+
1. Passion-driven productivity
|
| 752 |
+
2. Taking calculated risks
|
| 753 |
+
3. Setting big goals
|
| 754 |
+
4. Hard work and perseverance
|
| 755 |
+
5. Innovation and creativity
|
| 756 |
+
6. Authenticity in decision-making
|
| 757 |
+
7. Learning from failures
|
| 758 |
+
|
| 759 |
+
Incorporate these principles into your daily routine to maximize your potential and achieve your goals.
|
| 760 |
+
|
| 761 |
+
For more detailed information on how to use specific features, please refer to the respective tabs in the application.
|
| 762 |
+
""")
|
| 763 |
+
|
| 764 |
+
# New: Daily Checklist Tab
|
| 765 |
+
with gr.TabItem("Daily Checklist"):
|
| 766 |
+
gr.Markdown("## Daily Checklist and Notes")
|
| 767 |
+
checklist_date = gr.Textbox(label="Date", value=datetime.now().strftime("%Y-%m-%d"), placeholder="YYYY-MM-DD")
|
| 768 |
+
|
| 769 |
+
with gr.Row():
|
| 770 |
+
with gr.Column(scale=2):
|
| 771 |
+
checklist_items = [
|
| 772 |
+
gr.Checkbox(label="Wake up & Mindfulness (30 minutes)"),
|
| 773 |
+
gr.Checkbox(label="Exercise (30-45 minutes)"),
|
| 774 |
+
gr.Checkbox(label="Meditation (20 minutes)"),
|
| 775 |
+
gr.Checkbox(label="Morning Walk with Nala (1 hour 15 minutes)"),
|
| 776 |
+
gr.Checkbox(label="Active Learning with Breakfast (1 hour)"),
|
| 777 |
+
gr.Checkbox(label="Work (3 hours 30 minutes)"),
|
| 778 |
+
gr.Checkbox(label="Lunch Break (30 minutes)"),
|
| 779 |
+
gr.Checkbox(label="Work (4 hours)"),
|
| 780 |
+
gr.Checkbox(label="Active Learning (20 mins - 1 hour, 3x a week)"),
|
| 781 |
+
gr.Checkbox(label="Brain Training"),
|
| 782 |
+
gr.Checkbox(label="Reading"),
|
| 783 |
+
gr.Checkbox(label="Journaling"),
|
| 784 |
+
gr.Checkbox(label="Evening Reflection"),
|
| 785 |
+
gr.Checkbox(label="Plan for Tomorrow"),
|
| 786 |
+
]
|
| 787 |
+
|
| 788 |
+
with gr.Column(scale=1):
|
| 789 |
+
notes = gr.TextArea(label="Daily Notes")
|
| 790 |
+
|
| 791 |
+
save_checklist_btn = gr.Button("Save Daily Checklist")
|
| 792 |
+
load_checklist_btn = gr.Button("Load Checklist for Selected Date")
|
| 793 |
+
|
| 794 |
+
def get_daily_checklist(user_name, date):
|
| 795 |
+
conn = create_connection()
|
| 796 |
+
cursor = conn.cursor()
|
| 797 |
+
cursor.execute('''
|
| 798 |
+
SELECT checklist_data, notes FROM daily_checklist
|
| 799 |
+
WHERE user_id = (SELECT id FROM users WHERE name = ?) AND date = ?
|
| 800 |
+
''', (user_name, date))
|
| 801 |
+
result = cursor.fetchone()
|
| 802 |
+
conn.close()
|
| 803 |
+
if result:
|
| 804 |
+
return json.loads(result[0]), result[1]
|
| 805 |
+
return {}, ""
|
| 806 |
+
|
| 807 |
+
def save_daily_checklist(user_name, date, checklist_data, notes):
|
| 808 |
+
conn = create_connection()
|
| 809 |
+
cursor = conn.cursor()
|
| 810 |
+
cursor.execute('''
|
| 811 |
+
INSERT OR REPLACE INTO daily_checklist (user_id, date, checklist_data, notes)
|
| 812 |
+
VALUES ((SELECT id FROM users WHERE name = ?), ?, ?, ?)
|
| 813 |
+
''', (user_name, date, json.dumps(checklist_data), notes))
|
| 814 |
+
conn.commit()
|
| 815 |
+
conn.close()
|
| 816 |
+
|
| 817 |
+
def save_checklist(user_name, date_str, notes, *checklist_values):
|
| 818 |
+
try:
|
| 819 |
+
date_obj = datetime.strptime(date_str, "%Y-%m-%d").date()
|
| 820 |
+
checklist_data = {item.label: value for item, value in zip(checklist_items, checklist_values)}
|
| 821 |
+
save_daily_checklist(user_name, date_obj, checklist_data, notes)
|
| 822 |
+
return "Checklist saved successfully!"
|
| 823 |
+
except ValueError:
|
| 824 |
+
return "Invalid date format. Please use YYYY-MM-DD."
|
| 825 |
+
|
| 826 |
+
|
| 827 |
+
def load_checklist(user_name, date_str):
|
| 828 |
+
try:
|
| 829 |
+
date_obj = datetime.strptime(date_str, "%Y-%m-%d").date()
|
| 830 |
+
checklist_data, notes_text = get_daily_checklist(user_name, date_obj)
|
| 831 |
+
checkbox_values = [checklist_data.get(item.label, False) for item in checklist_items]
|
| 832 |
+
return checkbox_values + [notes_text, "Checklist loaded successfully!"]
|
| 833 |
+
except ValueError:
|
| 834 |
+
return [False] * len(checklist_items) + ["", "Invalid date format. Please use YYYY-MM-DD."]
|
| 835 |
+
|
| 836 |
+
save_checklist_btn.click(
|
| 837 |
+
save_checklist,
|
| 838 |
+
inputs=[user_name, checklist_date, notes] + checklist_items,
|
| 839 |
+
outputs=[gr.Text(label="Save Status")]
|
| 840 |
+
)
|
| 841 |
+
|
| 842 |
+
load_checklist_btn.click(
|
| 843 |
+
load_checklist,
|
| 844 |
+
inputs=[user_name, checklist_date],
|
| 845 |
+
outputs=checklist_items + [notes, gr.Text(label="Load Status")]
|
| 846 |
+
)
|
| 847 |
+
|
| 848 |
+
# Monthly Calendar Tab
|
| 849 |
+
with gr.TabItem("Monthly Calendar"):
|
| 850 |
+
gr.Markdown("## Monthly Time Allocation")
|
| 851 |
+
with gr.Row():
|
| 852 |
+
calendar_date = gr.Textbox(label="Select Month (YYYY-MM)", value=datetime.now().strftime("%Y-%m"))
|
| 853 |
+
update_calendar_btn = gr.Button("Update Calendar")
|
| 854 |
+
monthly_calendar = gr.DataFrame(label="Monthly Time Allocation")
|
| 855 |
+
|
| 856 |
+
day_edit_form = gr.Group(visible=False)
|
| 857 |
+
with day_edit_form:
|
| 858 |
+
selected_date = gr.Textbox(label="Date")
|
| 859 |
+
work_hours = gr.Number(label="Work Hours", minimum=0, maximum=24)
|
| 860 |
+
life_hours = gr.Number(label="Life Hours", minimum=0, maximum=24)
|
| 861 |
+
health_hours = gr.Number(label="Health Hours", minimum=0, maximum=24)
|
| 862 |
+
sleep_hours = gr.Number(label="Sleep Hours", minimum=0, maximum=24)
|
| 863 |
+
save_day_btn = gr.Button("Save")
|
| 864 |
+
|
| 865 |
+
edit_buttons = gr.HTML() # This will hold our edit buttons
|
| 866 |
+
|
| 867 |
+
def open_day_edit_form(date):
|
| 868 |
+
return gr.update(visible=True), gr.update(value=date)
|
| 869 |
+
|
| 870 |
+
def save_day_data(user_name, date, work, life, health, sleep):
|
| 871 |
+
save_day_activities(user_name, date, work, life, health, sleep)
|
| 872 |
+
return gr.update(visible=False), update_monthly_calendar(user_name, calendar_date.value)
|
| 873 |
+
|
| 874 |
+
save_day_btn.click(
|
| 875 |
+
save_day_data,
|
| 876 |
+
inputs=[user_name, selected_date, work_hours, life_hours, health_hours, sleep_hours],
|
| 877 |
+
outputs=[day_edit_form, monthly_calendar]
|
| 878 |
+
)
|
| 879 |
+
|
| 880 |
+
def update_monthly_calendar(user_name, date):
|
| 881 |
+
try:
|
| 882 |
+
year, month = map(int, date.split('-'))
|
| 883 |
+
except ValueError:
|
| 884 |
+
year, month = datetime.now().year, datetime.now().month
|
| 885 |
+
|
| 886 |
+
df = get_monthly_data(user_name, year, month)
|
| 887 |
+
calendar_df = format_monthly_data(df, year, month)
|
| 888 |
+
return calendar_df
|
| 889 |
+
|
| 890 |
+
def create_day_buttons(df):
|
| 891 |
+
buttons_html = ""
|
| 892 |
+
for _, row in df.iterrows():
|
| 893 |
+
date = row['date']
|
| 894 |
+
buttons_html += f'<button onclick="edit_day(\'{date}\')">{date}</button>'
|
| 895 |
+
return buttons_html
|
| 896 |
+
|
| 897 |
+
update_calendar_btn.click(
|
| 898 |
+
lambda user, date: (update_monthly_calendar(user, date), create_day_buttons(update_monthly_calendar(user, date))),
|
| 899 |
+
inputs=[user_name, calendar_date],
|
| 900 |
+
outputs=[monthly_calendar, edit_buttons]
|
| 901 |
+
)
|
| 902 |
+
|
| 903 |
+
# Event handlers and function definitions
|
| 904 |
+
def log_and_display(user_name, date, category, subcategory, start_time, end_time):
|
| 905 |
+
log_activity(user_name, date, category, subcategory, start_time, end_time)
|
| 906 |
+
activities = get_activities(user_name, date)
|
| 907 |
+
return activities, len(activities)
|
| 908 |
+
|
| 909 |
+
def log_and_display_metrics(user_name, date, life_score, work_score, health_score, wake_up_time, workouts, meditation_minutes, brain_training_minutes):
|
| 910 |
+
log_qualitative_metrics(user_name, date, life_score, work_score, health_score)
|
| 911 |
+
log_quantitative_metrics(user_name, date, wake_up_time, workouts, meditation_minutes, brain_training_minutes)
|
| 912 |
+
metrics = get_metrics(user_name, date)
|
| 913 |
+
return metrics, life_score, work_score, health_score, wake_up_time
|
| 914 |
+
|
| 915 |
+
def update_dashboard(user_name, date):
|
| 916 |
+
today_activities_data = get_activities(user_name, date)
|
| 917 |
+
today_metrics_data = get_metrics(user_name, date)
|
| 918 |
+
weekly_pie_chart_data, weekly_line_chart_data, total_hours = analyze_weekly_data(user_name)
|
| 919 |
+
|
| 920 |
+
# Calculate quick glance metrics
|
| 921 |
+
life_score = today_metrics_data['life_score'].values[0] if not today_metrics_data.empty else 0
|
| 922 |
+
work_score = today_metrics_data['work_score'].values[0] if not today_metrics_data.empty else 0
|
| 923 |
+
health_score = today_metrics_data['health_score'].values[0] if not today_metrics_data.empty else 0
|
| 924 |
+
wake_up = today_metrics_data['wake_up_time'].values[0] if not today_metrics_data.empty else ""
|
| 925 |
+
total_acts = len(today_activities_data)
|
| 926 |
+
|
| 927 |
+
return (today_activities_data, today_metrics_data, weekly_pie_chart_data, weekly_line_chart_data,
|
| 928 |
+
life_score, work_score, health_score, wake_up, total_acts)
|
| 929 |
+
|
| 930 |
+
def update_analysis(user_name, period):
|
| 931 |
+
current_date = datetime.now()
|
| 932 |
+
year, month = current_date.year, current_date.month
|
| 933 |
+
|
| 934 |
+
if period == "Weekly":
|
| 935 |
+
df = get_weekly_data(user_name)
|
| 936 |
+
scores = get_weekly_scores(user_name)
|
| 937 |
+
else: # Monthly
|
| 938 |
+
df = get_monthly_data(user_name, year, month)
|
| 939 |
+
scores = get_monthly_scores(user_name)
|
| 940 |
+
|
| 941 |
+
# Ensure df is not empty
|
| 942 |
+
if df.empty:
|
| 943 |
+
return px.pie(), px.line(), 0, pd.DataFrame()
|
| 944 |
+
|
| 945 |
+
# Calculate duration in hours
|
| 946 |
+
df['duration'] = (df['end_time'] - df['start_time']).dt.total_seconds() / 3600
|
| 947 |
+
|
| 948 |
+
breakdown_data = df.groupby(['category', 'subcategory'])['duration'].sum().reset_index()
|
| 949 |
+
breakdown_data = breakdown_data.sort_values('duration', ascending=False)
|
| 950 |
+
|
| 951 |
+
total_hours = breakdown_data['duration'].sum()
|
| 952 |
+
|
| 953 |
+
pie_chart = px.pie(breakdown_data, values='duration', names='category', title=f"{period} Activity Distribution")
|
| 954 |
+
|
| 955 |
+
# Ensure 'date' column exists in scores DataFrame
|
| 956 |
+
if 'date' not in scores.columns:
|
| 957 |
+
scores['date'] = scores.index if isinstance(scores.index, pd.DatetimeIndex) else pd.to_datetime(scores.index)
|
| 958 |
+
|
| 959 |
+
line_chart = px.line(scores, x='date', y=['life_score', 'work_score', 'health_score'], title=f"{period} Score Trends")
|
| 960 |
+
|
| 961 |
+
return pie_chart, line_chart, total_hours, breakdown_data
|
| 962 |
+
|
| 963 |
+
|
| 964 |
+
def set_new_goal(user_name, category, description, target, start_date, end_date):
|
| 965 |
+
set_goal(user_name, category, description, target, start_date, end_date)
|
| 966 |
+
return get_goals(user_name)
|
| 967 |
+
|
| 968 |
+
def load_user_settings(user_name):
|
| 969 |
+
settings = get_user_settings(user_name)
|
| 970 |
+
return settings[0], settings[1], settings[2], settings[3]
|
| 971 |
+
|
| 972 |
+
def save_user_settings(user_name, wake_time, w_weight, l_weight, h_weight):
|
| 973 |
+
update_user_settings(user_name, wake_time, w_weight, l_weight, h_weight)
|
| 974 |
+
return "Settings updated successfully"
|
| 975 |
+
|
| 976 |
+
def create_preset_template(preset_name):
|
| 977 |
+
if preset_name == "Rob Dyrdek":
|
| 978 |
+
return {
|
| 979 |
+
"default_wake_time": "05:00",
|
| 980 |
+
"work_weight": 1.0,
|
| 981 |
+
"life_weight": 1.0,
|
| 982 |
+
"health_weight": 1.0,
|
| 983 |
+
"categories": ["Work", "Life", "Health", "Sleep"],
|
| 984 |
+
"subcategories": {
|
| 985 |
+
"Work": ["Drydek Machine", "Television", "Other"],
|
| 986 |
+
"Life": ["Rob & Bre", "Kids", "Friends & Social", "Other"],
|
| 987 |
+
"Health": ["Gym", "Meditation", "Personal Care", "Other"],
|
| 988 |
+
"Sleep": []
|
| 989 |
+
}
|
| 990 |
+
}
|
| 991 |
+
elif preset_name == "Student":
|
| 992 |
+
return {
|
| 993 |
+
"default_wake_time": "07:00",
|
| 994 |
+
"work_weight": 1.2,
|
| 995 |
+
"life_weight": 0.8,
|
| 996 |
+
"health_weight": 1.0,
|
| 997 |
+
"categories": ["Study", "Life", "Health", "Sleep"],
|
| 998 |
+
"subcategories": {
|
| 999 |
+
"Study": ["Classes", "Homework", "Research", "Other"],
|
| 1000 |
+
"Life": ["Family", "Friends", "Hobbies", "Other"],
|
| 1001 |
+
"Health": ["Exercise", "Meditation", "Personal Care", "Other"],
|
| 1002 |
+
"Sleep": []
|
| 1003 |
+
}
|
| 1004 |
+
}
|
| 1005 |
+
else:
|
| 1006 |
+
# Return None or a default preset if the preset name is not recognized
|
| 1007 |
+
return None
|
| 1008 |
+
|
| 1009 |
+
def update_settings_from_preset(preset_name):
|
| 1010 |
+
if preset_name == "Custom":
|
| 1011 |
+
return gr.update(), gr.update(), gr.update(), gr.update()
|
| 1012 |
+
|
| 1013 |
+
preset = create_preset_template(preset_name)
|
| 1014 |
+
if preset is None:
|
| 1015 |
+
return gr.update(), gr.update(), gr.update(), gr.update()
|
| 1016 |
+
|
| 1017 |
+
return (
|
| 1018 |
+
gr.update(value=preset.get("default_wake_time", "")),
|
| 1019 |
+
gr.update(value=preset.get("work_weight", 1.0)),
|
| 1020 |
+
gr.update(value=preset.get("life_weight", 1.0)),
|
| 1021 |
+
gr.update(value=preset.get("health_weight", 1.0))
|
| 1022 |
+
)
|
| 1023 |
+
|
| 1024 |
+
def finish_guided_setup(user_name, preset, wake_time, w_weight, l_weight, h_weight, categories, subcategories, initial_goal):
|
| 1025 |
+
# Save user settings
|
| 1026 |
+
update_user_settings(user_name, wake_time, w_weight, l_weight, h_weight)
|
| 1027 |
+
|
| 1028 |
+
# Save categories and subcategories
|
| 1029 |
+
save_custom_categories(user_name, categories, subcategories)
|
| 1030 |
+
|
| 1031 |
+
# Set initial goal
|
| 1032 |
+
set_goal(user_name, "General", initial_goal, 100, datetime.now().date(), datetime.now().date() + timedelta(days=30))
|
| 1033 |
+
|
| 1034 |
+
return "Setup completed successfully!"
|
| 1035 |
+
|
| 1036 |
+
# Connect event handlers to UI components
|
| 1037 |
+
log_activity_btn.click(log_and_display, inputs=[user_name, date, category, subcategory, start_time, end_time], outputs=[today_activities, total_activities])
|
| 1038 |
+
log_metrics_btn.click(log_and_display_metrics, inputs=[user_name, date, life_score, work_score, health_score, wake_up_time, workouts, meditation_minutes, brain_training_minutes], outputs=[today_metrics, today_life_score, today_work_score, today_health_score, wake_up_time])
|
| 1039 |
+
update_dashboard_btn.click(update_dashboard, inputs=[user_name, date], outputs=[today_activities, today_metrics, weekly_pie_chart, weekly_line_chart, today_life_score, today_work_score, today_health_score, wake_up_time, total_activities])
|
| 1040 |
+
update_analysis_btn.click(update_analysis, inputs=[user_name, analysis_period], outputs=[analysis_pie_chart, analysis_line_chart, analysis_total_hours])
|
| 1041 |
+
set_goal_btn.click(set_new_goal, inputs=[user_name, goal_category, goal_description, goal_target, goal_start_date, goal_end_date], outputs=[goals_table])
|
| 1042 |
+
update_settings_btn.click(save_user_settings, inputs=[user_name, default_wake_time, work_weight, life_weight, health_weight], outputs=[gr.Textbox(label="Settings Status")])
|
| 1043 |
+
preset_dropdown.change(update_settings_from_preset, inputs=[preset_dropdown], outputs=[default_wake_time, work_weight, life_weight, health_weight])
|
| 1044 |
+
|
| 1045 |
+
# Additional functions that might be needed
|
| 1046 |
+
|
| 1047 |
+
def save_custom_categories(user_name, categories, subcategories):
|
| 1048 |
+
conn = create_connection()
|
| 1049 |
+
cursor = conn.cursor()
|
| 1050 |
+
|
| 1051 |
+
# First, delete existing custom categories for the user
|
| 1052 |
+
cursor.execute("DELETE FROM custom_categories WHERE user_id = (SELECT id FROM users WHERE name = ?)", (user_name,))
|
| 1053 |
+
|
| 1054 |
+
# Insert new custom categories
|
| 1055 |
+
for category in categories:
|
| 1056 |
+
cursor.execute("""
|
| 1057 |
+
INSERT INTO custom_categories (user_id, category_name, subcategories)
|
| 1058 |
+
VALUES ((SELECT id FROM users WHERE name = ?), ?, ?)
|
| 1059 |
+
""", (user_name, category, ','.join(subcategories.get(category, []))))
|
| 1060 |
+
|
| 1061 |
+
conn.commit()
|
| 1062 |
+
conn.close()
|
| 1063 |
+
|
| 1064 |
+
def get_custom_categories(user_name):
|
| 1065 |
+
conn = create_connection()
|
| 1066 |
+
cursor = conn.cursor()
|
| 1067 |
+
|
| 1068 |
+
cursor.execute("""
|
| 1069 |
+
SELECT category_name, subcategories
|
| 1070 |
+
FROM custom_categories
|
| 1071 |
+
WHERE user_id = (SELECT id FROM users WHERE name = ?)
|
| 1072 |
+
""", (user_name,))
|
| 1073 |
+
|
| 1074 |
+
results = cursor.fetchall()
|
| 1075 |
+
conn.close()
|
| 1076 |
+
|
| 1077 |
+
categories = [row[0] for row in results]
|
| 1078 |
+
subcategories = {row[0]: row[1].split(',') for row in results}
|
| 1079 |
+
|
| 1080 |
+
return categories, subcategories
|
| 1081 |
+
|
| 1082 |
+
# Add this function to update the category dropdown in the UI
|
| 1083 |
+
def update_category_dropdown(user_name):
|
| 1084 |
+
categories, _ = get_custom_categories(user_name)
|
| 1085 |
+
return gr.update(choices=categories)
|
| 1086 |
+
|
| 1087 |
+
# Connect the update_category_dropdown function to the user_name input
|
| 1088 |
+
user_name.change(update_category_dropdown, inputs=[user_name], outputs=[category])
|
| 1089 |
+
|
| 1090 |
+
# Add event handlers for adding and deleting user profiles
|
| 1091 |
+
def add_user(new_name):
|
| 1092 |
+
add_user_profile(new_name)
|
| 1093 |
+
generate_placeholder_data(new_name)
|
| 1094 |
+
return gr.update(choices=get_user_list(), value=new_name)
|
| 1095 |
+
|
| 1096 |
+
def delete_user(name):
|
| 1097 |
+
delete_user_profile(name)
|
| 1098 |
+
return gr.update(choices=get_user_list(), value=get_user_list()[0] if get_user_list() else None)
|
| 1099 |
+
|
| 1100 |
+
add_user_btn.click(add_user, inputs=[new_user_name], outputs=[user_name])
|
| 1101 |
+
delete_user_btn.click(delete_user, inputs=[user_name], outputs=[user_name])
|
| 1102 |
+
|
| 1103 |
+
# Function to get the list of users
|
| 1104 |
+
def get_user_list():
|
| 1105 |
+
conn = create_connection()
|
| 1106 |
+
cursor = conn.cursor()
|
| 1107 |
+
cursor.execute("SELECT name FROM users")
|
| 1108 |
+
users = [row[0] for row in cursor.fetchall()]
|
| 1109 |
+
conn.close()
|
| 1110 |
+
return users
|
| 1111 |
+
|
| 1112 |
+
# Update the user_name dropdown when the interface loads
|
| 1113 |
+
demo.load(lambda: gr.update(choices=get_user_list()), outputs=[user_name])
|
| 1114 |
+
|
| 1115 |
+
# Launch the application
|
| 1116 |
+
if __name__ == "__main__":
|
| 1117 |
+
create_tables()
|
| 1118 |
+
test_user = "John Doe"
|
| 1119 |
+
add_user_profile(test_user)
|
| 1120 |
+
generate_placeholder_data(test_user)
|
| 1121 |
+
demo.launch(share=False, inbrowser=True, show_api=False, show_error=True)
|