@dra2020/district-analytics 7.0.0 → 7.1.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
@@ -89649,11 +89649,8 @@ const C = __importStar(__webpack_require__(/*! ./config */ "./src/config.ts"));
89649
89649
  const normalize_1 = __webpack_require__(/*! ./normalize */ "./src/normalize.ts");
89650
89650
  // NOTE - I'm passing T.VfArray's into everything. District indices = array indices.
89651
89651
  // NOTE - I do not (cannot) assume that the values are sorted.
89652
- // TODO - Revise this.
89653
89652
  // SCORE BIAS & COMPETITIVENESS
89654
- /* SCORECARD FIELDS:
89655
-
89656
- * ??? [statewideV] (V) = the average statewide two-party vote for Democrats
89653
+ /* Report fields:
89657
89654
 
89658
89655
  * ^S# [bestS] = the Democratic seats closest to proportional
89659
89656
  * ^S% [bestSf] = the corresponding Democratic seat share
@@ -89707,10 +89704,11 @@ function scorePartisan(Vf, VfArray, options) {
89707
89704
  const estSf = estSeatShare(estS, N);
89708
89705
  const deviation = estDeviation(estSf, bestSf);
89709
89706
  const proportionalityScore = scoreDeviation(deviation, Vf, estSf);
89707
+ const unearnedS = estUnearnedSeats(bestS, estS);
89708
+ const impactScore = scoreImpact(unearnedS, Vf, estSf, N);
89710
89709
  // Calculate additional alternate metrics for reference
89711
89710
  const dSVpoints = inferSVpoints(Vf, VfArray, shift);
89712
89711
  const rSVpoints = invertSVPoints(dSVpoints);
89713
- // const dSVpoints = bAdvanced ? inferSVpoints(Vf, VfArray, shift) : undefined;
89714
89712
  const TOf = bAdvanced ? calcTurnoutBias(Vf, VfArray) : undefined;
89715
89713
  const Bs50 = bAdvanced ? estPartisanBias(dSVpoints, N) : undefined;
89716
89714
  const Bs50f = (!(Bs50 === undefined)) ? U.trim(Bs50 / N) : undefined;
@@ -89745,6 +89743,10 @@ function scorePartisan(Vf, VfArray, options) {
89745
89743
  deviation: deviation,
89746
89744
  score: proportionalityScore
89747
89745
  };
89746
+ const impactScoring = {
89747
+ unearnedS: unearnedS,
89748
+ score: impactScore
89749
+ };
89748
89750
  let competitiveScoring = {
89749
89751
  cSimple: Cn,
89750
89752
  cD: cD,
@@ -89778,6 +89780,7 @@ function scorePartisan(Vf, VfArray, options) {
89778
89780
  const averageRVf = (RWins.length > 0) ? U.avgArray(RWins) : undefined;
89779
89781
  const s = {
89780
89782
  bias: biasScoring,
89783
+ impact: impactScoring,
89781
89784
  responsiveness: competitiveScoring,
89782
89785
  dSVpoints: dSVpoints,
89783
89786
  rSVpoints: rSVpoints,
@@ -89878,44 +89881,6 @@ function scoreCompetitiveness(Cdf) {
89878
89881
  return score;
89879
89882
  }
89880
89883
  exports.scoreCompetitiveness = scoreCompetitiveness;
89881
- /* NOTE - Original version:
89882
- export function scoreCompetitiveness(rawMarginal: number, rawOverall: number): number
89883
- {
89884
- // Normalize overall competitiveness - Raw values are in the range [0.0–1.0].
89885
- // But the practical max is more like 2/3's, so unitize that range to [0.0–1.0].
89886
- // Then scale the values to [0–100].
89887
- const _overall = new Normalizer(rawOverall);
89888
-
89889
- let worst = C.overallCompetitivenessRange()[C.BEG];
89890
- let best = C.overallCompetitivenessRange()[C.END];
89891
-
89892
- _overall.clip(worst, best);
89893
- _overall.unitize(worst, best);
89894
- _overall.rescale();
89895
-
89896
- const ocS = _overall.normalizedNum as number;
89897
-
89898
-
89899
- // Normalize marginal competitiveness
89900
- const _marginal = new Normalizer(rawMarginal);
89901
-
89902
- worst = C.marginalCompetitivenessRange()[C.BEG];
89903
- best = C.marginalCompetitivenessRange()[C.END];
89904
-
89905
- _marginal.clip(worst, best);
89906
- _marginal.unitize(worst, best);
89907
- _marginal.rescale();
89908
- const mcS = _marginal.normalizedNum as number;
89909
-
89910
- const mcW = C.marginalCompetitivenessWeight();
89911
- const ocW = C.overallCompetitivenessWeight();
89912
-
89913
- // Then combine the results
89914
- const score = ((mcW + ocW) > 0) ? Math.round(((mcW * mcS) + (ocW * ocS)) / (mcW + ocW)) : 0;
89915
-
89916
- return score;
89917
- }
89918
- */
89919
89884
  // CORE CAPABILITIES FROM JOHN NAGLE'S METHOD
89920
89885
  const { erf } = __webpack_require__(/*! mathjs */ "./node_modules/mathjs/main/esm/index.js");
89921
89886
  // console.log("erf(0.2) =", erf(0.2)); // returns 0.22270258921047847
@@ -104314,9 +104279,9 @@ function doAnalyzePostProcessing(s, bLog = false) {
104314
104279
  scorecard.details['shapes'] = datasets.shapes;
104315
104280
  scorecard.details['census'] = datasets.census;
104316
104281
  const simpleSplits = s.getTest(5 /* UnexpectedCountySplits */);
104317
- scorecard.compactness.details['unexpectedAffected'] = simpleSplits['score'];
104318
- scorecard.compactness.details['nSplits'] = simpleSplits['details']['nSplits'];
104319
- scorecard.compactness.details['countiesSplitUnexpectedly'] = U.deepCopy(simpleSplits['details']['countiesSplitUnexpectedly']);
104282
+ scorecard.splitting.details['unexpectedAffected'] = simpleSplits['score'];
104283
+ scorecard.splitting.details['nSplits'] = simpleSplits['details']['nSplits'];
104284
+ scorecard.splitting.details['countiesSplitUnexpectedly'] = U.deepCopy(simpleSplits['details']['countiesSplitUnexpectedly']);
104320
104285
  // NOTE - Add split precincts in dra-client directly
104321
104286
  // Derive secondary tests
104322
104287
  analyze_1.doDeriveSecondaryTests(s, bLog);