@dra2020/district-analytics 5.2.3 → 5.3.2

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;
@@ -90441,7 +90445,6 @@ function calcLopsidedOutcomes(VfArray) {
90441
90445
  return LO;
90442
90446
  }
90443
90447
  exports.calcLopsidedOutcomes = calcLopsidedOutcomes;
90444
- // TODO - Add unit tests <<< Depends on S(V)
90445
90448
  // GLOBAL SYMMETRY - Fig. 17 in Section 5.1
90446
90449
  function calcGlobalSymmetry(inferredSVpoints, S50V) {
90447
90450
  const invertedSVpoints = invertSVPoints(inferredSVpoints);
@@ -90451,19 +90454,18 @@ function calcGlobalSymmetry(inferredSVpoints, S50V) {
90451
90454
  }
90452
90455
  const sign = (S50V < 0) ? -1 : 1;
90453
90456
  gSym *= sign;
90454
- return U.trim(gSym);
90457
+ return U.trim(gSym / 100);
90455
90458
  }
90456
90459
  exports.calcGlobalSymmetry = calcGlobalSymmetry;
90457
90460
  // RAW DISPROPORTIONALITY
90458
90461
  //
90459
- // gamma = Sf – Vf : Eq.C.1.1 on P. 42
90462
+ // PR = Sf – Vf : Eq.C.1.1 on P. 42
90460
90463
  function calcDisproportionality(Vf, Sf) {
90461
- const gamma = Vf - Sf;
90462
- // const gamma = Sf - Vf;
90463
- return U.trim(gamma);
90464
+ const prop = Vf - Sf;
90465
+ // const prop = Sf - Vf;
90466
+ return U.trim(prop);
90464
90467
  }
90465
90468
  exports.calcDisproportionality = calcDisproportionality;
90466
- // TODO - Add unit tests <<< Depends on S(V)
90467
90469
  // BIG 'R': Defined in Footnote 22 on P. 10
90468
90470
  function calcBigR(Vf, Sf) {
90469
90471
  let bigR = undefined;
@@ -90474,7 +90476,6 @@ function calcBigR(Vf, Sf) {
90474
90476
  return bigR;
90475
90477
  }
90476
90478
  exports.calcBigR = calcBigR;
90477
- // TODO - Add unit tests <<< Depends on S(V)
90478
90479
  // MINIMAL INVERSE RESPONSIVENESS
90479
90480
  //
90480
90481
  // zeta = (1 / r) - (1 / r_sub_max) : Eq. 5.2.1
@@ -90496,6 +90497,17 @@ function isBalanced(Vf) {
90496
90497
  const bBalanced = ((Vf > upper) || (Vf < lower)) ? false : true;
90497
90498
  return bBalanced;
90498
90499
  }
90500
+ // GAMMA (NEW)
90501
+ // g = 50 + r<V>(<V>-50) – S(<V>)
90502
+ // def calc_gamma(plan):
90503
+ // return (0.5 + plan.responsiveness * (plan.statewide_vote_share - 0.5) \
90504
+ // - (plan.predicted_D_seats / plan.districts)) \
90505
+ // * 100
90506
+ function calcGammaNEW(Vf, Sf, r) {
90507
+ const g = 0.5 + (r * (Vf - 0.5)) - Sf;
90508
+ return U.trim(g);
90509
+ }
90510
+ exports.calcGammaNEW = calcGammaNEW;
90499
90511
  // HELPERS
90500
90512
  function printPartisanScorecardHeader() {
90501
90513
  console.log('XX, Name, N, V%, ^S#, S#, B%, B$, UE#, I$, C#, Cd, Md, C$, <P$');
@@ -90523,7 +90535,7 @@ exports.printPartisanDetailsHeader = printPartisanDetailsHeader;
90523
90535
  function printPartisanDetailsRow(xx, name, N, Vf, s) {
90524
90536
  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
90537
  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
90538
+ s.bias.prop, // PR
90527
90539
  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
90540
  );
90529
90541
  }
@@ -90605,8 +90617,9 @@ function scorePlan(p, overridesJSON) {
90605
90617
  // score for comparing plans w/in a state
90606
90618
  let score = weightOverall(pS.score2, tpS.score, 1 /* WithinAState */);
90607
90619
  const mS = minority_1.evalMinorityOpportunity(p);
90608
- // Add minority bonus, keeping score it to the range [0–100]
90609
- score = mixinMinorityBonus(score, mS.score);
90620
+ // Add minority bonus, keeping score to the range [0–100]
90621
+ const bonus = C.minorityBonus() * (mS.score / 100);
90622
+ score = mixinMinorityBonus(score, bonus);
90610
90623
  // Roll up an overall scorecard
90611
90624
  const scorecard = {
90612
90625
  partisan: pS,
@@ -90843,7 +90856,7 @@ module.exports = JSON.parse("{\"state\":\"NC\",\"planName\":\"NC 116th Congressi
90843
90856
  /*! exports provided: score, partisan, minority, traditionalPrinciples, details, default */
90844
90857
  /***/ (function(module) {
90845
90858
 
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\":{}}");
90859
+ 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
90860
 
90848
90861
  /***/ })
90849
90862