@dra2020/district-analytics 8.1.2 → 8.2.2

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.
@@ -380,6 +380,9 @@ class Districts {
380
380
  this._shapes = ds;
381
381
  this.statistics = this.initStatistics();
382
382
  }
383
+ getDistrictShapes() {
384
+ return this._shapes;
385
+ }
383
386
  getDistrictShapeByID(id) {
384
387
  // NOTE - Find the district shape by ID (not index)
385
388
  // return this._shapes.features[id];
@@ -1186,8 +1189,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
1186
1189
  return result;
1187
1190
  };
1188
1191
  Object.defineProperty(exports, "__esModule", { value: true });
1189
- // NOTE - This file will NOT be empty, when legacy code is deleted.
1190
1192
  const Poly = __importStar(__webpack_require__(/*! @dra2020/poly */ "@dra2020/poly"));
1193
+ const Compactness = __importStar(__webpack_require__(/*! @dra2020/compactness */ "@dra2020/compactness"));
1194
+ const U = __importStar(__webpack_require__(/*! ./utils */ "./src/utils.ts"));
1191
1195
  // HELPER TO EXTRACT PROPERTIES OF DISTRICT SHAPES
1192
1196
  // TODO - Create an array, as opposed to a dict
1193
1197
  function extractDistrictProperties(s, bLog = false) {
@@ -1195,13 +1199,12 @@ function extractDistrictProperties(s, bLog = false) {
1195
1199
  for (let i = 1; i <= s.state.nDistricts; i++) {
1196
1200
  const poly = s.districts.getDistrictShapeByID(i);
1197
1201
  // Guard against no shape for empty districts AND null shapes
1198
- const bNull = Poly.polyNull(poly);
1199
- if (!bNull) {
1202
+ if (isAShape(poly)) {
1200
1203
  // TODO - OPTIMIZE: Bundle these calls?
1201
1204
  const area = Poly.polyAreaFlat(poly);
1202
1205
  const perimeter = Poly.polyPerimeterFlat(poly);
1203
1206
  const diameter = Poly.polyDiameterFlat(poly);
1204
- const props = [0, 0, 0]; // TODO - TERRY?!?
1207
+ let props = [0, 0, 0];
1205
1208
  props[0 /* Area */] = area;
1206
1209
  props[1 /* Diameter */] = diameter;
1207
1210
  props[2 /* Perimeter */] = perimeter;
@@ -1212,6 +1215,39 @@ function extractDistrictProperties(s, bLog = false) {
1212
1215
  }
1213
1216
  }
1214
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
+ }
1224
+ // SCORE KIWYSI COMPACTNESS
1225
+ function scoreKIWYSICompactness(s, bLog = false) {
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);
1247
+ const avgKIWYSIScore = U.avgArray(scores);
1248
+ return avgKIWYSIScore;
1249
+ }
1250
+ exports.scoreKIWYSICompactness = scoreKIWYSICompactness;
1215
1251
  // SAVE THESE NOTES, IN CASE WE NEED TO REWORK HOW WE PERFORM THESE CALCS.
1216
1252
  // THEY REFLECT HOW I DID THEM IN PYTHON.
1217
1253
  //
@@ -1820,6 +1856,7 @@ const Score = __importStar(__webpack_require__(/*! @dra2020/dra-score */ "@dra20
1820
1856
  const U = __importStar(__webpack_require__(/*! ./utils */ "./src/utils.ts"));
1821
1857
  const D = __importStar(__webpack_require__(/*! ./_data */ "./src/_data.ts"));
1822
1858
  const M = __importStar(__webpack_require__(/*! ./minority */ "./src/minority.ts"));
1859
+ const C = __importStar(__webpack_require__(/*! ./compact */ "./src/compact.ts"));
1823
1860
  // PROFILE A PLAN
1824
1861
  function profilePlan(s, bLog = false) {
1825
1862
  const state = s.state.xx;
@@ -1944,6 +1981,9 @@ function scorePlan(s, p, bLog = false, overridesJSON) {
1944
1981
  // Add minority notes
1945
1982
  scorecard.minority.details['majorityMinority'] = M.getMajorityMinority(s);
1946
1983
  scorecard.minority.details['vraPreclearance'] = M.getVRASection5(s);
1984
+ // Add KIWYSI compactness score
1985
+ const kiwysiScore = C.scoreKIWYSICompactness(s, bLog);
1986
+ scorecard.compactness.details['kiwysi'] = kiwysiScore;
1947
1987
  return scorecard;
1948
1988
  }
1949
1989
  exports.scorePlan = scorePlan;
@@ -2568,6 +2608,17 @@ module.exports = JSON.parse("{\"AL\":\"all\",\"AK\":\"all\",\"AZ\":\"all\",\"CA\
2568
2608
 
2569
2609
  /***/ }),
2570
2610
 
2611
+ /***/ "@dra2020/compactness":
2612
+ /*!***************************************!*\
2613
+ !*** external "@dra2020/compactness" ***!
2614
+ \***************************************/
2615
+ /*! no static exports found */
2616
+ /***/ (function(module, exports) {
2617
+
2618
+ module.exports = require("@dra2020/compactness");
2619
+
2620
+ /***/ }),
2621
+
2571
2622
  /***/ "@dra2020/dra-score":
2572
2623
  /*!*************************************!*\
2573
2624
  !*** external "@dra2020/dra-score" ***!