Fix rural population calculation to only count small burgs

Rural population now correctly counted only from burgs with ≤100 people.
Eliminates double-counting and ensures consistent statistics across
charts and CSV exports.
This commit is contained in:
barrulus 2025-08-13 23:35:26 +01:00
parent e669549390
commit 8ec53293b7
2 changed files with 17 additions and 6 deletions

View file

@ -1026,13 +1026,17 @@ window.BurgsAndStates = (() => {
states[s].cells += 1;
states[s].area += cells.area[i];
if (cells.burg[i]) {
// Burg represents ALL population for this cell (stored in thousands)
states[s].urban += pack.burgs[cells.burg[i]].population;
const burgPopulation = pack.burgs[cells.burg[i]].population;
if (burgPopulation > 0.1) {
// Large burg (>100 people) = urban population
states[s].urban += burgPopulation;
} else {
// Small burg (≤100 people) = rural population
states[s].rural += burgPopulation;
}
states[s].burgs++;
} else {
// Only count cells.pop for unsettled areas (no burg present)
states[s].rural += cells.pop[i];
}
// Cells without burgs have no population (rural population is housed in small burgs)
}
// convert neighbors Set object into array

View file

@ -672,7 +672,14 @@ function getUrbanPopulation(cellId) {
}
function getRuralPopulation(cellId) {
return pack.cells.pop[cellId] * populationRate;
const burgId = pack.cells.burg[cellId];
if (!burgId) return 0; // No burg = no rural population
const burgPopulation = pack.burgs[burgId].population;
if (burgPopulation > 0.1) return 0; // Burg has >100 people = no rural population
// Small burg (≤100 people) = count the burg's actual population as rural
return burgPopulation * 1000 * populationRate;
}
function sortData(data, sorting) {