From 40f4f308142aebc86427c252046d3d53df81b1cc Mon Sep 17 00:00:00 2001 From: Legendsmith Date: Tue, 8 Oct 2019 23:46:56 +1100 Subject: [PATCH] #320 Export Urban and Rural populations (#321) * Export Rural and Urban populations for states and provinces Exactly what it says on the tin. * Replaced Floor with round For better accuracy, otherwise discrepancies of 1 or 2 may be present. Not really a big deal but still. * Update for urbanization value --- modules/ui/provinces-editor.js | 7 +++++-- modules/ui/states-editor.js | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/ui/provinces-editor.js b/modules/ui/provinces-editor.js index 76f3baf7..2feef3f1 100644 --- a/modules/ui/provinces-editor.js +++ b/modules/ui/provinces-editor.js @@ -761,9 +761,10 @@ function editProvinces() { function downloadProvincesData() { const unit = areaUnit.value === "square" ? distanceUnitInput.value + "2" : areaUnit.value; - let data = "Id,Province,Form,State,Color,Capital,Area "+unit+",Population\n"; // headers + let data = "Id,Province,Form,State,Color,Capital,Area "+unit+",Total Population,Rural Population,Urban Population\n"; // headers body.querySelectorAll(":scope > div").forEach(function(el) { + let key = parseInt(el.dataset.id) data += el.dataset.id + ","; data += el.dataset.name + ","; data += el.dataset.form + ","; @@ -771,7 +772,9 @@ function editProvinces() { data += el.dataset.color + ","; data += el.dataset.capital + ","; data += el.dataset.area + ","; - data += el.dataset.population + "\n"; + data += el.dataset.population + ","; + data += `${Math.round(pack.provinces[key].rural*populationRate.value)},` + data += `${Math.round(pack.provinces[key].urban*populationRate.value * urbanization.value)}\n` }); const dataBlob = new Blob([data], {type: "text/plain"}); diff --git a/modules/ui/states-editor.js b/modules/ui/states-editor.js index edfeab1a..a0e03c1b 100644 --- a/modules/ui/states-editor.js +++ b/modules/ui/states-editor.js @@ -869,9 +869,10 @@ function editStates() { function downloadStatesData() { const unit = areaUnit.value === "square" ? distanceUnitInput.value + "2" : areaUnit.value; - let data = "Id,State,Color,Capital,Culture,Type,Expansionism,Cells,Burgs,Area "+unit+",Population\n"; // headers + let data = "Id,State,Color,Capital,Culture,Type,Expansionism,Cells,Burgs,Area "+unit+",Total Population,Rural Population,Urban Population\n"; // headers body.querySelectorAll(":scope > div").forEach(function(el) { + let key = parseInt(el.dataset.id) data += el.dataset.id + ","; data += el.dataset.name + ","; data += el.dataset.color + ","; @@ -882,7 +883,9 @@ function editStates() { data += el.dataset.cells + ","; data += el.dataset.burgs + ","; data += el.dataset.area + ","; - data += el.dataset.population + "\n"; + data += el.dataset.population + ","; + data += `${Math.round(pack.states[key].rural*populationRate.value)},`; + data += `${Math.round(pack.states[key].urban*populationRate.value * urbanization.value)}\n`; }); const dataBlob = new Blob([data], {type: "text/plain"});