Repository navigation
Expand file tree
/
Copy pathschema.sql
More file actions
152 lines (138 loc) · 4.18 KB
/
Copy pathschema.sql
File metadata and controls
152 lines (138 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
-- LifeTrack Database Schema
-- Raw location pings from phone
CREATE TABLE IF NOT EXISTS locations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp TEXT NOT NULL,
latitude REAL NOT NULL,
longitude REAL NOT NULL,
accuracy REAL,
altitude REAL,
speed REAL,
battery INTEGER,
source TEXT DEFAULT "phone"
);
-- Named places (home, work, gym, etc.)
CREATE TABLE IF NOT EXISTS places (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
latitude REAL NOT NULL,
longitude REAL NOT NULL,
radius_meters INTEGER DEFAULT 100,
created_at TEXT DEFAULT CURRENT_TIMESTAMP
);
-- Place profiles (metadata about places)
CREATE TABLE IF NOT EXISTS place_profiles (
place_id INTEGER PRIMARY KEY,
is_home INTEGER DEFAULT 0,
is_workplace INTEGER DEFAULT 0,
category TEXT,
typical_duration_mins INTEGER,
FOREIGN KEY (place_id) REFERENCES places(id)
);
-- Visit records (arrivals/departures)
CREATE TABLE IF NOT EXISTS visits_v2 (
id INTEGER PRIMARY KEY AUTOINCREMENT,
place_id INTEGER,
arrived_at TEXT NOT NULL,
departed_at TEXT,
duration_minutes INTEGER,
activity_type TEXT,
FOREIGN KEY (place_id) REFERENCES places(id)
);
-- Motion states (moving, stationary, etc.)
CREATE TABLE IF NOT EXISTS motion_states (
id INTEGER PRIMARY KEY AUTOINCREMENT,
state TEXT NOT NULL,
start_time TEXT NOT NULL,
end_time TEXT,
confidence REAL
);
-- Activity classifications
CREATE TABLE IF NOT EXISTS activity_classifications (
id INTEGER PRIMARY KEY AUTOINCREMENT,
visit_id INTEGER,
activity_type TEXT,
confidence REAL,
user_corrected INTEGER DEFAULT 0,
corrected_activity_type TEXT,
classified_at TEXT DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (visit_id) REFERENCES visits_v2(id)
);
-- Place suggestions (discovered patterns)
CREATE TABLE IF NOT EXISTS place_suggestions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
latitude REAL NOT NULL,
longitude REAL NOT NULL,
visit_count INTEGER DEFAULT 1,
suggested_name TEXT,
dismissed INTEGER DEFAULT 0,
created_at TEXT DEFAULT CURRENT_TIMESTAMP
);
-- Goals
CREATE TABLE IF NOT EXISTS goals (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
target_type TEXT,
target_value REAL,
current_value REAL DEFAULT 0,
period TEXT DEFAULT "daily",
active INTEGER DEFAULT 1
);
-- Daily summaries (cached)
CREATE TABLE IF NOT EXISTS daily_summaries (
date TEXT PRIMARY KEY,
total_places INTEGER,
total_duration_mins INTEGER,
work_mins INTEGER,
home_mins INTEGER,
travel_mins INTEGER,
life_score REAL,
computed_at TEXT
);
-- Indexes for performance
CREATE INDEX IF NOT EXISTS idx_locations_timestamp ON locations(timestamp);
CREATE INDEX IF NOT EXISTS idx_visits_arrived ON visits_v2(arrived_at);
CREATE INDEX IF NOT EXISTS idx_visits_place ON visits_v2(place_id);
-- Oura ring sleep data cache
CREATE TABLE IF NOT EXISTS oura_sleep_cache (
date TEXT PRIMARY KEY,
bedtime_start TEXT,
bedtime_end TEXT,
duration_minutes INTEGER,
sleep_score INTEGER,
readiness_score INTEGER,
deep_sleep_minutes INTEGER,
rem_sleep_minutes INTEGER,
light_sleep_minutes INTEGER,
awake_minutes INTEGER,
hr_average REAL,
hr_lowest INTEGER,
hrv_average REAL,
raw_json TEXT,
synced_at TEXT
);
-- Learned rules for activity classification
CREATE TABLE IF NOT EXISTS learned_rules (
id INTEGER PRIMARY KEY AUTOINCREMENT,
rule_type TEXT NOT NULL,
place_id INTEGER,
time_pattern TEXT,
activity_type TEXT NOT NULL,
confidence REAL DEFAULT 1.0,
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (place_id) REFERENCES places(id)
);
-- Discovered location clusters
CREATE TABLE IF NOT EXISTS discovered_clusters (
id INTEGER PRIMARY KEY AUTOINCREMENT,
center_lat REAL NOT NULL,
center_lon REAL NOT NULL,
visit_count INTEGER DEFAULT 1,
suggested_name TEXT,
category_guess TEXT,
is_dismissed INTEGER DEFAULT 0,
promoted_to_place_id INTEGER,
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (promoted_to_place_id) REFERENCES places(id)
);
CREATE INDEX IF NOT EXISTS idx_oura_date ON oura_sleep_cache(date);