@dra2020/district-analytics 2.0.6 → 2.0.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.
@@ -396,6 +396,9 @@ class Districts {
396
396
  // 3 - MORE ...
397
397
  // HACK - Because "this" gets ghosted inside the forEach loop below
398
398
  let outerThis = this;
399
+ // Default the pop dev % for the dummy Unassigned district to 0%.
400
+ // Default the pop dev % for real (1–N) but empty districts to 100%.
401
+ let popDevPct = (i > 0) ? (targetSize / targetSize) : 0 / targetSize;
399
402
  // Get the geoIDs assigned to the district
400
403
  // Guard against empty districts
401
404
  let geoIDs = this._session.plan.geoIDsForDistrictID(i);
@@ -442,11 +445,11 @@ class Districts {
442
445
  });
443
446
  // COMPUTE DERIVED VALUES
444
447
  // Population deviation % and equal population (boolean) by district.
445
- // Default the value for the dummy unassigned district to 0%.
446
- let popDevPct = 0 / targetSize;
447
448
  if (i > 0) {
448
- popDevPct = (totalPop - targetSize) / targetSize;
449
- bEqualPop = (popDevPct <= deviationThreshold);
449
+ if (totalPop > 0) {
450
+ popDevPct = (totalPop - targetSize) / targetSize;
451
+ bEqualPop = (popDevPct <= deviationThreshold);
452
+ }
450
453
  }
451
454
  // Total two-party (not total total!) votes, Democratic and Republican vote
452
455
  // shares, and Democratic first-past-the-post win (= 1) or loss (= 0).
@@ -535,7 +538,7 @@ class Districts {
535
538
  }
536
539
  }
537
540
  else { // If a district is empty, zero these results (vs. null)
538
- this.statistics[DistrictField.PopDevPct][i] = 0.0;
541
+ this.statistics[DistrictField.PopDevPct][i] = popDevPct;
539
542
  this.statistics[DistrictField.DemVotes][i] = 0;
540
543
  this.statistics[DistrictField.RepVotes][i] = 0;
541
544
  this.statistics[DistrictField.TwoPartyVote][i] = 0;