-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstate_table_data.js
73 lines (68 loc) · 3.39 KB
/
state_table_data.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
68
69
70
71
72
73
function makeSPARQLQuery( endpointUrl, sparqlQuery, doneCallback ) {
var settings = {
headers: { Accept: 'application/sparql-results+json' },
data: { query: sparqlQuery }
};
return $.ajax( endpointUrl, settings ).then( doneCallback );
}
var endpointUrl = 'https://query.wikidata.org/sparql',
sparqlQuery = "SELECT DISTINCT ?stateLabel ?cases ?recs ?deaths ?tests\n" +
"WITH {\n" +
" SELECT ?item ?dist ?state ?cases ?cases_time {\n" +
" wd:Q84055514 wdt:P527? ?item. ?item wdt:P276 ?state.\n" +
" OPTIONAL { ?item p:P1603 ?casestmt. ?casestmt ps:P1603 ?cases. OPTIONAL { ?casestmt pq:P585 ?cases_time } }\n" +
" FILTER NOT EXISTS { ?item p:P1603/pq:P585 ?cases_time_ . FILTER(?cases_time_ > ?cases_time) }\n" +
" }\n" +
"}\n" +
"AS %cases\n" +
"WITH {\n" +
" SELECT ?item ?deaths ?deaths_time {\n" +
" wd:Q84055514 wdt:P527? ?item.\n" +
" OPTIONAL { ?item p:P1120 ?deathstmt. ?deathstmt ps:P1120 ?deaths. OPTIONAL { ?deathstmt pq:P585 ?deaths_time } }\n" +
" FILTER NOT EXISTS { ?item p:P1120/pq:P585 ?deaths_time_ . FILTER(?deaths_time_ > ?deaths_time) }\n" +
" }\n" +
"}\n" +
"AS %deaths\n" +
"WITH {\n" +
" SELECT ?item ?recs ?recs_time {\n" +
" wd:Q84055514 wdt:P527? ?item.\n" +
" OPTIONAL { ?item p:P8010 ?recstmt. ?recstmt ps:P8010 ?recs. OPTIONAL { ?recstmt pq:P585 ?recs_time } }\n" +
" FILTER NOT EXISTS { ?item p:P8010/pq:P585 ?recs_time_ . FILTER(?recs_time_ > ?recs_time) }\n" +
" }\n" +
"}\n" +
"AS %recs\n" +
"WITH {\n" +
" SELECT ?item ?tests ?tests_time {\n" +
" wd:Q84055514 wdt:P527? ?item.\n" +
" OPTIONAL { ?item p:P8011 ?testmt. ?testmt ps:P8011 ?tests. OPTIONAL { ?testmt pq:P585 ?tests_time } }\n" +
" FILTER NOT EXISTS { ?item p:P8011/pq:P585 ?tests_time_ . FILTER(?tests_time_ > ?tests_time) }\n" +
" }\n" +
"}\n" +
"AS %tests\n" +
"WHERE {\n" +
" INCLUDE %cases. INCLUDE %deaths. INCLUDE %recs. INCLUDE %tests.\n" +
" OPTIONAL { ?item wdt:P580 ?start_time. }\n" +
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],en\". }\n" +
"}\n" +
"ORDER BY DESC (?cases)";
$(document).ready(function() {
makeSPARQLQuery( endpointUrl, sparqlQuery, function( data ) {
$.each(data.results.bindings, function(index, element) {
if(element.stateLabel.value == active_state) {
var cases = element.cases.value;
var recovered = element.recs.value;
var deceased = element.deaths.value;
var tests = element.tests.value;
var output_html = '<tr>'
+'<td><center>'+cases+'</center></td>'
+'<td><center>'+recovered+'</center></td>'
+'<td><center>'+deceased+'</center></td>'
+'<td><center>'+tests+'</center></td>'
+'</tr>';
console.log(output_html);
$('#stats_table').html(output_html);
}
});
}
);
});