@dra2020/district-analytics 5.5.0 → 5.6.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 CHANGED
@@ -88611,13 +88611,11 @@ const U = __importStar(__webpack_require__(/*! ./utils */ "./src/utils.ts"));
88611
88611
  const S = __importStar(__webpack_require__(/*! ./settings */ "./src/settings.ts"));
88612
88612
  const C = __importStar(__webpack_require__(/*! ./config */ "./src/config.ts"));
88613
88613
  const normalize_1 = __webpack_require__(/*! ./normalize */ "./src/normalize.ts");
88614
- function scoreCountySplitting(rawValue, nCounties, nDistricts) {
88614
+ function scoreCountySplitting(rawValue, nCounties, nDistricts, bLD = false) {
88615
88615
  const _normalizer = new normalize_1.Normalizer(rawValue);
88616
- const singleBest = C.countySplittingRange()[C.BEG];
88617
- const singleWorst = C.countySplittingRange()[C.END];
88618
88616
  // The practical ideal score depends on the # of counties & districts
88619
- const avgBest = countySplitBest(nCounties, nDistricts);
88620
- const avgWorst = countySplitWorst(avgBest);
88617
+ const avgBest = countySplitBest(nCounties, nDistricts, bLD);
88618
+ const avgWorst = countySplitWorst(avgBest, bLD);
88621
88619
  _normalizer.clip(avgBest, avgWorst);
88622
88620
  _normalizer.unitize(avgBest, avgWorst);
88623
88621
  _normalizer.invert();
@@ -88625,25 +88623,28 @@ function scoreCountySplitting(rawValue, nCounties, nDistricts) {
88625
88623
  return _normalizer.normalizedNum;
88626
88624
  }
88627
88625
  exports.scoreCountySplitting = scoreCountySplitting;
88628
- function countySplitBest(nCounties, nDistricts) {
88629
- const practicalBest = C.countySplittingRange()[C.BEG];
88626
+ function countySplitBest(nCounties, nDistricts, bLD = false) {
88627
+ const districtType = (bLD) ? 1 /* StateLegistlative */ : 0 /* Congressional */;
88628
+ const practicalBest = C.countySplittingRange(districtType)[C.BEG];
88630
88629
  const nAllowableSplits = Math.min(nDistricts - 1, nCounties);
88631
88630
  const threshold = ((nAllowableSplits * practicalBest) + ((nCounties - nAllowableSplits) * 1.0)) / nCounties;
88632
88631
  return threshold;
88633
88632
  }
88634
88633
  exports.countySplitBest = countySplitBest;
88635
- function countySplitWorst(avgBest) {
88636
- const singleBest = C.countySplittingRange()[C.BEG];
88637
- const singleWorst = C.countySplittingRange()[C.END];
88634
+ function countySplitWorst(avgBest, bLD = false) {
88635
+ const districtType = (bLD) ? 1 /* StateLegistlative */ : 0 /* Congressional */;
88636
+ const singleBest = C.countySplittingRange(districtType)[C.BEG];
88637
+ const singleWorst = C.countySplittingRange(districtType)[C.END];
88638
88638
  // The practical ideal score depends on the # of counties & districts
88639
88639
  const avgWorst = avgBest * (singleWorst / singleBest);
88640
88640
  return avgWorst;
88641
88641
  }
88642
88642
  exports.countySplitWorst = countySplitWorst;
88643
- function scoreDistrictSplitting(rawValue) {
88643
+ function scoreDistrictSplitting(rawValue, bLD = false) {
88644
+ const districtType = (bLD) ? 1 /* StateLegistlative */ : 0 /* Congressional */;
88644
88645
  const _normalizer = new normalize_1.Normalizer(rawValue);
88645
- const best = C.districtSplittingRange()[C.BEG];
88646
- const worst = C.districtSplittingRange()[C.END];
88646
+ const best = C.districtSplittingRange(districtType)[C.BEG];
88647
+ const worst = C.districtSplittingRange(districtType)[C.END];
88647
88648
  _normalizer.clip(best, worst);
88648
88649
  _normalizer.unitize(best, worst);
88649
88650
  _normalizer.invert();
@@ -88653,14 +88654,14 @@ function scoreDistrictSplitting(rawValue) {
88653
88654
  exports.scoreDistrictSplitting = scoreDistrictSplitting;
88654
88655
  // Migrated from district-analytics
88655
88656
  // CALCULATE ENHANCED SQRT ENTROPY METRIC
88656
- function doCountySplittingReduced(CxD, districtTotals, countyTotals, bLog = false) {
88657
+ function doCountySplittingReduced(CxD, districtTotals, countyTotals, bLD = false) {
88657
88658
  const rC = reduceCSplits(CxD, districtTotals);
88658
88659
  const f = calcCountyFractions(rC, countyTotals);
88659
88660
  const w = calcCountyWeights(countyTotals);
88660
88661
  const nD = districtTotals.length;
88661
88662
  const nC = countyTotals.length;
88662
- const rawSqEnt_DC = countySplitting(f, w, bLog);
88663
- const normalizedSqEnt_DC = scoreCountySplitting(rawSqEnt_DC, nC, nD);
88663
+ const rawSqEnt_DC = countySplitting(f, w);
88664
+ const normalizedSqEnt_DC = scoreCountySplitting(rawSqEnt_DC, nC, nD, bLD);
88664
88665
  const m = {
88665
88666
  raw: rawSqEnt_DC,
88666
88667
  normalized: normalizedSqEnt_DC,
@@ -88676,12 +88677,12 @@ function doCountySplitting(CxD, countyTotals, bLog = false) {
88676
88677
  return SqEnt_DC;
88677
88678
  }
88678
88679
  exports.doCountySplitting = doCountySplitting;
88679
- function doDistrictSplittingReduced(CxD, districtTotals, countyTotals, bLog = false) {
88680
+ function doDistrictSplittingReduced(CxD, districtTotals, countyTotals, bLD = false) {
88680
88681
  const rD = reduceDSplits(CxD, countyTotals);
88681
88682
  const g = calcDistrictFractions(rD, districtTotals);
88682
88683
  const x = calcDistrictWeights(districtTotals);
88683
- const rawSqEnt_CD = districtSplitting(g, x, bLog);
88684
- const normalizedSqEnt_CD = scoreDistrictSplitting(rawSqEnt_CD);
88684
+ const rawSqEnt_CD = districtSplitting(g, x);
88685
+ const normalizedSqEnt_CD = scoreDistrictSplitting(rawSqEnt_CD, bLD);
88685
88686
  const m = {
88686
88687
  raw: rawSqEnt_CD,
88687
88688
  normalized: normalizedSqEnt_CD,
@@ -89101,7 +89102,7 @@ exports.scorePolsbyPopper = scorePolsbyPopper;
89101
89102
  /*! exports provided: partisan, minority, traditionalPrinciples, default */
89102
89103
  /***/ (function(module) {
89103
89104
 
89104
- 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],\"weight\":50},\"district\":{\"range\":[1.26,1.68],\"weight\":50},\"weight\":[0,50]},\"popdev\":{\"range\":[[0.0075,0.002],[0.1,-1]],\"weight\":[0,0]},\"weight\":[0,20]}}");
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.16,1.55]],\"weight\":50},\"district\":{\"range\":[[1.26,1.68],[1.16,1.55]],\"weight\":50},\"weight\":[0,50]},\"popdev\":{\"range\":[[0.0075,0.002],[0.1,-1]],\"weight\":[0,0]},\"weight\":[0,20]}}");
89105
89106
 
89106
89107
  /***/ }),
89107
89108
 
@@ -89251,8 +89252,8 @@ function countySplittingWeight(overridesJSON) {
89251
89252
  return csW;
89252
89253
  }
89253
89254
  exports.countySplittingWeight = countySplittingWeight;
89254
- function countySplittingRange(overridesJSON) {
89255
- const range = config_json_1.default.traditionalPrinciples.splitting.county.range;
89255
+ function countySplittingRange(d, overridesJSON) {
89256
+ const range = config_json_1.default.traditionalPrinciples.splitting.county.range[d];
89256
89257
  return range;
89257
89258
  }
89258
89259
  exports.countySplittingRange = countySplittingRange;
@@ -89261,8 +89262,8 @@ function districtSplittingWeight(overridesJSON) {
89261
89262
  return dsW;
89262
89263
  }
89263
89264
  exports.districtSplittingWeight = districtSplittingWeight;
89264
- function districtSplittingRange(overridesJSON) {
89265
- const range = config_json_1.default.traditionalPrinciples.splitting.district.range;
89265
+ function districtSplittingRange(d, overridesJSON) {
89266
+ const range = config_json_1.default.traditionalPrinciples.splitting.district.range[d];
89266
89267
  return range;
89267
89268
  }
89268
89269
  exports.districtSplittingRange = districtSplittingRange;
@@ -90177,9 +90178,9 @@ function estMarginalCompetitiveDistricts(Mrange, VfArray) {
90177
90178
  const maxId = Mrange[C.END];
90178
90179
  // Sort the array values, and subset it to those districts
90179
90180
  // NOTE - I'm *not* keeping track of the district indexes right now
90180
- let subsetVfArray = VfArray.sort().slice(minId - 1, maxId);
90181
+ let subsetVfArray = U.deepCopy(VfArray).sort().slice(minId - 1, maxId);
90181
90182
  // Est. competitive districts on that array
90182
- const Md = U.sumArray(subsetVfArray.map(v => estDistrictCompetitiveness(v)));
90183
+ const Md = U.sumArray(subsetVfArray.map((v) => estDistrictCompetitiveness(v)));
90183
90184
  return U.trim(Md);
90184
90185
  }
90185
90186
  exports.estMarginalCompetitiveDistricts = estMarginalCompetitiveDistricts;
@@ -90578,7 +90579,7 @@ const equal_1 = __webpack_require__(/*! ./equal */ "./src/equal.ts");
90578
90579
  const partisan_1 = __webpack_require__(/*! ./partisan */ "./src/partisan.ts");
90579
90580
  const minority_1 = __webpack_require__(/*! ./minority */ "./src/minority.ts");
90580
90581
  function scorePlan(p, overridesJSON) {
90581
- // TRADITIONAL DISTRICTING PRINCIPLES ("best") subcategories - compactness, splitting, population deviation
90582
+ const bLD = p.legislativeDistricts;
90582
90583
  // Compactness
90583
90584
  const reockM = compact_1.doReock(p.compactnessProfile.geometryByDistrict);
90584
90585
  const polsbyM = compact_1.doPolsbyPopper(p.compactnessProfile.geometryByDistrict);
@@ -90787,16 +90788,18 @@ function maxArray(arr) {
90787
90788
  }
90788
90789
  exports.maxArray = maxArray;
90789
90790
  // Modified from https://jsfiddle.net/Lucky500/3sy5au0c/
90791
+ // NOTE - Copy the array, because arr.sort() sorts in place!
90790
90792
  function medianArray(arr) {
90791
90793
  if (arr.length === 0)
90792
90794
  return 0;
90793
- arr.sort(function (a, b) {
90795
+ let copyArr = deepCopy(arr);
90796
+ copyArr.sort(function (a, b) {
90794
90797
  return a - b;
90795
90798
  });
90796
- var half = Math.floor(arr.length / 2);
90797
- if (arr.length % 2)
90798
- return arr[half];
90799
- return (arr[half - 1] + arr[half]) / 2.0;
90799
+ var half = Math.floor(copyArr.length / 2);
90800
+ if (copyArr.length % 2)
90801
+ return copyArr[half];
90802
+ return (copyArr[half - 1] + copyArr[half]) / 2.0;
90800
90803
  }
90801
90804
  exports.medianArray = medianArray;
90802
90805
  function initArray(n, value) {