@dra2020/district-analytics 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +15 -10
- package/dist/cli.js.map +1 -1
- package/dist/district-analytics.js +15 -10
- package/dist/district-analytics.js.map +1 -1
- package/package.json +1 -1
|
@@ -1447,17 +1447,22 @@ const U = __importStar(__webpack_require__(/*! ./utils */ "./src/utils.ts"));
|
|
|
1447
1447
|
const D = __importStar(__webpack_require__(/*! ./_data */ "./src/_data.ts"));
|
|
1448
1448
|
function doPopulationDeviation(s, bLog = false) {
|
|
1449
1449
|
let test = s.getTest(4 /* PopulationDeviation */);
|
|
1450
|
-
|
|
1451
|
-
//
|
|
1450
|
+
let targetSize = s.state.totalPop / s.state.nDistricts;
|
|
1451
|
+
// Compute the min & max district populations
|
|
1452
|
+
// ... excluding the dummy the 'unassigned' 0 and N+1 summary "districts"
|
|
1452
1453
|
let totPopByDistrict = s.districts.statistics[D.DistrictField.TotalPop];
|
|
1453
1454
|
totPopByDistrict = totPopByDistrict.slice(1, -1);
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
let
|
|
1457
|
-
|
|
1458
|
-
//
|
|
1459
|
-
|
|
1460
|
-
|
|
1455
|
+
// Remove empty districts
|
|
1456
|
+
totPopByDistrict = totPopByDistrict.filter(x => x > 0);
|
|
1457
|
+
let min = 0;
|
|
1458
|
+
let max = 0;
|
|
1459
|
+
// If there's more than 1 non-empty district, calculate a non-zero deviation
|
|
1460
|
+
if (totPopByDistrict.length > 1) {
|
|
1461
|
+
min = U.minArray(totPopByDistrict);
|
|
1462
|
+
max = U.maxArray(totPopByDistrict);
|
|
1463
|
+
}
|
|
1464
|
+
// Calculate the raw population deviation
|
|
1465
|
+
let popDev = (max - min) / targetSize;
|
|
1461
1466
|
// Round the raw value to the desired level of precision
|
|
1462
1467
|
popDev = U.trim(popDev);
|
|
1463
1468
|
// Populate the test entry
|
|
@@ -1467,7 +1472,7 @@ function doPopulationDeviation(s, bLog = false) {
|
|
|
1467
1472
|
let totalPop = s.districts.statistics[D.DistrictField.TotalPop];
|
|
1468
1473
|
let popDevPct = s.districts.statistics[D.DistrictField.PopDevPct];
|
|
1469
1474
|
let summaryRow = s.districts.numberOfRows() - 1;
|
|
1470
|
-
totalPop[summaryRow] =
|
|
1475
|
+
totalPop[summaryRow] = targetSize;
|
|
1471
1476
|
popDevPct[summaryRow] = popDev;
|
|
1472
1477
|
return test;
|
|
1473
1478
|
}
|