@dra2020/district-analytics 6.3.1 → 7.1.1
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 +116 -294
- package/dist/cli.js.map +1 -1
- package/dist/district-analytics.js +11 -11
- package/dist/district-analytics.js.map +1 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -89099,10 +89099,10 @@ exports.scorePolsbyPopper = scorePolsbyPopper;
|
|
|
89099
89099
|
/*!*************************!*\
|
|
89100
89100
|
!*** ./src/config.json ***!
|
|
89101
89101
|
\*************************/
|
|
89102
|
-
/*! exports provided: partisan, minority,
|
|
89102
|
+
/*! exports provided: partisan, minority, compactness, splitting, popdev, 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\":{\"range\":[0,0.75],\"distribution\":[0.25,0.75],\"simpleRange\":[0.45,0.55],\"weight\":[0,20]},\"bonus\":2
|
|
89105
|
+
module.exports = JSON.parse("{\"partisan\":{\"bias\":{\"range\":[0,0.2],\"weight\":[50,80]},\"impact\":{\"weight\":[50,0],\"threshold\":4},\"competitiveness\":{\"range\":[0,0.75],\"distribution\":[0.25,0.75],\"simpleRange\":[0.45,0.55],\"weight\":[0,20]},\"bonus\":2},\"minority\":{\"range\":[0.37,0.5],\"distribution\":[0.25,0.75],\"shift\":0.15,\"coalition\":{\"weight\":0.5}},\"compactness\":{\"reock\":{\"range\":[0.25,0.5],\"weight\":50},\"polsby\":{\"range\":[0.1,0.5],\"weight\":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}},\"popdev\":{\"range\":[[0.0075,0.002],[0.1,-1]]}}");
|
|
89106
89106
|
|
|
89107
89107
|
/***/ }),
|
|
89108
89108
|
|
|
@@ -89118,7 +89118,8 @@ module.exports = JSON.parse("{\"partisan\":{\"bias\":{\"range\":[0,0.2],\"weight
|
|
|
89118
89118
|
//
|
|
89119
89119
|
// THRESHOLDS, SCALES, AND WEIGHTS FOR SCORING MODEL
|
|
89120
89120
|
//
|
|
89121
|
-
// * A layer of functions over config.json, so that they
|
|
89121
|
+
// * A layer of functions over config.json, so that they could be overridden dynamically.
|
|
89122
|
+
// That is not implemented yet.
|
|
89122
89123
|
//
|
|
89123
89124
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
89124
89125
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -89160,7 +89161,7 @@ function competitivenessWeight(context, overridesJSON) {
|
|
|
89160
89161
|
return cW;
|
|
89161
89162
|
}
|
|
89162
89163
|
exports.competitivenessWeight = competitivenessWeight;
|
|
89163
|
-
//
|
|
89164
|
+
// The simple user-facing range, i.e., 45–55%.
|
|
89164
89165
|
function competitiveRange(overridesJSON) {
|
|
89165
89166
|
const range = config_json_1.default.partisan.competitiveness.simpleRange;
|
|
89166
89167
|
return range;
|
|
@@ -89171,9 +89172,9 @@ function competitiveDistribution(overridesJSON) {
|
|
|
89171
89172
|
return dist;
|
|
89172
89173
|
}
|
|
89173
89174
|
exports.competitiveDistribution = competitiveDistribution;
|
|
89174
|
-
//
|
|
89175
|
-
//
|
|
89176
|
-
//
|
|
89175
|
+
// The more complex internal range for normalizing Cdf.
|
|
89176
|
+
// * 06/23/2020 - As part of relaxing the competitive range, I changed this max
|
|
89177
|
+
// from 0.67 to 0.75.
|
|
89177
89178
|
function overallCompetitivenessRange(overridesJSON) {
|
|
89178
89179
|
const range = config_json_1.default.partisan.competitiveness.range;
|
|
89179
89180
|
return range;
|
|
@@ -89181,17 +89182,17 @@ function overallCompetitivenessRange(overridesJSON) {
|
|
|
89181
89182
|
exports.overallCompetitivenessRange = overallCompetitivenessRange;
|
|
89182
89183
|
// export function marginalCompetitivenessRange(overridesJSON?: any): number[]
|
|
89183
89184
|
// {
|
|
89184
|
-
// const range = config.partisan.
|
|
89185
|
+
// const range = config.partisan.responsiveness.marginal.range;
|
|
89185
89186
|
// return range;
|
|
89186
89187
|
// }
|
|
89187
89188
|
// export function marginalCompetitivenessWeight(overridesJSON?: any): number
|
|
89188
89189
|
// {
|
|
89189
|
-
// const mcW = config.partisan.
|
|
89190
|
+
// const mcW = config.partisan.responsiveness.marginal.weight;
|
|
89190
89191
|
// return mcW;
|
|
89191
89192
|
// }
|
|
89192
89193
|
// export function overallCompetitivenessWeight(overridesJSON?: any): number
|
|
89193
89194
|
// {
|
|
89194
|
-
// const ocW = config.partisan.
|
|
89195
|
+
// const ocW = config.partisan.responsiveness.overall.weight;
|
|
89195
89196
|
// return ocW;
|
|
89196
89197
|
// }
|
|
89197
89198
|
// MINORITY
|
|
@@ -89215,74 +89216,55 @@ function coalitionDistrictWeight(overridesJSON) {
|
|
|
89215
89216
|
return weight;
|
|
89216
89217
|
}
|
|
89217
89218
|
exports.coalitionDistrictWeight = coalitionDistrictWeight;
|
|
89218
|
-
|
|
89219
|
-
const bonus = config_json_1.default.minority.bonus;
|
|
89220
|
-
return bonus;
|
|
89221
|
-
}
|
|
89222
|
-
exports.minorityBonus = minorityBonus;
|
|
89223
|
-
// TRADITIONAL DISTRICTING PRINCIPLES
|
|
89224
|
-
function compactnessWeight(context, overridesJSON) {
|
|
89225
|
-
const cW = config_json_1.default.traditionalPrinciples.compactness.weight[context];
|
|
89226
|
-
return cW;
|
|
89227
|
-
}
|
|
89228
|
-
exports.compactnessWeight = compactnessWeight;
|
|
89219
|
+
// COMPACTNESS
|
|
89229
89220
|
function reockWeight(overridesJSON) {
|
|
89230
|
-
const rW = config_json_1.default.
|
|
89221
|
+
const rW = config_json_1.default.compactness.reock.weight;
|
|
89231
89222
|
return rW;
|
|
89232
89223
|
}
|
|
89233
89224
|
exports.reockWeight = reockWeight;
|
|
89234
89225
|
function reockRange(overridesJSON) {
|
|
89235
|
-
const range = config_json_1.default.
|
|
89226
|
+
const range = config_json_1.default.compactness.reock.range;
|
|
89236
89227
|
return range;
|
|
89237
89228
|
}
|
|
89238
89229
|
exports.reockRange = reockRange;
|
|
89239
89230
|
function polsbyWeight(overridesJSON) {
|
|
89240
|
-
const ppW = config_json_1.default.
|
|
89231
|
+
const ppW = config_json_1.default.compactness.polsby.weight;
|
|
89241
89232
|
return ppW;
|
|
89242
89233
|
}
|
|
89243
89234
|
exports.polsbyWeight = polsbyWeight;
|
|
89244
89235
|
function polsbyRange(overridesJSON) {
|
|
89245
|
-
const range = config_json_1.default.
|
|
89236
|
+
const range = config_json_1.default.compactness.polsby.range;
|
|
89246
89237
|
return range;
|
|
89247
89238
|
}
|
|
89248
89239
|
exports.polsbyRange = polsbyRange;
|
|
89249
|
-
|
|
89250
|
-
const sW = config_json_1.default.traditionalPrinciples.splitting.weight[context];
|
|
89251
|
-
return sW;
|
|
89252
|
-
}
|
|
89253
|
-
exports.splittingWeight = splittingWeight;
|
|
89240
|
+
// SPLITTING
|
|
89254
89241
|
function countySplittingWeight(overridesJSON) {
|
|
89255
|
-
const csW = config_json_1.default.
|
|
89242
|
+
const csW = config_json_1.default.splitting.county.weight;
|
|
89256
89243
|
return csW;
|
|
89257
89244
|
}
|
|
89258
89245
|
exports.countySplittingWeight = countySplittingWeight;
|
|
89259
89246
|
function countySplittingRange(d, overridesJSON) {
|
|
89260
|
-
const range = config_json_1.default.
|
|
89247
|
+
const range = config_json_1.default.splitting.county.range[d];
|
|
89261
89248
|
return range;
|
|
89262
89249
|
}
|
|
89263
89250
|
exports.countySplittingRange = countySplittingRange;
|
|
89264
89251
|
function districtSplittingWeight(overridesJSON) {
|
|
89265
|
-
const dsW = config_json_1.default.
|
|
89252
|
+
const dsW = config_json_1.default.splitting.district.weight;
|
|
89266
89253
|
return dsW;
|
|
89267
89254
|
}
|
|
89268
89255
|
exports.districtSplittingWeight = districtSplittingWeight;
|
|
89269
89256
|
function districtSplittingRange(d, overridesJSON) {
|
|
89270
|
-
const range = config_json_1.default.
|
|
89257
|
+
const range = config_json_1.default.splitting.district.range[d];
|
|
89271
89258
|
return range;
|
|
89272
89259
|
}
|
|
89273
89260
|
exports.districtSplittingRange = districtSplittingRange;
|
|
89274
|
-
function popdevWeight(context, overridesJSON) {
|
|
89275
|
-
const pdW = config_json_1.default.traditionalPrinciples.popdev.weight[context];
|
|
89276
|
-
return pdW;
|
|
89277
|
-
}
|
|
89278
|
-
exports.popdevWeight = popdevWeight;
|
|
89279
89261
|
// NOTE - Raw ranges, not inverted (i.e., smaller is better)
|
|
89280
89262
|
// NOTE - This could be optimized to not calc LD values for CD's (or do it once)
|
|
89281
89263
|
function popdevRange(bLegislative, overridesJSON) {
|
|
89282
|
-
const cdRange = config_json_1.default.
|
|
89264
|
+
const cdRange = config_json_1.default.popdev.range[0 /* Congressional */];
|
|
89283
89265
|
const worstCD = cdRange[exports.BEG];
|
|
89284
89266
|
const bestCD = cdRange[exports.END];
|
|
89285
|
-
const ldRange = config_json_1.default.
|
|
89267
|
+
const ldRange = config_json_1.default.popdev.range[1 /* StateLegislative */];
|
|
89286
89268
|
const iRange = bLegislative ? ldRange : cdRange;
|
|
89287
89269
|
const worst = iRange[exports.BEG];
|
|
89288
89270
|
const best = bLegislative ? (bestCD / worstCD) * iRange[exports.BEG] : iRange[exports.END];
|
|
@@ -89296,17 +89278,6 @@ function popdevThreshold(bLegislative, overridesJSON) {
|
|
|
89296
89278
|
return threshold;
|
|
89297
89279
|
}
|
|
89298
89280
|
exports.popdevThreshold = popdevThreshold;
|
|
89299
|
-
// OVERALL SCORE
|
|
89300
|
-
function partisanWeight(context, overridesJSON) {
|
|
89301
|
-
const pW = config_json_1.default.partisan.weight[context];
|
|
89302
|
-
return pW;
|
|
89303
|
-
}
|
|
89304
|
-
exports.partisanWeight = partisanWeight;
|
|
89305
|
-
function traditionalPrinciplesWeight(context, overridesJSON) {
|
|
89306
|
-
const tpW = config_json_1.default.traditionalPrinciples.weight[context];
|
|
89307
|
-
return tpW;
|
|
89308
|
-
}
|
|
89309
|
-
exports.traditionalPrinciplesWeight = traditionalPrinciplesWeight;
|
|
89310
89281
|
|
|
89311
89282
|
|
|
89312
89283
|
/***/ }),
|
|
@@ -89431,19 +89402,12 @@ const C = __importStar(__webpack_require__(/*! ./config */ "./src/config.ts"));
|
|
|
89431
89402
|
const normalize_1 = __webpack_require__(/*! ./normalize */ "./src/normalize.ts");
|
|
89432
89403
|
const partisan_1 = __webpack_require__(/*! ./partisan */ "./src/partisan.ts");
|
|
89433
89404
|
function evalMinorityOpportunity(p, bLog = false) {
|
|
89434
|
-
// Calculate average Democratic win share
|
|
89435
|
-
const VfArray = p.partisanProfile.vfArray;
|
|
89436
|
-
const DWins = VfArray.filter(x => x > 0.5);
|
|
89437
|
-
const RWins = VfArray.filter(x => x <= 0.5); // Ties credited to R's
|
|
89438
|
-
const averageDVf = (DWins.length > 0) ? U.avgArray(DWins) : undefined;
|
|
89439
|
-
const averageRVf = (RWins.length > 0) ? U.avgArray(RWins) : undefined;
|
|
89440
89405
|
// Initialize arrays for results
|
|
89441
89406
|
const offset = 1; // Don't process 'White'
|
|
89442
89407
|
const nDemos = 6 /* Total */; // Ditto
|
|
89443
89408
|
// const nDemos = T.DemographicField.Native + 1 - offset; // Ditto
|
|
89444
89409
|
const demosByDistrict = p.demographicProfile.mfArrayByDistrict;
|
|
89445
89410
|
// Initialize the demographic buckets
|
|
89446
|
-
// COMPETITIVENESS - 06/23/2020 - And populate the statewide values.
|
|
89447
89411
|
// Get the statewide minority VAP/CVAP % (ignore 'White')
|
|
89448
89412
|
const vapPctArray = p.demographicProfile.stateMfArray.slice(1);
|
|
89449
89413
|
// Determine proportional minority districts by demographic (ignoring'White')
|
|
@@ -89486,25 +89450,14 @@ function evalMinorityOpportunity(p, bLog = false) {
|
|
|
89486
89450
|
// The # of opportunity districts for each separate demographic and all minorities
|
|
89487
89451
|
const oD = U.sumArray(opptyByDemo.slice(1)); // Sum individual demos, skipping all minorities
|
|
89488
89452
|
const cD = opptyByDemo[0 /* Minority */]; // All minorities
|
|
89489
|
-
// const cD: number = opptyByDemo[T.DemographicField.Minority - offset]; // All minorities
|
|
89490
89453
|
// The # of proportional districts for each separate demographic and all minorities
|
|
89491
89454
|
const pOd = bucketsByDemo[6 /* Total */][4 /* PropSeats */];
|
|
89492
89455
|
const pCd = bucketsByDemo[0 /* Minority */][4 /* PropSeats */];
|
|
89493
|
-
// const pOd: number = bucketsByDemo[T.DemographicField.Total - 1][T.PivotField.PropSeats];
|
|
89494
|
-
// const pCd: number = bucketsByDemo[T.DemographicField.Minority - 1][T.PivotField.PropSeats];
|
|
89495
|
-
// const pOd: number = U.sumArray(districtsByDemo.slice(1)); // Sum individual demos, skipping all minorities
|
|
89496
|
-
// const pCd: number = districtsByDemo[0]; // All minorities
|
|
89497
89456
|
// Score opportunity
|
|
89498
89457
|
const score = scoreMinority(oD, pOd, cD, pCd);
|
|
89499
89458
|
let mS = {
|
|
89500
|
-
|
|
89501
|
-
averageDVf: averageDVf,
|
|
89502
|
-
averageRVf: averageRVf,
|
|
89503
|
-
bucketsByDemographic: bucketsByDemo
|
|
89504
|
-
},
|
|
89505
|
-
// proportionalOpportunities: pOd,
|
|
89459
|
+
pivotByDemographic: bucketsByDemo,
|
|
89506
89460
|
opportunityDistricts: oD,
|
|
89507
|
-
// proportionalCoalitions: pCd,
|
|
89508
89461
|
coalitionDistricts: cD,
|
|
89509
89462
|
score: score,
|
|
89510
89463
|
details: {}
|
|
@@ -89517,14 +89470,13 @@ exports.evalMinorityOpportunity = evalMinorityOpportunity;
|
|
|
89517
89470
|
// how minority opportunities are estimated (so that 37% minority shares score
|
|
89518
89471
|
// like 52% share).
|
|
89519
89472
|
function scoreMinority(oD, pOd, cD, pCd) {
|
|
89520
|
-
// Score minority opportunity [0–100]
|
|
89521
|
-
const bonus = 100; // C.minorityBonus();
|
|
89473
|
+
// Score minority opportunity [0–100]
|
|
89522
89474
|
const cDWeight = C.coalitionDistrictWeight();
|
|
89523
89475
|
// Cap opportunity & coalition districts
|
|
89524
89476
|
const oDCapped = Math.min(oD, pOd);
|
|
89525
89477
|
const cdCapped = Math.min(cD, pCd);
|
|
89526
|
-
const opportunityScore = (pOd > 0) ? Math.round((oDCapped / pOd) *
|
|
89527
|
-
const coalitionScore = (pCd > 0) ? Math.round((cdCapped / pCd) *
|
|
89478
|
+
const opportunityScore = (pOd > 0) ? Math.round((oDCapped / pOd) * 100) : 0;
|
|
89479
|
+
const coalitionScore = (pCd > 0) ? Math.round((cdCapped / pCd) * 100) : 0;
|
|
89528
89480
|
const score = Math.round(Math.min(opportunityScore + cDWeight * Math.max(coalitionScore - opportunityScore, 0), 100));
|
|
89529
89481
|
return score;
|
|
89530
89482
|
}
|
|
@@ -89565,7 +89517,6 @@ function exceedsMaximumThreshold(Mf) {
|
|
|
89565
89517
|
return Mf > threshold;
|
|
89566
89518
|
}
|
|
89567
89519
|
function calcProportionalDistricts(proportion, nDistricts) {
|
|
89568
|
-
// TODO - Maybe bump up to get a statewide proportion on the bubble to rate one district?
|
|
89569
89520
|
const roundUp = 0.0;
|
|
89570
89521
|
const fractional = proportion * nDistricts;
|
|
89571
89522
|
const integral = Math.round(fractional + roundUp);
|
|
@@ -89617,7 +89568,6 @@ class Normalizer {
|
|
|
89617
89568
|
}
|
|
89618
89569
|
// Invert a value in the unit range [0.0–1.0] (so that bigger is better).
|
|
89619
89570
|
invert() {
|
|
89620
|
-
// TODO - DAVID: Can we make this throw an Error and expect that in unit test?
|
|
89621
89571
|
console.assert(((this.wipNum >= 0.0) && (this.wipNum <= 1.0)), "Inverting: " + S.OUT_OF_RANGE_MSG, this.wipNum);
|
|
89622
89572
|
this.wipNum = 1.0 - this.wipNum;
|
|
89623
89573
|
return this.wipNum;
|
|
@@ -89641,7 +89591,6 @@ class Normalizer {
|
|
|
89641
89591
|
unitize(begin_range, end_range) {
|
|
89642
89592
|
const min_range = Math.min(begin_range, end_range);
|
|
89643
89593
|
const max_range = Math.max(begin_range, end_range);
|
|
89644
|
-
// TODO - DAVID: Can we make this throw an Error and expect that in unit test?
|
|
89645
89594
|
console.assert(((this.wipNum >= min_range) && (this.wipNum <= max_range)), "Unitizing: " + S.OUT_OF_RANGE_MSG, this.wipNum);
|
|
89646
89595
|
const ranged = this.wipNum - min_range;
|
|
89647
89596
|
this.wipNum = Math.abs(ranged / (end_range - begin_range));
|
|
@@ -89651,7 +89600,6 @@ class Normalizer {
|
|
|
89651
89600
|
// NOTE - If the range is already such that "bigger is better," then the closer
|
|
89652
89601
|
// the value is to 1.0 (the best) the *less* it will decay.
|
|
89653
89602
|
decay(fn = 0 /* Gravity */) {
|
|
89654
|
-
// TODO - DAVID: Can we make this throw an Error and expect that in unit test?
|
|
89655
89603
|
console.assert(((this.wipNum >= 0.0) && (this.wipNum <= 1.0)), "Decaying: " + S.OUT_OF_RANGE_MSG, this.wipNum);
|
|
89656
89604
|
switch (fn) {
|
|
89657
89605
|
case 0 /* Gravity */: {
|
|
@@ -89665,7 +89613,6 @@ class Normalizer {
|
|
|
89665
89613
|
}
|
|
89666
89614
|
// Translate a value in the unit range to the user-friendly range [0 – 100].
|
|
89667
89615
|
rescale() {
|
|
89668
|
-
// TODO - DAVID: Can we make this throw an Error and expect that in unit test?
|
|
89669
89616
|
console.assert(((this.wipNum >= 0.0) && (this.wipNum <= 1.0)), "Rescaling: " + S.OUT_OF_RANGE_MSG, this.wipNum);
|
|
89670
89617
|
this.normalizedNum = Math.round(this.wipNum * S.NORMALIZED_RANGE);
|
|
89671
89618
|
return this.normalizedNum;
|
|
@@ -89703,10 +89650,7 @@ const normalize_1 = __webpack_require__(/*! ./normalize */ "./src/normalize.ts")
|
|
|
89703
89650
|
// NOTE - I'm passing T.VfArray's into everything. District indices = array indices.
|
|
89704
89651
|
// NOTE - I do not (cannot) assume that the values are sorted.
|
|
89705
89652
|
// SCORE BIAS & COMPETITIVENESS
|
|
89706
|
-
/*
|
|
89707
|
-
|
|
89708
|
-
* ??? [statewideV] (V) = the average statewide two-party vote for Democrats
|
|
89709
|
-
|
|
89653
|
+
/* Report fields:
|
|
89710
89654
|
|
|
89711
89655
|
* ^S# [bestS] = the Democratic seats closest to proportional
|
|
89712
89656
|
* ^S% [bestSf] = the corresponding Democratic seat share
|
|
@@ -89718,7 +89662,7 @@ const normalize_1 = __webpack_require__(/*! ./normalize */ "./src/normalize.ts")
|
|
|
89718
89662
|
* BV_50 [bV50] = Votes bias as a fraction
|
|
89719
89663
|
* decl [decl] = Declination
|
|
89720
89664
|
* GS [gSym] = Global symmetry
|
|
89721
|
-
* ?? [gamma] = TODO
|
|
89665
|
+
* ?? [gamma] = TODO: describe
|
|
89722
89666
|
|
|
89723
89667
|
* EG [EG] = Efficiency gap as a fraction
|
|
89724
89668
|
* BS_V [bSV] = Seats bias @ <V> (geometric)
|
|
@@ -89731,9 +89675,6 @@ const normalize_1 = __webpack_require__(/*! ./normalize */ "./src/normalize.ts")
|
|
|
89731
89675
|
* B% [bias] = the bias calculated as S% – ^S%
|
|
89732
89676
|
* B$ [bias.score] = the bias score normalized [0–100]
|
|
89733
89677
|
|
|
89734
|
-
* UE# [unearnedS] = the number of unearned seats (R = positive; D = negative)
|
|
89735
|
-
* I$ [impact.score] -- the unearned seats normalized [0–100] as impact
|
|
89736
|
-
|
|
89737
89678
|
* R [bigR] = Overall responsiveness or winner’s bonus
|
|
89738
89679
|
* r [littleR] = The point responsiveness at V% (the slope of the S(V) curve at <V>)
|
|
89739
89680
|
* MIR [MIR] = Minimal inverse responsiveness
|
|
@@ -89748,70 +89689,59 @@ const normalize_1 = __webpack_require__(/*! ./normalize */ "./src/normalize.ts")
|
|
|
89748
89689
|
* Md% [mDf] = the probability that the marginal seats will flip, so S% => ^S%
|
|
89749
89690
|
* C$ [competitiveness.score] = the competitiveness score normalized [0–100]
|
|
89750
89691
|
|
|
89751
|
-
* <P$ [score] = the combined partisan score used to compare plans *across* states
|
|
89752
|
-
* >P$ [score2] = the combined partisan score used to compare plans *within* a state, along with traditional districting principles
|
|
89753
|
-
|
|
89754
89692
|
*/
|
|
89755
89693
|
function scorePartisan(Vf, VfArray, options) {
|
|
89756
|
-
const
|
|
89694
|
+
const bAdvanced = options.advanced;
|
|
89757
89695
|
const bConstrained = options.constrained;
|
|
89758
89696
|
const shift = options.shift;
|
|
89759
89697
|
const N = VfArray.length;
|
|
89760
89698
|
const bestS = bestSeats(N, Vf);
|
|
89761
89699
|
const bestSf = bestSeatShare(bestS, N);
|
|
89762
|
-
const fptpS =
|
|
89763
|
-
//
|
|
89700
|
+
const fptpS = bAdvanced ? estFPTPSeats(VfArray) : undefined;
|
|
89701
|
+
// When not constrained, use the full probability distribution to calc metrics.
|
|
89764
89702
|
const range = bConstrained ? C.competitiveDistribution() : undefined;
|
|
89765
89703
|
const estS = estSeats(VfArray, range);
|
|
89766
89704
|
const estSf = estSeatShare(estS, N);
|
|
89767
|
-
const
|
|
89768
|
-
const
|
|
89705
|
+
const deviation = estDeviation(estSf, bestSf);
|
|
89706
|
+
const proportionalityScore = scoreDeviation(deviation, Vf, estSf);
|
|
89769
89707
|
const unearnedS = estUnearnedSeats(bestS, estS);
|
|
89770
89708
|
const impactScore = scoreImpact(unearnedS, Vf, estSf, N);
|
|
89771
89709
|
// Calculate additional alternate metrics for reference
|
|
89772
|
-
// NOTE - Use the uncompressed seat probability function
|
|
89773
89710
|
const dSVpoints = inferSVpoints(Vf, VfArray, shift);
|
|
89774
89711
|
const rSVpoints = invertSVPoints(dSVpoints);
|
|
89775
|
-
|
|
89776
|
-
const
|
|
89777
|
-
const Bs50 = bAlternateMetrics ? estPartisanBias(dSVpoints, N) : undefined;
|
|
89712
|
+
const TOf = bAdvanced ? calcTurnoutBias(Vf, VfArray) : undefined;
|
|
89713
|
+
const Bs50 = bAdvanced ? estPartisanBias(dSVpoints, N) : undefined;
|
|
89778
89714
|
const Bs50f = (!(Bs50 === undefined)) ? U.trim(Bs50 / N) : undefined;
|
|
89779
|
-
const Bv50f =
|
|
89780
|
-
const rvPoints =
|
|
89781
|
-
const decl =
|
|
89782
|
-
const gSym =
|
|
89783
|
-
const EG =
|
|
89784
|
-
const BsGf =
|
|
89785
|
-
const prop =
|
|
89786
|
-
const mMs =
|
|
89787
|
-
const mMd =
|
|
89788
|
-
const LO =
|
|
89715
|
+
const Bv50f = bAdvanced ? estVotesBias(dSVpoints, N) : undefined;
|
|
89716
|
+
const rvPoints = bAdvanced ? keyRVpoints(VfArray) : undefined;
|
|
89717
|
+
const decl = bAdvanced ? calcDeclination(VfArray) : undefined;
|
|
89718
|
+
const gSym = bAdvanced ? calcGlobalSymmetry(dSVpoints, rSVpoints, Bs50f) : undefined;
|
|
89719
|
+
const EG = bAdvanced ? calcEfficiencyGap(Vf, estSf) : undefined;
|
|
89720
|
+
const BsGf = bAdvanced ? estGeometricSeatsBias(Vf, dSVpoints, rSVpoints) : undefined;
|
|
89721
|
+
const prop = bAdvanced ? calcDisproportionality(Vf, estSf) : undefined;
|
|
89722
|
+
const mMs = bAdvanced ? estMeanMedianDifference(VfArray, Vf) : undefined;
|
|
89723
|
+
const mMd = bAdvanced ? estMeanMedianDifference(VfArray) : undefined;
|
|
89724
|
+
const LO = bAdvanced ? calcLopsidedOutcomes(VfArray) : undefined;
|
|
89789
89725
|
// Calculate alternate responsiveness metrics for reference
|
|
89790
|
-
const bigR =
|
|
89791
|
-
const littleR =
|
|
89792
|
-
const MIR = (
|
|
89793
|
-
const rD = (!bConstrained ||
|
|
89794
|
-
const rDf =
|
|
89795
|
-
const gamma = (
|
|
89726
|
+
const bigR = bAdvanced ? calcBigR(Vf, estSf) : undefined;
|
|
89727
|
+
const littleR = bAdvanced ? estResponsiveness(Vf, dSVpoints) : undefined;
|
|
89728
|
+
const MIR = (bAdvanced && littleR) ? calcMinimalInverseResponsiveness(Vf, littleR) : undefined;
|
|
89729
|
+
const rD = (!bConstrained || bAdvanced) ? estResponsiveDistricts(VfArray) : undefined;
|
|
89730
|
+
const rDf = bAdvanced ? estResponsiveDistrictsShare(rD, N) : undefined;
|
|
89731
|
+
const gamma = (bAdvanced && littleR) ? calcGamma(Vf, estSf, littleR) : undefined;
|
|
89796
89732
|
const Cn = countCompetitiveDistricts(VfArray);
|
|
89797
89733
|
// NOTE - Cd by definition uses a *possibly* different (more narrow) probability
|
|
89798
89734
|
// distribution than Rd.
|
|
89799
89735
|
const cD = estCompetitiveDistricts(VfArray);
|
|
89800
|
-
// const cD = bConstrained ? estCompetitiveDistricts(VfArray) : rD as number;
|
|
89801
89736
|
const cDf = estCompetitiveDistrictsShare(cD, N);
|
|
89802
89737
|
const competitivenessScore = scoreCompetitiveness(cDf);
|
|
89803
|
-
// NOTE: Original version:
|
|
89804
|
-
// const Mrange = findMarginalDistricts(Vf, VfArray, N);
|
|
89805
|
-
// const Md = estMarginalCompetitiveDistricts(Mrange, VfArray);
|
|
89806
|
-
// const Mdf = estMarginalCompetitiveShare(Md, Mrange);
|
|
89807
|
-
// const competitivenessScore = scoreCompetitiveness(Mdf, cDf);
|
|
89808
89738
|
let biasScoring = {
|
|
89809
89739
|
bestS: bestS,
|
|
89810
89740
|
bestSf: bestSf,
|
|
89811
89741
|
estS: estS,
|
|
89812
89742
|
estSf: estSf,
|
|
89813
|
-
|
|
89814
|
-
score:
|
|
89743
|
+
deviation: deviation,
|
|
89744
|
+
score: proportionalityScore
|
|
89815
89745
|
};
|
|
89816
89746
|
const impactScoring = {
|
|
89817
89747
|
unearnedS: unearnedS,
|
|
@@ -89821,12 +89751,9 @@ function scorePartisan(Vf, VfArray, options) {
|
|
|
89821
89751
|
cSimple: Cn,
|
|
89822
89752
|
cD: cD,
|
|
89823
89753
|
cDf: cDf,
|
|
89824
|
-
// mRange: Mrange,
|
|
89825
|
-
// mD: Md,
|
|
89826
|
-
// mDf: Mdf,
|
|
89827
89754
|
score: competitivenessScore
|
|
89828
89755
|
};
|
|
89829
|
-
if (
|
|
89756
|
+
if (bAdvanced) {
|
|
89830
89757
|
biasScoring.tOf = TOf;
|
|
89831
89758
|
biasScoring.fptpS = fptpS;
|
|
89832
89759
|
biasScoring.bS50 = Bs50f;
|
|
@@ -89847,50 +89774,37 @@ function scorePartisan(Vf, VfArray, options) {
|
|
|
89847
89774
|
competitiveScoring.rD = rD;
|
|
89848
89775
|
competitiveScoring.rDf = rDf;
|
|
89849
89776
|
}
|
|
89850
|
-
|
|
89851
|
-
|
|
89852
|
-
const
|
|
89853
|
-
const
|
|
89854
|
-
const cS = competitiveScoring.score;
|
|
89855
|
-
const acrossStatesPartisanScore = weightPartisan(bS, iS, cS, 0 /* AcrossStates */);
|
|
89856
|
-
const withinStatesPartisanScore = weightPartisan(bS, iS, cS, 1 /* WithinAState */);
|
|
89777
|
+
const DWins = VfArray.filter(x => x > 0.5);
|
|
89778
|
+
const RWins = VfArray.filter(x => x <= 0.5); // Ties credited to R's
|
|
89779
|
+
const averageDVf = (DWins.length > 0) ? U.avgArray(DWins) : undefined;
|
|
89780
|
+
const averageRVf = (RWins.length > 0) ? U.avgArray(RWins) : undefined;
|
|
89857
89781
|
const s = {
|
|
89858
89782
|
bias: biasScoring,
|
|
89859
89783
|
impact: impactScoring,
|
|
89860
|
-
|
|
89784
|
+
responsiveness: competitiveScoring,
|
|
89861
89785
|
dSVpoints: dSVpoints,
|
|
89862
89786
|
rSVpoints: rSVpoints,
|
|
89863
|
-
|
|
89864
|
-
|
|
89787
|
+
averageDVf: averageDVf,
|
|
89788
|
+
averageRVf: averageRVf,
|
|
89865
89789
|
details: {}
|
|
89866
89790
|
};
|
|
89867
89791
|
return s;
|
|
89868
89792
|
}
|
|
89869
89793
|
exports.scorePartisan = scorePartisan;
|
|
89870
|
-
function weightPartisan(bS, iS, cS, context) {
|
|
89871
|
-
const bW = C.biasWeight(context);
|
|
89872
|
-
const iW = C.impactWeight(context);
|
|
89873
|
-
const cW = C.competitivenessWeight(context);
|
|
89874
|
-
const score = Math.round(((bS * bW) + (iS * iW) + (cS * cW)) / (bW + iW + cW));
|
|
89875
|
-
return score;
|
|
89876
|
-
}
|
|
89877
|
-
exports.weightPartisan = weightPartisan;
|
|
89878
89794
|
function extraBonus(Vf) {
|
|
89879
|
-
// PROPORTIONALITY - 06/24/2020 - Making the OK extra amount always positive.
|
|
89880
|
-
// const okExtra: number = (0.5 - Vf) * (C.winnerBonus() - 1.0);
|
|
89881
89795
|
const over50Pct = (Vf > 0.5) ? (Vf - 0.5) : (0.5 - Vf);
|
|
89882
89796
|
const okExtra = over50Pct * (C.winnerBonus() - 1.0);
|
|
89883
89797
|
return U.trim(okExtra);
|
|
89884
89798
|
}
|
|
89885
89799
|
exports.extraBonus = extraBonus;
|
|
89886
|
-
function
|
|
89800
|
+
function scoreDeviation(deviation, Vf, Sf) {
|
|
89887
89801
|
if (isAntimajoritarian(Vf, Sf)) {
|
|
89888
89802
|
return 0;
|
|
89889
89803
|
}
|
|
89890
89804
|
else {
|
|
89891
89805
|
// Adjust bias to incorporate an acceptable winner's bonus based on Vf
|
|
89892
89806
|
const extra = extraBonus(Vf);
|
|
89893
|
-
const adjusted =
|
|
89807
|
+
const adjusted = adjustDeviation(Vf, deviation, extra);
|
|
89894
89808
|
// Then normalize
|
|
89895
89809
|
const _normalizer = new normalize_1.Normalizer(adjusted);
|
|
89896
89810
|
const worst = C.biasRange()[C.BEG];
|
|
@@ -89904,29 +89818,24 @@ function scorebias(rawBias, Vf, Sf) {
|
|
|
89904
89818
|
return score;
|
|
89905
89819
|
}
|
|
89906
89820
|
}
|
|
89907
|
-
exports.
|
|
89908
|
-
//
|
|
89909
|
-
// Adjust bias to account for a winner's bonus
|
|
89821
|
+
exports.scoreDeviation = scoreDeviation;
|
|
89822
|
+
// Adjust deviation from proportionality to account for a winner's bonus
|
|
89910
89823
|
// * If the bias is in the *same* direction as the statewide vote %, then
|
|
89911
89824
|
// discount the bias by the winner's bonus (extra).
|
|
89912
89825
|
// * But if the bias and statewide vote % go in opposite directions, leave the
|
|
89913
89826
|
// bias unadjusted.
|
|
89914
|
-
function
|
|
89915
|
-
let adjusted =
|
|
89916
|
-
if ((Vf > 0.5) && (
|
|
89917
|
-
adjusted = Math.min(
|
|
89827
|
+
function adjustDeviation(Vf, deviation, extra) {
|
|
89828
|
+
let adjusted = deviation;
|
|
89829
|
+
if ((Vf > 0.5) && (deviation < 0)) {
|
|
89830
|
+
adjusted = Math.min(deviation + extra, 0);
|
|
89918
89831
|
}
|
|
89919
|
-
else if ((Vf < 0.5) && (
|
|
89920
|
-
adjusted = Math.max(
|
|
89832
|
+
else if ((Vf < 0.5) && (deviation > 0)) {
|
|
89833
|
+
adjusted = Math.max(deviation - extra, 0);
|
|
89921
89834
|
}
|
|
89922
89835
|
return adjusted;
|
|
89923
|
-
// PROPORTIONALITY - 06/24/2020 - Original logic:
|
|
89924
|
-
// if (Vf > 0.5)
|
|
89925
|
-
// return Math.min(bias + extra, 0);
|
|
89926
|
-
// else
|
|
89927
|
-
// return Math.max(bias - extra, 0);
|
|
89928
89836
|
}
|
|
89929
|
-
exports.
|
|
89837
|
+
exports.adjustDeviation = adjustDeviation;
|
|
89838
|
+
// NOTE - Not used.
|
|
89930
89839
|
// Normalize unearned seats
|
|
89931
89840
|
function scoreImpact(rawUE, Vf, Sf, N) {
|
|
89932
89841
|
if (isAntimajoritarian(Vf, Sf)) {
|
|
@@ -89935,7 +89844,7 @@ function scoreImpact(rawUE, Vf, Sf, N) {
|
|
|
89935
89844
|
else {
|
|
89936
89845
|
// Adjust impact to incorporate an acceptable winner's bonus based on Vf
|
|
89937
89846
|
const extra = extraBonus(Vf);
|
|
89938
|
-
const adjustedBias =
|
|
89847
|
+
const adjustedBias = adjustDeviation(Vf, rawUE / N, extra);
|
|
89939
89848
|
const adjustedImpact = adjustedBias * N;
|
|
89940
89849
|
// Then normalize
|
|
89941
89850
|
const _normalizer = new normalize_1.Normalizer(adjustedImpact);
|
|
@@ -89958,9 +89867,8 @@ function isAntimajoritarian(Vf, Sf) {
|
|
|
89958
89867
|
return bDem || bRep;
|
|
89959
89868
|
}
|
|
89960
89869
|
exports.isAntimajoritarian = isAntimajoritarian;
|
|
89961
|
-
// COMPETITIVENESS - Revised 06/23/2020
|
|
89962
89870
|
// Normalize overall competitiveness - Raw values are in the range [0.0–1.0].
|
|
89963
|
-
// But the practical max is more like
|
|
89871
|
+
// But the practical max is more like 3/4's, so unitize that range to [0.0–1.0].
|
|
89964
89872
|
// Then scale the values to [0–100].
|
|
89965
89873
|
function scoreCompetitiveness(Cdf) {
|
|
89966
89874
|
const _normalizer = new normalize_1.Normalizer(Cdf);
|
|
@@ -89973,44 +89881,6 @@ function scoreCompetitiveness(Cdf) {
|
|
|
89973
89881
|
return score;
|
|
89974
89882
|
}
|
|
89975
89883
|
exports.scoreCompetitiveness = scoreCompetitiveness;
|
|
89976
|
-
/* NOTE - Original version:
|
|
89977
|
-
export function scoreCompetitiveness(rawMarginal: number, rawOverall: number): number
|
|
89978
|
-
{
|
|
89979
|
-
// Normalize overall competitiveness - Raw values are in the range [0.0–1.0].
|
|
89980
|
-
// But the practical max is more like 2/3's, so unitize that range to [0.0–1.0].
|
|
89981
|
-
// Then scale the values to [0–100].
|
|
89982
|
-
const _overall = new Normalizer(rawOverall);
|
|
89983
|
-
|
|
89984
|
-
let worst = C.overallCompetitivenessRange()[C.BEG];
|
|
89985
|
-
let best = C.overallCompetitivenessRange()[C.END];
|
|
89986
|
-
|
|
89987
|
-
_overall.clip(worst, best);
|
|
89988
|
-
_overall.unitize(worst, best);
|
|
89989
|
-
_overall.rescale();
|
|
89990
|
-
|
|
89991
|
-
const ocS = _overall.normalizedNum as number;
|
|
89992
|
-
|
|
89993
|
-
|
|
89994
|
-
// Normalize marginal competitiveness
|
|
89995
|
-
const _marginal = new Normalizer(rawMarginal);
|
|
89996
|
-
|
|
89997
|
-
worst = C.marginalCompetitivenessRange()[C.BEG];
|
|
89998
|
-
best = C.marginalCompetitivenessRange()[C.END];
|
|
89999
|
-
|
|
90000
|
-
_marginal.clip(worst, best);
|
|
90001
|
-
_marginal.unitize(worst, best);
|
|
90002
|
-
_marginal.rescale();
|
|
90003
|
-
const mcS = _marginal.normalizedNum as number;
|
|
90004
|
-
|
|
90005
|
-
const mcW = C.marginalCompetitivenessWeight();
|
|
90006
|
-
const ocW = C.overallCompetitivenessWeight();
|
|
90007
|
-
|
|
90008
|
-
// Then combine the results
|
|
90009
|
-
const score = ((mcW + ocW) > 0) ? Math.round(((mcW * mcS) + (ocW * ocS)) / (mcW + ocW)) : 0;
|
|
90010
|
-
|
|
90011
|
-
return score;
|
|
90012
|
-
}
|
|
90013
|
-
*/
|
|
90014
89884
|
// CORE CAPABILITIES FROM JOHN NAGLE'S METHOD
|
|
90015
89885
|
const { erf } = __webpack_require__(/*! mathjs */ "./node_modules/mathjs/main/esm/index.js");
|
|
90016
89886
|
// console.log("erf(0.2) =", erf(0.2)); // returns 0.22270258921047847
|
|
@@ -90053,8 +89923,6 @@ function inferSVpoints(Vf, VfArray, shift, range) {
|
|
|
90053
89923
|
const shiftedVPI = shiftDistricts(Vf, VfArray, shiftedVf, shift);
|
|
90054
89924
|
const shiftedSf = estSeats(shiftedVPI, range) / nDistricts;
|
|
90055
89925
|
SVpoints.push({ v: shiftedVf, s: shiftedSf });
|
|
90056
|
-
// TODO - Why can't I trim these? Why does that only break the Hypotheticals?!?
|
|
90057
|
-
// SVpoints.push({v: U.trim(Number(shiftedVf)), s: shiftedSf});
|
|
90058
89926
|
}
|
|
90059
89927
|
return SVpoints;
|
|
90060
89928
|
}
|
|
@@ -90139,11 +90007,12 @@ function estFPTPSeats(VfArray) {
|
|
|
90139
90007
|
}));
|
|
90140
90008
|
}
|
|
90141
90009
|
exports.estFPTPSeats = estFPTPSeats;
|
|
90142
|
-
// B% - The
|
|
90143
|
-
function
|
|
90010
|
+
// B% - The deviation from proportionality calculated as ^S% — S%
|
|
90011
|
+
function estDeviation(estSf, bestSf) {
|
|
90144
90012
|
return U.trim(bestSf - estSf);
|
|
90145
90013
|
}
|
|
90146
|
-
exports.
|
|
90014
|
+
exports.estDeviation = estDeviation;
|
|
90015
|
+
// NOTE - Not used.
|
|
90147
90016
|
// UE# - The estimated # of unearned seats
|
|
90148
90017
|
// UE_# from http://bit.ly/2Fcuf4q
|
|
90149
90018
|
function estUnearnedSeats(proportional, probable) {
|
|
@@ -90248,11 +90117,9 @@ function estCompetitiveDistricts(VfArray, bCompress = false) {
|
|
|
90248
90117
|
return U.trim(U.sumArray(VfArray.map(v => estDistrictCompetitiveness(v, bCompress))));
|
|
90249
90118
|
}
|
|
90250
90119
|
exports.estCompetitiveDistricts = estCompetitiveDistricts;
|
|
90251
|
-
// COMPETITIVENESS - Modified 06/22/2020
|
|
90252
|
-
// Re-scale a Democratic vote share to the competitive range (e.g., 45–55%).
|
|
90253
90120
|
function estDistrictCompetitiveness(Vf, bCompress = false) {
|
|
90254
90121
|
const _normalizer = new normalize_1.Normalizer(Vf);
|
|
90255
|
-
// The end points of
|
|
90122
|
+
// The end points of the probability distribution
|
|
90256
90123
|
// NOTE - These aren't the points where races start or stop being contested,
|
|
90257
90124
|
// just the end points of a distribution that yields the desired behavior
|
|
90258
90125
|
// in the typical competitive range [45-55%].
|
|
@@ -90477,9 +90344,6 @@ function keyRVpoints(VfArray) {
|
|
|
90477
90344
|
const nDistricts = VfArray.length;
|
|
90478
90345
|
const estS = estSeats(VfArray);
|
|
90479
90346
|
const Sb = estSeatShare(estS, nDistricts);
|
|
90480
|
-
// TODO - Understand why the corresponding V to Sb is always @ 0.5.
|
|
90481
|
-
// John Nagle: "This is the dividing vote for party A vs party B wins defined
|
|
90482
|
-
// by Warrington. My modification just puts fractions of districts to the each side."
|
|
90483
90347
|
const Rb = Sb / 2;
|
|
90484
90348
|
const Ra = (1 + Sb) / 2;
|
|
90485
90349
|
const Vb = 1.0 - (U.sumArray(VfArray.map(v => estSeatProbability(v) * v))) / estS;
|
|
@@ -90619,23 +90483,19 @@ function calcGamma(Vf, Sf, r) {
|
|
|
90619
90483
|
exports.calcGamma = calcGamma;
|
|
90620
90484
|
// HELPERS
|
|
90621
90485
|
function printPartisanScorecardHeader() {
|
|
90622
|
-
console.log('XX, Name, N, V%, ^S#, S#, B%, B$,
|
|
90486
|
+
console.log('XX, Name, N, V%, ^S#, S#, B%, B$, C#, Cd, Cdf, C$');
|
|
90623
90487
|
}
|
|
90624
90488
|
exports.printPartisanScorecardHeader = printPartisanScorecardHeader;
|
|
90625
90489
|
function printPartisanScorecardRow(xx, name, N, Vf, s) {
|
|
90626
|
-
console.log('%s, %s, %i, %f, %i, %f, %f, %i, %
|
|
90490
|
+
console.log('%s, %s, %i, %f, %i, %f, %f, %i, %i, %f, %f, %i', xx, // 1
|
|
90627
90491
|
name, // 2
|
|
90628
90492
|
N, // 3
|
|
90629
90493
|
Vf, // 4
|
|
90630
90494
|
s.bias.bestS, // 5
|
|
90631
90495
|
s.bias.estS, // 6
|
|
90632
|
-
s.bias.
|
|
90633
|
-
s.bias.score, s.
|
|
90634
|
-
s.
|
|
90635
|
-
s.competitiveness.cD, s.competitiveness.cDf,
|
|
90636
|
-
// s.competitiveness.mD,
|
|
90637
|
-
s.competitiveness.score, s.score // 15
|
|
90638
|
-
);
|
|
90496
|
+
s.bias.deviation, // 7
|
|
90497
|
+
s.bias.score, s.responsiveness.cSimple, // 9
|
|
90498
|
+
s.responsiveness.cD, s.responsiveness.cDf, s.responsiveness.score);
|
|
90639
90499
|
}
|
|
90640
90500
|
exports.printPartisanScorecardRow = printPartisanScorecardRow;
|
|
90641
90501
|
// Generate partisan details (Table 1)
|
|
@@ -90644,12 +90504,12 @@ function printPartisanDetailsHeader() {
|
|
|
90644
90504
|
}
|
|
90645
90505
|
exports.printPartisanDetailsHeader = printPartisanDetailsHeader;
|
|
90646
90506
|
function printPartisanDetailsRow(xx, name, N, Vf, s) {
|
|
90647
|
-
console.log('%s, %f, %f, %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.
|
|
90507
|
+
console.log('%s, %f, %f, %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.deviation, // Simple deviation from proportionality
|
|
90648
90508
|
s.bias.bS50, s.bias.bV50, s.bias.decl, s.bias.gSym, s.bias.eG, s.bias.bSV, // Beta
|
|
90649
90509
|
s.bias.prop, // PR
|
|
90650
|
-
s.bias.mMs, s.bias.tOf, s.bias.mMd, s.bias.lO, s.
|
|
90651
|
-
s.
|
|
90652
|
-
s.
|
|
90510
|
+
s.bias.mMs, s.bias.tOf, s.bias.mMd, s.bias.lO, s.responsiveness.rD, s.responsiveness.bigR, s.responsiveness.littleR, s.responsiveness.mIR, // Zeta
|
|
90511
|
+
s.responsiveness.cD, // COMPETITIVENESS - Temporary to confirm new calc
|
|
90512
|
+
s.responsiveness.cDf);
|
|
90653
90513
|
}
|
|
90654
90514
|
exports.printPartisanDetailsRow = printPartisanDetailsRow;
|
|
90655
90515
|
|
|
@@ -90676,7 +90536,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
90676
90536
|
return result;
|
|
90677
90537
|
};
|
|
90678
90538
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
90679
|
-
const S = __importStar(__webpack_require__(/*! ./settings */ "./src/settings.ts"));
|
|
90680
90539
|
const C = __importStar(__webpack_require__(/*! ./config */ "./src/config.ts"));
|
|
90681
90540
|
const compact_1 = __webpack_require__(/*! ./compact */ "./src/compact.ts");
|
|
90682
90541
|
const cohesive_1 = __webpack_require__(/*! ./cohesive */ "./src/cohesive.ts");
|
|
@@ -90692,7 +90551,8 @@ function scorePlan(p, overridesJSON) {
|
|
|
90692
90551
|
const cS = {
|
|
90693
90552
|
score: compactnessScore,
|
|
90694
90553
|
reock: reockM,
|
|
90695
|
-
polsby: polsbyM
|
|
90554
|
+
polsby: polsbyM,
|
|
90555
|
+
details: {}
|
|
90696
90556
|
};
|
|
90697
90557
|
// Splitting
|
|
90698
90558
|
const CxD = p.splittingProfile.countyPopByDistrict;
|
|
@@ -90704,40 +90564,26 @@ function scorePlan(p, overridesJSON) {
|
|
|
90704
90564
|
const sS = {
|
|
90705
90565
|
score: splittingScore,
|
|
90706
90566
|
county: countyM,
|
|
90707
|
-
district: districtM
|
|
90567
|
+
district: districtM,
|
|
90568
|
+
details: {}
|
|
90708
90569
|
};
|
|
90709
90570
|
// Population deviation
|
|
90710
90571
|
const pdS = equal_1.doPopulationDeviation(p.populationProfile.totalPopByDistrict, p.populationProfile.targetSize, p.legislativeDistricts);
|
|
90711
|
-
//
|
|
90712
|
-
const tpScore = weightTradtionalPrinciples(cS.score, sS.score, pdS.normalized, 1 /* WithinAState */);
|
|
90713
|
-
// Populate the "best" traditional principles scorecard
|
|
90714
|
-
const tpS = {
|
|
90715
|
-
score: tpScore,
|
|
90716
|
-
compactness: cS,
|
|
90717
|
-
splitting: sS,
|
|
90718
|
-
populationDeviation: pdS,
|
|
90719
|
-
details: {}
|
|
90720
|
-
};
|
|
90721
|
-
// PARTISAN ("fair") subcategories - bias, impact, & competitiveness (plus lots of supporting measures)
|
|
90572
|
+
// Partisan - bias & responsiveness
|
|
90722
90573
|
const options = {
|
|
90723
|
-
|
|
90574
|
+
advanced: true,
|
|
90724
90575
|
constrained: false,
|
|
90725
90576
|
shift: 0 /* Proportional */
|
|
90726
90577
|
};
|
|
90727
90578
|
const pS = partisan_1.scorePartisan(p.partisanProfile.statewideVf, p.partisanProfile.vfArray, options);
|
|
90728
|
-
// Combine the partisan/partisan & traditional principles/best scores into an overall
|
|
90729
|
-
// score for comparing plans w/in a state
|
|
90730
|
-
let score = weightOverall(pS.score2, tpS.score, 1 /* WithinAState */);
|
|
90731
90579
|
const mS = minority_1.evalMinorityOpportunity(p);
|
|
90732
|
-
//
|
|
90733
|
-
const bonus = C.minorityBonus() * (mS.score / 100);
|
|
90734
|
-
score = mixinMinorityBonus(score, bonus);
|
|
90735
|
-
// Roll up an overall scorecard
|
|
90580
|
+
// Combine the pieces into a scorecard
|
|
90736
90581
|
const scorecard = {
|
|
90737
90582
|
partisan: pS,
|
|
90738
90583
|
minority: mS,
|
|
90739
|
-
|
|
90740
|
-
|
|
90584
|
+
compactness: cS,
|
|
90585
|
+
splitting: sS,
|
|
90586
|
+
populationDeviation: pdS,
|
|
90741
90587
|
details: {}
|
|
90742
90588
|
};
|
|
90743
90589
|
return scorecard;
|
|
@@ -90758,44 +90604,20 @@ function weightSplitting(csS, dsS) {
|
|
|
90758
90604
|
return score;
|
|
90759
90605
|
}
|
|
90760
90606
|
exports.weightSplitting = weightSplitting;
|
|
90761
|
-
function weightTradtionalPrinciples(cS, sS, pdS, context) {
|
|
90762
|
-
const cW = C.compactnessWeight(context);
|
|
90763
|
-
const sW = C.splittingWeight(context);
|
|
90764
|
-
const pdW = C.popdevWeight(context);
|
|
90765
|
-
const score = Math.round(((cS * cW) + (sS * sW) + (pdS * pdW)) / (cW + sW + pdW));
|
|
90766
|
-
return score;
|
|
90767
|
-
}
|
|
90768
|
-
exports.weightTradtionalPrinciples = weightTradtionalPrinciples;
|
|
90769
|
-
function weightOverall(pS, tpS, context) {
|
|
90770
|
-
const pW = C.partisanWeight(context);
|
|
90771
|
-
const tpW = C.traditionalPrinciplesWeight(context);
|
|
90772
|
-
const score = Math.round(((pS * pW) + (tpS * tpW)) / (pW + tpW));
|
|
90773
|
-
return score;
|
|
90774
|
-
}
|
|
90775
|
-
exports.weightOverall = weightOverall;
|
|
90776
|
-
function mixinMinorityBonus(score, minorityBonus) {
|
|
90777
|
-
const modifiedScore = Math.min(score + minorityBonus, S.NORMALIZED_RANGE);
|
|
90778
|
-
return modifiedScore;
|
|
90779
|
-
}
|
|
90780
|
-
exports.mixinMinorityBonus = mixinMinorityBonus;
|
|
90781
90607
|
function printScorecardHeader() {
|
|
90782
|
-
console.log('XX, Name, N, V%, ^S#, S#, B%, B$,
|
|
90608
|
+
console.log('XX, Name, N, V%, ^S#, S#, B%, B$, C#, Cd, Cdf, C$, Rc, Rc$, Pc, Pc$, G$, Cs, Cs$, Ds, Ds$, S$, Eq, Eq$, Od, Md, M$');
|
|
90783
90609
|
}
|
|
90784
90610
|
exports.printScorecardHeader = printScorecardHeader;
|
|
90785
90611
|
function printScorecardRow(xx, name, N, Vf, s) {
|
|
90786
|
-
console.log('%s, %s, %i, %f, %i, %f, %f, %i, %
|
|
90612
|
+
console.log('%s, %s, %i, %f, %i, %f, %f, %i, %i, %f, %f, %i, %f, %i, %f, %i, %i, %f, %i, %f, %i, %i, %f, %i, %f, %f, %i', xx, // 1
|
|
90787
90613
|
name, // 2
|
|
90788
90614
|
N, // 3
|
|
90789
90615
|
Vf, // 4
|
|
90790
90616
|
s.partisan.bias.bestS, // 5
|
|
90791
90617
|
s.partisan.bias.estS, // 6
|
|
90792
|
-
s.partisan.bias.
|
|
90793
|
-
s.partisan.bias.score, s.partisan.
|
|
90794
|
-
s.partisan.
|
|
90795
|
-
s.partisan.competitiveness.cD, s.partisan.competitiveness.cDf,
|
|
90796
|
-
// s.partisan.competitiveness.mD,
|
|
90797
|
-
s.partisan.competitiveness.score, s.partisan.score2, // 15
|
|
90798
|
-
s.traditionalPrinciples.compactness.reock.raw, s.traditionalPrinciples.compactness.reock.normalized, s.traditionalPrinciples.compactness.polsby.raw, s.traditionalPrinciples.compactness.polsby.normalized, s.traditionalPrinciples.compactness.score, s.traditionalPrinciples.splitting.county.raw, s.traditionalPrinciples.splitting.county.normalized, s.traditionalPrinciples.splitting.district.raw, s.traditionalPrinciples.splitting.district.normalized, s.traditionalPrinciples.splitting.score, s.traditionalPrinciples.populationDeviation.raw, s.traditionalPrinciples.populationDeviation.normalized, s.traditionalPrinciples.score, s.minority.opportunityDistricts, s.minority.coalitionDistricts, s.minority.score, s.score);
|
|
90618
|
+
s.partisan.bias.deviation, // 7
|
|
90619
|
+
s.partisan.bias.score, s.partisan.responsiveness.cSimple, // 9
|
|
90620
|
+
s.partisan.responsiveness.cD, s.partisan.responsiveness.cDf, s.partisan.responsiveness.score, s.compactness.reock.raw, s.compactness.reock.normalized, s.compactness.polsby.raw, s.compactness.polsby.normalized, s.compactness.score, s.splitting.county.raw, s.splitting.county.normalized, s.splitting.district.raw, s.splitting.district.normalized, s.splitting.score, s.populationDeviation.raw, s.populationDeviation.normalized, s.minority.opportunityDistricts, s.minority.coalitionDistricts, s.minority.score);
|
|
90799
90621
|
}
|
|
90800
90622
|
exports.printScorecardRow = printScorecardRow;
|
|
90801
90623
|
|
|
@@ -102944,10 +102766,10 @@ class AnalyticsSession {
|
|
|
102944
102766
|
const scorecard = this._scorecard;
|
|
102945
102767
|
const r = {
|
|
102946
102768
|
proportionality: scorecard.partisan.bias.score,
|
|
102947
|
-
competitiveness: scorecard.partisan.
|
|
102769
|
+
competitiveness: scorecard.partisan.responsiveness.score,
|
|
102948
102770
|
minorityRights: scorecard.minority.score,
|
|
102949
|
-
compactness: scorecard.
|
|
102950
|
-
splitting: scorecard.
|
|
102771
|
+
compactness: scorecard.compactness.score,
|
|
102772
|
+
splitting: scorecard.splitting.score
|
|
102951
102773
|
};
|
|
102952
102774
|
return r;
|
|
102953
102775
|
}
|
|
@@ -104445,7 +104267,7 @@ function doAnalyzePostProcessing(s, bLog = false) {
|
|
|
104445
104267
|
// Just populate the normalized population deviation score in the test
|
|
104446
104268
|
const scorecard = s._scorecard;
|
|
104447
104269
|
let popDev = s.getTest(4 /* PopulationDeviation */);
|
|
104448
|
-
popDev['normalizedScore'] = scorecard.
|
|
104270
|
+
popDev['normalizedScore'] = scorecard.populationDeviation.normalized;
|
|
104449
104271
|
const datasets = {
|
|
104450
104272
|
shapes: S.SHAPES,
|
|
104451
104273
|
census: U.deepCopy(s.config['descriptions']['CENSUS']),
|
|
@@ -104454,12 +104276,12 @@ function doAnalyzePostProcessing(s, bLog = false) {
|
|
|
104454
104276
|
};
|
|
104455
104277
|
scorecard.partisan.details['election'] = datasets.election;
|
|
104456
104278
|
scorecard.minority.details['vap'] = datasets.vap;
|
|
104457
|
-
scorecard.
|
|
104458
|
-
scorecard.
|
|
104279
|
+
scorecard.details['shapes'] = datasets.shapes;
|
|
104280
|
+
scorecard.details['census'] = datasets.census;
|
|
104459
104281
|
const simpleSplits = s.getTest(5 /* UnexpectedCountySplits */);
|
|
104460
|
-
scorecard.
|
|
104461
|
-
scorecard.
|
|
104462
|
-
scorecard.
|
|
104282
|
+
scorecard.compactness.details['unexpectedAffected'] = simpleSplits['score'];
|
|
104283
|
+
scorecard.compactness.details['nSplits'] = simpleSplits['details']['nSplits'];
|
|
104284
|
+
scorecard.compactness.details['countiesSplitUnexpectedly'] = U.deepCopy(simpleSplits['details']['countiesSplitUnexpectedly']);
|
|
104463
104285
|
// NOTE - Add split precincts in dra-client directly
|
|
104464
104286
|
// Derive secondary tests
|
|
104465
104287
|
analyze_1.doDeriveSecondaryTests(s, bLog);
|
|
@@ -104604,10 +104426,10 @@ function scorePlan(s, p, bLog = false, overridesJSON) {
|
|
|
104604
104426
|
// doHasEqualPopulations() to use later.This is preserving the old calling sequence.
|
|
104605
104427
|
let test = s.getTest(4 /* PopulationDeviation */);
|
|
104606
104428
|
// Get the raw population deviation
|
|
104607
|
-
const popDev = scorecard.
|
|
104429
|
+
const popDev = scorecard.populationDeviation.raw;
|
|
104608
104430
|
// Populate the test entry
|
|
104609
104431
|
test['score'] = popDev;
|
|
104610
|
-
test['details'] = { 'maxDeviation': scorecard.
|
|
104432
|
+
test['details'] = { 'maxDeviation': scorecard.populationDeviation.notes['maxDeviation'] };
|
|
104611
104433
|
// Populate the N+1 summary "district" in district.statistics
|
|
104612
104434
|
let totalPop = s.districts.statistics[D.DistrictField.TotalPop];
|
|
104613
104435
|
let popDevPct = s.districts.statistics[D.DistrictField.PopDevPct];
|