-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainold.js
1 lines (1 loc) · 10.5 KB
/
mainold.js
1
function draw_chart(e,t,n,o,a){var r=document.getElementById(a).getContext("2d");new Chart(r,{type:"doughnut",data:{labels:["Confirmed Cases","Active Cases","Recovered Cases","Death"],datasets:[{label:"# of Votes",data:[e,t,n,o],backgroundColor:["rgba(7, 75, 201, 0.74)","rgba(26, 146, 239, 0.67)","rgba(27, 247, 178, 0.87)","rgba(247, 64, 27, 0.87)"],borderColor:["rgba(255, 255, 255, 1)"],borderWidth:2}]},options:{}})}function chart1(e){console.log("success"+e),e=e.replace(/\s/g,"").toLowerCase();var t=0,n=0,o=0,a=0;fetch("./plotting/district_count.json?ver=2.06").then(function(e){return e.json()}).then(function(r){var d;for(flag=0,d=0;d<r.length;d++){if(r[d].district.toLowerCase().replace(/\s/g,"")==e){console.log("SUCCESS"),flag=1;break}flag=0}r[0].district,t=r[d].confirmed,n=r[d].active,a=r[d].recovered,o=r[d].death,console.log("ugh"+t),document.getElementById("place_cases").innerHTML=t,document.getElementById("place_recovered").innerHTML=a,document.getElementById("place_death").innerHTML=o,0==t?document.getElementById("city_chart").innerHTML="Zero cases found in our database":draw_chart(t,n,a,o,"myChart1")})}function chart2(e){e=e.replace(/\s/g,"").toLowerCase();var t=0,n=0,o=0,a=0;fetch("./plotting/state_count.json?ver=2.06").then(function(e){return e.json()}).then(function(r){var d;for(flag=0,console.log(r[0].state),d=0;d<r.length;d++){if(r[d].state.toLowerCase().replace(/\s/g,"")==e){console.log(r[d].state),flag=1;break}flag=0}r[0].district,t=r[d].confirmed,n=r[d].active,a=r[d].recovered,o=r[d].death,console.log("ugh"+o),document.getElementById("state_cases").innerHTML=t,document.getElementById("state_recovered").innerHTML=a,document.getElementById("state_death").innerHTML=o,draw_chart(t,n,a,o,"myChart2")})}function chart3(){var e=0,t=0,n=0,o=0;fetch("./plotting/india.json?ver=2.3").then(function(e){return e.json()}).then(function(a){e=a[0].cnf,t=a[0].active,o=a[0].recovered,n=a[0].death,console.log("ugh"+n),document.getElementById("country_cases").innerHTML=e,document.getElementById("country_recovered").innerHTML=o,document.getElementById("country_death").innerHTML=n,draw_chart(e,t,o,n,"myChart3")})}function getLocation(){navigator.geolocation?navigator.geolocation.getCurrentPosition(showPosition,showError):x.innerHTML="Geolocation is not supported by this browser."}function showError(e){switch(document.getElementById("error_location").style.display="block",document.getElementById("wrapper").style.display="none",e.code){case e.PERMISSION_DENIED:console.log("User denied the request for Geolocation."),document.getElementById("loc_error_message").innerHTML=" User denied the request for Geolocation.";break;case e.POSITION_UNAVAILABLE:console.log("Location information is unavailable."),document.getElementById("loc_error_message").innerHTML=" Location information is unavailable.";break;case e.TIMEOUT:console.log("The request to get user location timed out."),document.getElementById("loc_error_message").innerHTML=" The request to get user location timed out.";break;case e.UNKNOWN_ERROR:console.log("An unknown error occurred."),document.getElementById("loc_error_message").innerHTML=" An unknown error occurred."}}function showPosition(e){var t=e.coords.latitude,n=e.coords.longitude;console.log("Your current coordinates:Lat:"+t+" Long:"+n);var o={async:!0,crossDomain:!0,url:"https://us1.locationiq.com/v1/reverse.php?key=59503131102f5b&lat="+t+"&lon="+n+"&format=json",method:"GET"};$.ajax(o).done(function(e){var t,n,o=document.getElementsByClassName("user_city");e.address.state_district?(o[0].innerHTML=e.address.state_district,o[1].innerHTML=e.address.state_district,t=e.address.state_district):(o[0].innerHTML=e.address.city,o[1].innerHTML=e.address.city,t=e.address.city);var a=document.getElementsByClassName("user_region");a[0].innerHTML=e.address.state,a[1].innerHTML=e.address.state,n=e.address.state;var r=document.getElementsByClassName("user_country");r[0].innerHTML=e.address.country,r[1].innerHTML=e.address.country,chart1(t),chart2(n),chart3()}),mapboxgl.accessToken="pk.eyJ1IjoiYWF5dXNoc2FpbmkiLCJhIjoiY2s4Zzl0cm0zMGFlNTNwbm9tZXJ5cThydiJ9.c8-bbolyM9LbA0zyO16wwg";var a=new mapboxgl.Map({container:"map",style:"mapbox://styles/mapbox/streets-v11",zoom:9,center:[n,t]});a.addControl(new mapboxgl.FullscreenControl);var r={width:200,height:200,data:new Uint8Array(16e4),onAdd:function(){var e=document.createElement("canvas");e.width=this.width,e.height=this.height,this.context=e.getContext("2d")},render:function(){var e=performance.now()%1e3/1e3,t=70*e+30,n=this.context;return n.clearRect(0,0,this.width,this.height),n.beginPath(),n.arc(this.width/2,this.height/2,t,0,2*Math.PI),n.fillStyle="rgba(255, 200, 200,"+(1-e)+")",n.fill(),n.beginPath(),n.arc(this.width/2,this.height/2,30,0,2*Math.PI),n.fillStyle="rgba(255, 100, 100, 1)",n.strokeStyle="white",n.lineWidth=2+4*(1-e),n.fill(),n.stroke(),this.data=n.getImageData(0,0,this.width,this.height).data,a.triggerRepaint(),!0}};a.on("load",function(){a.addImage("pulsing-dot",r,{pixelRatio:2}),a.addSource("points",{type:"geojson",data:{type:"FeatureCollection",features:[{type:"Feature",geometry:{type:"Point",coordinates:[n,t]}}]}}),a.addLayer({id:"points",type:"symbol",source:"points",layout:{"icon-image":"pulsing-dot"}}),a.addSource("earthquakes",{type:"geojson",data:"./plotting/map.geojson?ver=2.3",cluster:!0,clusterMaxZoom:14,clusterRadius:50}),a.addLayer({id:"clusters",type:"circle",source:"earthquakes",filter:["has","point_count"],paint:{"circle-color":["step",["get","point_count"],"rgba(29, 245, 195, 0.75)",100,"rgba(246, 168, 33, 0.77)",250,"rgba(245, 105, 29, 0.77)",600,"rgba(255, 15, 15, 0.84)"],"circle-radius":["step",["get","point_count"],20,100,30,750,40]}});document.getElementById("menu");a.addLayer({id:"cluster-count",type:"symbol",source:"earthquakes",filter:["has","point_count"],layout:{"text-field":"{point_count_abbreviated}","text-font":["DIN Offc Pro Medium","Arial Unicode MS Bold"],"text-size":12}}),a.addLayer({id:"unclustered-point",type:"circle",source:"earthquakes",filter:["!",["has","point_count"]],paint:{"circle-color":"#1df5c3","circle-radius":10,"circle-stroke-width":4,"circle-stroke-color":"#19c29b"}}),a.on("mouseenter","clusters",function(){a.getCanvas().style.cursor="pointer"}),a.on("mouseleave","clusters",function(){a.getCanvas().style.cursor=""});var e=new mapboxgl.Popup({closeButton:!1,closeOnClick:!1});a.on("mouseenter","unclustered-point",function(t){var n=t.features[0].geometry.coordinates.slice();a.getCanvas().style.cursor="pointer",e.setLngLat(n).setHTML("One Patient Registered Here").addTo(a)}),a.on("mouseleave","unclustered-point",function(){a.getCanvas().style.cursor="",e.remove()})})}document.addEventListener("DOMContentLoaded",function(){var e=document.querySelectorAll(".sidenav");M.Sidenav.init(e,{edge:"right"})});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=[];function load_analytics(){draw()}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 cases in each state",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(1);t.forEach(e=>{const t=e.split(","),n=t[0],o=t[2],a=t[4],r=t[6];console.log(t),x_axis_cnf.push(n),y_axis_cnf.push(o),y_axis_rec.push(a),y_axis_ded.push(r)});const n=fetch("./plotting/state_count.csv");(await(await n).text()).split("\n").slice(1).forEach(e=>{const t=e.split(","),n=t[0],o=t[1];x_axis_state.push(n),y_axis_state.push(o)});const o=t[t.length-1].split(","),a=t[t.length-2].split(","),r=t[t.length-1].split(","),d=t[t.length-2].split(","),s=t[t.length-1].split(","),c=t[t.length-2].split(",");document.getElementById("cnf_no").innerHTML=o[2],document.getElementById("cnf_no").style.color="#e68300",document.getElementById("rec_no").innerHTML=r[4],document.getElementById("rec_no").style.color="#13d68b",document.getElementById("ded_no").innerHTML=r[6],document.getElementById("ded_no").style.color="#db3030",console.log(o,a);const i=o[2]-a[2],l=r[4]-d[4],u=s[6]-c[6];console.log(i),i>0?(document.getElementById("daily_cnf_arrow").innerHTML="arrow_upward",document.getElementById("daily_cnf_arrow").style.color="red",document.getElementById("count_diff").innerHTML=i):(document.getElementById("daily_cnf_arrow").innerHTML="arrow_downward",document.getElementById("daily_cnf_arrow").style.color="green",document.getElementById("count_diff").innerHTML=i),l>0?(document.getElementById("daily_rec_arrow").innerHTML="arrow_upward",document.getElementById("daily_rec_arrow").style.color="green",document.getElementById("count_diff_rec").innerHTML=l):(document.getElementById("daily_rec_arrow").innerHTML="arrow_downward",document.getElementById("daily_rec_arrow").style.color="red",document.getElementById("count_diff_rec").innerHTML=l),u>0?(document.getElementById("daily_ded_arrow").innerHTML="arrow_upward",document.getElementById("daily_ded_arrow").style.color="red",document.getElementById("count_diff_ded").innerHTML=u):(document.getElementById("daily_ded_arrow").innerHTML="arrow_downward",document.getElementById("daily_ded_arrow").style.color="green",document.getElementById("count_diff_ded").innerHTML=u);const g="3:00PM - 12 Apr";document.getElementById("data_update_date_cnf").innerHTML=g,document.getElementById("data_update_date_rec").innerHTML=g,document.getElementById("data_update_date_ded").innerHTML=g,document.getElementById("data_update_date_state").innerHTML=g}