-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathapp.js
67 lines (60 loc) · 2.2 KB
/
app.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
63
64
65
66
67
(function () {
// Initialize Firebase
var config = {
apiKey: "AIzaSyDQcC0LgEKiiYClfUFFomcVKZLoeEp8E78",
authDomain: "upwork-nano-stream.firebaseapp.com",
databaseURL: "https://upwork-nano-stream.firebaseio.com",
projectId: "upwork-nano-stream",
storageBucket: "upwork-nano-stream.appspot.com",
messagingSenderId: "500629989505"
};
firebase.initializeApp(config);
var db = firebase.firestore();
db.settings({
timestampsInSnapshots: true
});
var timerInterval = 1500;
var donut = donutChart()
.width(960)
.height(500)
.transTime(750) // length of transitions in ms
.cornerRadius(3) // sets how rounded the corners are on each slice
.padAngle(0.015) // effectively dictates the gap between slices
.variable('prob')
.category('species');
var _transform = function (doc) {
console.log(doc);
timestring = '_ ' + doc.date.toDate().toISOString();
groupped = doc.sequenceRecords
.map(record => {
return {
probe: record.probe,
name: (record.taxonomy.length) ? record.taxonomy[0] : record.name
}
})
.map(record => {
return {
time: timestring,
prob: record.probe,
species: record.name
}
}).reduce(function (rv, x) {
rv[x['species']] = rv[x['species']] || { prob: 0 }
rv[x['species']].species = x.species;
rv[x['species']].time = x.time;
rv[x['species']].prob += x.prob;
// rv[x['species']].err = x.err;
return rv;
}, {});
var keys = Object.keys(groupped);
var items = keys.map(function (k) { return groupped[k]; })
return items;
};
db.collection("sequences_statistic").doc("resultDocument--2019-01-28T14-38-35UTC").get().then((doc) => {
results = _transform(doc.data());
console.log(results);
donut.data(results);
d3.select('#chart')
.call(donut); // draw chart in div
});
}());