-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
62 lines (49 loc) · 1.33 KB
/
index.js
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
const {
shuffle, slice, flow, map,
join, sample, random, set,
} = require('lodash/fp');
const co = require('co');
const moment = require('moment');
const config = require('./config');
const getOnlineMembers = require('./getOnlineMembers');
const Store = require('./Store');
const { callouts, exercises, officeHours } = config;
const store = new Store();
const pickParticipants = flow(
shuffle,
slice(0, callouts.numPeople)
);
const pickExercise = flow(
shuffle,
sample,
exercise => set('reps', random(exercise.minReps, exercise.maxReps), exercise)
);
const getMinutesToWait = () => {
const desiredMinutesToWait = random(
callouts.minutesBetween.min,
callouts.minutesBetween.max
);
const nextRunTime = moment().add(desiredMinutesToWait, 'minutes');
return nextRunTime.hours() > officeHours.end
? (officeHours.begin + 24 - officeHours.end) * 60
: desiredMinutesToWait;
};
co(function* () {
yield store.dispatch({
type: 'start'
});
while (true) {
const onlineMembers = yield getOnlineMembers();
yield store.dispatch({
type: 'callout',
participants: pickParticipants(onlineMembers),
exercise: pickExercise(exercises),
});
yield store.dispatch({
type: 'waiting',
minutes: getMinutesToWait(),
});
console.log(store.getStats());
}
})
.catch(console.error);