-
Notifications
You must be signed in to change notification settings - Fork 0
/
counter.js
50 lines (41 loc) · 1.35 KB
/
counter.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
const Firebase = require('firebase');
const firebase = new Firebase("https://fiery-inferno-7517.firebaseio.com/");
const users = [];
const stats = {
totalNumberOfEvents: -4,
totalNumberOfSpheroEvents: -1,
totalNumberOfGameEvents: -1,
totalNumberOfLampEvents: -1,
totalNumberOfUserEvents: -1
};
if (require.main === module) {
console.log("Start");
firebase.child("gadgets/sphero").on("value", function (snapshot) {
if (snapshot.val()) {
stats.totalNumberOfSpheroEvents++;
stats.totalNumberOfEvents++;
firebase.child("stats").set(stats);
}
});
firebase.child("gadgets/game").on("value", function (snapshot) {
if (snapshot.val()) {
stats.totalNumberOfGameEvents++;
stats.totalNumberOfEvents++;
firebase.child("stats").set(stats);
}
});
firebase.child("gadgets/lamp").on("value", function (snapshot) {
if (snapshot.val()) {
stats.totalNumberOfLampEvents++;
stats.totalNumberOfEvents++;
firebase.child("stats").set(stats);
}
});
firebase.child("users").on("value", function (snapshot) {
if (snapshot.val()) {
stats.totalNumberOfEvents++;
stats.totalNumberOfUserEvents++;
firebase.child("stats").set(stats);
}
});
}