-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalytics.js
1 lines (1 loc) · 3.8 KB
/
analytics.js
1
function load_scripts(){draw()}const x_axis_cnf=[],y_axis_cnf=[],x_axis_rec=[],y_axis_rec=[],x_axis_ded=[],y_axis_ded=[],x_axis_state=[],y_axis_state=[];async function draw(){await get_data(),document.getElementById("load").style.display="none",new Chart(document.getElementById("line-chart_cnf"),{type:"line",data:{labels:x_axis_cnf,datasets:[{data:y_axis_cnf,label:"No. of confirmed cases in India",borderColor:"#de7e00",backgroundColor:"#edaf5c",fill:!0}]}}),document.getElementById("load_rec").style.display="none",new Chart(document.getElementById("line-chart_rec"),{type:"line",data:{labels:x_axis_cnf,datasets:[{data:y_axis_rec,label:"No. of recovered cases in India",borderColor:"#13d68b",backgroundColor:"#71e3b7",fill:!0}]}}),document.getElementById("load_ded").style.display="none",new Chart(document.getElementById("line-chart_ded"),{type:"line",data:{labels:x_axis_cnf,datasets:[{data:y_axis_ded,label:"No. of death cases in India",borderColor:"#db3030",backgroundColor:"#e38686",fill:!0}]}}),document.getElementById("load_state").style.display="none",new Chart(document.getElementById("line-chart_ded1"),{type:"bar",data:{labels:x_axis_state,datasets:[{data:y_axis_state,label:"No. of death cases in India",borderColor:"#a900e6",backgroundColor:"#cf7bed",fill:!0}]}}),new Chart(document.getElementById("line-chart_dedm"),{type:"bar",data:{labels:x_axis_state,datasets:[{data:y_axis_state,label:"No. of cases in each state",borderColor:"#a900e6",backgroundColor:"#d593ed",fill:!0}]}})}async function get_data(){const e=fetch("./plotting/analytics_aoi_dw.csv"),t=(await(await e).text()).split("\n").slice(0);t.forEach(e=>{const t=e.split(","),n=t[0],d=t[2],a=t[4],o=t[6];x_axis_cnf.push(n),y_axis_cnf.push(d),y_axis_rec.push(a),y_axis_ded.push(o)});const n=fetch("./plotting/state_count.csv");(await(await n).text()).split("\n").slice(1).forEach(e=>{const t=e.split(","),n=t[0],d=t[2];x_axis_state.push(n),y_axis_state.push(d)});const d=t[t.length-1].split(","),a=t[t.length-2].split(","),o=t[t.length-1].split(","),l=t[t.length-2].split(","),r=t[t.length-1].split(","),c=t[t.length-2].split(",");document.getElementById("cnf_no").innerHTML=d[2],document.getElementById("cnf_no").style.color="#e68300",document.getElementById("rec_no").innerHTML=o[4],document.getElementById("rec_no").style.color="#13d68b",document.getElementById("ded_no").innerHTML=o[6],document.getElementById("ded_no").style.color="#db3030",console.log(d,a);const _=d[2]-a[2],i=o[4]-l[4],s=r[6]-c[6];console.log(_),_>0?(document.getElementById("daily_cnf_arrow").innerHTML="arrow_upward",document.getElementById("daily_cnf_arrow").style.color="red",document.getElementById("count_diff").innerHTML=_):(document.getElementById("daily_cnf_arrow").innerHTML="arrow_downward",document.getElementById("daily_cnf_arrow").style.color="green",document.getElementById("count_diff").innerHTML=_),i>0?(document.getElementById("daily_rec_arrow").innerHTML="arrow_upward",document.getElementById("daily_rec_arrow").style.color="green",document.getElementById("count_diff_rec").innerHTML=i):(document.getElementById("daily_rec_arrow").innerHTML="arrow_downward",document.getElementById("daily_rec_arrow").style.color="red",document.getElementById("count_diff_rec").innerHTML=i),s>0?(document.getElementById("daily_ded_arrow").innerHTML="arrow_upward",document.getElementById("daily_ded_arrow").style.color="red",document.getElementById("count_diff_ded").innerHTML=i):(document.getElementById("daily_ded_arrow").innerHTML="arrow_downward",document.getElementById("daily_ded_arrow").style.color="green",document.getElementById("count_diff_ded").innerHTML=s);const y="3:00PM - 12 Apr";document.getElementById("data_update_date_cnf").innerHTML=y,document.getElementById("data_update_date_rec").innerHTML=y,document.getElementById("data_update_date_ded").innerHTML=y,document.getElementById("data_update_date_state").innerHTML=y}