@dra2020/district-analytics 8.2.3 → 8.2.6
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 +64 -28
- package/dist/cli.js.map +1 -1
- package/dist/district-analytics.js +52 -21
- package/dist/district-analytics.js.map +1 -1
- package/dist/src/results.d.ts +2 -1
- package/package.json +3 -3
- package/dist/src/geofeature.d.ts +0 -0
|
@@ -503,10 +503,17 @@ class Districts {
|
|
|
503
503
|
featurePop = outerThis._session.features.fieldForFeature(f, "CENSUS" /* CENSUS */, "Tot" /* TotalPop */);
|
|
504
504
|
// Total district population
|
|
505
505
|
totalPop += featurePop;
|
|
506
|
-
//
|
|
507
|
-
|
|
508
|
-
if (
|
|
509
|
-
|
|
506
|
+
// Ignore features when the county is unrecognized
|
|
507
|
+
const countyFIPS = U.parseGeoID(geoID)['county'];
|
|
508
|
+
if (U.keyExists(countyFIPS, outerThis._session.counties.index)) {
|
|
509
|
+
// Total population by counties w/in a district,
|
|
510
|
+
// except the dummy unassigned district 0
|
|
511
|
+
if (i > 0)
|
|
512
|
+
countySplits[outerThis.getCountyIndex(geoID)] += featurePop;
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
console.log("County not recognized:", geoID);
|
|
516
|
+
}
|
|
510
517
|
// Democratic and Republican vote totals
|
|
511
518
|
demVotes += outerThis._session.features.fieldForFeature(f, "ELECTION" /* ELECTION */, "D" /* DemVotes */);
|
|
512
519
|
repVotes += outerThis._session.features.fieldForFeature(f, "ELECTION" /* ELECTION */, "R" /* RepVotes */);
|
|
@@ -1216,10 +1223,11 @@ function extractDistrictProperties(s, bLog = false) {
|
|
|
1216
1223
|
}
|
|
1217
1224
|
exports.extractDistrictProperties = extractDistrictProperties;
|
|
1218
1225
|
function isAShape(poly) {
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1226
|
+
if (poly == null)
|
|
1227
|
+
return false;
|
|
1228
|
+
if (Poly.polyNull(poly))
|
|
1229
|
+
return false;
|
|
1230
|
+
return poly.geometry && poly.geometry.coordinates && !U.isArrayEmpty(poly.geometry.coordinates);
|
|
1223
1231
|
}
|
|
1224
1232
|
// SCORE KIWYSI COMPACTNESS
|
|
1225
1233
|
function scoreKIWYSICompactness(s, bLog = false) {
|
|
@@ -1457,12 +1465,25 @@ function doPreprocessData(s, bLog = false) {
|
|
|
1457
1465
|
exports.doPreprocessData = doPreprocessData;
|
|
1458
1466
|
// CREATE A FIPS CODE TO COUNTY NAME LOOKUP
|
|
1459
1467
|
function doPreprocessCountyFeatures(s, bLog = false) {
|
|
1468
|
+
let fipsCodes = [];
|
|
1469
|
+
// CREATE A MAP OF FIPS CODES TO NAMES
|
|
1460
1470
|
for (let i = 0; i < s.counties.nCounties; i++) {
|
|
1461
1471
|
let county = s.counties.countyByIndex(i);
|
|
1462
1472
|
let fips = s.counties.propertyForCounty(county, 'COUNTYFP');
|
|
1473
|
+
fipsCodes.push(fips);
|
|
1463
1474
|
let name = s.counties.propertyForCounty(county, 'NAME');
|
|
1464
1475
|
s.counties.mapFIPSToName(fips, name);
|
|
1465
1476
|
}
|
|
1477
|
+
// CREATE A FIPS CODE-ORDINAL MAP
|
|
1478
|
+
// Sort the FIPS codes in the county shapes
|
|
1479
|
+
fipsCodes = fipsCodes.sort();
|
|
1480
|
+
// Add a dummy county, for county-district splitting analysis.
|
|
1481
|
+
fipsCodes.unshift('000');
|
|
1482
|
+
// NOTE - This was added for the legacy SPLITTING implementation.
|
|
1483
|
+
// Create the ID-ordinal map
|
|
1484
|
+
for (let i in fipsCodes) {
|
|
1485
|
+
s.counties.index[fipsCodes[i]] = Number(i);
|
|
1486
|
+
}
|
|
1466
1487
|
}
|
|
1467
1488
|
// ANALYZE THE CENSUS BY COUNTY
|
|
1468
1489
|
function doPreprocessCensus(s, bLog = false) {
|
|
@@ -1482,12 +1503,18 @@ function doPreprocessCensus(s, bLog = false) {
|
|
|
1482
1503
|
s.state.totalPop += value;
|
|
1483
1504
|
// Get the county FIPS code for the feature
|
|
1484
1505
|
let countyFIPS = U.parseGeoID(geoID)['county'];
|
|
1485
|
-
//
|
|
1486
|
-
if (
|
|
1487
|
-
|
|
1506
|
+
// Ignore features when the county is unrecognized
|
|
1507
|
+
if (U.keyExists(countyFIPS, s.counties.index)) {
|
|
1508
|
+
// If a subtotal for the county doesn't exist, initialize one
|
|
1509
|
+
if (!(U.keyExists(countyFIPS, totalByCounty))) {
|
|
1510
|
+
totalByCounty[countyFIPS] = 0;
|
|
1511
|
+
}
|
|
1512
|
+
// Sum total population by county
|
|
1513
|
+
totalByCounty[countyFIPS] += value;
|
|
1514
|
+
}
|
|
1515
|
+
else {
|
|
1516
|
+
console.log("County not recognized:", geoID);
|
|
1488
1517
|
}
|
|
1489
|
-
// Sum total population by county
|
|
1490
|
-
totalByCounty[countyFIPS] += value;
|
|
1491
1518
|
}
|
|
1492
1519
|
else {
|
|
1493
1520
|
if (bLog)
|
|
@@ -1495,18 +1522,24 @@ function doPreprocessCensus(s, bLog = false) {
|
|
|
1495
1522
|
}
|
|
1496
1523
|
}
|
|
1497
1524
|
// NOTE - The above could be replaced, if I got totals on county.geojson.
|
|
1525
|
+
/* Moved this to doPreprocessCountyFeatures() - 09-14-2020 to fix VA county mismatch bug
|
|
1498
1526
|
// CREATE A FIPS CODE-ORDINAL MAP
|
|
1527
|
+
|
|
1499
1528
|
// Get the county FIPS codes
|
|
1500
1529
|
let fipsCodes = U.getObjectKeys(totalByCounty);
|
|
1501
1530
|
// Sort the results
|
|
1502
1531
|
fipsCodes = fipsCodes.sort();
|
|
1532
|
+
|
|
1503
1533
|
// NOTE - This was added for the legacy SPLITTING implementation.
|
|
1504
1534
|
// Add a dummy county, for county-district splitting analysis.
|
|
1505
1535
|
fipsCodes.unshift('000');
|
|
1536
|
+
|
|
1506
1537
|
// Create the ID-ordinal map
|
|
1507
|
-
for (let i in fipsCodes)
|
|
1508
|
-
|
|
1538
|
+
for (let i in fipsCodes)
|
|
1539
|
+
{
|
|
1540
|
+
s.counties.index[fipsCodes[i]] = Number(i);
|
|
1509
1541
|
}
|
|
1542
|
+
*/
|
|
1510
1543
|
// MAKE AN ARRAY OF TOTAL POPULATIONS BY COUNTY INDEX
|
|
1511
1544
|
// Add an extra 0th virtual county bucket for county-district splitting analysis
|
|
1512
1545
|
let nCountyBuckets = s.counties.nCounties + 1;
|
|
@@ -1528,6 +1561,8 @@ function doPreprocessCensus(s, bLog = false) {
|
|
|
1528
1561
|
let tooBigName = [];
|
|
1529
1562
|
let expectedSplits = 0;
|
|
1530
1563
|
let expectedAffected = 0;
|
|
1564
|
+
// Get the county FIPS codes
|
|
1565
|
+
let fipsCodes = U.getObjectKeys(s.counties.index);
|
|
1531
1566
|
// Loop over the counties
|
|
1532
1567
|
for (let county in fipsCodes) {
|
|
1533
1568
|
let fipsCode = fipsCodes[county];
|
|
@@ -1981,13 +2016,9 @@ function scorePlan(s, p, bLog = false, overridesJSON) {
|
|
|
1981
2016
|
// Add minority notes
|
|
1982
2017
|
scorecard.minority.details['majorityMinority'] = M.getMajorityMinority(s);
|
|
1983
2018
|
scorecard.minority.details['vraPreclearance'] = M.getVRASection5(s);
|
|
1984
|
-
// TODO - KIWYSI
|
|
1985
2019
|
// Add KIWYSI compactness score
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
const kiwysiScore = C.scoreKIWYSICompactness(s, bLog);
|
|
1989
|
-
scorecard.compactness.details['kiwysi'] = kiwysiScore;
|
|
1990
|
-
}
|
|
2020
|
+
const kiwysiScore = C.scoreKIWYSICompactness(s, bLog);
|
|
2021
|
+
scorecard.compactness.details['kiwysi'] = kiwysiScore;
|
|
1991
2022
|
return scorecard;
|
|
1992
2023
|
}
|
|
1993
2024
|
exports.scorePlan = scorePlan;
|