@dra2020/district-analytics 8.2.5 → 8.2.8

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.
@@ -1223,10 +1223,11 @@ function extractDistrictProperties(s, bLog = false) {
1223
1223
  }
1224
1224
  exports.extractDistrictProperties = extractDistrictProperties;
1225
1225
  function isAShape(poly) {
1226
- const bPolyUndefined = (poly === undefined) ? true : false;
1227
- const bNull = (bPolyUndefined) ? true : Poly.polyNull(poly); // TODO - poly
1228
- const bNoCoordinates = U.isArrayEmpty((poly.geometry.coordinates)) ? true : false;
1229
- return (!bPolyUndefined && !bNull && !bNoCoordinates);
1226
+ if (poly == null)
1227
+ return false;
1228
+ if (Poly.polyNull(poly))
1229
+ return false;
1230
+ return poly.geometry && poly.geometry.coordinates && !U.isArrayEmpty(poly.geometry.coordinates);
1230
1231
  }
1231
1232
  // SCORE KIWYSI COMPACTNESS
1232
1233
  function scoreKIWYSICompactness(s, bLog = false) {
@@ -1316,8 +1317,12 @@ function doHasEqualPopulations(s, bLog = false) {
1316
1317
  let popDevTest = s.getTest(4 /* PopulationDeviation */);
1317
1318
  const popDevPct = popDevTest['score'];
1318
1319
  const popDevNormalized = popDevTest['normalizedScore'];
1320
+ // 09-19-2020 - Added to catch edge case of only one non-empty district
1321
+ const p = s._profile;
1322
+ const totPopByDistrict = p.populationProfile.totalPopByDistrict.filter(x => x > 0);
1323
+ const bTwoOrMoreDistricts = (totPopByDistrict.length > 1) ? true : false;
1319
1324
  // Populate the test entry
1320
- if (popDevNormalized > 0) {
1325
+ if (bTwoOrMoreDistricts && (popDevNormalized > 0)) {
1321
1326
  test['score'] = true;
1322
1327
  }
1323
1328
  else {
@@ -2015,9 +2020,16 @@ function scorePlan(s, p, bLog = false, overridesJSON) {
2015
2020
  // Add minority notes
2016
2021
  scorecard.minority.details['majorityMinority'] = M.getMajorityMinority(s);
2017
2022
  scorecard.minority.details['vraPreclearance'] = M.getVRASection5(s);
2018
- // Add KIWYSI compactness score
2019
- const kiwysiScore = C.scoreKIWYSICompactness(s, bLog);
2020
- scorecard.compactness.details['kiwysi'] = kiwysiScore;
2023
+ try {
2024
+ // Add KIWYSI compactness score
2025
+ const kiwysiScore = C.scoreKIWYSICompactness(s, bLog);
2026
+ scorecard.compactness.details['kiwysi'] = kiwysiScore;
2027
+ }
2028
+ catch (e) {
2029
+ console.log("Exception caught scoring KIWYSI compactness.");
2030
+ console.log(e.message);
2031
+ // throw e;
2032
+ }
2021
2033
  return scorecard;
2022
2034
  }
2023
2035
  exports.scorePlan = scorePlan;