-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
107 lines (99 loc) · 2.09 KB
/
Copy pathmain.js
File metadata and controls
107 lines (99 loc) · 2.09 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
var bot = require('./bot');
var uniqueList = (list) => {
return [...new Set(list)]; // Thanks, Eric Elliott
}
bot.calculations = {
countUsers: {
question: 'How many users were active {in date range}?',
type: 'count',
state: {
count: 0
},
aggregator: (state, visits) => {
if(visits.length > 0){
state.count++;
}
return state;
},
response: (state) => {
return `I counted ${state.count} users.`;
}
},
countMeetings: {
question: 'How many meetings were active {in date range}?',
type: 'count',
state: {
mids: []
},
aggregator: (state, visits) => {
var mids = visits.filter((v) => {
return v.visit.mid || false;
}).map((v) => {
return v.visit.mid;
});
state.mids.push.apply(state.mids, mids);
return state;
},
response: (state) => {
return `I counted ${uniqueList(state.mids).length} active meetings.`;
}
},
rankCreators: {
question: 'Who were the top meeting creators {in date range}?',
type: 'rank',
aggregator: (visits) => {
return {
creates: visits.filter((v) => {
return v.visit.type === 'CREATE_MEETING';
}).length
}
},
limit: 20,
filter: (user) => {
return user.creates > 0;
},
sort: (a, b) => {
return b.creates - a.creates;
},
response: (user, rank) => {
return `${user.profile.name} (${user.creates} meetings.)`;
}
},
compareDemo: {
question: 'What were conversion rates for the demo {in date range}?',
type: 'compare',
state: {
usedDemo: {
true: 0,
false: 0
},
total: 0
},
aggregator: (state, visits) => {
var usedDemo = false;
for(var v = 0; v < visits.length; v++){
var visit = visits[v].visit;
if(visit.mid === 'sample'){
usedDemo = true;
break;
}
}
state.usedDemo[usedDemo]++;
state.total++;
return state;
},
response: (state) =>{
var res = `Comparison for Demo Page:\n`;
var tag = {
true: 'Tried Demo',
false: 'Did not try Demo'
}
for(var i in tag){
var num = state.usedDemo[i] || 0;
res += `${tag[i]}: ${((num/state.total)*100).toFixed(2)}%\n`;
}
return res;
}
}
}
bot.init();