@dra2020/district-analytics 2.0.0 → 2.0.1

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
@@ -9034,19 +9034,14 @@ class AnalyticsSession {
9034
9034
  // Convert them into a (possibly empty) list of features
9035
9035
  let discontiguousDistrictFeatures = { type: 'FeatureCollection', features: [] };
9036
9036
  if (!(U.isArrayEmpty(discontiguousDistrictIDs))) {
9037
- for (let i = 0; i < discontiguousDistrictIDs.length; i++) {
9038
- let poly = this.districts.getShape(i);
9039
- discontiguousDistrictFeatures.features.push(poly);
9037
+ for (let id of discontiguousDistrictIDs) {
9038
+ let poly = this.districts.getDistrictShapeByID(id);
9039
+ if (poly)
9040
+ discontiguousDistrictFeatures.features.push(poly);
9040
9041
  }
9041
9042
  }
9042
9043
  return discontiguousDistrictFeatures;
9043
9044
  }
9044
- // TODO - DASHBOARD: Delete, when cut over to the new analytics UI.
9045
- // Prepare a scorecard for rendering
9046
- // NOTE - This assumes that analyzePlan() has been run!
9047
- // prepareScorecard(): any {
9048
- // return doPrepareScorecard(this);
9049
- // }
9050
9045
  // HELPERS USED INTERNALLY
9051
9046
  // Get an individual test, so you can drive UI with the results.
9052
9047
  getTest(testID) {
@@ -9062,12 +9057,6 @@ class AnalyticsSession {
9062
9057
  // Return a pointer to the the test entry for this test
9063
9058
  return this.tests[testID];
9064
9059
  }
9065
- // TODO - DASHBOARD: Delete, when cut over to the new analytics UI.
9066
- // Prepare test results for rendering
9067
- // NOTE - This assumes that analyzePlan() has been run!
9068
- // prepareTestLog(): any {
9069
- // return doPrepareTestLog(this);
9070
- // }
9071
9060
  // NOTE - Not sure why this has to be up here.
9072
9061
  populationDeviationThreshold() {
9073
9062
  return 1 - this.testScales[4 /* PopulationDeviation */]['scale'][0];
@@ -9145,7 +9134,16 @@ class Districts {
9145
9134
  this._shapes = ds;
9146
9135
  this.statistics = this.initStatistics();
9147
9136
  }
9148
- getShape(i) { return this._shapes.features[i]; }
9137
+ getDistrictShapeByID(id) {
9138
+ // NOTE - Find the district shape by ID (not index)
9139
+ // return this._shapes.features[id];
9140
+ for (let f of this._shapes.features) {
9141
+ if (f.properties && (f.properties.id == id)) {
9142
+ return f;
9143
+ }
9144
+ }
9145
+ return undefined;
9146
+ }
9149
9147
  getGeoProperties(i) {
9150
9148
  // Make sure the district shape exists & has geo properties
9151
9149
  if (i in this._geoProperties)
@@ -9616,7 +9614,12 @@ class Graph {
9616
9614
  // Ignore the lengths of the shared borders (the values), for now
9617
9615
  // Protect against getting a GEOID that's not in the graph
9618
9616
  if (U.keyExists(node, this._graph)) {
9619
- return U.getObjectKeys(this._graph[node]);
9617
+ // NOTE - CONTIGUITY GRAPHS
9618
+ // Handle both unweighted & weighted neighbors
9619
+ let n = this._graph[node];
9620
+ let l = (n instanceof Array) ? n : U.getObjectKeys(n);
9621
+ return l;
9622
+ // return U.getObjectKeys(this._graph[node]);
9620
9623
  }
9621
9624
  else
9622
9625
  return [];
@@ -10210,9 +10213,9 @@ function doPolsbyPopper(s, bLog = false) {
10210
10213
  exports.doPolsbyPopper = doPolsbyPopper;
10211
10214
  // HELPER TO EXTRACT PROPERTIES OF DISTRICT SHAPES
10212
10215
  function extractDistrictProperties(s, bLog = false) {
10216
+ // NOTE - I am assuming that district IDs are integers 1–N
10213
10217
  for (let i = 1; i <= s.state.nDistricts; i++) {
10214
- let j = i - 1; // TODO - TERRY: How do you get away w/o this?!?
10215
- let poly = s.districts.getShape(j);
10218
+ let poly = s.districts.getDistrictShapeByID(i);
10216
10219
  // Guard against no shape for empty districts AND null shapes
10217
10220
  let polyOptions = { noLatitudeCorrection: true };
10218
10221
  let bNull = (!Poly.polyNormalize(poly, polyOptions));
@@ -11727,7 +11730,6 @@ function doIsContiguous(s, bLog = false) {
11727
11730
  exports.doIsContiguous = doIsContiguous;
11728
11731
  // Are the features in a district fully connected?
11729
11732
  function isConnected(districtGeos, graph) {
11730
- // export function isConnected(districtGeos: Set<string>, graph: T.ContiguityGraph): boolean {
11731
11733
  // TODO - TERRY, why does this constructor need a <T> type specification?
11732
11734
  let visited = new Set();
11733
11735
  let toProcess = [];
@@ -12272,36 +12274,6 @@ switch (command) {
12272
12274
  // echoTestResult("Majority-Minority Districts:", t1); TODO
12273
12275
  break;
12274
12276
  }
12275
- // TODO - DASHBOARD: DELETE
12276
- // case 'analyze': {
12277
- // console.log("");
12278
- // console.log("Analyzing a plan ...");
12279
- // console.log("");
12280
- // s.analyzePlan(bLog);
12281
- // break;
12282
- // }
12283
- // TODO - DASHBOARD: DELETE
12284
- // case 'scorecard': {
12285
- // s.analyzePlan(bLog);
12286
- // text = s.prepareScorecard();
12287
- // console.log("");
12288
- // for (let line of text.data) {
12289
- // switch (line['variant']) {
12290
- // case 'beginTable':
12291
- // case 'endTable':
12292
- // console.log(line['variant']);
12293
- // break;
12294
- // case 'row':
12295
- // console.log(line['variant'], line['cells']);
12296
- // break;
12297
- // default:
12298
- // console.log(line['variant'], line['text']);
12299
- // break;
12300
- // }
12301
- // }
12302
- // console.log("");
12303
- // break;
12304
- // }
12305
12277
  // TODO - DASHBOARD: Print the structures out
12306
12278
  case 'analyze': {
12307
12279
  s.analyzePlan(bLog);
@@ -12311,39 +12283,6 @@ switch (command) {
12311
12283
  echoDistrictStatistics(districtStatistics);
12312
12284
  break;
12313
12285
  }
12314
- // // TODO - DASHBOARD: DELETE
12315
- // case 'testlog': {
12316
- // s.analyzePlan(bLog);
12317
- // text = s.prepareTestLog();
12318
- // console.log("");
12319
- // for (let line of text.data) {
12320
- // console.log(line['variant'], line['text']);
12321
- // }
12322
- // console.log("");
12323
- // break;
12324
- // }
12325
- // TODO - DASHBOARD: DELETE
12326
- // case 'limit': {
12327
- // s.analyzePlan(bLog);
12328
- // text = s.prepareScorecard();
12329
- // console.log("");
12330
- // for (let line of text.data) {
12331
- // switch (line['variant']) {
12332
- // case 'beginTable':
12333
- // case 'endTable':
12334
- // console.log(line['variant']);
12335
- // break;
12336
- // case 'row':
12337
- // console.log(line['variant'], line['cells']);
12338
- // break;
12339
- // default:
12340
- // console.log(line['variant'], line['text']);
12341
- // break;
12342
- // }
12343
- // }
12344
- // console.log("");
12345
- // break;
12346
- // }
12347
12286
  }
12348
12287
  console.log("Ending command @ ", new Date());
12349
12288
  // HELPER FUNCTIONS FOR ECHOING RESULTS