Severian commited on
Commit
34ecef9
·
verified ·
1 Parent(s): 9cde64b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +103 -0
app.py CHANGED
@@ -11,6 +11,104 @@ import json
11
 
12
  DB_FILE = "life_tracker.db"
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  def create_connection():
15
  return sqlite3.connect(DB_FILE)
16
 
@@ -503,6 +601,7 @@ function edit_day(date) {
503
 
504
  # Create the main Gradio interface with the custom theme and CSS
505
  with gr.Blocks(theme=custom_theme, css=custom_css) as demo:
 
506
  with gr.Row(equal_height=True):
507
  # Left sidebar
508
  with gr.Column(scale=1, min_width=200):
@@ -1007,6 +1106,10 @@ with gr.Blocks(theme=custom_theme, css=custom_css) as demo:
1007
  cursor = conn.cursor()
1008
  cursor.execute("SELECT name FROM users")
1009
  users = [row[0] for row in cursor.fetchall()]
 
 
 
 
1010
  conn.close()
1011
  return users
1012
 
 
11
 
12
  DB_FILE = "life_tracker.db"
13
 
14
+ def create_tables():
15
+ conn = create_connection()
16
+ cursor = conn.cursor()
17
+
18
+ cursor.execute('''
19
+ CREATE TABLE IF NOT EXISTS users (
20
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
21
+ name TEXT UNIQUE
22
+ )
23
+ ''')
24
+
25
+ cursor.execute('''
26
+ CREATE TABLE IF NOT EXISTS daily_activities (
27
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
28
+ user_id INTEGER,
29
+ date TEXT,
30
+ category TEXT,
31
+ subcategory TEXT,
32
+ start_time TEXT,
33
+ end_time TEXT,
34
+ FOREIGN KEY (user_id) REFERENCES users (id)
35
+ )
36
+ ''')
37
+
38
+ cursor.execute('''
39
+ CREATE TABLE IF NOT EXISTS qualitative_metrics (
40
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
41
+ user_id INTEGER,
42
+ date TEXT,
43
+ life_score INTEGER,
44
+ work_score INTEGER,
45
+ health_score INTEGER,
46
+ FOREIGN KEY (user_id) REFERENCES users (id)
47
+ )
48
+ ''')
49
+
50
+ cursor.execute('''
51
+ CREATE TABLE IF NOT EXISTS quantitative_metrics (
52
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
53
+ user_id INTEGER,
54
+ date TEXT,
55
+ wake_up_time TEXT,
56
+ workouts INTEGER,
57
+ meditation_minutes INTEGER,
58
+ brain_training_minutes INTEGER,
59
+ FOREIGN KEY (user_id) REFERENCES users (id)
60
+ )
61
+ ''')
62
+
63
+ cursor.execute('''
64
+ CREATE TABLE IF NOT EXISTS goals (
65
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
66
+ user_id INTEGER,
67
+ category TEXT,
68
+ description TEXT,
69
+ target_value REAL,
70
+ current_value REAL,
71
+ start_date TEXT,
72
+ end_date TEXT,
73
+ FOREIGN KEY (user_id) REFERENCES users (id)
74
+ )
75
+ ''')
76
+
77
+ cursor.execute('''
78
+ CREATE TABLE IF NOT EXISTS user_settings (
79
+ user_id INTEGER PRIMARY KEY,
80
+ default_wake_time TEXT,
81
+ work_weight REAL,
82
+ life_weight REAL,
83
+ health_weight REAL,
84
+ FOREIGN KEY (user_id) REFERENCES users (id)
85
+ )
86
+ ''')
87
+
88
+ cursor.execute('''
89
+ CREATE TABLE IF NOT EXISTS custom_categories (
90
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
91
+ user_id INTEGER,
92
+ category_name TEXT,
93
+ subcategories TEXT,
94
+ FOREIGN KEY (user_id) REFERENCES users (id)
95
+ )
96
+ ''')
97
+
98
+ cursor.execute('''
99
+ CREATE TABLE IF NOT EXISTS daily_checklist (
100
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
101
+ user_id INTEGER,
102
+ date TEXT,
103
+ checklist_data TEXT,
104
+ notes TEXT,
105
+ FOREIGN KEY (user_id) REFERENCES users (id)
106
+ )
107
+ ''')
108
+
109
+ conn.commit()
110
+ conn.close()
111
+
112
  def create_connection():
113
  return sqlite3.connect(DB_FILE)
114
 
 
601
 
602
  # Create the main Gradio interface with the custom theme and CSS
603
  with gr.Blocks(theme=custom_theme, css=custom_css) as demo:
604
+ create_tables()
605
  with gr.Row(equal_height=True):
606
  # Left sidebar
607
  with gr.Column(scale=1, min_width=200):
 
1106
  cursor = conn.cursor()
1107
  cursor.execute("SELECT name FROM users")
1108
  users = [row[0] for row in cursor.fetchall()]
1109
+ if not users:
1110
+ cursor.execute("INSERT INTO users (name) VALUES (?)", ("John Doe",))
1111
+ conn.commit()
1112
+ users = ["John Doe"]
1113
  conn.close()
1114
  return users
1115