@dra2020/district-analytics 8.2.0 → 8.2.3

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.
@@ -1199,13 +1199,12 @@ function extractDistrictProperties(s, bLog = false) {
1199
1199
  for (let i = 1; i <= s.state.nDistricts; i++) {
1200
1200
  const poly = s.districts.getDistrictShapeByID(i);
1201
1201
  // Guard against no shape for empty districts AND null shapes
1202
- const bNull = Poly.polyNull(poly);
1203
- if (!bNull) {
1202
+ if (isAShape(poly)) {
1204
1203
  // TODO - OPTIMIZE: Bundle these calls?
1205
1204
  const area = Poly.polyAreaFlat(poly);
1206
1205
  const perimeter = Poly.polyPerimeterFlat(poly);
1207
1206
  const diameter = Poly.polyDiameterFlat(poly);
1208
- const props = [0, 0, 0]; // TODO - TERRY?!?
1207
+ let props = [0, 0, 0];
1209
1208
  props[0 /* Area */] = area;
1210
1209
  props[1 /* Diameter */] = diameter;
1211
1210
  props[2 /* Perimeter */] = perimeter;
@@ -1216,10 +1215,35 @@ function extractDistrictProperties(s, bLog = false) {
1216
1215
  }
1217
1216
  }
1218
1217
  exports.extractDistrictProperties = extractDistrictProperties;
1218
+ function isAShape(poly) {
1219
+ const bPolyUndefined = (poly === undefined) ? true : false;
1220
+ const bNull = (bPolyUndefined) ? true : Poly.polyNull(poly); // TODO
1221
+ const bNoCoordinates = U.isArrayEmpty((poly.geometry.coordinates)) ? true : false;
1222
+ return (!bPolyUndefined && !bNull && !bNoCoordinates);
1223
+ }
1219
1224
  // SCORE KIWYSI COMPACTNESS
1220
1225
  function scoreKIWYSICompactness(s, bLog = false) {
1221
- const shapes = s.districts.getDistrictShapes();
1222
- const scores = Compactness.scoreShapes(shapes);
1226
+ const rawShapes = s.districts.getDistrictShapes();
1227
+ // Filter the real shapes & throw everything else away
1228
+ let goodShapes = {};
1229
+ goodShapes['type'] = "FeatureCollection";
1230
+ goodShapes['features'] = [];
1231
+ for (let i = 0; i < rawShapes.features.length; i++) {
1232
+ const shape = rawShapes.features[i];
1233
+ if (isAShape(shape)) {
1234
+ const d = Poly.polyDescribe(shape);
1235
+ let f = {
1236
+ type: 'Feature',
1237
+ properties: { districtID: `${i + 1}` },
1238
+ geometry: {
1239
+ type: (d.npoly > 1) ? 'MultiPolygon' : 'Polygon',
1240
+ coordinates: shape.geometry.coordinates
1241
+ }
1242
+ };
1243
+ goodShapes.features.push(f);
1244
+ }
1245
+ }
1246
+ const scores = Compactness.scoreShapes(goodShapes);
1223
1247
  const avgKIWYSIScore = U.avgArray(scores);
1224
1248
  return avgKIWYSIScore;
1225
1249
  }
@@ -1957,9 +1981,13 @@ function scorePlan(s, p, bLog = false, overridesJSON) {
1957
1981
  // Add minority notes
1958
1982
  scorecard.minority.details['majorityMinority'] = M.getMajorityMinority(s);
1959
1983
  scorecard.minority.details['vraPreclearance'] = M.getVRASection5(s);
1984
+ // TODO - KIWYSI
1960
1985
  // Add KIWYSI compactness score
1961
- const kiwysiScore = C.scoreKIWYSICompactness(s, bLog);
1962
- scorecard.compactness.details['kiwysi'] = kiwysiScore;
1986
+ if (('kiwysi' in s.config) && (s.config['kiwysi'])) {
1987
+ console.log("Scoring KIWYSI compactness ...");
1988
+ const kiwysiScore = C.scoreKIWYSICompactness(s, bLog);
1989
+ scorecard.compactness.details['kiwysi'] = kiwysiScore;
1990
+ }
1963
1991
  return scorecard;
1964
1992
  }
1965
1993
  exports.scorePlan = scorePlan;