@dra2020/district-analytics 8.2.4 → 8.2.7

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 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
- // Total population by counties w/in a district,
281282
- // except the dummy unassigned district 0
281283
- if (i > 0)
281284
- countySplits[outerThis.getCountyIndex(geoID)] += featurePop;
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 */);
@@ -281991,10 +281998,11 @@ function extractDistrictProperties(s, bLog = false) {
281991
281998
  }
281992
281999
  exports.extractDistrictProperties = extractDistrictProperties;
281993
282000
  function isAShape(poly) {
281994
- const bPolyUndefined = (poly === undefined) ? true : false;
281995
- const bNull = (bPolyUndefined) ? true : Poly.polyNull(poly); // TODO
281996
- const bNoCoordinates = U.isArrayEmpty((poly.geometry.coordinates)) ? true : false;
281997
- return (!bPolyUndefined && !bNull && !bNoCoordinates);
282001
+ if (poly == null)
282002
+ return false;
282003
+ if (Poly.polyNull(poly))
282004
+ return false;
282005
+ return poly.geometry && poly.geometry.coordinates && !U.isArrayEmpty(poly.geometry.coordinates);
281998
282006
  }
281999
282007
  // SCORE KIWYSI COMPACTNESS
282000
282008
  function scoreKIWYSICompactness(s, bLog = false) {
@@ -282084,8 +282092,12 @@ function doHasEqualPopulations(s, bLog = false) {
282084
282092
  let popDevTest = s.getTest(4 /* PopulationDeviation */);
282085
282093
  const popDevPct = popDevTest['score'];
282086
282094
  const popDevNormalized = popDevTest['normalizedScore'];
282095
+ // 09-19-2020 - Added to catch edge case of only one non-empty district
282096
+ const p = s._profile;
282097
+ const totPopByDistrict = p.populationProfile.totalPopByDistrict.filter(x => x > 0);
282098
+ const bTwoOrMoreDistricts = (totPopByDistrict.length > 1) ? true : false;
282087
282099
  // Populate the test entry
282088
- if (popDevNormalized > 0) {
282100
+ if (bTwoOrMoreDistricts && (popDevNormalized > 0)) {
282089
282101
  test['score'] = true;
282090
282102
  }
282091
282103
  else {
@@ -282208,12 +282220,25 @@ function doPreprocessData(s, bLog = false) {
282208
282220
  exports.doPreprocessData = doPreprocessData;
282209
282221
  // CREATE A FIPS CODE TO COUNTY NAME LOOKUP
282210
282222
  function doPreprocessCountyFeatures(s, bLog = false) {
282223
+ let fipsCodes = [];
282224
+ // CREATE A MAP OF FIPS CODES TO NAMES
282211
282225
  for (let i = 0; i < s.counties.nCounties; i++) {
282212
282226
  let county = s.counties.countyByIndex(i);
282213
282227
  let fips = s.counties.propertyForCounty(county, 'COUNTYFP');
282228
+ fipsCodes.push(fips);
282214
282229
  let name = s.counties.propertyForCounty(county, 'NAME');
282215
282230
  s.counties.mapFIPSToName(fips, name);
282216
282231
  }
282232
+ // CREATE A FIPS CODE-ORDINAL MAP
282233
+ // Sort the FIPS codes in the county shapes
282234
+ fipsCodes = fipsCodes.sort();
282235
+ // Add a dummy county, for county-district splitting analysis.
282236
+ fipsCodes.unshift('000');
282237
+ // NOTE - This was added for the legacy SPLITTING implementation.
282238
+ // Create the ID-ordinal map
282239
+ for (let i in fipsCodes) {
282240
+ s.counties.index[fipsCodes[i]] = Number(i);
282241
+ }
282217
282242
  }
282218
282243
  // ANALYZE THE CENSUS BY COUNTY
282219
282244
  function doPreprocessCensus(s, bLog = false) {
@@ -282233,12 +282258,18 @@ function doPreprocessCensus(s, bLog = false) {
282233
282258
  s.state.totalPop += value;
282234
282259
  // Get the county FIPS code for the feature
282235
282260
  let countyFIPS = U.parseGeoID(geoID)['county'];
282236
- // If a subtotal for the county doesn't exist, initialize one
282237
- if (!(U.keyExists(countyFIPS, totalByCounty))) {
282238
- totalByCounty[countyFIPS] = 0;
282261
+ // Ignore features when the county is unrecognized
282262
+ if (U.keyExists(countyFIPS, s.counties.index)) {
282263
+ // If a subtotal for the county doesn't exist, initialize one
282264
+ if (!(U.keyExists(countyFIPS, totalByCounty))) {
282265
+ totalByCounty[countyFIPS] = 0;
282266
+ }
282267
+ // Sum total population by county
282268
+ totalByCounty[countyFIPS] += value;
282269
+ }
282270
+ else {
282271
+ console.log("County not recognized:", geoID);
282239
282272
  }
282240
- // Sum total population by county
282241
- totalByCounty[countyFIPS] += value;
282242
282273
  }
282243
282274
  else {
282244
282275
  if (bLog)
@@ -282246,18 +282277,24 @@ function doPreprocessCensus(s, bLog = false) {
282246
282277
  }
282247
282278
  }
282248
282279
  // NOTE - The above could be replaced, if I got totals on county.geojson.
282280
+ /* Moved this to doPreprocessCountyFeatures() - 09-14-2020 to fix VA county mismatch bug
282249
282281
  // CREATE A FIPS CODE-ORDINAL MAP
282282
+
282250
282283
  // Get the county FIPS codes
282251
282284
  let fipsCodes = U.getObjectKeys(totalByCounty);
282252
282285
  // Sort the results
282253
282286
  fipsCodes = fipsCodes.sort();
282287
+
282254
282288
  // NOTE - This was added for the legacy SPLITTING implementation.
282255
282289
  // Add a dummy county, for county-district splitting analysis.
282256
282290
  fipsCodes.unshift('000');
282291
+
282257
282292
  // Create the ID-ordinal map
282258
- for (let i in fipsCodes) {
282259
- s.counties.index[fipsCodes[i]] = Number(i);
282293
+ for (let i in fipsCodes)
282294
+ {
282295
+ s.counties.index[fipsCodes[i]] = Number(i);
282260
282296
  }
282297
+ */
282261
282298
  // MAKE AN ARRAY OF TOTAL POPULATIONS BY COUNTY INDEX
282262
282299
  // Add an extra 0th virtual county bucket for county-district splitting analysis
282263
282300
  let nCountyBuckets = s.counties.nCounties + 1;
@@ -282279,6 +282316,8 @@ function doPreprocessCensus(s, bLog = false) {
282279
282316
  let tooBigName = [];
282280
282317
  let expectedSplits = 0;
282281
282318
  let expectedAffected = 0;
282319
+ // Get the county FIPS codes
282320
+ let fipsCodes = U.getObjectKeys(s.counties.index);
282282
282321
  // Loop over the counties
282283
282322
  for (let county in fipsCodes) {
282284
282323
  let fipsCode = fipsCodes[county];