@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
package/dist/cli.js
CHANGED
|
@@ -9382,17 +9382,22 @@ const U = __importStar(__webpack_require__(/*! ./utils */ "./src/utils.ts"));
|
|
|
9382
9382
|
const D = __importStar(__webpack_require__(/*! ./_data */ "./src/_data.ts"));
|
|
9383
9383
|
function doPopulationDeviation(s, bLog = false) {
|
|
9384
9384
|
let test = s.getTest(4 /* PopulationDeviation */);
|
|
9385
|
-
|
|
9386
|
-
//
|
|
9385
|
+
let targetSize = s.state.totalPop / s.state.nDistricts;
|
|
9386
|
+
// Compute the min & max district populations
|
|
9387
|
+
// ... excluding the dummy the 'unassigned' 0 and N+1 summary "districts"
|
|
9387
9388
|
let totPopByDistrict = s.districts.statistics[D.DistrictField.TotalPop];
|
|
9388
9389
|
totPopByDistrict = totPopByDistrict.slice(1, -1);
|
|
9389
|
-
|
|
9390
|
-
|
|
9391
|
-
let
|
|
9392
|
-
|
|
9393
|
-
//
|
|
9394
|
-
|
|
9395
|
-
|
|
9390
|
+
// Remove empty districts
|
|
9391
|
+
totPopByDistrict = totPopByDistrict.filter(x => x > 0);
|
|
9392
|
+
let min = 0;
|
|
9393
|
+
let max = 0;
|
|
9394
|
+
// If there's more than 1 non-empty district, calculate a non-zero deviation
|
|
9395
|
+
if (totPopByDistrict.length > 1) {
|
|
9396
|
+
min = U.minArray(totPopByDistrict);
|
|
9397
|
+
max = U.maxArray(totPopByDistrict);
|
|
9398
|
+
}
|
|
9399
|
+
// Calculate the raw population deviation
|
|
9400
|
+
let popDev = (max - min) / targetSize;
|
|
9396
9401
|
// Round the raw value to the desired level of precision
|
|
9397
9402
|
popDev = U.trim(popDev);
|
|
9398
9403
|
// Populate the test entry
|
|
@@ -9402,7 +9407,7 @@ function doPopulationDeviation(s, bLog = false) {
|
|
|
9402
9407
|
let totalPop = s.districts.statistics[D.DistrictField.TotalPop];
|
|
9403
9408
|
let popDevPct = s.districts.statistics[D.DistrictField.PopDevPct];
|
|
9404
9409
|
let summaryRow = s.districts.numberOfRows() - 1;
|
|
9405
|
-
totalPop[summaryRow] =
|
|
9410
|
+
totalPop[summaryRow] = targetSize;
|
|
9406
9411
|
popDevPct[summaryRow] = popDev;
|
|
9407
9412
|
return test;
|
|
9408
9413
|
}
|