Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regional data for Brazil #190

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 58 additions & 7 deletions vue-definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ window.app = new Vue({

pullData(selectedData, selectedRegion, updateSelectedCountries = true) {

if (selectedRegion != 'US') {
if (selectedRegion != 'US' && selectedRegion != 'Brazil') {
let url;
if (selectedData == 'Confirmed Cases') {
url = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv';
Expand All @@ -330,10 +330,17 @@ window.app = new Vue({
return;
}
Plotly.d3.csv(url, (data) => this.processData(data, selectedRegion, updateSelectedCountries));
} else { // selectedRegion == 'US'
const type = (selectedData == 'Reported Deaths') ? 'deaths' : 'cases';
const url = 'https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv';
Plotly.d3.csv(url, (data) => this.processData(this.preprocessNYTData(data, type), selectedRegion, updateSelectedCountries));
} else { // selectedRegion == 'US' or selectedRegion == 'Brazil
if (selectedRegion == 'US') {
const type = (selectedData == 'Reported Deaths') ? 'deaths' : 'cases';
const url = 'https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv';
Plotly.d3.csv(url, (data) => this.processData(this.preprocessNYTData(data, type), selectedRegion, updateSelectedCountries));
}
if (selectedRegion == 'Brazil') {
const type = (selectedData == 'Reported Deaths') ? 'last_available_deaths' : 'last_available_confirmed';
const url = 'https://brasil.io/dataset/covid19/caso_full/?place_type=state&format=csv';
Plotly.d3.csv(url, (data) => this.processData(this.preprocessBrasilIOData(data, type), selectedRegion, updateSelectedCountries));
}
}
},

Expand Down Expand Up @@ -444,7 +451,7 @@ window.app = new Vue({
const notableCountries = ['China (Mainland)', 'India', 'US', // Top 3 by population
'South Korea', 'Japan', 'Taiwan', 'Singapore', // Observed success so far
'Hong Kong', // Was previously included in China's numbers
'Canada', 'Australia']; // These appear in the region selector
'Canada', 'Australia', 'Brazil']; // These appear in the region selector

// TODO: clean this logic up later
// expected behavior: generate/overwrite selected locations if: 1. data loaded from URL, but no selected locations are loaded. 2. data refreshed (e.g. changing region)
Expand All @@ -467,6 +474,49 @@ window.app = new Vue({
this.createURL();
},

preprocessBrasilIOData(data, type) {
let recastData = {};
let states = {
'AC': 'Acre',
'AL': 'Alagoas',
'AP': 'Amapá',
'AM': 'Amazonas',
'BA': 'Bahia',
'CE': 'Ceará',
'DF': 'Distrito Federal',
'ES': 'Espírito Santo',
'GO': 'Goiás',
'MA': 'Maranhão',
'MT': 'Mato Grosso',
'MS': 'Mato Grosso do Sul',
'MG': 'Minas Gerais',
'PA': 'Pará',
'PB': 'Paraíba',
'PR': 'Paraná',
'PE': 'Pernambuco',
'PI': 'Piauí',
'RJ': 'Rio de Janeiro',
'RN': 'Rio Grande do Norte',
'RS': 'Rio Grande do Sul',
'RO': 'Rondônia',
'RR': 'Roraima',
'SC': 'Santa Catarina',
'SP': 'São Paulo',
'SE': 'Sergipe',
'TO': 'Tocantins'
};
data.reverse().forEach(e => {
let st = recastData[states[e.state]] = (recastData[states[e.state]] || {'Province/State': states[e.state], 'Country/Region': 'Brazil', 'Lat': null, 'Long': null});
st[fixBrasilIODate(e.date)] = parseInt(e[type]);
});
return Object.values(recastData);

// same format as NYT - but I needed to access that function here...
function fixBrasilIODate(date) {
let tmp = date.split('-');
return `${tmp[1]}/${tmp[2]}/${tmp[0].substr(2)}`;
}
},
preprocessNYTData(data, type) {
let recastData = {};
data.forEach(e => {
Expand Down Expand Up @@ -644,6 +694,7 @@ window.app = new Vue({
switch (this.selectedRegion) {
case 'World':
return 'Countries';
case 'Brazil':
case 'Australia':
case 'US':
return 'States / Territories';
Expand Down Expand Up @@ -903,7 +954,7 @@ window.app = new Vue({

selectedData: 'Confirmed Cases',

regions: ['World', 'US', 'China', 'Australia', 'Canada'],
regions: ['World', 'US', 'China', 'Australia', 'Canada', 'Brazil'],

selectedRegion: 'World',

Expand Down