@dra2020/district-analytics 11.2.0 → 11.4.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.
@@ -1144,15 +1144,14 @@ function doFindCountiesSplitUnexpectedly(s, bLog = false) {
1144
1144
  // FIRST, ANALYZE THE COUNTY SPLITTING FOR THE PLAN
1145
1145
  // Get the county-district pivot ("splits")
1146
1146
  let countiesByDistrict = s.districts.table.countySplits;
1147
- // let countiesByDistrict = s.districts.statistics[D.DistrictField.CountySplits];
1148
- // countiesByDistrict = countiesByDistrict.slice(1, -1);
1149
1147
  // Find the single-county districts, i.e., districts NOT split across counties.
1150
1148
  // Ignore the dummy unassigned 0 and N+1 summary "districts."
1151
1149
  let singleCountyDistricts = [];
1152
1150
  for (let d = 1; d <= s.state.nDistricts; d++) {
1153
1151
  // See if there's only one county partition
1152
+ // Ignore the dummy unassigned 0 "county."
1154
1153
  let nCountiesInDistrict = 0;
1155
- for (let c = 0; c < s.counties.nCounties; c++) {
1154
+ for (let c = 1; c <= s.counties.nCounties; c++) {
1156
1155
  // Guard against empty district
1157
1156
  if (countiesByDistrict[d]) {
1158
1157
  if (countiesByDistrict[d][c] > 0) {
@@ -1175,9 +1174,11 @@ function doFindCountiesSplitUnexpectedly(s, bLog = false) {
1175
1174
  let nPartitionsOverall = 0;
1176
1175
  let splitCounties = new Set(); // The counties that are split across districts
1177
1176
  let totalAffected = 0; // The total population affected by those splits
1178
- for (let c = 0; c < s.counties.nCounties; c++) {
1177
+ // Ignore the dummy unassigned 0 "county."
1178
+ for (let c = 1; c <= s.counties.nCounties; c++) {
1179
1179
  let nCountyParts = 0;
1180
1180
  let subtotal = 0;
1181
+ // Ignore the dummy unassigned 0 and N+1 summary "districts."
1181
1182
  for (let d = 1; d <= s.state.nDistricts; d++) {
1182
1183
  // Guard against empty district
1183
1184
  if (countiesByDistrict[d]) {
@@ -1235,6 +1236,9 @@ function doFindCountiesSplitUnexpectedly(s, bLog = false) {
1235
1236
  test['details']['nSplits'] = nSplits;
1236
1237
  test['details']['unexpectedSplits'] = unexpectedSplits;
1237
1238
  test['details']['countiesSplitUnexpectedly'] = countiesSplitUnexpectedly;
1239
+ // 02-23-21 - Added single-county district details
1240
+ test['details']['expectedSplits'] = s.state.expectedSplits;
1241
+ test['details']['tooBigName'] = s.state.tooBigName;
1238
1242
  return test;
1239
1243
  }
1240
1244
  exports.doFindCountiesSplitUnexpectedly = doFindCountiesSplitUnexpectedly;
@@ -1334,12 +1338,10 @@ function scoreKIWYSICompactness(s, bLog = false) {
1334
1338
  goodShapes.features.push(f);
1335
1339
  }
1336
1340
  }
1337
- const scores = Compactness.scoreShapes(goodShapes);
1338
- // 10-21-2020 - Returned all by-district scores instead of just the average.
1339
- // - Round & invert the scores here at the source vs. later on, higher up.
1340
- return scores.map(n => 100 - Math.round(n));
1341
- // const avgKIWYSIScore: number = U.avgArray(scores);
1342
- // return avgKIWYSIScore;
1341
+ const scores = Compactness.scoreShapes(goodShapes, 0 /* Revised */);
1342
+ // Round & invert the scores here at the source vs. later on, higher up.
1343
+ // Raw KIWYSI scores will be 1–100 with smaller better, so map to 1–100 bigger better.
1344
+ return scores.map(n => 100 - Math.round(n) + 1);
1343
1345
  }
1344
1346
  exports.scoreKIWYSICompactness = scoreKIWYSICompactness;
1345
1347
  // SAVE THESE NOTES, IN CASE WE NEED TO REWORK HOW WE PERFORM THESE CALCS.