@dra2020/district-analytics 9.0.1 → 9.2.0

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.
@@ -1,8 +1,5 @@
1
1
  import * as T from './types';
2
- import * as D from './_data';
3
2
  import { AnalyticsSession } from './_api';
4
3
  export declare function doIsComplete(s: AnalyticsSession, bLog?: boolean): T.TestEntry;
5
4
  export declare function doIsContiguous(s: AnalyticsSession, bLog?: boolean): T.TestEntry;
6
- export declare function isConnected(districtGeos: Set<string>, graph: D.Graph): boolean;
7
5
  export declare function doIsFreeOfHoles(s: AnalyticsSession, bLog?: boolean): T.TestEntry;
8
- export declare function isEmbedded(districtID: number, geoIDs: Set<string>, plan: D.Plan, graph: D.Graph): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/district-analytics",
3
- "version": "9.0.1",
3
+ "version": "9.2.0",
4
4
  "description": "District analytics TypeScript package",
5
5
  "main": "dist/district-analytics.js",
6
6
  "files": [
@@ -48,8 +48,9 @@
48
48
  "yargs": "^12.0.5"
49
49
  },
50
50
  "dependencies": {
51
- "@dra2020/compactness": "^1.1.1",
52
- "@dra2020/dra-score": "^9.2.1",
51
+ "@dra2020/compactness": "^1.1.3",
52
+ "@dra2020/dra-graph": "^1.0.0",
53
+ "@dra2020/dra-score": "^9.2.2",
53
54
  "@dra2020/dra-types": "^1.6.1",
54
55
  "@dra2020/poly": "^1.5.0",
55
56
  "@dra2020/util": "^1.0.54",
package/dist/cli.js DELETED
@@ -1,611 +0,0 @@
1
- /******/ (function(modules) { // webpackBootstrap
2
- /******/ // The module cache
3
- /******/ var installedModules = {};
4
- /******/
5
- /******/ // The require function
6
- /******/ function __webpack_require__(moduleId) {
7
- /******/
8
- /******/ // Check if module is in cache
9
- /******/ if(installedModules[moduleId]) {
10
- /******/ return installedModules[moduleId].exports;
11
- /******/ }
12
- /******/ // Create a new module (and put it into the cache)
13
- /******/ var module = installedModules[moduleId] = {
14
- /******/ i: moduleId,
15
- /******/ l: false,
16
- /******/ exports: {}
17
- /******/ };
18
- /******/
19
- /******/ // Execute the module function
20
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21
- /******/
22
- /******/ // Flag the module as loaded
23
- /******/ module.l = true;
24
- /******/
25
- /******/ // Return the exports of the module
26
- /******/ return module.exports;
27
- /******/ }
28
- /******/
29
- /******/
30
- /******/ // expose the modules object (__webpack_modules__)
31
- /******/ __webpack_require__.m = modules;
32
- /******/
33
- /******/ // expose the module cache
34
- /******/ __webpack_require__.c = installedModules;
35
- /******/
36
- /******/ // define getter function for harmony exports
37
- /******/ __webpack_require__.d = function(exports, name, getter) {
38
- /******/ if(!__webpack_require__.o(exports, name)) {
39
- /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
40
- /******/ }
41
- /******/ };
42
- /******/
43
- /******/ // define __esModule on exports
44
- /******/ __webpack_require__.r = function(exports) {
45
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
46
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
47
- /******/ }
48
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
49
- /******/ };
50
- /******/
51
- /******/ // create a fake namespace object
52
- /******/ // mode & 1: value is a module id, require it
53
- /******/ // mode & 2: merge all properties of value into the ns
54
- /******/ // mode & 4: return value when already ns object
55
- /******/ // mode & 8|1: behave like require
56
- /******/ __webpack_require__.t = function(value, mode) {
57
- /******/ if(mode & 1) value = __webpack_require__(value);
58
- /******/ if(mode & 8) return value;
59
- /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
60
- /******/ var ns = Object.create(null);
61
- /******/ __webpack_require__.r(ns);
62
- /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
63
- /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
64
- /******/ return ns;
65
- /******/ };
66
- /******/
67
- /******/ // getDefaultExport function for compatibility with non-harmony modules
68
- /******/ __webpack_require__.n = function(module) {
69
- /******/ var getter = module && module.__esModule ?
70
- /******/ function getDefault() { return module['default']; } :
71
- /******/ function getModuleExports() { return module; };
72
- /******/ __webpack_require__.d(getter, 'a', getter);
73
- /******/ return getter;
74
- /******/ };
75
- /******/
76
- /******/ // Object.prototype.hasOwnProperty.call
77
- /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
78
- /******/
79
- /******/ // __webpack_public_path__
80
- /******/ __webpack_require__.p = "";
81
- /******/
82
- /******/
83
- /******/ // Load entry module and return exports
84
- /******/ return __webpack_require__(__webpack_require__.s = "./test/_cli.ts");
85
- /******/ })
86
- /************************************************************************/
87
- /******/ ({
88
-
89
- /***/ "./test/_cli.ts":
90
- /*!**********************!*\
91
- !*** ./test/_cli.ts ***!
92
- \**********************/
93
- /*! no static exports found */
94
- /***/ (function(module, exports, __webpack_require__) {
95
-
96
- "use strict";
97
-
98
- //
99
- // A SIMPLE COMMAND-LINE INTERFACE FOR EXERCISING THE ANALYTICS & VALIDATIONS
100
- //
101
- console.log("This has been deprecated! ");
102
- /*
103
-
104
- CONFIGURATIONS
105
-
106
- These configurations implement various CLI tests (using the commands in parens)
107
- w/in VS Code:
108
-
109
- * api-analyze (analyze) - Analyzes a plan and logs the results.
110
-
111
- * unit-valid (valid) - Exercises the validations.
112
-
113
- * invalid-unassigned (valid) - Tests a plan w/ unassigned features.
114
- * invalid-missing (valid) - Tests a plan w/ a missing district.
115
- * invalid-empty (valid) - Tests a plan w/ an empty district.
116
- * invalid-discontiguous (valid) - Tests a plan w/ a discontiguous district.
117
- * invalid-hole (valid) - Tests a plan w/ an embedded district.
118
-
119
-
120
- COMMANDS
121
-
122
- Tests can also be exercised from the commmand line from the project directory.
123
- This is a sample. Use "node --inspect --inspect-brk main.js ..." to attach a debugger.
124
-
125
- 1 - Plain vanilla run:
126
- ./main.js analyze -x NC -n 13 -p data/SAMPLE-BG-map.csv -d data/SAMPLE-BG-data2.json -s data/SAMPLE-BG-shapes.geojson -g data/SAMPLE-BG-graph.json -c data/SAMPLE-COUNTY.geojson
127
-
128
- 2 - Missing district:
129
- ./main.js analyze -x NC -n 13 -p data/SAMPLE-BG-map-missing.csv -d data/SAMPLE-BG-data2.json -s data/SAMPLE-BG-shapes.geojson -g data/SAMPLE-BG-graph.json -c data/SAMPLE-COUNTY.geojson
130
-
131
- 3 - Empty district:
132
- ./main.js valid -x NC -n 13 -p data/SAMPLE-BG-map.csv -d data/SAMPLE-BG-data2.json -s data/SAMPLE-BG-shapes.geojson -g data/SAMPLE-BG-graph.json -c data/SAMPLE-COUNTY.geojson --empty
133
-
134
- 4 - Unassigned features:
135
- ./main.js analyze -x NC -n 13 -p data/SAMPLE-BG-map-unassigned.csv -d data/SAMPLE-BG-data2.json -s data/SAMPLE-BG-shapes.geojson -g data/SAMPLE-BG-graph.json -c data/SAMPLE-COUNTY.geojson
136
-
137
- 5 - Discontiguous districts:
138
- ./main.js analyze -n 13 -p data/SAMPLE-BG-map-discontiguous.csv -d data/SAMPLE-BG-data2.json -s data/SAMPLE-BG-shapes.geojson -g data/SAMPLE-BG-graph.json -c data/SAMPLE-COUNTY.geojson
139
-
140
- 6 - Embedded district:
141
- ./main.js analyze -n 13 -p data/SAMPLE-BG-map-hole.csv -d data/SAMPLE-BG-data2.json -s data/SAMPLE-BG-shapes.geojson -g data/SAMPLE-BG-graph.json -c data/SAMPLE-COUNTY.geojson
142
-
143
- 7 - Test using NC block-level data <<< TODO - Need BLOCK-data2.json & COUNTY.geojson to run this again.
144
-
145
- cd ~/Documents/Professional/Projects/Redistricting/DRA2020/Analytics/compact/classic/ts_sample
146
- ./main.js analyze -v -n 13 -p SAMPLE-BLOCK-map.csv -d SAMPLE-BLOCK-data2.json -s SAMPLE-BLOCK-shapes.geojson -g SAMPLE-BLOCK-graph.json -c SAMPLE-COUNTY.geojson
147
-
148
- */
149
- // import yargs from 'yargs';
150
- // // TODO - Fix this import, so I don't have to do the 'union' workaround below.
151
- // import * as PC from 'polygon-clipping';
152
- // import * as Poly from '@dra2020/poly';
153
- // import * as fs from 'fs';
154
- // import * as path from 'path';
155
- // import parse from 'csv-parse/lib/sync';
156
- // import { AnalyticsSession } from '../src/_api'
157
- // import { doPreprocessData } from '../src/preprocess'
158
- // import { doAnalyzeDistricts } from '../src/analyze'
159
- // import { doAnalyzePostProcessing, DistrictStatistics, DistrictColumn } from '../src/results'
160
- // import { doIsComplete, doIsContiguous, doIsFreeOfHoles } from '../src/valid'
161
- // import { doHasEqualPopulations } from '../src/equal';
162
- // import * as T from '../src/types'
163
- // import * as U from '../src/utils';
164
- // import * as S from '../src/settings';
165
- // import * as D from '../src/_data';
166
- // // Simulate DRA unioning district shapes in the background
167
- // function addToPoly(poly: any, polys: any[]): any
168
- // {
169
- // // Terry's workaround
170
- // let _union: any = undefined;
171
- // let anyPC: any = PC;
172
- // if (anyPC.union) _union = anyPC.union;
173
- // if (anyPC.default.union) _union = anyPC.default.union;
174
- // if (_union === undefined) throw 'Unable to load union function from polygon-clipping';
175
- // return _union(poly, ...polys);
176
- // }
177
- // console.log("Starting command @ ", new Date());
178
- // // COMMAND LINE
179
- // let argv = yargs
180
- // .usage('Usage: $0 command [options]')
181
- // .example('$0 equal -f foo.geojson', 'Calculate population deviation')
182
- // .demandCommand(1, 'You must specify a command to execute.')
183
- // .command('valid', 'Perform validations.')
184
- // .command('analyze', 'API call to analyze a plan.')
185
- // .option('state', {
186
- // alias: 'x',
187
- // describe: 'Specify the state.',
188
- // type: 'string'
189
- // })
190
- // .option('number', {
191
- // alias: 'n',
192
- // describe: 'Specify the number of districts.',
193
- // type: 'number'
194
- // })
195
- // .option('legislative', {
196
- // alias: 'l',
197
- // describe: 'Specify that districts are legislative.',
198
- // type: 'boolean',
199
- // default: false
200
- // })
201
- // .option('plan', {
202
- // alias: 'p',
203
- // describe: 'Specify the plan to evaluate.',
204
- // type: 'string'
205
- // })
206
- // .option('data', {
207
- // alias: 'd',
208
- // describe: 'Specify the census & election data to use.',
209
- // type: 'string'
210
- // })
211
- // .option('shapes', {
212
- // alias: 's',
213
- // describe: 'Specify the shapes to use.',
214
- // type: 'string'
215
- // })
216
- // .option('graph', {
217
- // alias: 'g',
218
- // describe: 'Specify the contiguity graph to use.',
219
- // type: 'string'
220
- // })
221
- // .option('counties', {
222
- // alias: 'c',
223
- // describe: 'Specify the FIPS-to-county-name map to use.',
224
- // type: 'string'
225
- // })
226
- // .option('empty', {
227
- // describe: 'Specify whether a district should be empty.',
228
- // type: 'boolean',
229
- // default: false
230
- // })
231
- // .option('suites', {
232
- // describe: 'Specify the test suites to run.',
233
- // type: 'array',
234
- // default: []
235
- // })
236
- // .option('verbose', {
237
- // alias: 'v',
238
- // describe: 'Specify whether code should log to STDOUT.',
239
- // type: 'boolean',
240
- // default: false
241
- // })
242
- // .demandOption(['number', 'plan', 'data', 'shapes', 'counties'],
243
- // 'Please specify all the args.')
244
- // .help()
245
- // .argv;
246
- // // PROCESS COMMAND LINE ARGS
247
- // let command = argv._[0]
248
- // let xx = argv.state as string;
249
- // let bLegislativeDistricts = argv.legislative as boolean;
250
- // let nDistricts = argv.n as number;
251
- // let planByGeoID = readPlanCSV(argv.plan as string);
252
- // let graph = readJSON(argv.graph as string);
253
- // let data = readJSON(argv.data as string) as T.GeoFeatureCollection;
254
- // let counties = readJSON(argv.counties as string) as T.GeoFeatureCollection;
255
- // let shapes = readJSON(argv.shapes as string) as T.GeoFeatureCollection;
256
- // let bEmpty = argv.empty as boolean;
257
- // let suites = argv.suites as [];
258
- // // Some default dataset keys
259
- // let datasetKeys = {
260
- // SHAPES: "2010_VD",
261
- // CENSUS: "D16F",
262
- // VAP: "D16T",
263
- // ELECTION: "E16GPR"
264
- // } as T.DatasetKeys;
265
- // let datasetDescriptions = {
266
- // SHAPES: "2010 Voting Districts",
267
- // CENSUS: "2016 ACS Total Population",
268
- // VAP: "2016 ACS Voting Age Population",
269
- // ELECTION: "2016 Presidential Election",
270
- // }
271
- // // Session settings are required:
272
- // // - Analytics suites can be defaulted to all with [], but
273
- // // - Datasets must be explicitly specified
274
- // let sessionSettings = {
275
- // 'suites': suites,
276
- // 'datasets': datasetKeys,
277
- // 'descriptions': datasetDescriptions
278
- // } as T.Dict;
279
- // let bLog = argv.verbose as boolean;
280
- // // Invert the plan, so you can create the district shapes for the SessionRequest.
281
- // // NOTE - The plan here is complete (all features assigned).
282
- // let planByDistrictID = D.invertPlan(planByGeoID, undefined, bLog);
283
- // // SIMULATE THE HOST
284
- // // Create district shapes & extract properties (area, diameter, perimeter)
285
- // // Index the shapes by geoID
286
- // let shapesByGeoID: T.GeoFeatureMap = {};
287
- // let idStr = "GEOID";
288
- // // TODO - Terry: But sometimes "GEOID10" hasn't been set to "GEOID"
289
- // let firstFeature = shapes.features[0];
290
- // if (!(firstFeature.properties == null))
291
- // {
292
- // if (U.keyExists("GEOID10", firstFeature.properties)) idStr = "GEOID10";
293
- // }
294
- // for (let f of shapes.features)
295
- // {
296
- // if (!(f.properties == null))
297
- // {
298
- // // let idStr = "GEOID";
299
- // // TODO - Terry: Sometimes "GEOID10" hasn't been => to "GEOID!"
300
- // // if (U.keyExists("GEOID10", f.properties)) idStr = "GEOID10";
301
- // let geoID = f.properties[idStr];
302
- // shapesByGeoID[geoID] = f;
303
- // }
304
- // }
305
- // // Find the smallest Feature
306
- // // COPIED from dra-client/geodistrict.ts, and lightly modified
307
- // let geo = shapes;
308
- // let minFeatureArea = Poly.polyArea(geo.features[0]);
309
- // for (let i = 1; i < geo.features.length; i++)
310
- // {
311
- // let a = Poly.polyArea(geo.features[i]);
312
- // if (a < minFeatureArea) minFeatureArea = a;
313
- // }
314
- // // Eliminate anomalous holes
315
- // // COPIED from dra-client/geodistrict.ts, and lightly modified
316
- // // This is a bit of a hack in the sense that it is still an open question as to whether this is a problem
317
- // // with either the underlying shape data or a problem in our simplification of that shape data.
318
- // // But in any case, what this does is eliminate any holes that are smaller than the smallest feature. Such
319
- // // a hole must be an anomaly. CA/2010_VT in particular seems to have many such issues.
320
- // function eliminateAnomalousHoles(mp: any): void
321
- // {
322
- // // Normalize to multipolygon
323
- // if (U.depthof(mp) == 4) mp = [mp];
324
- // for (let i: number = 0; i < mp.length; i++)
325
- // {
326
- // let p: any = mp[i];
327
- // let cleanp: any[] = [p[0]];
328
- // for (let j: number = 1; j < p.length; j++)
329
- // {
330
- // let a = Poly.polyArea(p[j]);
331
- // if (a >= minFeatureArea)
332
- // cleanp.push(p[j]);
333
- // }
334
- // if (cleanp.length < p.length)
335
- // mp[i] = cleanp;
336
- // }
337
- // }
338
- // // Create district shapes
339
- // let districtShapes = {} as T.GeoFeatureCollection;
340
- // districtShapes['type'] = "FeatureCollection";
341
- // districtShapes['features'] = [] as T.GeoFeatureArray;
342
- // for (let districtID = 1; districtID <= nDistricts; districtID++)
343
- // {
344
- // let districtFeatures: T.GeoFeatureArray = [];
345
- // // If the district is not empty, collect its Features
346
- // // TODO - Should we generate degenerate shape, if a district is empty?
347
- // if (planByDistrictID[districtID])
348
- // {
349
- // planByDistrictID[districtID].forEach(function (geoID: string): void
350
- // {
351
- // districtFeatures.push(shapesByGeoID[geoID]);
352
- // });
353
- // // Union them together
354
- // let poly1Coordinates: any = Poly.polyNormalize(districtFeatures[0]);
355
- // let polyNCoordinates = districtFeatures.slice(1).map((i) => Poly.polyNormalize(i));
356
- // let poly = addToPoly(poly1Coordinates, polyNCoordinates);
357
- // // Convert the result to a Feature
358
- // let bPolygon: boolean = U.depthof(poly) == 4;
359
- // if (!bPolygon && poly.length == 1)
360
- // {
361
- // bPolygon = true;
362
- // poly = poly[0];
363
- // }
364
- // eliminateAnomalousHoles(poly);
365
- // let f: any = {
366
- // type: 'Feature',
367
- // properties: { districtID: `${districtID}` },
368
- // geometry: {
369
- // type: bPolygon ? 'Polygon' : 'MultiPolygon',
370
- // coordinates: poly
371
- // }
372
- // };
373
- // districtShapes.features.push(f);
374
- // } // End non-empty districts
375
- // }
376
- // // CONSTRUCT A SESSION REQUEST
377
- // let SessionRequest = {} as T.SessionRequest;
378
- // SessionRequest['title'] = "CLI Test";
379
- // SessionRequest['stateXX'] = xx;
380
- // SessionRequest['nDistricts'] = nDistricts;
381
- // SessionRequest['legislativeDistricts'] = bLegislativeDistricts;
382
- // SessionRequest['data'] = data;
383
- // SessionRequest['counties'] = counties;
384
- // SessionRequest['graph'] = graph;
385
- // SessionRequest['plan'] = planByGeoID;
386
- // SessionRequest['districtShapes'] = districtShapes;
387
- // SessionRequest['config'] = sessionSettings;
388
- // // CREATE AND INITIALIZE AN ANALYTICS SESSION
389
- // let s = new AnalyticsSession(SessionRequest);
390
- // // DISPATCH TO REQUESTED COMMAND W/ NEEDED SCAFFOLDING
391
- // let t: T.TestEntry;
392
- // // let text: any;
393
- // switch (command)
394
- // {
395
- // case 'valid': {
396
- // doPreprocessData(s);
397
- // if (bEmpty)
398
- // {
399
- // // Make one random district empty
400
- // let randomDistrict = Math.floor(Math.random() * s.state.nDistricts) + 1;
401
- // let reassignFeatures = s.plan._planByDistrictID[randomDistrict];
402
- // s.plan._planByDistrictID[S.NOT_ASSIGNED] = reassignFeatures;
403
- // s.plan.initializeDistrict(randomDistrict);
404
- // }
405
- // doAnalyzeDistricts(s);
406
- // let t1 = doIsComplete(s);
407
- // let t2 = doIsContiguous(s);
408
- // let t3 = doIsFreeOfHoles(s);
409
- // let t5 = doHasEqualPopulations(s);
410
- // doAnalyzePostProcessing(s);
411
- // echoTestResult("Complete:", t1);
412
- // echoTestResult("Contiguous:", t2);
413
- // echoTestResult("Free of holes:", t3);
414
- // echoTestResult("Equal populations:", t5);
415
- // break;
416
- // }
417
- // // TODO - Update this w/ scoring info
418
- // case 'analyze': {
419
- // s.analyzePlan(bLog);
420
- // // let planAnalytics = s.getPlanAnalytics(bLog);
421
- // let districtStatistics = s.getDistrictStatistics(bLog);
422
- // // echoPlanAnalytics(planAnalytics);
423
- // echoDistrictStatistics(districtStatistics);
424
- // break;
425
- // }
426
- // }
427
- // console.log("Ending command @ ", new Date());
428
- // // HELPER FUNCTIONS FOR ECHOING RESULTS
429
- // function echoTestResult(test: string, t: T.TestEntry): void
430
- // {
431
- // console.log("");
432
- // console.log("Test:", test);
433
- // console.log("Score:", t['score']);
434
- // let keys = U.getObjectKeys(t['details']);
435
- // if (keys.length > 0)
436
- // {
437
- // console.log("Details:");
438
- // for (let i in keys)
439
- // {
440
- // let key = keys[i];
441
- // console.log("-", key, "=", t['details'][key]);
442
- // }
443
- // }
444
- // console.log("___");
445
- // }
446
- // // Prepare the items in a list for rendering
447
- // function prepareListItems(list: any[]): string
448
- // {
449
- // if (U.isArrayEmpty(list))
450
- // {
451
- // return "";
452
- // }
453
- // else
454
- // {
455
- // let nItems = list.length;
456
- // let listStr: string;
457
- // switch (nItems)
458
- // {
459
- // case 1: {
460
- // listStr = list[0];
461
- // break;
462
- // }
463
- // case 2: {
464
- // listStr = list[0] + " and " + list[1];
465
- // break;
466
- // }
467
- // default: {
468
- // let listWithCommas = list.join(', ');
469
- // let lastCommaIndex = listWithCommas.length - ((list[list.length - 1].length) + 1);
470
- // let beforeAnd = listWithCommas.substr(0, lastCommaIndex);
471
- // let afterAnd = listWithCommas.substr(lastCommaIndex + 1);
472
- // listStr = beforeAnd + " and " + afterAnd;
473
- // break;
474
- // }
475
- // }
476
- // return listStr;
477
- // }
478
- // }
479
- // function formatNumber(n: number): string
480
- // {
481
- // let p = S.PRECISION;
482
- // return n.toLocaleString('en-US', { minimumFractionDigits: p, maximumFractionDigits: p });
483
- // }
484
- // export function echoDistrictStatistics(ds: DistrictStatistics): void
485
- // {
486
- // console.log("District Statistics:");
487
- // for (let row of ds.table)
488
- // {
489
- // let DistrictID = row[DistrictColumn.DistrictID];
490
- // let TotalPop = row[DistrictColumn.TotalPop];
491
- // let PopDevPct = row[DistrictColumn.PopDevPct];
492
- // let bEqualPop = row[DistrictColumn.bEqualPop];
493
- // let bNotEmpty = row[DistrictColumn.bNotEmpty];
494
- // let bContiguous = row[DistrictColumn.bContiguous];
495
- // let bNotEmbedded = row[DistrictColumn.bNotEmbedded];
496
- // let DemPct = row[DistrictColumn.DemPct];
497
- // let RepPct = row[DistrictColumn.RepPct];
498
- // let WhitePct = row[DistrictColumn.WhitePct];
499
- // let MinorityPct = row[DistrictColumn.MinorityPct];
500
- // let BlackPct = row[DistrictColumn.BlackPct];
501
- // let HispanicPct = row[DistrictColumn.HispanicPct];
502
- // let PacificPct = row[DistrictColumn.PacificPct];
503
- // let AsianPct = row[DistrictColumn.AsianPct];
504
- // let NativePct = row[DistrictColumn.NativePct];
505
- // console.log(
506
- // DistrictID,
507
- // formatNumber(TotalPop),
508
- // formatNumber(PopDevPct),
509
- // bEqualPop,
510
- // bNotEmpty,
511
- // bContiguous,
512
- // bNotEmbedded,
513
- // formatNumber(DemPct),
514
- // formatNumber(RepPct),
515
- // formatNumber(WhitePct),
516
- // formatNumber(MinorityPct),
517
- // formatNumber(BlackPct),
518
- // formatNumber(HispanicPct),
519
- // formatNumber(PacificPct),
520
- // formatNumber(AsianPct),
521
- // formatNumber(NativePct)
522
- // );
523
- // }
524
- // console.log("");
525
- // console.log("* Details:");
526
- // console.log(" - N/A");
527
- // console.log("* Datasets:");
528
- // console.log("- Shapes:", ds.datasets.shapes);
529
- // console.log("- Census:", ds.datasets.census);
530
- // console.log("- VAP:", ds.datasets.vap);
531
- // console.log("- Election:", ds.datasets.election);
532
- // console.log("* Resources:");
533
- // console.log("- N/A");
534
- // console.log("");
535
- // }
536
- // // HELPERS TO LOAD SAMPLE DATA FROM DISK
537
- // // A clone of 'carefulRead' in DRA-CLI
538
- // export function readJSONcareful(file: string): any
539
- // {
540
- // try
541
- // {
542
- // let s: string = fs.readFileSync(file, 'utf8');
543
- // let o: any = JSON.parse(s);
544
- // return o;
545
- // }
546
- // catch (err)
547
- // {
548
- // console.log("Error reading JSON file ...");
549
- // return null;
550
- // }
551
- // }
552
- // export function readJSON(file: string): any
553
- // {
554
- // let fullPath: string;
555
- // if (path.isAbsolute(file))
556
- // {
557
- // fullPath = file;
558
- // }
559
- // else
560
- // {
561
- // fullPath = path.resolve(file);
562
- // }
563
- // return readJSONcareful(fullPath);
564
- // }
565
- // // Following the clone above, except for CSV, using the csv-parse/sync API
566
- // export function readCSV(file: string): any
567
- // {
568
- // try
569
- // {
570
- // let input: string = fs.readFileSync(file, 'utf8');
571
- // let dictRows: any = parse(input, {
572
- // columns: true,
573
- // skip_empty_lines: true
574
- // });
575
- // return dictRows;
576
- // }
577
- // catch (err)
578
- // {
579
- // console.log("Error reading CSV file ...");
580
- // return null;
581
- // }
582
- // }
583
- // // Read a plan from a .csv file
584
- // export function readPlanCSV(file: string): T.PlanByGeoID
585
- // {
586
- // var plan = {} as T.PlanByGeoID;
587
- // let fullPath: string;
588
- // if (path.isAbsolute(file))
589
- // {
590
- // fullPath = file;
591
- // }
592
- // else
593
- // {
594
- // fullPath = path.resolve(file);
595
- // }
596
- // var csvArray: any = readCSV(fullPath);
597
- // for (let dictRow of csvArray)
598
- // {
599
- // let geoID: string = dictRow['GEOID'];
600
- // let districtID: number = Number(dictRow['DISTRICT']);
601
- // plan[geoID] = districtID;
602
- // }
603
- // return plan;
604
- // }
605
- // // END
606
-
607
-
608
- /***/ })
609
-
610
- /******/ });
611
- //# sourceMappingURL=cli.js.map