@dra2020/district-analytics 7.1.4 → 7.1.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.
@@ -490,7 +490,8 @@ class Districts {
490
490
  let featureID = outerThis._session.features.featureID(geoID);
491
491
  let f = outerThis._session.features.featureByIndex(featureID);
492
492
  if (f == undefined) {
493
- console.log("Skipping undefined feature in district statistics: GEOID =", geoID, "Feature ID =", featureID);
493
+ if (bLog)
494
+ console.log("Skipping undefined feature in district statistics: GEOID =", geoID, "Feature ID =", featureID);
494
495
  }
495
496
  else {
496
497
  // ACCUMULATE VALUES
@@ -517,8 +518,10 @@ class Districts {
517
518
  // 4 - MORE ...
518
519
  }
519
520
  }
520
- else
521
- console.log("Skipping water-only feature in district statistics:", geoID);
521
+ else {
522
+ if (bLog)
523
+ console.log("Skipping water-only feature in district statistics:", geoID);
524
+ }
522
525
  });
523
526
  // COMPUTE DERIVED VALUES
524
527
  // Population deviation % and equal population (boolean) by district.
@@ -663,8 +666,10 @@ class Districts {
663
666
  this.statistics[DistrictField.AsianPct][summaryRow] = stateAsianPop / stateVAPPop;
664
667
  this.statistics[DistrictField.NativePct][summaryRow] = stateNativePop / stateVAPPop;
665
668
  }
666
- console.log(`${nMissingDataset} features with missing datasets.`);
667
- console.log(`${nMissingProperty} features with missing properties.`);
669
+ if (bLog) {
670
+ console.log(`${nMissingDataset} features with missing datasets.`);
671
+ console.log(`${nMissingProperty} features with missing properties.`);
672
+ }
668
673
  }
669
674
  // NOTE - I did not roll these into district statistics, because creating the
670
675
  // district shapes themselves is the big district-by-district activity, these
@@ -688,6 +693,8 @@ class Features {
688
693
  this._session = s;
689
694
  this._data = data;
690
695
  this._keys = keys;
696
+ // For debugging PVI
697
+ // console.log("Election dataset =", this._keys[Dataset.ELECTION]);
691
698
  }
692
699
  nFeatures() { return this._data.features.length; }
693
700
  featureByIndex(i) { return this._data.features[i]; }
@@ -698,8 +705,15 @@ class Features {
698
705
  return value;
699
706
  }
700
707
  fieldForFeature(f, dt, fk) {
701
- let dk = this._keys[dt];
702
- return _getFeatures(f, dk, fk);
708
+ const dk = this._keys[dt];
709
+ let result = undefined;
710
+ // 07-31-2020 - Fix to post-process PVI into the expected election composite format.
711
+ if (dk === 'P16GPR') {
712
+ result = (_getFeatures(f, dk, (fk === 'D' ? 'D12' : 'R12')) + _getFeatures(f, dk, (fk === 'D' ? 'D16' : 'R16'))) / 2;
713
+ }
714
+ else
715
+ result = _getFeatures(f, dk, fk);
716
+ return result;
703
717
  }
704
718
  resetDataset(d, k) {
705
719
  this._keys[d] = k;
@@ -817,8 +831,8 @@ class Plan {
817
831
  // }
818
832
  // return newPlan;
819
833
  // }
820
- invertPlan() {
821
- this._planByDistrictID = invertPlan(this._planByGeoID, this._session);
834
+ invertPlan(bLog = false) {
835
+ this._planByDistrictID = invertPlan(this._planByGeoID, this._session, bLog);
822
836
  this.districtIDs = U.getNumericObjectKeys(this._planByDistrictID);
823
837
  }
824
838
  initializeDistrict(i) { this._planByDistrictID[i] = new Set(); }
@@ -829,7 +843,7 @@ class Plan {
829
843
  }
830
844
  exports.Plan = Plan;
831
845
  // Invert a feature assignment structure to sets of ids by district
832
- function invertPlan(plan, s) {
846
+ function invertPlan(plan, s, bLog = false) {
833
847
  let invertedPlan = {};
834
848
  // Add a dummy 'unassigned' district
835
849
  invertedPlan[S.NOT_ASSIGNED] = new Set();
@@ -859,7 +873,7 @@ function invertPlan(plan, s) {
859
873
  }
860
874
  // Add the geoID to the districtID's set
861
875
  invertedPlan[districtID].add(geoID);
862
- if (U.isWaterOnly(geoID))
876
+ if (U.isWaterOnly(geoID) && bLog)
863
877
  console.log("Water-only feature still in plan!", geoID);
864
878
  }
865
879
  return invertedPlan;
@@ -1367,7 +1381,7 @@ function doPreprocessData(s, bLog = false) {
1367
1381
  s.bOneTimeProcessingDone = true;
1368
1382
  }
1369
1383
  // Invert the plan by district ID
1370
- s.plan.invertPlan();
1384
+ s.plan.invertPlan(bLog);
1371
1385
  // Create a map of geoIDs to feature IDs
1372
1386
  s.features.mapGeoIDsToFeatureIDs();
1373
1387
  }
@@ -1407,7 +1421,8 @@ function doPreprocessCensus(s, bLog = false) {
1407
1421
  totalByCounty[countyFIPS] += value;
1408
1422
  }
1409
1423
  else {
1410
- console.log("Skipping water-only feature in Census preprocessing:", geoID);
1424
+ if (bLog)
1425
+ console.log("Skipping water-only feature in Census preprocessing:", geoID);
1411
1426
  }
1412
1427
  }
1413
1428
  // NOTE - The above could be replaced, if I got totals on county.geojson.