@dra2020/district-analytics 8.2.4 → 8.2.5
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 +46 -12
- package/dist/cli.js.map +1 -1
- package/dist/district-analytics.js +46 -12
- package/dist/district-analytics.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -281278,10 +281278,17 @@ class Districts {
|
|
|
281278
281278
|
featurePop = outerThis._session.features.fieldForFeature(f, "CENSUS" /* CENSUS */, "Tot" /* TotalPop */);
|
|
281279
281279
|
// Total district population
|
|
281280
281280
|
totalPop += featurePop;
|
|
281281
|
-
//
|
|
281282
|
-
|
|
281283
|
-
if (
|
|
281284
|
-
|
|
281281
|
+
// Ignore features when the county is unrecognized
|
|
281282
|
+
const countyFIPS = U.parseGeoID(geoID)['county'];
|
|
281283
|
+
if (U.keyExists(countyFIPS, outerThis._session.counties.index)) {
|
|
281284
|
+
// Total population by counties w/in a district,
|
|
281285
|
+
// except the dummy unassigned district 0
|
|
281286
|
+
if (i > 0)
|
|
281287
|
+
countySplits[outerThis.getCountyIndex(geoID)] += featurePop;
|
|
281288
|
+
}
|
|
281289
|
+
else {
|
|
281290
|
+
console.log("County not recognized:", geoID);
|
|
281291
|
+
}
|
|
281285
281292
|
// Democratic and Republican vote totals
|
|
281286
281293
|
demVotes += outerThis._session.features.fieldForFeature(f, "ELECTION" /* ELECTION */, "D" /* DemVotes */);
|
|
281287
281294
|
repVotes += outerThis._session.features.fieldForFeature(f, "ELECTION" /* ELECTION */, "R" /* RepVotes */);
|
|
@@ -281992,7 +281999,7 @@ function extractDistrictProperties(s, bLog = false) {
|
|
|
281992
281999
|
exports.extractDistrictProperties = extractDistrictProperties;
|
|
281993
282000
|
function isAShape(poly) {
|
|
281994
282001
|
const bPolyUndefined = (poly === undefined) ? true : false;
|
|
281995
|
-
const bNull = (bPolyUndefined) ? true : Poly.polyNull(poly); // TODO
|
|
282002
|
+
const bNull = (bPolyUndefined) ? true : Poly.polyNull(poly); // TODO - poly
|
|
281996
282003
|
const bNoCoordinates = U.isArrayEmpty((poly.geometry.coordinates)) ? true : false;
|
|
281997
282004
|
return (!bPolyUndefined && !bNull && !bNoCoordinates);
|
|
281998
282005
|
}
|
|
@@ -282208,12 +282215,25 @@ function doPreprocessData(s, bLog = false) {
|
|
|
282208
282215
|
exports.doPreprocessData = doPreprocessData;
|
|
282209
282216
|
// CREATE A FIPS CODE TO COUNTY NAME LOOKUP
|
|
282210
282217
|
function doPreprocessCountyFeatures(s, bLog = false) {
|
|
282218
|
+
let fipsCodes = [];
|
|
282219
|
+
// CREATE A MAP OF FIPS CODES TO NAMES
|
|
282211
282220
|
for (let i = 0; i < s.counties.nCounties; i++) {
|
|
282212
282221
|
let county = s.counties.countyByIndex(i);
|
|
282213
282222
|
let fips = s.counties.propertyForCounty(county, 'COUNTYFP');
|
|
282223
|
+
fipsCodes.push(fips);
|
|
282214
282224
|
let name = s.counties.propertyForCounty(county, 'NAME');
|
|
282215
282225
|
s.counties.mapFIPSToName(fips, name);
|
|
282216
282226
|
}
|
|
282227
|
+
// CREATE A FIPS CODE-ORDINAL MAP
|
|
282228
|
+
// Sort the FIPS codes in the county shapes
|
|
282229
|
+
fipsCodes = fipsCodes.sort();
|
|
282230
|
+
// Add a dummy county, for county-district splitting analysis.
|
|
282231
|
+
fipsCodes.unshift('000');
|
|
282232
|
+
// NOTE - This was added for the legacy SPLITTING implementation.
|
|
282233
|
+
// Create the ID-ordinal map
|
|
282234
|
+
for (let i in fipsCodes) {
|
|
282235
|
+
s.counties.index[fipsCodes[i]] = Number(i);
|
|
282236
|
+
}
|
|
282217
282237
|
}
|
|
282218
282238
|
// ANALYZE THE CENSUS BY COUNTY
|
|
282219
282239
|
function doPreprocessCensus(s, bLog = false) {
|
|
@@ -282233,12 +282253,18 @@ function doPreprocessCensus(s, bLog = false) {
|
|
|
282233
282253
|
s.state.totalPop += value;
|
|
282234
282254
|
// Get the county FIPS code for the feature
|
|
282235
282255
|
let countyFIPS = U.parseGeoID(geoID)['county'];
|
|
282236
|
-
//
|
|
282237
|
-
if (
|
|
282238
|
-
|
|
282256
|
+
// Ignore features when the county is unrecognized
|
|
282257
|
+
if (U.keyExists(countyFIPS, s.counties.index)) {
|
|
282258
|
+
// If a subtotal for the county doesn't exist, initialize one
|
|
282259
|
+
if (!(U.keyExists(countyFIPS, totalByCounty))) {
|
|
282260
|
+
totalByCounty[countyFIPS] = 0;
|
|
282261
|
+
}
|
|
282262
|
+
// Sum total population by county
|
|
282263
|
+
totalByCounty[countyFIPS] += value;
|
|
282264
|
+
}
|
|
282265
|
+
else {
|
|
282266
|
+
console.log("County not recognized:", geoID);
|
|
282239
282267
|
}
|
|
282240
|
-
// Sum total population by county
|
|
282241
|
-
totalByCounty[countyFIPS] += value;
|
|
282242
282268
|
}
|
|
282243
282269
|
else {
|
|
282244
282270
|
if (bLog)
|
|
@@ -282246,18 +282272,24 @@ function doPreprocessCensus(s, bLog = false) {
|
|
|
282246
282272
|
}
|
|
282247
282273
|
}
|
|
282248
282274
|
// NOTE - The above could be replaced, if I got totals on county.geojson.
|
|
282275
|
+
/* Moved this to doPreprocessCountyFeatures() - 09-14-2020 to fix VA county mismatch bug
|
|
282249
282276
|
// CREATE A FIPS CODE-ORDINAL MAP
|
|
282277
|
+
|
|
282250
282278
|
// Get the county FIPS codes
|
|
282251
282279
|
let fipsCodes = U.getObjectKeys(totalByCounty);
|
|
282252
282280
|
// Sort the results
|
|
282253
282281
|
fipsCodes = fipsCodes.sort();
|
|
282282
|
+
|
|
282254
282283
|
// NOTE - This was added for the legacy SPLITTING implementation.
|
|
282255
282284
|
// Add a dummy county, for county-district splitting analysis.
|
|
282256
282285
|
fipsCodes.unshift('000');
|
|
282286
|
+
|
|
282257
282287
|
// Create the ID-ordinal map
|
|
282258
|
-
for (let i in fipsCodes)
|
|
282259
|
-
|
|
282288
|
+
for (let i in fipsCodes)
|
|
282289
|
+
{
|
|
282290
|
+
s.counties.index[fipsCodes[i]] = Number(i);
|
|
282260
282291
|
}
|
|
282292
|
+
*/
|
|
282261
282293
|
// MAKE AN ARRAY OF TOTAL POPULATIONS BY COUNTY INDEX
|
|
282262
282294
|
// Add an extra 0th virtual county bucket for county-district splitting analysis
|
|
282263
282295
|
let nCountyBuckets = s.counties.nCounties + 1;
|
|
@@ -282279,6 +282311,8 @@ function doPreprocessCensus(s, bLog = false) {
|
|
|
282279
282311
|
let tooBigName = [];
|
|
282280
282312
|
let expectedSplits = 0;
|
|
282281
282313
|
let expectedAffected = 0;
|
|
282314
|
+
// Get the county FIPS codes
|
|
282315
|
+
let fipsCodes = U.getObjectKeys(s.counties.index);
|
|
282282
282316
|
// Loop over the counties
|
|
282283
282317
|
for (let county in fipsCodes) {
|
|
282284
282318
|
let fipsCode = fipsCodes[county];
|