@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.
package/dist/cli.js CHANGED
@@ -90537,45 +90537,6 @@ function __export(m) {
90537
90537
  Object.defineProperty(exports, "__esModule", { value: true });
90538
90538
  __export(__webpack_require__(/*! ./features */ "./src/features.ts"));
90539
90539
  __export(__webpack_require__(/*! ./kiwysi */ "./src/kiwysi.ts"));
90540
- /* TODO - DELETE
90541
- // HACK - To get this package to import correctly
90542
- export class _Hack
90543
- {
90544
- constructor()
90545
- {
90546
- }
90547
- }
90548
-
90549
- */
90550
- /* TODO - DELETE
90551
- import
90552
- {
90553
- calcXSymmetry,
90554
- calcYSymmetry,
90555
- calcReock,
90556
- calcBoundingBox,
90557
- calcPolsbyPopper,
90558
- calcConvexHullFeature,
90559
- calcSchwartzberg
90560
- } from '../src/features';
90561
-
90562
- import
90563
- {
90564
- scoreShapes
90565
- } from '../src/kiwysi';
90566
-
90567
- export = {
90568
- calcXSymmetry: calcXSymmetry,
90569
- calcYSymmetry: calcYSymmetry,
90570
- calcReock: calcReock,
90571
- calcBoundingBox: calcBoundingBox,
90572
- calcPolsbyPopper: calcPolsbyPopper,
90573
- calcConvexHullFeature: calcConvexHullFeature,
90574
- calcSchwartzberg: calcSchwartzberg,
90575
- scoreShapes: scoreShapes
90576
- };
90577
-
90578
- */
90579
90540
 
90580
90541
 
90581
90542
  /***/ }),
@@ -282008,13 +281969,12 @@ function extractDistrictProperties(s, bLog = false) {
282008
281969
  for (let i = 1; i <= s.state.nDistricts; i++) {
282009
281970
  const poly = s.districts.getDistrictShapeByID(i);
282010
281971
  // Guard against no shape for empty districts AND null shapes
282011
- const bNull = Poly.polyNull(poly);
282012
- if (!bNull) {
281972
+ if (isAShape(poly)) {
282013
281973
  // TODO - OPTIMIZE: Bundle these calls?
282014
281974
  const area = Poly.polyAreaFlat(poly);
282015
281975
  const perimeter = Poly.polyPerimeterFlat(poly);
282016
281976
  const diameter = Poly.polyDiameterFlat(poly);
282017
- const props = [0, 0, 0]; // TODO - TERRY?!?
281977
+ let props = [0, 0, 0];
282018
281978
  props[0 /* Area */] = area;
282019
281979
  props[1 /* Diameter */] = diameter;
282020
281980
  props[2 /* Perimeter */] = perimeter;
@@ -282025,10 +281985,35 @@ function extractDistrictProperties(s, bLog = false) {
282025
281985
  }
282026
281986
  }
282027
281987
  exports.extractDistrictProperties = extractDistrictProperties;
281988
+ function isAShape(poly) {
281989
+ const bPolyUndefined = (poly === undefined) ? true : false;
281990
+ const bNull = (bPolyUndefined) ? true : Poly.polyNull(poly); // TODO
281991
+ const bNoCoordinates = U.isArrayEmpty((poly.geometry.coordinates)) ? true : false;
281992
+ return (!bPolyUndefined && !bNull && !bNoCoordinates);
281993
+ }
282028
281994
  // SCORE KIWYSI COMPACTNESS
282029
281995
  function scoreKIWYSICompactness(s, bLog = false) {
282030
- const shapes = s.districts.getDistrictShapes();
282031
- const scores = Compactness.scoreShapes(shapes);
281996
+ const rawShapes = s.districts.getDistrictShapes();
281997
+ // Filter the real shapes & throw everything else away
281998
+ let goodShapes = {};
281999
+ goodShapes['type'] = "FeatureCollection";
282000
+ goodShapes['features'] = [];
282001
+ for (let i = 0; i < rawShapes.features.length; i++) {
282002
+ const shape = rawShapes.features[i];
282003
+ if (isAShape(shape)) {
282004
+ const d = Poly.polyDescribe(shape);
282005
+ let f = {
282006
+ type: 'Feature',
282007
+ properties: { districtID: `${i + 1}` },
282008
+ geometry: {
282009
+ type: (d.npoly > 1) ? 'MultiPolygon' : 'Polygon',
282010
+ coordinates: shape.geometry.coordinates
282011
+ }
282012
+ };
282013
+ goodShapes.features.push(f);
282014
+ }
282015
+ }
282016
+ const scores = Compactness.scoreShapes(goodShapes);
282032
282017
  const avgKIWYSIScore = U.avgArray(scores);
282033
282018
  return avgKIWYSIScore;
282034
282019
  }
@@ -282742,9 +282727,13 @@ function scorePlan(s, p, bLog = false, overridesJSON) {
282742
282727
  // Add minority notes
282743
282728
  scorecard.minority.details['majorityMinority'] = M.getMajorityMinority(s);
282744
282729
  scorecard.minority.details['vraPreclearance'] = M.getVRASection5(s);
282730
+ // TODO - KIWYSI
282745
282731
  // Add KIWYSI compactness score
282746
- const kiwysiScore = C.scoreKIWYSICompactness(s, bLog);
282747
- scorecard.compactness.details['kiwysi'] = kiwysiScore;
282732
+ if (('kiwysi' in s.config) && (s.config['kiwysi'])) {
282733
+ console.log("Scoring KIWYSI compactness ...");
282734
+ const kiwysiScore = C.scoreKIWYSICompactness(s, bLog);
282735
+ scorecard.compactness.details['kiwysi'] = kiwysiScore;
282736
+ }
282748
282737
  return scorecard;
282749
282738
  }
282750
282739
  exports.scorePlan = scorePlan;