@dra2020/district-analytics 3.1.0 → 3.2.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 +149 -113
- package/dist/cli.js.map +1 -1
- package/dist/district-analytics.js +103 -61
- package/dist/district-analytics.js.map +1 -1
- package/dist/src/score.d.ts +1 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -86,10 +86,10 @@
|
|
|
86
86
|
/************************************************************************/
|
|
87
87
|
/******/ ({
|
|
88
88
|
|
|
89
|
-
/***/ "
|
|
90
|
-
|
|
91
|
-
!***
|
|
92
|
-
|
|
89
|
+
/***/ "./node_modules/@dra2020/dra-score/dist/dra-score.bundle.js":
|
|
90
|
+
/*!******************************************************************!*\
|
|
91
|
+
!*** ./node_modules/@dra2020/dra-score/dist/dra-score.bundle.js ***!
|
|
92
|
+
\******************************************************************/
|
|
93
93
|
/*! no static exports found */
|
|
94
94
|
/***/ (function(module, exports, __webpack_require__) {
|
|
95
95
|
|
|
@@ -89269,8 +89269,8 @@ const score_1 = __webpack_require__(/*! ./score */ "./src/score.ts");
|
|
|
89269
89269
|
class Scorer {
|
|
89270
89270
|
constructor() {
|
|
89271
89271
|
}
|
|
89272
|
-
score(
|
|
89273
|
-
return score_1.scorePlan(
|
|
89272
|
+
score(profile, overridesJSON) {
|
|
89273
|
+
return score_1.scorePlan(profile, overridesJSON);
|
|
89274
89274
|
}
|
|
89275
89275
|
}
|
|
89276
89276
|
exports.Scorer = Scorer;
|
|
@@ -90353,7 +90353,7 @@ const cohesive_1 = __webpack_require__(/*! ./cohesive */ "./src/cohesive.ts");
|
|
|
90353
90353
|
const equal_1 = __webpack_require__(/*! ./equal */ "./src/equal.ts");
|
|
90354
90354
|
const fair_1 = __webpack_require__(/*! ./fair */ "./src/fair.ts");
|
|
90355
90355
|
// TODO - Score opportunity for minority representation
|
|
90356
|
-
function scorePlan(p, overridesJSON
|
|
90356
|
+
function scorePlan(p, overridesJSON) {
|
|
90357
90357
|
// BEST subcategories - compactness, splitting, population deviation
|
|
90358
90358
|
// Compactness
|
|
90359
90359
|
const reockM = compact_1.doReock(p.compactnessProfile.GeometryByDistrict);
|
|
@@ -90406,10 +90406,10 @@ exports.scorePlan = scorePlan;
|
|
|
90406
90406
|
|
|
90407
90407
|
/***/ }),
|
|
90408
90408
|
|
|
90409
|
-
/***/ "./src/
|
|
90410
|
-
|
|
90411
|
-
!*** ./src/
|
|
90412
|
-
|
|
90409
|
+
/***/ "./src/settings.json":
|
|
90410
|
+
/*!***************************!*\
|
|
90411
|
+
!*** ./src/settings.json ***!
|
|
90412
|
+
\***************************/
|
|
90413
90413
|
/*! exports provided: fair, best, default */
|
|
90414
90414
|
/***/ (function(module) {
|
|
90415
90415
|
|
|
@@ -90447,39 +90447,33 @@ exports.PRECISION = 4;
|
|
|
90447
90447
|
exports.AVERAGE_BLOCK_SIZE = 30;
|
|
90448
90448
|
exports.EQUAL_TOLERANCE = exports.AVERAGE_BLOCK_SIZE / 2;
|
|
90449
90449
|
// SCORING PARAMETERS
|
|
90450
|
-
const
|
|
90450
|
+
const settings_json_1 = __importDefault(__webpack_require__(/*! ./settings.json */ "./src/settings.json"));
|
|
90451
|
+
// TODO - DELETE
|
|
90451
90452
|
function readOverrides() {
|
|
90452
|
-
// TODO - TERRY: Replumb this to:
|
|
90453
|
-
// - Respond to an environment variable or config.json, and
|
|
90454
|
-
// - Read settings.json at runtime from S3
|
|
90455
|
-
// - Otherwise return false/null, so the conditionals below work
|
|
90456
|
-
// - Note the utils/settings interdependency
|
|
90457
|
-
// return U.readJSON('scoring-overrides.json');
|
|
90458
90453
|
return undefined;
|
|
90459
90454
|
}
|
|
90460
|
-
|
|
90461
|
-
let overrides = readOverrides();
|
|
90455
|
+
const overrides = readOverrides();
|
|
90462
90456
|
// SETTINGS FOR PARTISAN SCORING
|
|
90463
|
-
exports.MIN_CONTESTED = overrides ? overrides.fair.competitive.min :
|
|
90464
|
-
exports.MAX_CONTESTED = overrides ? overrides.fair.competitive.max :
|
|
90457
|
+
exports.MIN_CONTESTED = overrides ? overrides.fair.competitive.min : settings_json_1.default.fair.competitive.min;
|
|
90458
|
+
exports.MAX_CONTESTED = overrides ? overrides.fair.competitive.max : settings_json_1.default.fair.competitive.max;
|
|
90465
90459
|
// SCALES FOR NORMALIZING RAW VALUES
|
|
90466
90460
|
// Compactness scales
|
|
90467
|
-
exports.REOCK_WORST = overrides ? overrides.best.compact.reock.worst :
|
|
90468
|
-
exports.REOCK_BEST = overrides ? overrides.best.compact.reock.best :
|
|
90469
|
-
exports.POLSBY_WORST = overrides ? overrides.best.compact.polsby.worst :
|
|
90470
|
-
exports.POLSBY_BEST = overrides ? overrides.best.compact.polsby.best :
|
|
90461
|
+
exports.REOCK_WORST = overrides ? overrides.best.compact.reock.worst : settings_json_1.default.best.compact.reock.worst;
|
|
90462
|
+
exports.REOCK_BEST = overrides ? overrides.best.compact.reock.best : settings_json_1.default.best.compact.reock.best;
|
|
90463
|
+
exports.POLSBY_WORST = overrides ? overrides.best.compact.polsby.worst : settings_json_1.default.best.compact.polsby.worst;
|
|
90464
|
+
exports.POLSBY_BEST = overrides ? overrides.best.compact.polsby.best : settings_json_1.default.best.compact.polsby.best;
|
|
90471
90465
|
// County-District splitting scales (not inverted)
|
|
90472
|
-
exports.COUNTY_BEST = overrides ? overrides.best.cohesive.county.best :
|
|
90473
|
-
exports.COUNTY_WORST = overrides ? overrides.best.cohesive.county.worst :
|
|
90474
|
-
exports.ALLOWABLE_SPLITS_MULTIPLIER = overrides ? overrides.best.cohesive.county.allowableSplitsMultiplier :
|
|
90475
|
-
exports.DISTRICT_BEST = overrides ? overrides.best.cohesive.district.best :
|
|
90476
|
-
exports.DISTRICT_WORST = overrides ? overrides.best.cohesive.district.worst :
|
|
90466
|
+
exports.COUNTY_BEST = overrides ? overrides.best.cohesive.county.best : settings_json_1.default.best.cohesive.county.best;
|
|
90467
|
+
exports.COUNTY_WORST = overrides ? overrides.best.cohesive.county.worst : settings_json_1.default.best.cohesive.county.worst;
|
|
90468
|
+
exports.ALLOWABLE_SPLITS_MULTIPLIER = overrides ? overrides.best.cohesive.county.allowableSplitsMultiplier : settings_json_1.default.best.cohesive.county.allowableSplitsMultiplier;
|
|
90469
|
+
exports.DISTRICT_BEST = overrides ? overrides.best.cohesive.district.best : settings_json_1.default.best.cohesive.district.best;
|
|
90470
|
+
exports.DISTRICT_WORST = overrides ? overrides.best.cohesive.district.worst : settings_json_1.default.best.cohesive.district.worst;
|
|
90477
90471
|
// Population deviation thresholds & scales (inverted)
|
|
90478
|
-
exports.POPDEV_WORST = overrides ? overrides.best.equal.worst :
|
|
90479
|
-
exports.POPDEV_BEST = overrides ? overrides.best.equal.best :
|
|
90472
|
+
exports.POPDEV_WORST = overrides ? overrides.best.equal.worst : settings_json_1.default.best.equal.worst;
|
|
90473
|
+
exports.POPDEV_BEST = overrides ? overrides.best.equal.best : settings_json_1.default.best.equal.best;
|
|
90480
90474
|
exports.POPEQ_MIN = 1.0 - exports.POPDEV_WORST;
|
|
90481
90475
|
exports.POPEQ_MAX = 1.0 - exports.POPDEV_BEST;
|
|
90482
|
-
exports.POPDEV_WORST_LD = overrides ? overrides.best.equal.stateLeg.worst :
|
|
90476
|
+
exports.POPDEV_WORST_LD = overrides ? overrides.best.equal.stateLeg.worst : settings_json_1.default.best.equal.stateLeg.worst;
|
|
90483
90477
|
exports.POPDEV_BEST_LD = ((exports.POPDEV_BEST / exports.POPDEV_WORST) * exports.POPDEV_WORST_LD);
|
|
90484
90478
|
exports.POPEQ_MIN_LD = 1.0 - exports.POPDEV_WORST_LD;
|
|
90485
90479
|
exports.POPEQ_MAX_LD = 1.0 - exports.POPDEV_BEST_LD;
|
|
@@ -90487,27 +90481,27 @@ exports.POPEQ_MAX_LD = 1.0 - exports.POPDEV_BEST_LD;
|
|
|
90487
90481
|
// TODO - SCORE:
|
|
90488
90482
|
// * How wide a range do we want for bias? 10%? 20%?
|
|
90489
90483
|
// * Do we want it to be state-specific? E.g., one seat?
|
|
90490
|
-
exports.BIAS_WORST = overrides ? overrides.fair.unbiased.worst :
|
|
90491
|
-
exports.BIAS_BEST = overrides ? overrides.fair.unbiased.best :
|
|
90484
|
+
exports.BIAS_WORST = overrides ? overrides.fair.unbiased.worst : settings_json_1.default.fair.unbiased.worst;
|
|
90485
|
+
exports.BIAS_BEST = overrides ? overrides.fair.unbiased.best : settings_json_1.default.fair.unbiased.best;
|
|
90492
90486
|
// The range for raw overall competitiveness values
|
|
90493
|
-
exports.COMPETITIVE_WORST = overrides ? overrides.fair.competitive.worst :
|
|
90494
|
-
exports.COMPETITIVE_BEST = overrides ? overrides.fair.competitive.best :
|
|
90487
|
+
exports.COMPETITIVE_WORST = overrides ? overrides.fair.competitive.worst : settings_json_1.default.fair.competitive.worst;
|
|
90488
|
+
exports.COMPETITIVE_BEST = overrides ? overrides.fair.competitive.best : settings_json_1.default.fair.competitive.best;
|
|
90495
90489
|
// WEIGHTS FOR COMBINING NORMALIZED VALUES
|
|
90496
|
-
exports.REOCK_WEIGHT = overrides ? overrides.best.compact.reock.weight :
|
|
90497
|
-
exports.POLSBY_WEIGHT = overrides ? overrides.best.compact.polsby.weight :
|
|
90498
|
-
exports.COUNTY_WEIGHT = overrides ? overrides.best.cohesive.county.weight :
|
|
90499
|
-
exports.DISTRICT_WEIGHT = overrides ? overrides.best.cohesive.district.weight :
|
|
90500
|
-
exports.COMPACTNESS_WEIGHT = overrides ? overrides.best.compact.weight :
|
|
90501
|
-
exports.SPLITTING_WEIGHT = overrides ? overrides.best.cohesive.weight :
|
|
90502
|
-
exports.POPDEV_WEIGHT = overrides ? overrides.best.equal.weight :
|
|
90490
|
+
exports.REOCK_WEIGHT = overrides ? overrides.best.compact.reock.weight : settings_json_1.default.best.compact.reock.weight;
|
|
90491
|
+
exports.POLSBY_WEIGHT = overrides ? overrides.best.compact.polsby.weight : settings_json_1.default.best.compact.polsby.weight;
|
|
90492
|
+
exports.COUNTY_WEIGHT = overrides ? overrides.best.cohesive.county.weight : settings_json_1.default.best.cohesive.county.weight;
|
|
90493
|
+
exports.DISTRICT_WEIGHT = overrides ? overrides.best.cohesive.district.weight : settings_json_1.default.best.cohesive.district.weight;
|
|
90494
|
+
exports.COMPACTNESS_WEIGHT = overrides ? overrides.best.compact.weight : settings_json_1.default.best.compact.weight;
|
|
90495
|
+
exports.SPLITTING_WEIGHT = overrides ? overrides.best.cohesive.weight : settings_json_1.default.best.cohesive.weight;
|
|
90496
|
+
exports.POPDEV_WEIGHT = overrides ? overrides.best.equal.weight : settings_json_1.default.best.equal.weight;
|
|
90503
90497
|
// TODO - SCORE: What kind of relative weighting do we want between marginal and
|
|
90504
90498
|
// overall competitiveness?
|
|
90505
|
-
exports.MARGINAL_WEIGHT = overrides ? overrides.fair.competitive.marginal :
|
|
90506
|
-
exports.OVERALL_WEIGHT = overrides ? overrides.fair.competitive.overall :
|
|
90507
|
-
exports.BIAS_WEIGHT = overrides ? overrides.fair.unbiased.weight :
|
|
90508
|
-
exports.COMPETITIVE_WEIGHT = overrides ? overrides.fair.competitive.weight :
|
|
90509
|
-
exports.FAIR_WEIGHT = overrides ? overrides.fair.weight :
|
|
90510
|
-
exports.BEST_WEIGHT = overrides ? overrides.best.weight :
|
|
90499
|
+
exports.MARGINAL_WEIGHT = overrides ? overrides.fair.competitive.marginal : settings_json_1.default.fair.competitive.marginal;
|
|
90500
|
+
exports.OVERALL_WEIGHT = overrides ? overrides.fair.competitive.overall : settings_json_1.default.fair.competitive.overall;
|
|
90501
|
+
exports.BIAS_WEIGHT = overrides ? overrides.fair.unbiased.weight : settings_json_1.default.fair.unbiased.weight;
|
|
90502
|
+
exports.COMPETITIVE_WEIGHT = overrides ? overrides.fair.competitive.weight : settings_json_1.default.fair.competitive.weight;
|
|
90503
|
+
exports.FAIR_WEIGHT = overrides ? overrides.fair.weight : settings_json_1.default.fair.weight;
|
|
90504
|
+
exports.BEST_WEIGHT = overrides ? overrides.best.weight : settings_json_1.default.best.weight;
|
|
90511
90505
|
|
|
90512
90506
|
|
|
90513
90507
|
/***/ }),
|
|
@@ -100443,37 +100437,47 @@ class AnalyticsSession {
|
|
|
100443
100437
|
this.districts = new D.Districts(this, SessionRequest['districtShapes']);
|
|
100444
100438
|
// TODO - SCORE: Toggle
|
|
100445
100439
|
if (this.useLegacy()) {
|
|
100440
|
+
console.log("Using legacy district-analytics.");
|
|
100446
100441
|
// NOTE: I've pulled these out of the individual analytics to here. Eventually,
|
|
100447
100442
|
// we could want them to passed into an analytics session as data, along with
|
|
100448
100443
|
// everything else. For now, this keeps branching out of the main code.
|
|
100449
100444
|
results_1.doConfigureScales(this);
|
|
100450
100445
|
}
|
|
100446
|
+
else {
|
|
100447
|
+
console.log("Using dra-score analytics.");
|
|
100448
|
+
// TODO - SCORE: Temporary HACK. Query dra-score for threshold.
|
|
100449
|
+
results_1.doConfigureScales(this);
|
|
100450
|
+
}
|
|
100451
100451
|
}
|
|
100452
100452
|
processConfig(config) {
|
|
100453
100453
|
// NOTE - Session settings are required:
|
|
100454
100454
|
// - Analytics suites can be defaulted to all with [], but
|
|
100455
100455
|
// - Dataset keys must be explicitly specified with 'dataset'
|
|
100456
|
+
// TODO - SCORE: Delete
|
|
100456
100457
|
config['suites'] = [0 /* Legal */, 1 /* Fair */, 2 /* Best */];
|
|
100457
100458
|
// Default the Census & redistricting cycle to 2010
|
|
100458
100459
|
if (!(U.keyExists('cycle', config)))
|
|
100459
100460
|
config['cycle'] = 2010;
|
|
100460
100461
|
return config;
|
|
100461
100462
|
}
|
|
100463
|
+
// TODO - SCORE: Toggle = Invert this logic
|
|
100462
100464
|
useLegacy() {
|
|
100463
|
-
|
|
100465
|
+
// TODO - SCORE: Opt-out
|
|
100466
|
+
return (U.keyExists('useScore', this.config) && (this.config['useScore'] != null) && (!(this.config['useScore']))) ? true : false;
|
|
100467
|
+
// TODO - SCORE: Opt-in
|
|
100468
|
+
// return (U.keyExists('useScore', this.config) && (this.config['useScore'])) ? false : true;
|
|
100464
100469
|
}
|
|
100465
100470
|
// Using the the data in the analytics session, calculate all the
|
|
100466
100471
|
// analytics & validations, saving/updating the individual test results.
|
|
100467
|
-
analyzePlan(bLog = false, overridesJSON
|
|
100472
|
+
analyzePlan(bLog = false, overridesJSON) {
|
|
100468
100473
|
try {
|
|
100469
100474
|
preprocess_1.doPreprocessData(this, bLog);
|
|
100470
100475
|
analyze_1.doAnalyzeDistricts(this, bLog);
|
|
100471
|
-
// TODO - SCORE
|
|
100472
100476
|
analyze_1.doAnalyzePlan(this, bLog);
|
|
100477
|
+
// TODO - SCORE
|
|
100473
100478
|
this._profile = score_1.profilePlan(this, bLog);
|
|
100474
|
-
this._scorecard = score_1.scorePlan(this._profile, bLog);
|
|
100479
|
+
this._scorecard = score_1.scorePlan(this, this._profile, bLog, overridesJSON);
|
|
100475
100480
|
results_1.doAnalyzePostProcessing(this, bLog);
|
|
100476
|
-
//
|
|
100477
100481
|
}
|
|
100478
100482
|
catch (_a) {
|
|
100479
100483
|
console.log("Exception caught by analyzePlan()");
|
|
@@ -100595,13 +100599,13 @@ class AnalyticsSession {
|
|
|
100595
100599
|
// NOTE - Not sure why this has to be up here ...
|
|
100596
100600
|
populationDeviationThreshold() {
|
|
100597
100601
|
// TODO - SCORE: Toggle
|
|
100598
|
-
// const bLegacy = this._bLegacy; DELETE
|
|
100599
100602
|
if (this.useLegacy()) {
|
|
100600
100603
|
return 1 - this.testScales[4 /* PopulationDeviation */]['scale'][0];
|
|
100601
100604
|
}
|
|
100602
100605
|
else {
|
|
100603
|
-
|
|
100604
|
-
|
|
100606
|
+
// TODO - SCORE: Temporary HACK. Query dra-score for threshold.
|
|
100607
|
+
// NOTE - The plan may not have been scored yet, i.e., no scorecard yet.
|
|
100608
|
+
return 1 - this.testScales[4 /* PopulationDeviation */]['scale'][0];
|
|
100605
100609
|
}
|
|
100606
100610
|
}
|
|
100607
100611
|
}
|
|
@@ -100778,7 +100782,6 @@ class Districts {
|
|
|
100778
100782
|
let outerThis = this;
|
|
100779
100783
|
// Default the pop dev % for the dummy Unassigned district to 0%.
|
|
100780
100784
|
// Default the pop dev % for real (1–N) but empty districts to 100%.
|
|
100781
|
-
// TODO - SCORE: Why did I mark this?
|
|
100782
100785
|
let popDevPct = (i > 0) ? (targetSize / targetSize) : 0 / targetSize;
|
|
100783
100786
|
// Get the geoIDs assigned to the district
|
|
100784
100787
|
// Guard against empty districts
|
|
@@ -101228,12 +101231,44 @@ exports.doAnalyzeDistricts = doAnalyzeDistricts;
|
|
|
101228
101231
|
// calls might make chunking for aync easier.
|
|
101229
101232
|
function doAnalyzePlan(s, bLog = false) {
|
|
101230
101233
|
// TODO - SCORE: Toggle
|
|
101231
|
-
|
|
101232
|
-
|
|
101233
|
-
|
|
101234
|
-
|
|
101235
|
-
|
|
101236
|
-
|
|
101234
|
+
if (s.useLegacy()) {
|
|
101235
|
+
// Disable most legacy analytics
|
|
101236
|
+
// Get the requested suites, and only execute those tests
|
|
101237
|
+
let requestedSuites = s.config['suites'];
|
|
101238
|
+
// Tests in the "Legal" suite, i.e., pass/ fail constraints
|
|
101239
|
+
if (requestedSuites.includes(0 /* Legal */)) {
|
|
101240
|
+
s.tests[0 /* Complete */] = valid_1.doIsComplete(s, bLog);
|
|
101241
|
+
s.tests[1 /* Contiguous */] = valid_1.doIsContiguous(s, bLog);
|
|
101242
|
+
s.tests[2 /* FreeOfHoles */] = valid_1.doIsFreeOfHoles(s, bLog);
|
|
101243
|
+
s.tests[4 /* PopulationDeviation */] = equal_1.doPopulationDeviation(s, bLog);
|
|
101244
|
+
// NOTE - I can't check whether a population deviation is legal or not, until
|
|
101245
|
+
// the raw % is normalized. A zero (0) would mean "too much" / "not legal," for
|
|
101246
|
+
// the given type of district (CD vs. LD). The EqualPopulation test is derived
|
|
101247
|
+
// from PopulationDeviation, as part of scorecard or test log preparation.
|
|
101248
|
+
// Create an empty test entry here though ...
|
|
101249
|
+
s.tests[3 /* EqualPopulation */] = s.getTest(3 /* EqualPopulation */);
|
|
101250
|
+
}
|
|
101251
|
+
// Tests in the "Fair" suite
|
|
101252
|
+
if (requestedSuites.includes(1 /* Fair */)) {
|
|
101253
|
+
s.tests[11 /* SeatsBias */] = political_1.doSeatsBias(s, bLog);
|
|
101254
|
+
s.tests[12 /* VotesBias */] = political_1.doVotesBias(s, bLog);
|
|
101255
|
+
s.tests[13 /* Responsiveness */] = political_1.doResponsiveness(s, bLog);
|
|
101256
|
+
s.tests[14 /* ResponsiveDistricts */] = political_1.doResponsiveDistricts(s, bLog);
|
|
101257
|
+
s.tests[15 /* EfficiencyGap */] = political_1.doEfficiencyGap(s, bLog);
|
|
101258
|
+
s.tests[16 /* MajorityMinorityDistricts */] = minority_1.doMajorityMinorityDistricts(s, bLog);
|
|
101259
|
+
}
|
|
101260
|
+
// Tests in the "Best" suite, i.e., criteria for better/worse
|
|
101261
|
+
if (requestedSuites.includes(2 /* Best */)) {
|
|
101262
|
+
s.tests[5 /* Reock */] = compact_1.doReock(s, bLog);
|
|
101263
|
+
s.tests[6 /* PolsbyPopper */] = compact_1.doPolsbyPopper(s, bLog);
|
|
101264
|
+
s.tests[7 /* UnexpectedCountySplits */] = cohesive_1.doFindCountiesSplitUnexpectedly(s, bLog);
|
|
101265
|
+
s.tests[10 /* VTDSplits */] = cohesive_1.doFindSplitVTDs(s, bLog);
|
|
101266
|
+
s.tests[8 /* CountySplitting */] = cohesive_1.doCountySplitting(s, bLog);
|
|
101267
|
+
s.tests[9 /* DistrictSplitting */] = cohesive_1.doDistrictSplitting(s, bLog);
|
|
101268
|
+
}
|
|
101269
|
+
}
|
|
101270
|
+
else {
|
|
101271
|
+
// TODO - SCORE: Except these. Continue to do these here vs. dra-score.
|
|
101237
101272
|
s.tests[0 /* Complete */] = valid_1.doIsComplete(s, bLog);
|
|
101238
101273
|
s.tests[1 /* Contiguous */] = valid_1.doIsContiguous(s, bLog);
|
|
101239
101274
|
s.tests[2 /* FreeOfHoles */] = valid_1.doIsFreeOfHoles(s, bLog);
|
|
@@ -101244,24 +101279,8 @@ function doAnalyzePlan(s, bLog = false) {
|
|
|
101244
101279
|
// from PopulationDeviation, as part of scorecard or test log preparation.
|
|
101245
101280
|
// Create an empty test entry here though ...
|
|
101246
101281
|
s.tests[3 /* EqualPopulation */] = s.getTest(3 /* EqualPopulation */);
|
|
101247
|
-
}
|
|
101248
|
-
// Tests in the "Fair" suite
|
|
101249
|
-
if (requestedSuites.includes(1 /* Fair */)) {
|
|
101250
|
-
s.tests[11 /* SeatsBias */] = political_1.doSeatsBias(s, bLog);
|
|
101251
|
-
s.tests[12 /* VotesBias */] = political_1.doVotesBias(s, bLog);
|
|
101252
|
-
s.tests[13 /* Responsiveness */] = political_1.doResponsiveness(s, bLog);
|
|
101253
|
-
s.tests[14 /* ResponsiveDistricts */] = political_1.doResponsiveDistricts(s, bLog);
|
|
101254
|
-
s.tests[15 /* EfficiencyGap */] = political_1.doEfficiencyGap(s, bLog);
|
|
101255
|
-
s.tests[16 /* MajorityMinorityDistricts */] = minority_1.doMajorityMinorityDistricts(s, bLog);
|
|
101256
|
-
}
|
|
101257
|
-
// Tests in the "Best" suite, i.e., criteria for better/worse
|
|
101258
|
-
if (requestedSuites.includes(2 /* Best */)) {
|
|
101259
|
-
s.tests[5 /* Reock */] = compact_1.doReock(s, bLog);
|
|
101260
|
-
s.tests[6 /* PolsbyPopper */] = compact_1.doPolsbyPopper(s, bLog);
|
|
101261
101282
|
s.tests[7 /* UnexpectedCountySplits */] = cohesive_1.doFindCountiesSplitUnexpectedly(s, bLog);
|
|
101262
101283
|
s.tests[10 /* VTDSplits */] = cohesive_1.doFindSplitVTDs(s, bLog);
|
|
101263
|
-
s.tests[8 /* CountySplitting */] = cohesive_1.doCountySplitting(s, bLog);
|
|
101264
|
-
s.tests[9 /* DistrictSplitting */] = cohesive_1.doDistrictSplitting(s, bLog);
|
|
101265
101284
|
}
|
|
101266
101285
|
// Enable a Test Log and Scorecard to be generated
|
|
101267
101286
|
s.bPlanAnalyzed = true;
|
|
@@ -101275,8 +101294,6 @@ exports.doAnalyzePlan = doAnalyzePlan;
|
|
|
101275
101294
|
// NOTE - Should this be conditionalized on the test suites requested?
|
|
101276
101295
|
// Those are encapsulated in reports.ts right now, so not doing that.
|
|
101277
101296
|
function doDeriveSecondaryTests(s, bLog = false) {
|
|
101278
|
-
// TODO - SCORE: Toggle
|
|
101279
|
-
// const bLegacy = s._bLegacy;
|
|
101280
101297
|
s.tests[3 /* EqualPopulation */] = equal_1.doHasEqualPopulations(s, bLog);
|
|
101281
101298
|
}
|
|
101282
101299
|
exports.doDeriveSecondaryTests = doDeriveSecondaryTests;
|
|
@@ -101896,18 +101913,11 @@ exports.doPopulationDeviation = doPopulationDeviation;
|
|
|
101896
101913
|
// NOTE - This validity check is *derived* and depends on population deviation %
|
|
101897
101914
|
// being computed (above) and normalized in test log & scorecard generation.
|
|
101898
101915
|
function doHasEqualPopulations(s, bLog = false) {
|
|
101899
|
-
// TODO - SCORE: Toggle
|
|
101900
|
-
// const bLegacy = s._bLegacy;
|
|
101901
|
-
const scorecard = s._scorecard;
|
|
101902
|
-
const popDevNormalizedNEW = scorecard.best.populationDeviation.normalized;
|
|
101903
|
-
const bScore = (popDevNormalizedNEW > 0) ? true : false;
|
|
101904
|
-
// TODO - Get scales
|
|
101905
|
-
// TODO - Flow through to RequirementsChecklist
|
|
101906
101916
|
let test = s.getTest(3 /* EqualPopulation */);
|
|
101907
101917
|
// Get the normalized population deviation %
|
|
101908
101918
|
let popDevTest = s.getTest(4 /* PopulationDeviation */);
|
|
101909
|
-
|
|
101910
|
-
|
|
101919
|
+
const popDevPct = popDevTest['score'];
|
|
101920
|
+
const popDevNormalized = popDevTest['normalizedScore'];
|
|
101911
101921
|
// Populate the test entry
|
|
101912
101922
|
if (popDevNormalized > 0) {
|
|
101913
101923
|
test['score'] = true;
|
|
@@ -101917,7 +101927,6 @@ function doHasEqualPopulations(s, bLog = false) {
|
|
|
101917
101927
|
}
|
|
101918
101928
|
test['details']['deviation'] = popDevPct;
|
|
101919
101929
|
test['details']['thresholds'] = popDevTest['details']['scale'];
|
|
101920
|
-
console.log("Equal population =", test['score'], bScore);
|
|
101921
101930
|
// Populate the N+1 summary "district" in district.statistics
|
|
101922
101931
|
let bEqualPop = s.districts.statistics[D.DistrictField.bEqualPop];
|
|
101923
101932
|
let summaryRow = s.districts.numberOfRows() - 1;
|
|
@@ -102512,12 +102521,14 @@ function prepareRequirementsChecklist(s, bLog = false) {
|
|
|
102512
102521
|
const emptyDistrictsDetail = U.deepCopy(completeTest['details']['emptyDistricts']) || [];
|
|
102513
102522
|
const discontiguousDistrictsDetail = U.deepCopy(contiguousTest['details']['discontiguousDistricts']) || [];
|
|
102514
102523
|
const embeddedDistrictsDetail = U.deepCopy(freeOfHolesTest['details']['embeddedDistricts']) || [];
|
|
102515
|
-
|
|
102516
|
-
const
|
|
102517
|
-
//
|
|
102524
|
+
// TODO - SCORE: DELETE - This code is hooked correctly to use dra-score
|
|
102525
|
+
// const scorecard = s._scorecard as Score.Scorecard;
|
|
102526
|
+
// const populationDeviation = scorecard.best.populationDeviation.raw;
|
|
102518
102527
|
const populationDeviationDetail = U.deepCopy(equalPopulationTest['details']['deviation']);
|
|
102528
|
+
// console.log("Population deviations =", populationDeviationDetail, populationDeviation);
|
|
102529
|
+
// const deviationThreshold = scorecard.best.populationDeviation.notes['threshold'];
|
|
102519
102530
|
const deviationThresholdDetail = U.trim(s.populationDeviationThreshold());
|
|
102520
|
-
console.log("Population deviation thresholds =", deviationThresholdDetail, deviationThreshold);
|
|
102531
|
+
// console.log("Population deviation thresholds =", deviationThresholdDetail, deviationThreshold);
|
|
102521
102532
|
const xx = s.state.xx;
|
|
102522
102533
|
// TODO - JSON: Is there a better / easier way to work with the variable?
|
|
102523
102534
|
const stateReqsDict = state_reqs_json_1.default;
|
|
@@ -102785,20 +102796,27 @@ exports.doConfigureScales = doConfigureScales;
|
|
|
102785
102796
|
// Do this after analytics have been run and before preparing a test log or scorecard.
|
|
102786
102797
|
function doAnalyzePostProcessing(s, bLog = false) {
|
|
102787
102798
|
// TODO - SCORE: Toggle
|
|
102788
|
-
|
|
102789
|
-
|
|
102790
|
-
|
|
102791
|
-
|
|
102792
|
-
|
|
102793
|
-
|
|
102794
|
-
|
|
102795
|
-
|
|
102796
|
-
|
|
102797
|
-
|
|
102798
|
-
|
|
102799
|
-
|
|
102799
|
+
if (s.useLegacy()) {
|
|
102800
|
+
// Normalize the raw scores for all the numerics tests
|
|
102801
|
+
let testResults = U.getNumericObjectKeys(testDefns);
|
|
102802
|
+
for (let testID of testResults) {
|
|
102803
|
+
if (testDefns[testID]['normalize']) {
|
|
102804
|
+
let testResult = s.getTest(testID);
|
|
102805
|
+
let rawScore = testResult['score'];
|
|
102806
|
+
let normalizedScore;
|
|
102807
|
+
normalizedScore = U.normalize(rawScore, s.testScales[testID]);
|
|
102808
|
+
testResult['normalizedScore'] = normalizedScore;
|
|
102809
|
+
// Add the scale used to normalize the raw score to the details
|
|
102810
|
+
testResult['details']['scale'] = s.testScales[testID].scale;
|
|
102811
|
+
}
|
|
102800
102812
|
}
|
|
102801
102813
|
}
|
|
102814
|
+
else {
|
|
102815
|
+
// Just populate the normalized population deviation score in the test
|
|
102816
|
+
const scorecard = s._scorecard;
|
|
102817
|
+
let test = s.getTest(4 /* PopulationDeviation */);
|
|
102818
|
+
test['normalizedScore'] = scorecard.best.populationDeviation.normalized;
|
|
102819
|
+
}
|
|
102802
102820
|
// Derive secondary tests
|
|
102803
102821
|
analyze_1.doDeriveSecondaryTests(s, bLog);
|
|
102804
102822
|
// Toggle the semaphore, so postprocessing isn't for both the testlog & scorecard
|
|
@@ -102829,7 +102847,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
102829
102847
|
return result;
|
|
102830
102848
|
};
|
|
102831
102849
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
102832
|
-
const Score = __importStar(__webpack_require__(/*! @dra2020/dra-score */ "
|
|
102850
|
+
const Score = __importStar(__webpack_require__(/*! @dra2020/dra-score */ "./node_modules/@dra2020/dra-score/dist/dra-score.bundle.js"));
|
|
102833
102851
|
const U = __importStar(__webpack_require__(/*! ./utils */ "./src/utils.ts"));
|
|
102834
102852
|
const D = __importStar(__webpack_require__(/*! ./_data */ "./src/_data.ts"));
|
|
102835
102853
|
// PROFILE A PLAN
|
|
@@ -102919,9 +102937,27 @@ function makeArrayOfDemographics(s, bLog = false) {
|
|
|
102919
102937
|
return demographicsArray;
|
|
102920
102938
|
}
|
|
102921
102939
|
// SCORE A PLAN
|
|
102922
|
-
function scorePlan(p, bLog = false) {
|
|
102940
|
+
function scorePlan(s, p, bLog = false, overridesJSON) {
|
|
102923
102941
|
let scorer = new Score.Scorer();
|
|
102924
|
-
|
|
102942
|
+
const scorecard = scorer.score(p, overridesJSON);
|
|
102943
|
+
// TODO - SCORE: Toggle: Before returning, create a dummy population deviation
|
|
102944
|
+
// test, for doHasEqualPopulations() to use later. This is preserving the old
|
|
102945
|
+
// calling sequence.
|
|
102946
|
+
let test = s.getTest(4 /* PopulationDeviation */);
|
|
102947
|
+
// TODO - SCORE: U.trim(popDev)???
|
|
102948
|
+
// Get the raw population deviation
|
|
102949
|
+
const popDev = scorecard.best.populationDeviation.raw;
|
|
102950
|
+
// Populate the test entry
|
|
102951
|
+
test['score'] = popDev;
|
|
102952
|
+
test['details'] = { 'maxDeviation': scorecard.best.populationDeviation.notes['maxDeviation'] };
|
|
102953
|
+
// Populate the N+1 summary "district" in district.statistics
|
|
102954
|
+
let totalPop = s.districts.statistics[D.DistrictField.TotalPop];
|
|
102955
|
+
let popDevPct = s.districts.statistics[D.DistrictField.PopDevPct];
|
|
102956
|
+
let summaryRow = s.districts.numberOfRows() - 1;
|
|
102957
|
+
totalPop[summaryRow] = p.populationProfile.targetSize;
|
|
102958
|
+
popDevPct[summaryRow] = popDev;
|
|
102959
|
+
//
|
|
102960
|
+
return scorecard;
|
|
102925
102961
|
}
|
|
102926
102962
|
exports.scorePlan = scorePlan;
|
|
102927
102963
|
|