@dra2020/district-analytics 5.6.0 → 5.6.3
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/LICENSE +1 -1
- package/dist/cli.js +30 -22
- package/dist/cli.js.map +1 -1
- package/package.json +2 -2
package/LICENSE
CHANGED
package/dist/cli.js
CHANGED
|
@@ -89102,7 +89102,7 @@ exports.scorePolsbyPopper = scorePolsbyPopper;
|
|
|
89102
89102
|
/*! exports provided: partisan, minority, traditionalPrinciples, default */
|
|
89103
89103
|
/***/ (function(module) {
|
|
89104
89104
|
|
|
89105
|
-
module.exports = JSON.parse("{\"partisan\":{\"bias\":{\"range\":[0,0.2],\"weight\":[50,80]},\"impact\":{\"weight\":[50,0],\"threshold\":4},\"competitiveness\":{\"overall\":{\"range\":[0,0.67],\"weight\":100},\"marginal\":{\"range\":[0,0.85],\"weight\":0},\"range\":[0.45,0.55],\"distribution\":[0.25,0.75],\"weight\":[0,20]},\"bonus\":2,\"weight\":[100,80]},\"minority\":{\"range\":[0.37,0.5],\"distribution\":[0.25,0.75],\"shift\":0.15,\"bonus\":20},\"traditionalPrinciples\":{\"compactness\":{\"reock\":{\"range\":[0.25,0.5],\"weight\":50},\"polsby\":{\"range\":[0.1,0.5],\"weight\":50},\"weight\":[0,50]},\"splitting\":{\"county\":{\"range\":[[1.26,1.68],[1.
|
|
89105
|
+
module.exports = JSON.parse("{\"partisan\":{\"bias\":{\"range\":[0,0.2],\"weight\":[50,80]},\"impact\":{\"weight\":[50,0],\"threshold\":4},\"competitiveness\":{\"overall\":{\"range\":[0,0.67],\"weight\":100},\"marginal\":{\"range\":[0,0.85],\"weight\":0},\"range\":[0.45,0.55],\"distribution\":[0.25,0.75],\"weight\":[0,20]},\"bonus\":2,\"weight\":[100,80]},\"minority\":{\"range\":[0.37,0.5],\"distribution\":[0.25,0.75],\"shift\":0.15,\"bonus\":20},\"traditionalPrinciples\":{\"compactness\":{\"reock\":{\"range\":[0.25,0.5],\"weight\":50},\"polsby\":{\"range\":[0.1,0.5],\"weight\":50},\"weight\":[0,50]},\"splitting\":{\"county\":{\"range\":[[1.26,1.68],[1.09,1.45]],\"weight\":50},\"district\":{\"range\":[[1.26,1.68],[1.09,1.45]],\"weight\":50},\"weight\":[0,50]},\"popdev\":{\"range\":[[0.0075,0.002],[0.1,-1]],\"weight\":[0,0]},\"weight\":[0,20]}}");
|
|
89106
89106
|
|
|
89107
89107
|
/***/ }),
|
|
89108
89108
|
|
|
@@ -89745,10 +89745,10 @@ function scorePartisan(Vf, VfArray, options) {
|
|
|
89745
89745
|
// Calculate alternate responsiveness metrics for reference
|
|
89746
89746
|
const bigR = bAlternateMetrics ? calcBigR(Vf, estSf) : undefined;
|
|
89747
89747
|
const littleR = bAlternateMetrics ? estResponsiveness(Vf, inferredSVpoints) : undefined;
|
|
89748
|
-
const MIR = bAlternateMetrics ? calcMinimalInverseResponsiveness(Vf, littleR) : undefined;
|
|
89748
|
+
const MIR = (bAlternateMetrics && littleR) ? calcMinimalInverseResponsiveness(Vf, littleR) : undefined;
|
|
89749
89749
|
const rD = (!bConstrained || bAlternateMetrics) ? estResponsiveDistricts(VfArray) : undefined;
|
|
89750
89750
|
const rDf = bAlternateMetrics ? estResponsiveDistrictsShare(rD, N) : undefined;
|
|
89751
|
-
const gamma = bAlternateMetrics ?
|
|
89751
|
+
const gamma = (bAlternateMetrics && littleR) ? calcGamma(Vf, estSf, littleR) : undefined;
|
|
89752
89752
|
const Cn = countCompetitiveDistricts(VfArray);
|
|
89753
89753
|
const cD = estCompetitiveDistricts(VfArray); // NOTE - Cd by definition uses a more narrow probability distribution vs. Rd
|
|
89754
89754
|
// const cD = bConstrained ? estCompetitiveDistricts(VfArray) : rD as number;
|
|
@@ -89912,7 +89912,7 @@ function scoreCompetitiveness(rawMarginal, rawOverall) {
|
|
|
89912
89912
|
const mcW = C.marginalCompetitivenessWeight();
|
|
89913
89913
|
const ocW = C.overallCompetitivenessWeight();
|
|
89914
89914
|
// Then combine the results
|
|
89915
|
-
const score = Math.round(((mcW * mcS) + (ocW * ocS)) / (mcW + ocW));
|
|
89915
|
+
const score = ((mcW + ocW) > 0) ? Math.round(((mcW * mcS) + (ocW * ocS)) / (mcW + ocW)) : 0;
|
|
89916
89916
|
return score;
|
|
89917
89917
|
}
|
|
89918
89918
|
exports.scoreCompetitiveness = scoreCompetitiveness;
|
|
@@ -90058,15 +90058,17 @@ exports.estUnearnedSeats = estUnearnedSeats;
|
|
|
90058
90058
|
// ESTIMATE RESPONSIVENESS ("COMPETITIVE")
|
|
90059
90059
|
// R# - Estimate responsiveness at the statewide vote share
|
|
90060
90060
|
function estResponsiveness(Vf, inferredSVpoints) {
|
|
90061
|
-
let
|
|
90061
|
+
let r = undefined;
|
|
90062
90062
|
// NOTE - Seat values are already fractions [0.0–1.0] here.
|
|
90063
90063
|
const lowerPt = findBracketingLowerVf(Vf, inferredSVpoints);
|
|
90064
90064
|
const upperPt = findBracketingUpperVf(Vf, inferredSVpoints);
|
|
90065
|
-
if (
|
|
90066
|
-
|
|
90067
|
-
|
|
90065
|
+
if (lowerPt && upperPt) {
|
|
90066
|
+
if (!(U.areRoughlyEqual((upperPt.v - lowerPt.v), 0, S.EPSILON))) {
|
|
90067
|
+
r = ((upperPt.s - lowerPt.s) / (upperPt.v - lowerPt.v));
|
|
90068
|
+
r = U.trim(r);
|
|
90069
|
+
}
|
|
90068
90070
|
}
|
|
90069
|
-
return
|
|
90071
|
+
return r;
|
|
90070
90072
|
}
|
|
90071
90073
|
exports.estResponsiveness = estResponsiveness;
|
|
90072
90074
|
// Find the S(V) point that brackets a Vf value on the lower end
|
|
@@ -90261,30 +90263,36 @@ function estSeatBias(inferredSVpoints, nDistricts) {
|
|
|
90261
90263
|
exports.estSeatBias = estSeatBias;
|
|
90262
90264
|
// VOTES BIAS -- John Nagle's simple vote bias @ 50% (alpha2), a percentage.
|
|
90263
90265
|
function estVotesBias(inferredSVpoints, nDistricts) {
|
|
90264
|
-
let extraVf =
|
|
90266
|
+
let extraVf = undefined;
|
|
90265
90267
|
// Interpolate the extra Vf required @ Sf = 0.5
|
|
90266
90268
|
const lowerPt = findBracketingLowerSf(0.5, inferredSVpoints);
|
|
90267
90269
|
const upperPt = findBracketingUpperSf(0.5, inferredSVpoints);
|
|
90268
|
-
if (
|
|
90269
|
-
|
|
90270
|
-
|
|
90271
|
-
|
|
90270
|
+
if (lowerPt && upperPt) {
|
|
90271
|
+
extraVf = 0.0;
|
|
90272
|
+
if ((upperPt.s - lowerPt.s) != 0) {
|
|
90273
|
+
const ratio = (upperPt.v - lowerPt.v) / (upperPt.s - lowerPt.s);
|
|
90274
|
+
const deltaS = 0.5 - lowerPt.s;
|
|
90275
|
+
extraVf = lowerPt.v + (ratio * deltaS) - 0.5;
|
|
90276
|
+
}
|
|
90277
|
+
extraVf = U.trim(extraVf);
|
|
90272
90278
|
}
|
|
90273
|
-
extraVf = U.trim(extraVf);
|
|
90274
90279
|
return extraVf;
|
|
90275
90280
|
}
|
|
90276
90281
|
exports.estVotesBias = estVotesBias;
|
|
90277
90282
|
// GEOMETRIC SEATS BIAS (@ V = statewide vote share)
|
|
90278
90283
|
function estGeometricSeatsBias(Vf, inferredSVpoints) {
|
|
90284
|
+
let BsGf = undefined;
|
|
90279
90285
|
const bgsSVpoints = inferGeometricSeatsBiasPoints(inferredSVpoints);
|
|
90280
90286
|
// Interpolate the seat fraction @ Vf
|
|
90281
90287
|
const lowerPt = findBracketingLowerVf(Vf, bgsSVpoints);
|
|
90282
90288
|
const upperPt = findBracketingUpperVf(Vf, bgsSVpoints);
|
|
90283
|
-
|
|
90284
|
-
|
|
90285
|
-
|
|
90286
|
-
|
|
90287
|
-
|
|
90289
|
+
if (lowerPt && upperPt) {
|
|
90290
|
+
const ratio = (upperPt.s - lowerPt.s) / (upperPt.v - lowerPt.v);
|
|
90291
|
+
const deltaV = Vf - lowerPt.v;
|
|
90292
|
+
const deltaS = ratio * deltaV;
|
|
90293
|
+
BsGf = U.trim(lowerPt.s + deltaS);
|
|
90294
|
+
}
|
|
90295
|
+
return BsGf;
|
|
90288
90296
|
}
|
|
90289
90297
|
exports.estGeometricSeatsBias = estGeometricSeatsBias;
|
|
90290
90298
|
function inferGeometricSeatsBiasPoints(inferredSVpoints) {
|
|
@@ -90510,11 +90518,11 @@ function isBalanced(Vf) {
|
|
|
90510
90518
|
// return (0.5 + plan.responsiveness * (plan.statewide_vote_share - 0.5) \
|
|
90511
90519
|
// - (plan.predicted_D_seats / plan.districts)) \
|
|
90512
90520
|
// * 100
|
|
90513
|
-
function
|
|
90521
|
+
function calcGamma(Vf, Sf, r) {
|
|
90514
90522
|
const g = 0.5 + (r * (Vf - 0.5)) - Sf;
|
|
90515
90523
|
return U.trim(g);
|
|
90516
90524
|
}
|
|
90517
|
-
exports.
|
|
90525
|
+
exports.calcGamma = calcGamma;
|
|
90518
90526
|
// HELPERS
|
|
90519
90527
|
function printPartisanScorecardHeader() {
|
|
90520
90528
|
console.log('XX, Name, N, V%, ^S#, S#, B%, B$, UE#, I$, C#, Cd, Md, C$, <P$');
|