forked from pasky/papalala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordstats.sql
48 lines (40 loc) · 1.32 KB
/
wordstats.sql
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
CREATE TABLE users (
name TEXT PRIMARY KEY
);
CREATE TABLE channels (
name TEXT,
network TEXT,
PRIMARY KEY (name, network)
);
CREATE TABLE stats (
user TEXT REFERENCES users (name) ON DELETE CASCADE,
channel TEXT REFERENCES channels (name) ON DELETE CASCADE,
network TEXT REFERENCES channels (network) ON DELETE CASCADE,
-- [time, time + timespan] time period
time INT,
timespan INT,
letters INT,
words INT,
actions INT,
smileys INT,
kicks INT,
modes INT,
topics INT,
seconds INT,
PRIMARY KEY (user, channel, network, time, timespan)
);
CREATE TABLE words (
user TEXT REFERENCES users (name) ON DELETE CASCADE,
channel TEXT REFERENCES channels (name) ON DELETE CASCADE,
network TEXT REFERENCES channels (network) ON DELETE CASCADE,
word TEXT,
hits INT,
last INT, -- timestamp
PRIMARY KEY (user, channel, network, word)
);
-- stats shakedown:
-- each segment adds at a timespan boundary (each hour-segment time is divisible by 3600, etc.)
-- last 24 hours are kept in 1-minute segments
-- if there exists a 1m segment from last midnight, merge all 1m segments from prev. day to a 1-day segment
-- if there exists a 1d segment from lastmonth 1st, merge all 1d segments from prev. month to a 1-month segment
-- if there exists a 1y segment from lastyear Jan 1, merge all 1y segments from prev. year to a 1-year segment