Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,102 +14,6 @@ DB_FILE = "life_tracker.db"
|
|
| 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()
|
|
@@ -193,9 +97,6 @@ def generate_placeholder_data(user_name):
|
|
| 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()
|
|
@@ -1113,9 +1014,4 @@ with gr.Blocks(theme=custom_theme, css=custom_css) as demo:
|
|
| 1113 |
demo.load(lambda: gr.update(choices=get_user_list()), outputs=[user_name])
|
| 1114 |
|
| 1115 |
# Launch the application
|
| 1116 |
-
|
| 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)
|
|
|
|
| 14 |
def create_connection():
|
| 15 |
return sqlite3.connect(DB_FILE)
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def add_user_profile(name):
|
| 18 |
conn = create_connection()
|
| 19 |
cursor = conn.cursor()
|
|
|
|
| 97 |
conn.commit()
|
| 98 |
conn.close()
|
| 99 |
|
|
|
|
|
|
|
|
|
|
| 100 |
def get_weekly_data(user_name):
|
| 101 |
conn = create_connection()
|
| 102 |
end_date = datetime.now().date()
|
|
|
|
| 1014 |
demo.load(lambda: gr.update(choices=get_user_list()), outputs=[user_name])
|
| 1015 |
|
| 1016 |
# Launch the application
|
| 1017 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|