@dra2020/district-analytics 3.2.0 → 4.1.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.
@@ -116,6 +116,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
116
116
  return result;
117
117
  };
118
118
  Object.defineProperty(exports, "__esModule", { value: true });
119
+ const Score = __importStar(__webpack_require__(/*! @dra2020/dra-score */ "@dra2020/dra-score"));
119
120
  const preprocess_1 = __webpack_require__(/*! ./preprocess */ "./src/preprocess.ts");
120
121
  const analyze_1 = __webpack_require__(/*! ./analyze */ "./src/analyze.ts");
121
122
  const score_1 = __webpack_require__(/*! ./score */ "./src/score.ts");
@@ -309,9 +310,13 @@ class AnalyticsSession {
309
310
  return 1 - this.testScales[4 /* PopulationDeviation */]['scale'][0];
310
311
  }
311
312
  else {
313
+ // NOTE - This assumes the plan has been profiled
314
+ const scorer = new Score.Scorer();
315
+ const popdev = scorer.populationDeviationThreshold(this.legislativeDistricts);
316
+ return popdev;
312
317
  // TODO - SCORE: Temporary HACK. Query dra-score for threshold.
313
318
  // NOTE - The plan may not have been scored yet, i.e., no scorecard yet.
314
- return 1 - this.testScales[4 /* PopulationDeviation */]['scale'][0];
319
+ // return 1 - this.testScales[T.Test.PopulationDeviation]['scale'][0];
315
320
  }
316
321
  }
317
322
  }
@@ -2545,7 +2550,9 @@ function doAnalyzePostProcessing(s, bLog = false) {
2545
2550
  // Just populate the normalized population deviation score in the test
2546
2551
  const scorecard = s._scorecard;
2547
2552
  let test = s.getTest(4 /* PopulationDeviation */);
2548
- test['normalizedScore'] = scorecard.best.populationDeviation.normalized;
2553
+ test['normalizedScore'] = scorecard.traditionalPrinciples.populationDeviation.normalized;
2554
+ // TODO - DELETE
2555
+ // test['normalizedScore'] = scorecard.best.populationDeviation.normalized;
2549
2556
  }
2550
2557
  // Derive secondary tests
2551
2558
  analyze_1.doDeriveSecondaryTests(s, bLog);
