Skip to content

Commit

Permalink
added active cases
Browse files Browse the repository at this point in the history
  • Loading branch information
maurya-anand committed Dec 16, 2020
1 parent 36db83d commit f1b004e
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 8 deletions.
Binary file added gettingstarted/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file not shown.
Binary file added gettingstarted/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file added gettingstarted/__pycache__/wsgi.cpython-38.pyc
Binary file not shown.
Binary file added tracker/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added tracker/__pycache__/admin.cpython-38.pyc
Binary file not shown.
Binary file added tracker/__pycache__/models.cpython-38.pyc
Binary file not shown.
Binary file added tracker/__pycache__/urls.cpython-38.pyc
Binary file not shown.
Binary file added tracker/__pycache__/views.cpython-38.pyc
Binary file not shown.
Binary file not shown.
10 changes: 7 additions & 3 deletions tracker/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function getLiveData (){
// console.log(new Date().toLocaleString());
//$('#total_recovered_cases').text(total_recovered_cases);
$('#last_updated_recovered').text(new Date(Date.parse(last_updated_recovered_cases)));
$('#last_updated_active').text(new Date(Date.parse(last_updated_recovered_cases)));


//$('#total_death_cases').text(total_death_cases);
Expand All @@ -52,6 +53,7 @@ Highcharts.getJSON('data/', function (data) {
$('#total_confirmed_cases').text(data.total_reported);
$('#total_recovered_cases').text(data.total_recovered);
$('#total_death_cases').text(data.total_deaths);
$('#total_active_cases').text(data.total_active);
createTable(data.dt_table);
}
else {
Expand Down Expand Up @@ -94,7 +96,6 @@ Highcharts.getJSON('data/', function (data) {
legend: {
enabled: false
},

colorAxis: {
min: 1,
max: 10000,
Expand Down Expand Up @@ -149,7 +150,7 @@ Highcharts.getJSON('data/', function (data) {
//pointFormat: '<span style="font-size:12px">{point.name} ({point.properties.hc-a2}):</span><br><span style="font-size:20px">{point.z}</span>'
//pointFormat: '<span style="font-size:12px">{point.name} ({point.properties.hc-a2}):</span><br>Confirmed:<span style="font-size:20px"> {point.z}</span><br>Recovered:<span style="font-size:20px"> {point.recovered}</span><br>Deaths:<span style="font-size:20px"> {point.deaths}</span>'
pointFormat: '<span style="font-size:20px">{point.name}<br></span><br></br>' +
'<span style="font-size:12px;">Confirmed: </span><span style="font-size:15px"> {point.z}</span><br><br>' +
'<span style="font-size:12px;">Active: </span><span style="font-size:15px"> {point.z}</span><br><br>' +
'<span style="font-size:12px; color:green">Recovered: </span><span style="font-size:15px"> {point.recovered}</span><br><br>' +
'<span style="font-size:12px; color:red">Deaths: </span><span style="font-size:15px"> {point.deaths}</span>'

Expand Down Expand Up @@ -177,9 +178,12 @@ function createTable(dataSet){
columns: [
{ title: "Country",width:'30%' },
{ title: "Code",visible: false, },
{ title: "Confirmed", searchable: false },
{ title: "Active", searchable: false },
{ title: "Recovered", searchable: false },
{ title: "Deaths", searchable: false },

{ title: "Total cases", searchable: false },

],
order: [[ 2, "desc" ],[ 0, 'asc' ]],
paging: false,
Expand Down
8 changes: 8 additions & 0 deletions tracker/templates/tracker/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ <h2 class="card-text font-weight-bolder" id="total_confirmed_cases"><span class=
<p class="text-muted small mb-0">Last updated: <span class="text-muted" id="last_updated_confirmed"><span class="spinner-grow spinner-grow-sm" role="status"><span class="sr-only">Live...</span></span></p>
</div>
</div>
<div class="card alert alert-info">
<div class="card-body p-1">
<h5 class="card-title mb-0">Active</h5>
<hr class="mt-1">
<h2 class="card-text font-weight-bolder" id="total_active_cases"><span class="spinner-grow spinner-grow-sm" role="status"><span class="sr-only">Live...</span></h2>
<p class="text-muted small mb-0">Last updated: <span class="text-muted" id="last_updated_active"><span class="spinner-grow spinner-grow-sm" role="status"><span class="sr-only">Live...</span></span></p>
</div>
</div>
<div class="card alert alert-success">
<div class="card-body p-1">
<h5 class="card-title mb-0">Recovered</h5>
Expand Down
23 changes: 18 additions & 5 deletions tracker/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def getData(request):
confirmed_cases={}
recovered_cases={}
deaths_cases={}
active_cases={} #
res_arr2=[]
res_arr_obj2={}
res_obj3={}
Expand All @@ -91,6 +92,7 @@ def getData(request):
total_reported=total_reported+info['properties']['Confirmed']
total_recovered=total_recovered+info['properties']['Recovered']
total_deaths=total_deaths+info['properties']['Deaths']
total_active=total_deaths+info['properties']['Active'] #
if info['properties']['Province_State']=='Greenland':
info['properties']['Country_Region']='Greenland'
if info['properties']['Province_State']=='Hong Kong':
Expand All @@ -114,7 +116,15 @@ def getData(request):
deaths_cases[country_code2[info['properties']['Country_Region']]]+=info['properties']['Deaths']
else:
deaths_cases[country_code2[info['properties']['Country_Region']]]=info['properties']['Deaths']


if country_code2[info['properties']['Country_Region']] in active_cases: #
active_cases[country_code2[info['properties']['Country_Region']]]+=info['properties']['Active']
else:
active_cases[country_code2[info['properties']['Country_Region']]]=info['properties']['Active']
print (confirmed_cases)
print (active_cases)
print (recovered_cases)

for c3code,c2code in country_code2.items():
outstr=None

Expand All @@ -131,15 +141,17 @@ def getData(request):
countryNameDt= c3code

if c2code in confirmed_cases:
res_arr2.append({"code3":country_code[c2code],"z":confirmed_cases[c2code],"code":c2code,"value":confirmed_cases[c2code],"recovered":recovered_cases.get(c2code, 0),"deaths":deaths_cases.get(c2code, 0) })
#res_arr2.append({"code3":country_code[c2code],"z":confirmed_cases[c2code],"code":c2code,"value":confirmed_cases[c2code],"recovered":recovered_cases.get(c2code, 0),"deaths":deaths_cases.get(c2code, 0) })
res_arr2.append({"code3":country_code[c2code],"z":active_cases.get(c2code, 0),"code":c2code,"value":active_cases.get(c2code, 0),"active":active_cases.get(c2code, 0),"deaths":deaths_cases.get(c2code, 0),"recovered":recovered_cases.get(c2code, 0)})
outstr = '{}\t{}\t{}\t{}\t{}\n'.format(c3code,country_code[c2code],confirmed_cases[c2code],recovered_cases.get(c2code, 0),deaths_cases.get(c2code, 0))
#dt_data['data'].append([c3code,country_code[c2code],confirmed_cases[c2code],recovered_cases.get(c2code, 0),deaths_cases.get(c2code, 0)])
dt_data['data'].append([countryNameDt,country_code[c2code],confirmed_cases[c2code],recovered_cases.get(c2code, 0),deaths_cases.get(c2code, 0)])
dt_data['data'].append([countryNameDt,country_code[c2code],active_cases.get(c2code,0),recovered_cases.get(c2code, 0),deaths_cases.get(c2code, 0),confirmed_cases[c2code]])
else:
res_arr2.append({"code3":country_code[c2code],"z":0,"code":c2code,"value":0,"recovered":0,"deaths":0 })
#res_arr2.append({"code3":country_code[c2code],"z":0,"code":c2code,"value":0,"recovered":0,"deaths":0 })
res_arr2.append({"code3":country_code[c2code],"z":0,"code":c2code,"value":0,"recovered":0,"deaths":0,"active":0 })
outstr = '{}\t{}\t{}\t{}\t{}\n'.format(c3code,country_code[c2code],0,0,0)
#dt_data['data'].append([c3code,country_code[c2code],0,0,0])
dt_data['data'].append([countryNameDt,country_code[c2code],0,0,0])
dt_data['data'].append([countryNameDt,country_code[c2code],0,0,0,0])

dt_data_response=json.dumps(dt_data['data'])

Expand All @@ -148,6 +160,7 @@ def getData(request):
'total_reported':total_reported,
'total_recovered':total_recovered,
'total_deaths':total_deaths,
'total_active':total_active,
'plotdata':res_arr2,
'dt_table':dt_data_response
}
Expand Down

0 comments on commit f1b004e

Please sign in to comment.