-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlongest_streak.py
179 lines (164 loc) · 5.07 KB
/
longest_streak.py
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
import toolforge
import pywikibot as pw
from pywikibot.data import api
import helpers
hywiki: pw.Site = pw.Site('hy', 'wikipedia')
def streak(sql, title, lr):
global hywiki
gen = hywiki._generator(api.ListGenerator, type_arg='allusers',
auprop='editcount|groups|registration',
auactiveusers=True,
aufrom='!', total=None)
user_data = [['Մասնակից', 'Վերջին անգամ չի խմբագրել', lr]]
for user in gen:
conn = toolforge.connect('hywiki')
with conn.cursor() as cur:
cur.execute(sql, ((str(user['name']),)))
results = cur.fetchall()
for r in results:
if r[2] == 0:
continue
user_data.append([user['name'], r[1], r[2]])
hypage = pw.Page(hywiki, title)
hypage.text = helpers.matrix_to_wikitable(user_data)
hypage.save('թարմացում')
streak_by_day = '''WITH mymonths AS
(SELECT DISTINCT DATE_FORMAT(DATE_ADD('2004-04-07', INTERVAL (t4*10000 + t3*1000 + t2*100 + t1*10 + t0) DAY), '%%Y-%%m-%%d') AS mymonths_month
FROM
(SELECT 0 AS t0
UNION SELECT 1
UNION SELECT 2
UNION SELECT 3
UNION SELECT 4
UNION SELECT 5
UNION SELECT 6
UNION SELECT 7
UNION SELECT 8
UNION SELECT 9) AS t0,
(SELECT 0 AS t1
UNION SELECT 1
UNION SELECT 2
UNION SELECT 3
UNION SELECT 4
UNION SELECT 5
UNION SELECT 6
UNION SELECT 7
UNION SELECT 8
UNION SELECT 9) AS t1,
(SELECT 0 AS t2
UNION SELECT 1
UNION SELECT 2
UNION SELECT 3
UNION SELECT 4
UNION SELECT 5
UNION SELECT 6
UNION SELECT 7
UNION SELECT 8
UNION SELECT 9) AS t2,
(SELECT 0 AS t3
UNION SELECT 1
UNION SELECT 2
UNION SELECT 3
UNION SELECT 4
UNION SELECT 5
UNION SELECT 6
UNION SELECT 7
UNION SELECT 8
UNION SELECT 9) AS t3,
(SELECT 0 AS t4
UNION SELECT 1
UNION SELECT 2
UNION SELECT 3
UNION SELECT 4
UNION SELECT 5
UNION SELECT 6
UNION SELECT 7
UNION SELECT 8
UNION SELECT 9) AS t4
WHERE DATE_ADD('2004-04-07', INTERVAL (t4*10000 + t3*1000 + t2*100 + t1*10 + t0) DAY) <= NOW()),
editsbymonth AS
(SELECT DATE_FORMAT(STR_TO_DATE(CAST(rev_timestamp AS CHAR), '%%Y%%m%%d%%H%%i%%s'), '%%Y-%%m-%%d') AS editsbymonth_month,
COUNT(*) AS C
FROM revision_userindex
JOIN actor ON rev_actor = actor_id
WHERE actor_name = %s
GROUP BY editsbymonth_month)
SELECT COALESCE(C, 0) AS Cc,
mymonths_month,
DATEDIFF(NOW(), mymonths_month) days
FROM editsbymonth
RIGHT JOIN mymonths ON mymonths_month = editsbymonth_month
HAVING Cc = 0
ORDER BY mymonths_month DESC
LIMIT 1'''
streak_by_month = '''WITH mymonths AS
(SELECT DISTINCT DATE_FORMAT(DATE_ADD('2004-04-07', INTERVAL (t4*10000 + t3*1000 + t2*100 + t1*10 + t0) MONTH), '%%Y-%%m') AS mymonths_month
FROM
(SELECT 0 AS t0
UNION SELECT 1
UNION SELECT 2
UNION SELECT 3
UNION SELECT 4
UNION SELECT 5
UNION SELECT 6
UNION SELECT 7
UNION SELECT 8
UNION SELECT 9) AS t0,
(SELECT 0 AS t1
UNION SELECT 1
UNION SELECT 2
UNION SELECT 3
UNION SELECT 4
UNION SELECT 5
UNION SELECT 6
UNION SELECT 7
UNION SELECT 8
UNION SELECT 9) AS t1,
(SELECT 0 AS t2
UNION SELECT 1
UNION SELECT 2
UNION SELECT 3
UNION SELECT 4
UNION SELECT 5
UNION SELECT 6
UNION SELECT 7
UNION SELECT 8
UNION SELECT 9) AS t2,
(SELECT 0 AS t3
UNION SELECT 1
UNION SELECT 2
UNION SELECT 3
UNION SELECT 4
UNION SELECT 5
UNION SELECT 6
UNION SELECT 7
UNION SELECT 8
UNION SELECT 9) AS t3,
(SELECT 0 AS t4
UNION SELECT 1
UNION SELECT 2
UNION SELECT 3
UNION SELECT 4
UNION SELECT 5
UNION SELECT 6
UNION SELECT 7
UNION SELECT 8
UNION SELECT 9) AS t4
WHERE DATE_ADD('2004-04-07', INTERVAL (t4*10000 + t3*1000 + t2*100 + t1*10 + t0) MONTH) <= NOW()),
editsbymonth AS
(SELECT DATE_FORMAT(STR_TO_DATE(CAST(rev_timestamp AS CHAR), '%%Y%%m%%d%%H%%i%%s'), '%%Y-%%m') AS editsbymonth_month,
COUNT(*) AS C
FROM revision_userindex
JOIN actor ON rev_actor = actor_id
WHERE actor_name = %s
GROUP BY editsbymonth_month)
SELECT COALESCE(C, 0) AS Cc,
mymonths_month,
TIMESTAMPDIFF(MONTH, CONCAT(mymonths_month, '-01'), NOW()) days
FROM editsbymonth
RIGHT JOIN mymonths ON mymonths_month = editsbymonth_month
HAVING Cc = 0
ORDER BY mymonths_month DESC
LIMIT 1'''
streak(streak_by_day, 'Վիքիպեդիա:Ցանկեր/խմբագիրներ ըստ անդադար խմբագրման օրերի', 'Քանի՞ օր է անդադար խմբագրել')
streak(streak_by_month, 'Վիքիպեդիա:Ցանկեր/խմբագիրներ ըստ անդադար խմբագրման ամիսների', 'Քանի՞ ամիս է անդադար խմբագրել')