-
Notifications
You must be signed in to change notification settings - Fork 5
/
dashboard.html
432 lines (352 loc) · 13.5 KB
/
dashboard.html
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
<!DOCTYPE html>
<html>
<head>
<title>Dashboard</title>
<script src="bower_components/moment/moment.js"></script>
<script src="bower_components/moment-timezone/builds/moment-timezone-with-data.js"></script>
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/localforage/dist/localforage.min.js"></script>
<script src="bower_components/mathjs/dist/math.min.js"></script>
<script src="bower_components/prelude-ls/browser/prelude-browser-min.js"></script>
<script src="libfrontend.js"></script>
<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="bower_components/google-chart/google-chart.html">
</head>
<body>
<style>
#days_ago_to_num_installs {
width: 100%;
}
#days_ago_to_num_uninstalls {
width: 100%;
}
#install_primary_language {
width: 100%;
}
#install_country {
width: 100%;
}
#install_source {
width: 100%;
}
</style>
<a href="interventions.html">Overall effectiveness of interventions across all users</a><br><br>
<div>Num active users within past week:</div>
<div id="num_active_users"></div>
<br>
<div>Num active users within past week who have logging enabled:</div>
<div id="num_active_users_logging_enabled"></div>
<br>
<div>Num active users within past week who have logging disabled:</div>
<div id="num_active_users_logging_disabled"></div>
<br>
<div>Num active users within past week who have logging not set:</div>
<div id="num_active_users_logging_not_set"></div>
<br>
<div>Retention curves:</div>
<retention-rates id="retention_curves"></div>
<br>
<div>List of users active in the past week:</div>
<div id="user_list"></div>
<br>
<div>List of users with logging enabled:</div>
<div id="user_list_logging_enabled"></div>
<br>
<div>List of users with logging disabled:</div>
<div id="user_list_logging_disabled"></div>
<br>
<div>List of users with logging not set:</div>
<div id="user_list_logging_not_set"></div>
<br>
<div>Goal to number of users who have tried it:</div>
<div id="goals_tried"></div>
<br>
<div>Goal to number of users who have it enabled:</div>
<div id="goals_enabled"></div>
<br>
<div>Interventions to number of users who have it enabled:</div>
<div id="interventions_enabled"></div>
<br>
<div>Interventions to number of users who have it disabled:</div>
<div id="interventions_disabled"></div>
<br>
<div>Number of users who have tried at least one non-default goal:</div>
<div id="users_who_tried_a_nondefault_goal"></div>
<br>
<div>Number of users who have tried at least one custom goal:</div>
<div id="users_who_tried_a_custom_goal"></div>
<br>
<div>Number of users who have at least one non-default goal target:</div>
<div id="users_who_changed_a_goal_target"></div>
<br>
<div>Last interventions seen before user stops using habitlab:</div>
<div id="last_intervention_before_stop"></div>
<br>
<div>Last interventions seen before user stops using habitlab, with total impressions:</div>
<div id="last_intervention_before_stop_with_total_impressions"></div>
<br>
<!--
<google-chart id="days_ago_to_num_installs" cols='[{"label": "Data", "type": "string"},{"label": "Installs", "type": "number"}]' rows='[["Something", 1]]'></google-chart>
<google-chart id="days_ago_to_num_uninstalls" cols='[{"label": "Data", "type": "string"},{"label": "Uninstalls", "type": "number"}]' rows='[["Something", 1]]'></google-chart>
<google-chart id="install_primary_language" cols='[{"label": "Data", "type": "string"},{"label": "Languages", "type": "number"}]' rows='[["Something", 1]]'></google-chart>
<google-chart id="install_country" cols='[{"label": "Data", "type": "string"},{"label": "Country", "type": "number"}]' rows='[["Something", 1]]'></google-chart>
<google-chart id="install_source" cols='[{"label": "Data", "type": "string"},{"label": "Installs", "type": "number"}]' rows='[["Something", 1]]'></google-chart>
-->
<script>
let user_ids = null
async function get_user_ids() {
let active_users = await getjson('/getactiveusers_week')
return active_users
}
async function get_goal_popularity() {
let goal_to_num_users = {}
for (let user_id of user_ids) {
let enabled_goals = await get_enabled_goals_for_user(user_id)
for (let goal_name of enabled_goals) {
if (goal_to_num_users[goal_name] == null) {
goal_to_num_users[goal_name] = 0
}
goal_to_num_users[goal_name] += 1
}
}
console.log(goal_to_num_users)
return goal_to_num_users
}
async function get_goals_tried_by_all_users() {
let goal_to_num_users = {}
for (let user_id of user_ids) {
let enabled_goals = await get_goals_tried_by_user(user_id)
for (let goal_name of enabled_goals) {
if (goal_to_num_users[goal_name] == null) {
goal_to_num_users[goal_name] = 0
}
goal_to_num_users[goal_name] += 1
}
}
console.log(goal_to_num_users)
return goal_to_num_users
}
async function get_num_users_who_have_tried_nondefault_goal() {
let output = 0
for (let user_id of user_ids) {
let enabled_goals = await get_goals_tried_by_user(user_id)
let tried_nondefault_goal = false
for (let goal_name of enabled_goals) {
if (goal_name != 'facebook/spend_less_time' && goal_name != 'youtube/spend_less_time') {
tried_nondefault_goal = true
}
}
if (tried_nondefault_goal) {
output += 1
}
}
return output
}
async function get_num_users_who_have_tried_custom_goal() {
let output = 0
for (let user_id of user_ids) {
let enabled_goals = await get_goals_tried_by_user(user_id)
let tried_nondefault_goal = false
for (let goal_name of enabled_goals) {
if (goal_name.startsWith('custom/')) {
tried_nondefault_goal = true
}
}
if (tried_nondefault_goal) {
output += 1
}
}
return output
}
async function get_num_users_who_have_set_nondefault_target() {
let output = 0
for (let user_id of user_ids) {
let goal_targets = await get_goal_targets_for_user(user_id)
let have_nondefault_target = false
for (let goal_name of Object.keys(goal_targets)) {
let target_value = goal_targets[goal_name]
if (target_value != 20) {
have_nondefault_target = true
}
}
if (have_nondefault_target) {
output += 1
}
}
return output
}
async function show_user_list() {
$('#num_active_users').text(user_ids.length)
for (let user_id of user_ids) {
$('#user_list').append($('<a href="/viewuser.html?userid=' + user_id + '">' + user_id + '</a>'))
$('#user_list').append($('<br>'))
}
}
async function get_temporary_disable_count(){
let user_to_uninstall_times = await get_user_to_uninstall_times()
let count_for_uninstalled = []
let count_for_not_uninstalled = []
for (let user_id of user_ids) {
let intervention_logs = await get_collection_for_user(user_id, 'logs:interventions')
let uninstall_time = user_to_uninstall_times[user_id]
if (uninstall_time == undefined) {
count_for_not_uninstalled.push(intervention_logs.length)
} else {
count_for_uninstalled.push(intervention_logs.length)
}
console.log(count_for_uninstalled, count_for_not_uninstalled)
}
}
async function display_goals_tried_by_users() {
let goal_to_num_users = await get_goals_tried_by_all_users()
display_dictionary_as_table(goal_to_num_users, '#goals_tried')
}
async function get_interventions_enabled_by_users() {
let intervention_to_num_users = {}
for (let user_id of user_ids) {
let enabled_interventions = await get_enabled_interventions_for_user(user_id)
for (let intervention_name of Object.keys(enabled_interventions)) {
let is_enabled = enabled_interventions[intervention_name]
if (is_enabled) {
if (intervention_to_num_users[intervention_name] == null) {
intervention_to_num_users[intervention_name] = 0
}
intervention_to_num_users[intervention_name] += 1
}
}
}
console.log(intervention_to_num_users)
return intervention_to_num_users
}
async function get_interventions_disabled_by_users() {
let intervention_to_num_users = {}
for (let user_id of user_ids) {
let enabled_interventions = await get_enabled_interventions_for_user(user_id)
for (let intervention_name of Object.keys(enabled_interventions)) {
let is_enabled = enabled_interventions[intervention_name]
if (!is_enabled) {
if (intervention_to_num_users[intervention_name] == null) {
intervention_to_num_users[intervention_name] = 0
}
intervention_to_num_users[intervention_name] += 1
}
}
}
console.log(intervention_to_num_users)
return intervention_to_num_users
}
async function get_goals_enabled_by_users() {
let goal_to_num_users = {}
for (let user_id of user_ids) {
let enabled_goals = await get_enabled_goals_for_user(user_id)
for (let goal_name of Object.keys(enabled_goals)) {
let is_enabled = enabled_goals[goal_name]
if (is_enabled) {
if (goal_to_num_users[goal_name] == null) {
goal_to_num_users[goal_name] = 0
}
goal_to_num_users[goal_name] += 1
}
}
}
console.log(goal_to_num_users)
return goal_to_num_users
}
async function display_goals_enabled_by_users() {
let goal_to_num_users = await get_goals_enabled_by_users()
display_dictionary_as_table(goal_to_num_users, '#goals_enabled')
}
async function display_interventions_enabled_by_users() {
console.log("done")
let intervention_to_num_users = await get_interventions_enabled_by_users()
console.log("done")
display_dictionary_as_table(intervention_to_num_users, '#interventions_enabled')
}
async function display_interventions_disabled_by_users() {
let intervention_to_num_users = await get_interventions_disabled_by_users()
display_dictionary_as_table(intervention_to_num_users, '#interventions_disabled')
}
async function display_users_with_logging_enabled() {
let user_to_is_logging_enabled = await get_user_to_is_logging_enabled()
let user_ids_with_logging_enabled = []
for (let user_id of user_ids) {
if (user_to_is_logging_enabled[user_id]) {
user_ids_with_logging_enabled.push(user_id)
}
}
for (let user_id of user_ids_with_logging_enabled) {
$('#user_list_logging_enabled').append($('<a href="/viewuser.html?userid=' + user_id + '">' + user_id + '</a>'))
$('#user_list_logging_enabled').append('<br>')
}
$('#num_active_users_logging_enabled').text(user_ids_with_logging_enabled.length)
}
async function display_users_with_logging_disabled() {
let user_to_is_logging_enabled = await get_user_to_is_logging_enabled()
let user_ids_with_logging_disabled = []
for (let user_id of user_ids) {
if (user_to_is_logging_enabled[user_id] == false) {
user_ids_with_logging_disabled.push(user_id)
}
}
for (let user_id of user_ids_with_logging_disabled) {
$('#user_list_logging_disabled').append($('<a href="/viewuser.html?userid=' + user_id + '">' + user_id + '</a>'))
$('#user_list_logging_disabled').append('<br>')
}
$('#num_active_users_logging_disabled').text(user_ids_with_logging_disabled.length)
}
async function display_users_with_logging_not_set() {
let user_to_is_logging_enabled = await get_user_to_is_logging_enabled()
let user_ids_with_logging_enabled = []
for (let user_id of user_ids) {
if (user_to_is_logging_enabled[user_id] == null) {
user_ids_with_logging_enabled.push(user_id)
}
}
for (let user_id of user_ids_with_logging_enabled) {
$('#user_list_logging_not_set').append($('<a href="/viewuser.html?userid=' + user_id + '">' + user_id + '</a>'))
$('#user_list_logging_not_set').append('<br>')
}
$('#num_active_users_logging_not_set').text(user_ids_with_logging_enabled.length)
}
async function display_last_intervention_before_stop_using() {
let intervention_to_num_users = await get_last_interventions_for_former_users()
display_dictionary_as_table(intervention_to_num_users, '#last_intervention_before_stop')
}
async function display_last_intervention_before_stop_using_with_total_impressions() {
let intervention_to_last_info = await get_last_interventions_and_num_impressions_for_former_users()
let display_list = []
for (let intervention_name of Object.keys(intervention_to_last_info)) {
let display_info = intervention_to_last_info[intervention_name]
display_info.name = intervention_name
display_list.push(display_info)
}
display_list.sort(function(a, b) {
return a.uninstall_fraction - b.uninstall_fraction
})
display_list.reverse()
display_list_as_table(display_list, '#last_intervention_before_stop_with_total_impressions')
}
async function main() {
user_ids = await get_user_ids()
// show_user_list()
// get_temporary_disable_count()
display_users_with_logging_enabled()
display_users_with_logging_disabled()
display_users_with_logging_not_set()
display_goals_tried_by_users()
display_goals_enabled_by_users()
display_interventions_enabled_by_users()
display_interventions_disabled_by_users()
//display_last_intervention_before_stop_using()
//display_last_intervention_before_stop_using_with_total_impressions()
let num_users_who_have_tried_nondefault_goal = await get_num_users_who_have_tried_nondefault_goal()
let num_users_who_have_tried_custom_goal = await get_num_users_who_have_tried_custom_goal()
let num_users_who_have_set_nondefault_target = await get_num_users_who_have_set_nondefault_target()
$('#users_who_tried_a_nondefault_goal').text(num_users_who_have_tried_nondefault_goal)
$('#users_who_tried_a_custom_goal').text(num_users_who_have_tried_custom_goal)
$('#users_who_changed_a_goal_target').text(num_users_who_have_set_nondefault_target)
}
main();
</script>
</body>
</html>