@@ -2591,9 +2598,10 @@ function profilePlan(s, bLog = false) {
2591
2598
  const geoPropsByDistrict = makeArrayOfGeoProps(s, bLog);
2592
2599
  const splits = makeNakedCxD(s);
2593
2600
  const summaryRow = s.districts.numberOfRows() - 1;
2594
- const statewideVf = s.districts.statistics[D.DistrictField.DemPct][summaryRow];
2601
+ const statewideVf = U.trim(s.districts.statistics[D.DistrictField.DemPct][summaryRow], 6);
2595
2602
  const vpiArray = U.deepCopy(s.districts.statistics[D.DistrictField.DemPct].slice(1, -1));
2596
- const demographicsByDistrict = makeArrayOfDemographics(s);
2603
+ const statewideDemographics = getStatewideDemographics(s);
2604
+ const demographicsByDistrict = getDemographicsByDistrict(s);
2597
2605
  const profile = {
2598
2606
  state: state,
2599
2607
  planName: planName,
@@ -2601,21 +2609,22 @@ function profilePlan(s, bLog = false) {
2601
2609
  nCounties: nCounties,
2602
2610
  legislativeDistricts: s.legislativeDistricts,
2603
2611
  populationProfile: {
2604
- TotalPopByDistrict: popByDistrict,
2612
+ totalPopByDistrict: popByDistrict,
2605
2613
  targetSize: targetSize
2606
2614
  },
2607
2615
  compactnessProfile: {
2608
- GeometryByDistrict: geoPropsByDistrict
2616
+ geometryByDistrict: geoPropsByDistrict
2609
2617
  },
2610
2618
  splittingProfile: {
2611
- CountyPopByDistrict: splits
2619
+ countyPopByDistrict: splits
2612
2620
  },
2613
2621
  partisanProfile: {
2614
2622
  statewideVf: statewideVf,
2615
- VfArray: vpiArray
2623
+ vfArray: vpiArray
2616
2624
  },
2617
2625
  demographicProfile: {
2618
- DemographicsByDistrict: demographicsByDistrict
2626
+ stateMfArray: statewideDemographics,
2627
+ mfArrayByDistrict: demographicsByDistrict
2619
2628
  }
2620
2629
  };
2621
2630
  return profile;
@@ -2649,7 +2658,7 @@ function makeArrayOfGeoProps(s, bLog = false) {
2649
2658
  }
2650
2659
  return geometryByDistrict;
2651
2660
  }
2652
- function makeArrayOfDemographics(s, bLog = false) {
2661
+ function getDemographicsByDistrict(s, bLog = false) {
2653
2662
  let demographicsArray = [];
2654
2663
  // Remove the unassigned & total dummy "districts"
2655
2664
  for (let districtID = 1; districtID <= s.state.nDistricts; districtID++) {
@@ -2666,6 +2675,19 @@ function makeArrayOfDemographics(s, bLog = false) {
2666
2675
  }
2667
2676
  return demographicsArray;
2668
2677
  }
2678
+ function getStatewideDemographics(s, bLog = false) {
2679
+ const summaryRow = s.districts.numberOfRows() - 1;
2680
+ const demographicsArray = [
2681
+ U.deepCopy(s.districts.statistics[D.DistrictField.WhitePct][summaryRow]),
2682
+ U.deepCopy(s.districts.statistics[D.DistrictField.MinorityPct][summaryRow]),
2683
+ U.deepCopy(s.districts.statistics[D.DistrictField.BlackPct][summaryRow]),
2684
+ U.deepCopy(s.districts.statistics[D.DistrictField.HispanicPct][summaryRow]),
2685
+ U.deepCopy(s.districts.statistics[D.DistrictField.PacificPct][summaryRow]),
2686
+ U.deepCopy(s.districts.statistics[D.DistrictField.AsianPct][summaryRow]),
2687
+ U.deepCopy(s.districts.statistics[D.DistrictField.NativePct][summaryRow])
2688
+ ];
2689
+ return demographicsArray;
2690
+ }
2669
2691
  // SCORE A PLAN
2670
2692
  function scorePlan(s, p, bLog = false, overridesJSON) {
2671
2693
  let scorer = new Score.Scorer();
@@ -2675,11 +2697,14 @@ function scorePlan(s, p, bLog = false, overridesJSON) {
2675
2697
  // calling sequence.
2676
2698
  let test = s.getTest(4 /* PopulationDeviation */);
2677
2699
  // TODO - SCORE: U.trim(popDev)???
2700
+ // const popDev = scorecard.best.populationDeviation.raw;
2678
2701
  // Get the raw population deviation
2679
- const popDev = scorecard.best.populationDeviation.raw;
2702
+ const popDev = scorecard.traditionalPrinciples.populationDeviation.raw;
2680
2703
  // Populate the test entry
2681
2704
  test['score'] = popDev;
2682
- test['details'] = { 'maxDeviation': scorecard.best.populationDeviation.notes['maxDeviation'] };
2705
+ test['details'] = { 'maxDeviation': scorecard.traditionalPrinciples.populationDeviation.notes['maxDeviation'] };
2706
+ // TODO - DELETE
2707
+ // test['details'] = { 'maxDeviation': scorecard.best.populationDeviation.notes['maxDeviation'] };
2683
2708
  // Populate the N+1 summary "district" in district.statistics
2684
2709
  let totalPop = s.districts.statistics[D.DistrictField.TotalPop];
2685
2710
  let popDevPct = s.districts.statistics[D.DistrictField.PopDevPct];
@@ -2744,6 +2769,8 @@ exports.DISTRICT_SPLITTING_WEIGHT = 1.0 - exports.COUNTY_SPLITTING_WEIGHT;
2744
2769
  Object.defineProperty(exports, "__esModule", { value: true });
2745
2770
  // TODO - SCORE
2746
2771
  var dra_score_1 = __webpack_require__(/*! @dra2020/dra-score */ "@dra2020/dra-score");
2772
+ // PartisanProfile,
2773
+ // PopulationProfile, ShapeProfile, SplittingProfile,
2747
2774
  exports.sampleProfile = dra_score_1.sampleProfile;
2748
2775
  exports.sampleScorecard = dra_score_1.sampleScorecard;
2749
2776
  // END