Commit 05013e15 authored by Michał Woźniak's avatar Michał Woźniak
Browse files

better handling of snowflakes

parent fe995fd7
Pipeline #78 passed with stage
in 0 seconds
......@@ -82,7 +82,7 @@ var countries = [
"Iceland",
"India",
"Indonesia",
"Islamic Republic of Iran",
"Iran",
"Iraq",
"Ireland",
"Israel",
......@@ -145,7 +145,7 @@ var countries = [
"Republic of Korea",
"Republic of Moldova",
"Romania",
"Russian Federation",
"Russia",
"Rwanda",
"Saint Kitts and Nevis",
"Saint Lucia",
......@@ -185,13 +185,13 @@ var countries = [
"Uganda",
"Ukraine",
"United Arab Emirates",
"United Kingdom of Great Britain and Northern Ireland",
"United Kingdom",
"United Republic of Tanzania",
"United States of America",
"United States",
"Uruguay",
"Uzbekistan",
"Vanuatu",
"Bolivarian Republic of Venezuela",
"Venezuela",
"Viet Nam",
"Yemen",
"Zambia",
......@@ -218,7 +218,26 @@ let getCountries = () => {
.sections[2]
.tables[0]
.map((row)=>{
return row["Member state"].text.replace(/ \(.+\)$/, '')
var sane_country_name = row["Member state"].text.replace(/ \(.+\)$/, '')
switch (sane_country_name) {
case 'United Kingdom of Great Britain and Northern Ireland':
return "United Kingdom";
break;
case 'United States of America':
return "United States";
break;
case 'Islamic Republic of Iran':
return "Iran";
break;
case 'Bolivarian Republic of Venezuela':
return "Venezuela";
break;
case 'Russian Federation':
return "Russia";
break;
default:
return sane_country_name;
}
})
})
}
......@@ -260,6 +279,10 @@ let getCovidData = () => {
* (if all goes well, that is)
*/
let getCountryCases = (country) => {
// snowflake templates are snowflake
if (country === "China") {
country = "Mainland China"
}
console.log(`+-- fetching covid data for: ${country}`)
return wtf
.fetch(`Template:2019-20 coronavirus pandemic data/${country} medical cases chart`)
......@@ -272,9 +295,14 @@ let getCountryCases = (country) => {
.templates
.filter(row => row.template == 'medical cases chart/row')
.map((row)=>{
if (row.list[6] !== "") {
cases = 1 * row.list[6].replace(/,/g, '')
} else {
cases = 1 * row.list[8].replace(/,/g, '')
}
return {
date: row.list[0],
cases: 1 * row.list[3]
cases: cases
}
})
......@@ -305,18 +333,25 @@ let getCountryCases = (country) => {
* returns a promise that resolves to integer (if all goes well)
*/
let getCountryPopulation = (country) => {
// snowflake country pages are snowflake
if (country === "Georgia") {
country = "Georgia (country)"
}
console.log(`+-- fetching population data for ${country}`)
return wtf
.fetch(country)
.then((doc)=>{
return doc.json()
}).then((tdata)=>{
var pop_estimate = tdata.sections[0].infoboxes[0].population_estimate
infobox = doc.json().sections[0].infoboxes[0]
if (`population_estimate` in infobox) {
var pop_data = infobox.population_estimate
} else if (`population_census` in infobox) {
var pop_data = infobox.population_census
}
var population = false
if ('number' in pop_estimate) {
population = pop_estimate.number
if ('number' in pop_data) {
population = pop_data.number
} else {
population = pop_estimate.text.split(/\n/g)[0].replace(/^([0-9,]+).*$/g, '$1').replace(/,/g, '')
population = pop_data.text.split(/\n/g)[0].replace(/^([0-9,]+).*$/g, '$1').replace(/,/g, '')
}
console.log(`+-- got population data for ${country}:`
+ `\n population: ${population}`)
......@@ -373,23 +408,7 @@ document.addEventListener('DOMContentLoaded', (e)=>{
}
// need to handle the corner cases, eh
var country = false
switch (event.target.value) {
case 'United Kingdom of Great Britain and Northern Ireland':
country = "United Kingdom";
break;
case 'China':
country = "Mainland China";
break;
case 'United States of America':
country = "United States";
break;
case 'Islamic Republic of Iran':
country = "Iran";
break;
default:
country = event.target.value;
}
var country = event.target.value
countrySelectTimeout = setTimeout(function(){
countrySelectTimeout = false
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment