@dra2020/district-analytics 5.2.3 → 5.3.0

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
@@ -89477,7 +89477,8 @@ function evalMinorityOpportunity(p, bLog = false) {
89477
89477
  }
89478
89478
  exports.evalMinorityOpportunity = evalMinorityOpportunity;
89479
89479
  function scoreMinority(oD, pD) {
89480
- const bonus = C.minorityBonus();
89480
+ // Score minority opportunity [0–100] here; weight it later
89481
+ const bonus = 100; // C.minorityBonus();
89481
89482
  const score = (pD > 0) ? Math.round((Math.min(oD, pD) / pD) * bonus) : 0;
89482
89483
  return score;
89483
89484
  }
@@ -89671,6 +89672,7 @@ const normalize_1 = __webpack_require__(/*! ./normalize */ "./src/normalize.ts")
89671
89672
  * BV_50 [bV50] = Votes bias as a fraction
89672
89673
  * decl [decl] = Declination
89673
89674
  * GS [gSym] = Global symmetry
89675
+ * ?? [gamma] = TODO
89674
89676
 
89675
89677
  * EG [EG] = Efficiency gap as a fraction
89676
89678
  * BS_V [bSV] = Seats bias @ <V> (geometric)
@@ -89740,6 +89742,7 @@ function scorePartisan(Vf, VfArray, options) {
89740
89742
  const MIR = bAlternateMetrics ? calcMinimalInverseResponsiveness(Vf, littleR) : undefined;
89741
89743
  const rD = (!bConstrained || bAlternateMetrics) ? estResponsiveDistricts(VfArray) : undefined;
89742
89744
  const rDf = bAlternateMetrics ? estResponsiveDistrictsShare(rD, N) : undefined;
89745
+ const gamma = bAlternateMetrics ? calcGammaNEW(Vf, estSf, littleR) : undefined;
89743
89746
  const Cn = countCompetitiveDistricts(VfArray);
89744
89747
  const cD = estCompetitiveDistricts(VfArray); // NOTE - Cd by definition uses a more narrow probability distribution vs. Rd
89745
89748
  // const cD = bConstrained ? estCompetitiveDistricts(VfArray) : rD as number;
@@ -89776,6 +89779,7 @@ function scorePartisan(Vf, VfArray, options) {
89776
89779
  biasScoring.bV50 = Bv50f;
89777
89780
  biasScoring.decl = decl;
89778
89781
  biasScoring.gSym = gSym;
89782
+ biasScoring.gamma = gamma;
89779
89783
  biasScoring.eG = EG;
89780
89784
  biasScoring.bSV = BsGf;
89781
89785
  biasScoring.prop = prop;
@@ -90451,16 +90455,16 @@ function calcGlobalSymmetry(inferredSVpoints, S50V) {
90451
90455
  }
90452
90456
  const sign = (S50V < 0) ? -1 : 1;
90453
90457
  gSym *= sign;
90454
- return U.trim(gSym);
90458
+ return U.trim(gSym / 100);
90455
90459
  }
90456
90460
  exports.calcGlobalSymmetry = calcGlobalSymmetry;
90457
90461
  // RAW DISPROPORTIONALITY
90458
90462
  //
90459
- // gamma = Sf – Vf : Eq.C.1.1 on P. 42
90463
+ // PR = Sf – Vf : Eq.C.1.1 on P. 42
90460
90464
  function calcDisproportionality(Vf, Sf) {
90461
- const gamma = Vf - Sf;
90462
- // const gamma = Sf - Vf;
90463
- return U.trim(gamma);
90465
+ const prop = Vf - Sf;
90466
+ // const prop = Sf - Vf;
90467
+ return U.trim(prop);
90464
90468
  }
90465
90469
  exports.calcDisproportionality = calcDisproportionality;
90466
90470
  // TODO - Add unit tests <<< Depends on S(V)
@@ -90496,6 +90500,17 @@ function isBalanced(Vf) {
90496
90500
  const bBalanced = ((Vf > upper) || (Vf < lower)) ? false : true;
90497
90501
  return bBalanced;
90498
90502
  }
90503
+ // GAMMA (NEW)
90504
+ // g = 50 + r<V>(<V>-50) – S(<V>)
90505
+ // def calc_gamma(plan):
90506
+ // return (0.5 + plan.responsiveness * (plan.statewide_vote_share - 0.5) \
90507
+ // - (plan.predicted_D_seats / plan.districts)) \
90508
+ // * 100
90509
+ function calcGammaNEW(Vf, Sf, r) {
90510
+ const g = 0.5 + (r * (Vf - 0.5)) - Sf;
90511
+ return U.trim(g);
90512
+ }
90513
+ exports.calcGammaNEW = calcGammaNEW;
90499
90514
  // HELPERS
90500
90515
  function printPartisanScorecardHeader() {
90501
90516
  console.log('XX, Name, N, V%, ^S#, S#, B%, B$, UE#, I$, C#, Cd, Md, C$, <P$');
@@ -90523,7 +90538,7 @@ exports.printPartisanDetailsHeader = printPartisanDetailsHeader;
90523
90538
  function printPartisanDetailsRow(xx, name, N, Vf, s) {
90524
90539
  console.log('%s, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f', xx, Vf, s.bias.estSf, s.bias.bias, // Simple bias
90525
90540
  s.bias.bS50, s.bias.bV50, s.bias.decl, s.bias.gSym, s.bias.eG, s.bias.bSV, // Beta
90526
- s.bias.prop, // Lower-gamma
90541
+ s.bias.prop, // PR
90527
90542
  s.bias.mMs, s.bias.tOf, s.bias.mMd, s.bias.lO, s.competitiveness.rD, s.competitiveness.bigR, s.competitiveness.littleR, s.competitiveness.mIR // Zeta
90528
90543
  );
90529
90544
  }
@@ -90605,7 +90620,8 @@ function scorePlan(p, overridesJSON) {
90605
90620
  // score for comparing plans w/in a state
90606
90621
  let score = weightOverall(pS.score2, tpS.score, 1 /* WithinAState */);
90607
90622
  const mS = minority_1.evalMinorityOpportunity(p);
90608
- // Add minority bonus, keeping score it to the range [0–100]
90623
+ // Add minority bonus, keeping score to the range [0–100]
90624
+ const bonus = mS.score * (C.minorityBonus() / 100);
90609
90625
  score = mixinMinorityBonus(score, mS.score);
90610
90626
  // Roll up an overall scorecard
90611
90627
  const scorecard = {
@@ -90843,7 +90859,7 @@ module.exports = JSON.parse("{\"state\":\"NC\",\"planName\":\"NC 116th Congressi
90843
90859
  /*! exports provided: score, partisan, minority, traditionalPrinciples, details, default */
90844
90860
  /***/ (function(module) {
90845
90861
 
90846
- module.exports = JSON.parse("{\"score\":5,\"partisan\":{\"bias\":{\"bestS\":7,\"bestSf\":0.5385,\"estS\":4.1925,\"estSf\":0.3225,\"bias\":0.216,\"tOf\":-0.0023,\"fptpS\":3,\"bS50\":0.2172,\"bV50\":0.045,\"decl\":36.5164,\"gSym\":6.6602,\"eG\":0.2846,\"bSV\":0.2098,\"prop\":0.2695,\"mMd\":0.0593,\"mMs\":0.057,\"lO\":0.1106,\"score\":0},\"impact\":{\"unearnedS\":2.8075,\"score\":0},\"competitiveness\":{\"bigR\":-16.926,\"littleR\":4.3523,\"mIR\":0.1298,\"rD\":4.0207,\"rDf\":0.3093,\"cSimple\":6,\"cD\":0.7266,\"cDf\":0.0559,\"mRange\":[5,11],\"mD\":0.7134,\"mDf\":0.1019,\"score\":10},\"score\":3,\"score2\":2,\"details\":{\"election\":\"2016 Presidential, US Senate, Governor, and AG election results\"}},\"minority\":{\"report\":{\"bucketsByDemographic\":[[10,14],[3,0],[1,9],[0,0],[0,0],[0,0]],\"averageDVf\":0.6737588682747838},\"nProportional\":18,\"opportunityDistricts\":12.9424,\"score\":14,\"details\":{\"vap\":\"2010 Voting Age Population\"}},\"traditionalPrinciples\":{\"score\":18,\"compactness\":{\"score\":35,\"reock\":{\"raw\":0.3373,\"normalized\":35,\"notes\":{}},\"polsby\":{\"raw\":0.2418,\"normalized\":35,\"notes\":{}}},\"splitting\":{\"score\":0,\"county\":{\"raw\":1.1474,\"normalized\":0,\"notes\":{}},\"district\":{\"raw\":1.4839,\"normalized\":3,\"notes\":{}}},\"populationDeviation\":{\"raw\":0.016,\"normalized\":0,\"notes\":{\"maxDeviation\":11693}},\"details\":{\"countiesSplitUnexpectedly\":[\"Bladen\",\"Buncombe\",\"Catawba\",\"Cumberland\",\"Durham\",\"Guilford\",\"Iredell\",\"Johnston\",\"Pitt\",\"Rowan\",\"Wilson\"],\"unexpectedAffected\":0.3096,\"nSplitVTDs\":12,\"splitVTDs\":[\"VTD-01\",\"VTD-02\",\"VTD-03\",\"VTD-04\",\"VTD-05\",\"VTD-06\",\"VTD-07\",\"VTD-08\",\"VTD-09\",\"VTD-10\",\"VTD-11\",\"VTD-12\"],\"shapes\":\"2010 VTD shapes\",\"census\":\"2010 Census Total Population\"}},\"details\":{}}");
90862
+ module.exports = JSON.parse("{\"score\":5,\"partisan\":{\"bias\":{\"bestS\":7,\"bestSf\":0.5385,\"estS\":4.1925,\"estSf\":0.3225,\"bias\":0.216,\"tOf\":-0.0023,\"fptpS\":3,\"bS50\":0.2172,\"bV50\":0.045,\"decl\":36.5164,\"gSym\":0.066602,\"gamma\":0.0123,\"eG\":0.2846,\"bSV\":0.2098,\"prop\":0.2695,\"mMd\":0.0593,\"mMs\":0.057,\"lO\":0.1106,\"score\":0},\"impact\":{\"unearnedS\":2.8075,\"score\":0},\"competitiveness\":{\"bigR\":-16.926,\"littleR\":4.3523,\"mIR\":0.1298,\"rD\":4.0207,\"rDf\":0.3093,\"cSimple\":6,\"cD\":0.7266,\"cDf\":0.0559,\"mRange\":[5,11],\"mD\":0.7134,\"mDf\":0.1019,\"score\":10},\"score\":3,\"score2\":2,\"details\":{\"election\":\"2016 Presidential, US Senate, Governor, and AG election results\"}},\"minority\":{\"report\":{\"bucketsByDemographic\":[[10,14],[3,0],[1,9],[0,0],[0,0],[0,0]],\"averageDVf\":0.6737588682747838},\"nProportional\":18,\"opportunityDistricts\":12.9424,\"score\":14,\"details\":{\"vap\":\"2010 Voting Age Population\"}},\"traditionalPrinciples\":{\"score\":18,\"compactness\":{\"score\":35,\"reock\":{\"raw\":0.3373,\"normalized\":35,\"notes\":{}},\"polsby\":{\"raw\":0.2418,\"normalized\":35,\"notes\":{}}},\"splitting\":{\"score\":0,\"county\":{\"raw\":1.1474,\"normalized\":0,\"notes\":{}},\"district\":{\"raw\":1.4839,\"normalized\":3,\"notes\":{}}},\"populationDeviation\":{\"raw\":0.016,\"normalized\":0,\"notes\":{\"maxDeviation\":11693}},\"details\":{\"countiesSplitUnexpectedly\":[\"Bladen\",\"Buncombe\",\"Catawba\",\"Cumberland\",\"Durham\",\"Guilford\",\"Iredell\",\"Johnston\",\"Pitt\",\"Rowan\",\"Wilson\"],\"unexpectedAffected\":0.3096,\"nSplitVTDs\":12,\"splitVTDs\":[\"VTD-01\",\"VTD-02\",\"VTD-03\",\"VTD-04\",\"VTD-05\",\"VTD-06\",\"VTD-07\",\"VTD-08\",\"VTD-09\",\"VTD-10\",\"VTD-11\",\"VTD-12\"],\"shapes\":\"2010 VTD shapes\",\"census\":\"2010 Census Total Population\"}},\"details\":{}}");
90847
90863
 
90848
90864
  /***/ })
90849
90865