-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvrcx_queries.sql
More file actions
342 lines (314 loc) · 12.4 KB
/
Copy pathvrcx_queries.sql
File metadata and controls
342 lines (314 loc) · 12.4 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
-- ============================================================================
-- VRCX Database Query Examples
-- ============================================================================
-- These queries can be run directly against the VRCX.sqlite3 database
-- using any SQLite client (DB Browser, sqlite3 CLI, etc.)
--
-- Usage:
-- sqlite3 /path/to/VRCX.sqlite3 < vrcx_queries.sql
-- OR
-- sqlite3 /path/to/VRCX.sqlite3
-- sqlite> .read vrcx_queries.sql
-- ============================================================================
-- ============================================================================
-- PRIMARY QUERIES - For Your Use Case
-- ============================================================================
-- 1. HOUR-BY-HOUR PEOPLE COUNT (Main Query)
-- Shows for each hour: how many people joined, left, and total unique people
-- This is ideal for creating your hour-by-hour spreadsheet
-- ============================================================================
SELECT
CAST(strftime('%H', created_at) AS INTEGER) as hour,
PRINTF('%02d:00', CAST(strftime('%H', created_at) AS INTEGER)) as time_slot,
location,
world_name,
SUM(CASE WHEN type = 'join' THEN 1 ELSE 0 END) as people_joined,
SUM(CASE WHEN type = 'leave' THEN 1 ELSE 0 END) as people_left,
SUM(CASE WHEN type = 'join' THEN 1 ELSE -1 END) as net_change,
COUNT(DISTINCT display_name) as unique_people_this_hour
FROM gamelog_join_leave
WHERE DATE(created_at) = DATE('now') -- Change 'now' to specific date
GROUP BY hour, location
ORDER BY hour ASC, unique_people_this_hour DESC;
-- ============================================================================
-- 2. YOUR LOCATION TIMELINE
-- Shows where you were and for how long
-- ============================================================================
SELECT
DATETIME(created_at) as when_changed,
location,
world_name,
time as duration_seconds,
PRINTF('%d:%02d', time / 3600, (time % 3600) / 60) as duration_display,
group_name
FROM gamelog_location
WHERE DATE(created_at) = DATE('now') -- Change 'now' to specific date
ORDER BY created_at ASC;
-- ============================================================================
-- 3. PEOPLE JOIN/LEAVE TIMELINE
-- Detailed timeline of when people joined and left specific instances
-- ============================================================================
SELECT
DATETIME(created_at) as when_event_occurred,
PRINTF('%02d:00', CAST(strftime('%H', created_at) AS INTEGER)) as hour,
type as event_type,
display_name as person,
user_id,
location as instance,
world_name
FROM gamelog_join_leave
WHERE DATE(created_at) = DATE('now') -- Change 'now' to specific date
ORDER BY created_at ASC;
-- ============================================================================
-- ANALYSIS QUERIES - Insights and Patterns
-- ============================================================================
-- 4. BUSIEST HOURS (Most people overall)
-- ============================================================================
SELECT
PRINTF('%02d:00', hour) as time_slot,
SUM(unique_people) as total_unique_people,
COUNT(DISTINCT location) as different_instances,
ROUND(AVG(unique_people), 1) as avg_per_instance
FROM (
SELECT
CAST(strftime('%H', created_at) AS INTEGER) as hour,
location,
COUNT(DISTINCT display_name) as unique_people
FROM gamelog_join_leave
WHERE DATE(created_at) = DATE('now')
GROUP BY hour, location
)
GROUP BY hour
ORDER BY total_unique_people DESC;
-- 5. MOST POPULAR INSTANCES
-- ============================================================================
SELECT
location,
world_name,
COUNT(DISTINCT display_name) as total_unique_people,
SUM(CASE WHEN type = 'join' THEN 1 ELSE 0 END) as total_joins,
SUM(CASE WHEN type = 'leave' THEN 1 ELSE 0 END) as total_leaves
FROM gamelog_join_leave
WHERE DATE(created_at) = DATE('now')
GROUP BY location
ORDER BY total_unique_people DESC;
-- 6. MOST ACTIVE FRIENDS (By interaction count)
-- ============================================================================
SELECT
display_name,
user_id,
COUNT(*) as total_events,
SUM(CASE WHEN type = 'join' THEN 1 ELSE 0 END) as joined_count,
SUM(CASE WHEN type = 'leave' THEN 1 ELSE 0 END) as left_count,
COUNT(DISTINCT location) as different_instances
FROM gamelog_join_leave
WHERE DATE(created_at) = DATE('now')
GROUP BY user_id
ORDER BY total_events DESC
LIMIT 20;
-- 7. INSTANCE TIMELINE (Where you spent time)
-- ============================================================================
SELECT
DATETIME(created_at) as time_changed,
location,
world_name,
time as duration_seconds,
PRINTF('%d:%02d:%02d',
time / 3600,
(time % 3600) / 60,
time % 60) as duration_formatted
FROM gamelog_location
WHERE DATE(created_at) = DATE('now')
ORDER BY created_at ASC;
-- 8. FRIEND INTERACTION HEATMAP (When you see specific people)
-- ============================================================================
SELECT
CAST(strftime('%H', created_at) AS INTEGER) as hour,
display_name,
COUNT(*) as interaction_count,
GROUP_CONCAT(type, ',') as event_types
FROM gamelog_join_leave
WHERE DATE(created_at) = DATE('now')
GROUP BY hour, display_name
ORDER BY hour, interaction_count DESC;
-- ============================================================================
-- TIME SERIES ANALYSIS
-- ============================================================================
-- 9. HOURLY ROLLUP (Simple version)
-- ============================================================================
SELECT
PRINTF('%02d:00', CAST(strftime('%H', created_at) AS INTEGER)) as hour,
COUNT(CASE WHEN type = 'join' THEN 1 END) as joins,
COUNT(CASE WHEN type = 'leave' THEN 1 END) as leaves,
COUNT(DISTINCT display_name) as unique_people
FROM gamelog_join_leave
WHERE DATE(created_at) = DATE('now')
GROUP BY strftime('%H', created_at)
ORDER BY hour;
-- 10. CUMULATIVE PEOPLE IN INSTANCES BY HOUR
-- Shows how many people accumulated in each hour
-- ============================================================================
WITH hourly_events AS (
SELECT
CAST(strftime('%H', created_at) AS INTEGER) as hour,
location,
type,
COUNT(DISTINCT display_name) as count
FROM gamelog_join_leave
WHERE DATE(created_at) = DATE('now')
GROUP BY hour, location, type
)
SELECT
hour,
location,
SUM(CASE WHEN type = 'join' THEN count ELSE 0 END) as joins,
SUM(CASE WHEN type = 'leave' THEN count ELSE 0 END) as leaves,
SUM(CASE WHEN type = 'join' THEN count ELSE -count END) as net_people
FROM hourly_events
GROUP BY hour, location
ORDER BY hour, location;
-- ============================================================================
-- DATA QUALITY & STATISTICS
-- ============================================================================
-- 11. DATA COVERAGE CHECK
-- ============================================================================
SELECT
'gamelog_location' as table_name,
COUNT(*) as record_count,
MIN(created_at) as earliest_record,
MAX(created_at) as latest_record,
COUNT(DISTINCT DATE(created_at)) as days_of_data
FROM gamelog_location
UNION ALL
SELECT
'gamelog_join_leave',
COUNT(*),
MIN(created_at),
MAX(created_at),
COUNT(DISTINCT DATE(created_at))
FROM gamelog_join_leave;
-- 12. RECENT 7 DAYS SUMMARY
-- ============================================================================
SELECT
DATE(created_at) as date,
COUNT(DISTINCT location) as instances_visited,
COUNT(DISTINCT display_name) as unique_people_seen,
SUM(CASE WHEN type = 'join' THEN 1 ELSE 0 END) as total_joins
FROM gamelog_join_leave
WHERE created_at >= datetime('now', '-7 days')
GROUP BY DATE(created_at)
ORDER BY date DESC;
-- ============================================================================
-- ADVANCED ANALYSIS
-- ============================================================================
-- 13. INSTANCE VISIT DURATION STATISTICS
-- ============================================================================
SELECT
location,
world_name,
COUNT(*) as visits,
SUM(time) as total_seconds,
ROUND(SUM(time) / 3600.0, 2) as total_hours,
ROUND(AVG(time) / 60.0, 1) as avg_minutes_per_visit,
ROUND(MAX(time) / 60.0, 1) as max_duration_minutes,
ROUND(MIN(time) / 60.0, 1) as min_duration_minutes
FROM gamelog_location
WHERE created_at >= datetime('now', '-30 days')
GROUP BY location
ORDER BY total_hours DESC;
-- 14. FRIEND PRESENCE PATTERN (Who shows up when)
-- ============================================================================
SELECT
display_name,
PRINTF('%02d:00', CAST(strftime('%H', created_at) AS INTEGER)) as preferred_hours,
COUNT(*) as event_count,
COUNT(DISTINCT DATE(created_at)) as days_active
FROM gamelog_join_leave
WHERE created_at >= datetime('now', '-14 days')
GROUP BY display_name, strftime('%H', created_at)
HAVING COUNT(*) >= 2
ORDER BY display_name, preferred_hours;
-- 15. LOCATION TRANSITIONS (Where you went)
-- ============================================================================
WITH location_sequence AS (
SELECT
created_at,
location,
world_name,
LAG(location) OVER (ORDER BY created_at) as previous_location,
LAG(world_name) OVER (ORDER BY created_at) as previous_world_name
FROM gamelog_location
WHERE DATE(created_at) = DATE('now')
)
SELECT
DATETIME(created_at) as time,
previous_world_name as from_world,
world_name as to_world,
previous_location as from_location,
location as to_location
FROM location_sequence
WHERE previous_location IS NOT NULL
ORDER BY created_at ASC;
-- ============================================================================
-- EXPORT-READY QUERIES
-- ============================================================================
-- 16. CSV-FRIENDLY: Hour-by-Hour Report
-- ============================================================================
.mode csv
.output hourly_report.csv
SELECT
PRINTF('%02d:00', CAST(strftime('%H', created_at) AS INTEGER)) as hour,
location,
world_name,
SUM(CASE WHEN type = 'join' THEN 1 ELSE 0 END) as joins,
SUM(CASE WHEN type = 'leave' THEN 1 ELSE 0 END) as leaves,
COUNT(DISTINCT display_name) as unique_people
FROM gamelog_join_leave
WHERE DATE(created_at) = DATE('now')
GROUP BY CAST(strftime('%H', created_at) AS INTEGER), location
ORDER BY hour ASC;
.output stdout
-- 17. CSV-FRIENDLY: Full Join/Leave Log
-- ============================================================================
.mode csv
.output join_leave_log.csv
SELECT
DATETIME(created_at) as timestamp,
type,
display_name,
user_id,
location,
world_name
FROM gamelog_join_leave
WHERE DATE(created_at) = DATE('now')
ORDER BY created_at ASC;
.output stdout
-- ============================================================================
-- USEFUL REFERENCE QUERIES
-- ============================================================================
-- List all tables in database
-- ============================================================================
SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;
-- Show table structure
-- ============================================================================
-- Replace 'gamelog_location' with table name you want to inspect
PRAGMA table_info(gamelog_location);
-- Count records in each table
-- ============================================================================
SELECT
'cache_avatar' as table_name,
(SELECT COUNT(*) FROM cache_avatar) as count
UNION ALL SELECT 'cache_world', (SELECT COUNT(*) FROM cache_world)
UNION ALL SELECT 'gamelog_event', (SELECT COUNT(*) FROM gamelog_event)
UNION ALL SELECT 'gamelog_external', (SELECT COUNT(*) FROM gamelog_external)
UNION ALL SELECT 'gamelog_join_leave', (SELECT COUNT(*) FROM gamelog_join_leave)
UNION ALL SELECT 'gamelog_location', (SELECT COUNT(*) FROM gamelog_location)
UNION ALL SELECT 'gamelog_portal_spawn', (SELECT COUNT(*) FROM gamelog_portal_spawn)
UNION ALL SELECT 'gamelog_resource_load', (SELECT COUNT(*) FROM gamelog_resource_load)
UNION ALL SELECT 'gamelog_video_play', (SELECT COUNT(*) FROM gamelog_video_play)
ORDER BY table_name;
-- Database size and performance info
-- ============================================================================
PRAGMA database_list;
PRAGMA journal_mode;
PRAGMA cache_size;