This repository has been archived by the owner on Mar 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
67 lines (47 loc) · 1.66 KB
/
main.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
const data = document.querySelector('#data'); //reference
//create elements and render data
function add_data(doc){
let li = document.createElement('li');
let name = document.createElement('span');
let count = document.createElement('div');
li.setAttribute('data-id',doc.data);
name.textContent = doc.data().a_name;
count.textContent = doc.data().b_count;
li.appendChild(name);
li.appendChild(count);
data.appendChild(li);
}
//firebase
db.collection('Data').get().then((snapshot) => { //grab the collections and data
snapshot.docs.forEach(doc => { //cycle through each document
add_data(doc); //gets data
})
});
//added precentages
var doc1 = db.collection("Data").doc("a_totalConfirmed");
doc1.get().then(function par(doc) {
if (doc.exists) {
console.log("Document data:", doc.data());
var confirmed = doc.data().b_count;
}
var doc2 = db.collection("Data").doc("b_deaths");
doc2.get().then(function par(doc) {
if (doc.exists) {
console.log("Document data:", doc.data());
var deaths = doc.data().b_count;
}
var doc3 = db.collection("Data").doc("c_totalRecovered");
doc3.get().then(function par(doc) {
if (doc.exists) {
console.log("Document data:", doc.data());
var recover = doc.data().b_count;
}
document.getElementById("d_rate").innerHTML = "Death Rate";
var dvalue =deaths/confirmed*100;
document.getElementById("d_par").innerHTML = dvalue.toFixed(2)+"%";
document.getElementById("r_rate").innerHTML = "Death Rate";
var rvalue =recover/confirmed*100;
document.getElementById("r_par").innerHTML = rvalue.toFixed(2)+"%";
});
});
});