@dra2020/dra-types 1.0.18 → 1.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,3 +1,9 @@
1
+ export declare type BlockMap = {
2
+ [id: string]: number;
3
+ };
4
+ export declare type BlockMapping = {
5
+ [id: string]: string;
6
+ };
1
7
  export interface Comment {
2
8
  userid: string;
3
9
  text: string;
@@ -48,3 +54,22 @@ export declare type DistrictOrder = {
48
54
  [districtID: string]: number;
49
55
  };
50
56
  export declare function canonicalDistrictIDOrdering(order: DistrictOrder): DistrictOrder;
57
+ export interface OneCSVLine {
58
+ geoid: string;
59
+ districtID: string;
60
+ }
61
+ export declare function parseCSVLine(line: string): OneCSVLine;
62
+ export interface ConvertResult {
63
+ inBlockMap: BlockMapping;
64
+ inStateMap: BlockMapping;
65
+ outValid: boolean;
66
+ outState: string;
67
+ outMap: BlockMapping;
68
+ outOrder: DistrictOrder;
69
+ outDistrictToSplit: DistrictToSplitBlock;
70
+ }
71
+ export declare function blockmapToState(blockMap: BlockMapping): string;
72
+ export declare function blockmapToVTDmap(blockMap: BlockMapping, stateMap: BlockMapping): ConvertResult;
73
+ export declare const GEOIDToState: any;
74
+ export declare const StateToGEOID: any;
75
+ export declare function geoidToState(geoid: string): string;
package/dist/dra-types.js CHANGED
@@ -126,6 +126,7 @@ __export(__webpack_require__(/*! ./dra-types */ "./lib/dra-types.ts"));
126
126
  Object.defineProperty(exports, "__esModule", { value: true });
127
127
  // Public libraries
128
128
  const Hash = __webpack_require__(/*! object-hash */ "object-hash");
129
+ const Util = __webpack_require__(/*! @dra2020/util */ "@dra2020/util");
129
130
  // Canonical hashing of splitblock data
130
131
  function hash(o) {
131
132
  return Hash(o, { respectType: false,
@@ -273,10 +274,253 @@ function canonicalDistrictIDOrdering(order) {
273
274
  // Remove water districts
274
275
  if (order['ZZZ'])
275
276
  delete order['ZZZ'];
277
+ if (order['ZZ'])
278
+ delete order['ZZ'];
276
279
  return order;
277
280
  }
278
281
  exports.canonicalDistrictIDOrdering = canonicalDistrictIDOrdering;
282
+ let reArray = [
283
+ /^(\d\d[^\s,"']*)[\s]*,[\s]*([^\s'"]+)[\s]*$/,
284
+ /^["'](\d\d[^"']*)["'][\s]*,[\s]*["']([^"']*)["'][\s]*$/,
285
+ /^(\d\d[^\s,]*)[\s]*,[\s]*["']([^"']*)["'][\s]*$/,
286
+ /^["'](\d\d[^"']*)["'][\s]*,[\s]*([^\s]+)[\s]*$/,
287
+ ];
288
+ function parseCSVLine(line) {
289
+ if (line == null || line == '')
290
+ return null;
291
+ for (let i = 0; i < reArray.length; i++) {
292
+ let a = reArray[i].exec(line);
293
+ if (a && a.length === 3)
294
+ return { geoid: a[1], districtID: a[2] };
295
+ }
296
+ return null;
297
+ }
298
+ exports.parseCSVLine = parseCSVLine;
299
+ function blockmapToState(blockMap) {
300
+ for (var id in blockMap)
301
+ if (blockMap.hasOwnProperty(id))
302
+ return geoidToState(id);
303
+ return null;
304
+ }
305
+ exports.blockmapToState = blockmapToState;
306
+ // blockToVTD:
307
+ // Take BlockMapping (simple map of GEOID to districtID) and a per-state map of block-level GEOID to VTD
308
+ // and return the output mapping of VTD to districtID, as well a data structure that describes any VTD's
309
+ // that need to be split between districtIDs. Also returns the DistrictOrder structure that defines the
310
+ // districtIDs that were used by the file.
311
+ //
312
+ // The state (as specified by the first two digits of the GEOID) is also determined. If the GEOID's do
313
+ // not all specify the same state, the mapping is considered invalid and the outValid flag is set to false.
314
+ //
315
+ function blockmapToVTDmap(blockMap, stateMap) {
316
+ let res = {
317
+ inBlockMap: blockMap,
318
+ inStateMap: stateMap,
319
+ outValid: true,
320
+ outState: null,
321
+ outMap: {},
322
+ outOrder: {},
323
+ outDistrictToSplit: {}
324
+ };
325
+ let bmGather = {};
326
+ let revMap = {};
327
+ let id;
328
+ if (stateMap)
329
+ for (id in stateMap)
330
+ if (stateMap.hasOwnProperty(id))
331
+ revMap[stateMap[id]] = null;
332
+ // First aggregate into features across all the blocks
333
+ for (id in blockMap)
334
+ if (blockMap.hasOwnProperty(id)) {
335
+ let state = geoidToState(id);
336
+ if (res.outState == null)
337
+ res.outState = state;
338
+ else if (res.outState !== state) {
339
+ res.outValid = false;
340
+ break;
341
+ }
342
+ let districtID = canonicalDistrictID(blockMap[id]);
343
+ // Just ignore ZZZ (water) blocks
344
+ if (districtID === 'ZZZ')
345
+ continue;
346
+ let n = id.length;
347
+ let geoid;
348
+ // Simple test for block id (vs. voting district or block group) id
349
+ if (n >= 15) {
350
+ if (stateMap && stateMap[id] !== undefined)
351
+ geoid = stateMap[id];
352
+ else {
353
+ geoid = id.substr(0, 12); // heuristic for mapping blockID to blockgroupID
354
+ if (revMap[geoid] === undefined) {
355
+ res.outValid = false;
356
+ break;
357
+ }
358
+ }
359
+ }
360
+ else
361
+ geoid = id;
362
+ if (res.outOrder[districtID] === undefined)
363
+ res.outOrder[districtID] = 0;
364
+ let districtToBlocks = bmGather[geoid];
365
+ if (districtToBlocks === undefined)
366
+ bmGather[geoid] = { [districtID]: { [id]: true } };
367
+ else {
368
+ let thisDistrict = districtToBlocks[districtID];
369
+ if (thisDistrict === undefined) {
370
+ thisDistrict = {};
371
+ districtToBlocks[districtID] = thisDistrict;
372
+ }
373
+ thisDistrict[id] = true;
374
+ }
375
+ }
376
+ // Now determine actual mapping of blocks to features, looking for split features
377
+ for (let geoid in bmGather)
378
+ if (bmGather.hasOwnProperty(geoid)) {
379
+ let districtToBlocks = bmGather[geoid];
380
+ if (Util.countKeys(districtToBlocks) == 1) {
381
+ res.outMap[geoid] = Util.nthKey(districtToBlocks);
382
+ }
383
+ else {
384
+ for (let districtID in districtToBlocks)
385
+ if (districtToBlocks.hasOwnProperty(districtID)) {
386
+ let split = { state: '', datasource: '', geoid: geoid, blocks: Object.keys(districtToBlocks[districtID]) };
387
+ let splits = res.outDistrictToSplit[districtID];
388
+ if (splits === undefined) {
389
+ splits = [];
390
+ res.outDistrictToSplit[districtID] = splits;
391
+ }
392
+ splits.push(split);
393
+ }
394
+ }
395
+ }
396
+ res.outOrder = canonicalDistrictIDOrdering(res.outOrder);
397
+ return res;
398
+ }
399
+ exports.blockmapToVTDmap = blockmapToVTDmap;
400
+ exports.GEOIDToState = {
401
+ '01': 'AL',
402
+ '02': 'AK',
403
+ '04': 'AZ',
404
+ '05': 'AR',
405
+ '06': 'CA',
406
+ '08': 'CO',
407
+ '09': 'CT',
408
+ '10': 'DE',
409
+ '12': 'FL',
410
+ '13': 'GA',
411
+ '15': 'HI',
412
+ '16': 'ID',
413
+ '17': 'IL',
414
+ '18': 'IN',
415
+ '19': 'IA',
416
+ '20': 'KS',
417
+ '21': 'KY',
418
+ '22': 'LA',
419
+ '23': 'ME',
420
+ '24': 'MD',
421
+ '25': 'MA',
422
+ '26': 'MI',
423
+ '27': 'MN',
424
+ '28': 'MS',
425
+ '29': 'MO',
426
+ '30': 'MT',
427
+ '31': 'NE',
428
+ '32': 'NV',
429
+ '33': 'NH',
430
+ '34': 'NJ',
431
+ '35': 'NM',
432
+ '36': 'NY',
433
+ '37': 'NC',
434
+ '38': 'ND',
435
+ '39': 'OH',
436
+ '40': 'OK',
437
+ '41': 'OR',
438
+ '42': 'PA',
439
+ '44': 'RI',
440
+ '45': 'SC',
441
+ '46': 'SD',
442
+ '47': 'TN',
443
+ '48': 'TX',
444
+ '49': 'UT',
445
+ '50': 'VT',
446
+ '51': 'VA',
447
+ '53': 'WA',
448
+ '54': 'WV',
449
+ '55': 'WI',
450
+ '56': 'WY',
451
+ };
452
+ exports.StateToGEOID = {
453
+ 'AL': '01',
454
+ 'AK': '02',
455
+ 'AZ': '04',
456
+ 'AR': '05',
457
+ 'CA': '06',
458
+ 'CO': '08',
459
+ 'CT': '09',
460
+ 'DE': '10',
461
+ 'FL': '12',
462
+ 'GA': '13',
463
+ 'HI': '15',
464
+ 'ID': '16',
465
+ 'IL': '17',
466
+ 'IN': '18',
467
+ 'IA': '19',
468
+ 'KS': '20',
469
+ 'KY': '21',
470
+ 'LA': '22',
471
+ 'ME': '23',
472
+ 'MD': '24',
473
+ 'MA': '25',
474
+ 'MI': '26',
475
+ 'MN': '27',
476
+ 'MS': '28',
477
+ 'MO': '29',
478
+ 'MT': '30',
479
+ 'NE': '31',
480
+ 'NV': '32',
481
+ 'NH': '33',
482
+ 'NJ': '34',
483
+ 'NM': '35',
484
+ 'NY': '36',
485
+ 'NC': '37',
486
+ 'ND': '38',
487
+ 'OH': '39',
488
+ 'OK': '40',
489
+ 'OR': '41',
490
+ 'PA': '42',
491
+ 'RI': '44',
492
+ 'SC': '45',
493
+ 'SD': '46',
494
+ 'TN': '47',
495
+ 'TX': '48',
496
+ 'UT': '49',
497
+ 'VT': '50',
498
+ 'VA': '51',
499
+ 'WA': '53',
500
+ 'WV': '54',
501
+ 'WI': '55',
502
+ 'WY': '56',
503
+ };
504
+ function geoidToState(geoid) {
505
+ let re = /^(..).*$/;
506
+ let a = re.exec(geoid);
507
+ if (a == null || a.length != 2)
508
+ return null;
509
+ return exports.GEOIDToState[a[1]];
510
+ }
511
+ exports.geoidToState = geoidToState;
512
+
513
+
514
+ /***/ }),
515
+
516
+ /***/ "@dra2020/util":
517
+ /*!********************************!*\
518
+ !*** external "@dra2020/util" ***!
519
+ \********************************/
520
+ /*! no static exports found */
521
+ /***/ (function(module, exports) {
279
522
 
523
+ module.exports = require("@dra2020/util");
280
524
 
281
525
  /***/ }),
282
526
 
@@ -1 +1 @@
1
- {"version":3,"sources":["webpack://dra-types/webpack/universalModuleDefinition","webpack://dra-types/webpack/bootstrap","webpack://dra-types/./lib/all.ts","webpack://dra-types/./lib/dra-types.ts","webpack://dra-types/external \"object-hash\""],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;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C,GAAG,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACnC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,EACtB;QACE,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACjB,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KACtC;;QAEC,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACzB,OAAO,UAAU,CAAC;AACpB,CAAC;AAXD,sEAWC;AAKD,SAAgB,2BAA2B,CAAC,KAAoB;IAE9D,IAAI,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9B,IAAI,CAAS,CAAC;IACd,IAAI,CAAC,GAAQ,EAAE,CAAC;IAChB,IAAI,QAAQ,GAAW,SAAS,CAAC;IAEjC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D,IAAI,CAAC,IAAI,EAAE,CAAC;IACZ,KAAK,GAAG,EAAE,CAAC;IACX,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE;QAC9B,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAC,CAAC,CAAC;IAE5C,yBAAyB;IACzB,IAAI,KAAK,CAAC,KAAK,CAAC;QACd,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;IAEtB,OAAO,KAAK,CAAC;AACf,CAAC;AAlBD,kEAkBC;;;;;;;;;;;;ACvOD,wC","file":"dra-types.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"dra-types\"] = factory();\n\telse\n\t\troot[\"dra-types\"] = factory();\n})(global, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./lib/all.ts\");\n","export * from './dra-types';\n","// Public libraries\nimport * as Hash from 'object-hash';\n\n// Type for single comment\nexport interface Comment\n{\n userid: string;\n text: string;\n date: string;\n recommend: number;\n}\n\n// Comment record associated with a map\nexport interface CommentList\n{\n id?: string;\n [commentid: string]: Comment | string; // Really just Comment but make TypeScript happy\n}\n\n// Supported like kinds\nexport type LikeKind = 'like' | 'love' | 'wow' | 'angry' | 'funny';\n\n// Like record for an individual like\nexport interface Like\n{\n date: string;\n kind: LikeKind;\n}\n\n// Record for likes associated with a map\nexport interface LikeList\n{\n id?: string;\n [userid: string]: Like | string; // Really just Like but make TypeScript happy\n}\n\n// Record for likes an individual user has performed\nexport interface UserLikes\n{\n id?: string;\n [aid: string]: Like | string; // Really just Like but make TypeScript happy\n}\n\nexport interface SplitBlock\n{\n id?: string;\n chunk?: string;\n state: string;\n datasource: string;\n geoid: string;\n blocks: string[];\n}\n\nexport type DistrictToSplitBlock = { [districtID: string]: SplitBlock[] };\n\n// Canonical hashing of splitblock data\nfunction hash(o: any): string\n{\n return Hash(o,\n { respectType: false,\n unorderedArrays: true,\n unorderedObjects: true,\n excludeKeys: (k: string) => (k === 'id' || k === 'chunk')\n });\n}\n\nexport function vgeoidToGeoid(vgeoid: string): string\n{\n let re = /vfeature_([^_]*)_.*/;\n let a = re.exec(vgeoid);\n if (a == null || a.length != 2)\n return '';\n else\n return a[1];\n}\n\nexport function vgeoidToChunk(vgeoid: string): string\n{\n // vgeoid is string of form: \"vfeature_[geoid]_[chunkid]_[hash]\"\n // the contents are chunked into a file of form \"vfeature_chunk_[chunkid]\"\n // So extract the chunk ID and download that.\n let re = /vfeature_([^_]*)_([^_*])_(.*)/;\n let a = re.exec(vgeoid);\n if (a && a.length == 4)\n vgeoid = `vfeature_chunk_${a[2]}`;\n else\n vgeoid = null;\n\n return vgeoid;\n}\n\nexport function vgeoidToHash(vgeoid: string): string\n{\n // vgeoid is string of form: \"vfeature_[geoid]_[chunkid]_[hash]\"\n let re = /vfeature_([^_]*)_([^_*])_(.*)/;\n let a = re.exec(vgeoid);\n if (a && a.length == 4)\n vgeoid = a[3];\n else\n vgeoid = null;\n\n return vgeoid;\n}\n\nexport function isVfeature(geoid: string): boolean\n{\n return geoid.indexOf('vfeature') === 0;\n}\n\nexport function splitToCacheKey(s: SplitBlock): string\n{\n if (s.id === undefined)\n s.id = hash(s);\n if (s.chunk === undefined)\n s.chunk = \"0\";\n\n return `_${s.state}_${s.datasource}_vfeature_${s.geoid}_${s.chunk}_${s.id}.geojson`;\n}\n\nexport function splitToChunkKey(s: SplitBlock): string\n{\n if (s.chunk === undefined)\n s.chunk = \"0\";\n\n return `_${s.state}_${s.datasource}_vfeature_chunk_${s.chunk}.geojson`;\n}\n\nexport function splitToPrefix(s: SplitBlock): string\n{\n if (s.blocks === undefined)\n {\n let re = /_([^_]*)_(.*)_vfeature.*\\.geojson$/;\n let a = re.exec(s.id);\n if (a && a.length == 3)\n return `_${a[1]}_${a[2]}`;\n return s.id;\n }\n return `_${s.state}_${s.datasource}`;\n}\n\nexport function cacheKeysToChunkHash(keys: string[]): string\n{\n return hash(keys);\n}\n\nlet reNumeric = /^(\\D*)(\\d*)(\\D*)$/;\nlet reDistrictNumber = /^\\d+$/;\nlet reDistrictNumeric = /^\\d/;\n\n// Normalize any numeric part to have no padded leading zeros\nexport function canonicalDistrictID(districtID: string): string\n{\n let a = reNumeric.exec(districtID);\n if (a && a.length == 4)\n {\n if (a[2].length > 0)\n a[2] = String(Number(a[2]));\n districtID = `${a[1]}${a[2]}${a[3]}`;\n }\n return districtID;\n}\n\n// Normalize any numeric part to have four digits with padded leading zeros\nexport function canonicalSortingDistrictID(districtID: string): string\n{\n let a = reNumeric.exec(districtID);\n if (a && a.length == 4)\n {\n let s = a[2];\n if (s.length > 0)\n {\n switch (s.length)\n {\n case 1: s = `000${s}`; break;\n case 2: s = `00${s}`; break;\n case 3: s = `0${s}`; break;\n }\n a[2] = s;\n }\n districtID = `${a[1]}${a[2]}${a[3]}`;\n }\n return districtID;\n}\n\n// Return numeric part of districtID (or -1 if there is none)\nexport function canonicalNumericFromDistrictID(districtID: string): number\n{\n let a = reNumeric.exec(districtID);\n if (a && a.length == 4)\n {\n let s = a[2];\n if (s.length > 0)\n return Number(s);\n }\n return -1;\n}\n\nexport function canonicalDistrictIDFromNumber(districtID: string, n: number): string\n{\n let a = reNumeric.exec(districtID);\n if (a && a.length == 4)\n {\n a[2] = String(n);\n districtID = `${a[1]}${a[2]}${a[3]}`;\n }\n else\n districtID = String(n);\n return districtID;\n}\n\n// Numbers start at 1\nexport type DistrictOrder = { [districtID: string]: number };\n\nexport function canonicalDistrictIDOrdering(order: DistrictOrder): DistrictOrder\n{\n let keys = Object.keys(order);\n let i: number;\n let a: any = [];\n let template: string = undefined;\n\n keys = keys.map((s: string) => canonicalSortingDistrictID(s));\n keys.sort();\n order = {};\n for (i = 0; i < keys.length; i++)\n order[canonicalDistrictID(keys[i])] = i+1;\n\n // Remove water districts\n if (order['ZZZ'])\n delete order['ZZZ'];\n\n return order;\n}\n","module.exports = require(\"object-hash\");"],"sourceRoot":""}
1
+ {"version":3,"sources":["webpack://dra-types/webpack/universalModuleDefinition","webpack://dra-types/webpack/bootstrap","webpack://dra-types/./lib/all.ts","webpack://dra-types/./lib/dra-types.ts","webpack://dra-types/external \"@dra2020/util\"","webpack://dra-types/external \"object-hash\""],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;;QAGA;QACA;;;;;;;;;;;;;;;;;;AClFA,uEAA4B;;;;;;;;;;;;;;;ACA5B,mBAAmB;AACnB,mEAAoC;AACpC,uEAAsC;AA4DtC,uCAAuC;AACvC,SAAS,IAAI,CAAC,CAAM;IAElB,OAAO,IAAI,CAAC,CAAC,EACX,EAAE,WAAW,EAAE,KAAK;QAClB,eAAe,EAAE,IAAI;QACrB,gBAAgB,EAAE,IAAI;QACtB,WAAW,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,OAAO,CAAC;KAC1D,CAAC,CAAC;AACP,CAAC;AAED,SAAgB,aAAa,CAAC,MAAc;IAE1C,IAAI,EAAE,GAAG,qBAAqB,CAAC;IAC/B,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxB,IAAI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AE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;CACX,CAAC;AAEF,SAAgB,YAAY,CAAC,KAAa;IAExC,IAAI,EAAE,GAAG,UAAU,CAAC;IAEpB,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvB,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5C,OAAO,oBAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5B,CAAC;AAPD,oCAOC;;;;;;;;;;;;ACjgBD,0C;;;;;;;;;;;ACAA,wC","file":"dra-types.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"dra-types\"] = factory();\n\telse\n\t\troot[\"dra-types\"] = factory();\n})(global, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./lib/all.ts\");\n","export * from './dra-types';\n","// Public libraries\nimport * as Hash from 'object-hash';\nimport * as Util from '@dra2020/util';\n\n// Used internally to index into District Properties Array\nexport type BlockMap = { [id: string]: number };\n\n// Used more generically and allows string districtIDs\nexport type BlockMapping = { [id: string]: string };\n\n// Type for single comment\nexport interface Comment\n{\n userid: string;\n text: string;\n date: string;\n recommend: number;\n}\n\n// Comment record associated with a map\nexport interface CommentList\n{\n id?: string;\n [commentid: string]: Comment | string; // Really just Comment but make TypeScript happy\n}\n\n// Supported like kinds\nexport type LikeKind = 'like' | 'love' | 'wow' | 'angry' | 'funny';\n\n// Like record for an individual like\nexport interface Like\n{\n date: string;\n kind: LikeKind;\n}\n\n// Record for likes associated with a map\nexport interface LikeList\n{\n id?: string;\n [userid: string]: Like | string; // Really just Like but make TypeScript happy\n}\n\n// Record for likes an individual user has performed\nexport interface UserLikes\n{\n id?: string;\n [aid: string]: Like | string; // Really just Like but make TypeScript happy\n}\n\nexport interface SplitBlock\n{\n id?: string;\n chunk?: string;\n state: string;\n datasource: string;\n geoid: string;\n blocks: string[];\n}\n\nexport type DistrictToSplitBlock = { [districtID: string]: SplitBlock[] };\n\n// Canonical hashing of splitblock data\nfunction hash(o: any): string\n{\n return Hash(o,\n { respectType: false,\n unorderedArrays: true,\n unorderedObjects: true,\n excludeKeys: (k: string) => (k === 'id' || k === 'chunk')\n });\n}\n\nexport function vgeoidToGeoid(vgeoid: string): string\n{\n let re = /vfeature_([^_]*)_.*/;\n let a = re.exec(vgeoid);\n if (a == null || a.length != 2)\n return '';\n else\n return a[1];\n}\n\nexport function vgeoidToChunk(vgeoid: string): string\n{\n // vgeoid is string of form: \"vfeature_[geoid]_[chunkid]_[hash]\"\n // the contents are chunked into a file of form \"vfeature_chunk_[chunkid]\"\n // So extract the chunk ID and download that.\n let re = /vfeature_([^_]*)_([^_*])_(.*)/;\n let a = re.exec(vgeoid);\n if (a && a.length == 4)\n vgeoid = `vfeature_chunk_${a[2]}`;\n else\n vgeoid = null;\n\n return vgeoid;\n}\n\nexport function vgeoidToHash(vgeoid: string): string\n{\n // vgeoid is string of form: \"vfeature_[geoid]_[chunkid]_[hash]\"\n let re = /vfeature_([^_]*)_([^_*])_(.*)/;\n let a = re.exec(vgeoid);\n if (a && a.length == 4)\n vgeoid = a[3];\n else\n vgeoid = null;\n\n return vgeoid;\n}\n\nexport function isVfeature(geoid: string): boolean\n{\n return geoid.indexOf('vfeature') === 0;\n}\n\nexport function splitToCacheKey(s: SplitBlock): string\n{\n if (s.id === undefined)\n s.id = hash(s);\n if (s.chunk === undefined)\n s.chunk = \"0\";\n\n return `_${s.state}_${s.datasource}_vfeature_${s.geoid}_${s.chunk}_${s.id}.geojson`;\n}\n\nexport function splitToChunkKey(s: SplitBlock): string\n{\n if (s.chunk === undefined)\n s.chunk = \"0\";\n\n return `_${s.state}_${s.datasource}_vfeature_chunk_${s.chunk}.geojson`;\n}\n\nexport function splitToPrefix(s: SplitBlock): string\n{\n if (s.blocks === undefined)\n {\n let re = /_([^_]*)_(.*)_vfeature.*\\.geojson$/;\n let a = re.exec(s.id);\n if (a && a.length == 3)\n return `_${a[1]}_${a[2]}`;\n return s.id;\n }\n return `_${s.state}_${s.datasource}`;\n}\n\nexport function cacheKeysToChunkHash(keys: string[]): string\n{\n return hash(keys);\n}\n\nlet reNumeric = /^(\\D*)(\\d*)(\\D*)$/;\nlet reDistrictNumber = /^\\d+$/;\nlet reDistrictNumeric = /^\\d/;\n\n// Normalize any numeric part to have no padded leading zeros\nexport function canonicalDistrictID(districtID: string): string\n{\n let a = reNumeric.exec(districtID);\n if (a && a.length == 4)\n {\n if (a[2].length > 0)\n a[2] = String(Number(a[2]));\n districtID = `${a[1]}${a[2]}${a[3]}`;\n }\n return districtID;\n}\n\n// Normalize any numeric part to have four digits with padded leading zeros\nexport function canonicalSortingDistrictID(districtID: string): string\n{\n let a = reNumeric.exec(districtID);\n if (a && a.length == 4)\n {\n let s = a[2];\n if (s.length > 0)\n {\n switch (s.length)\n {\n case 1: s = `000${s}`; break;\n case 2: s = `00${s}`; break;\n case 3: s = `0${s}`; break;\n }\n a[2] = s;\n }\n districtID = `${a[1]}${a[2]}${a[3]}`;\n }\n return districtID;\n}\n\n// Return numeric part of districtID (or -1 if there is none)\nexport function canonicalNumericFromDistrictID(districtID: string): number\n{\n let a = reNumeric.exec(districtID);\n if (a && a.length == 4)\n {\n let s = a[2];\n if (s.length > 0)\n return Number(s);\n }\n return -1;\n}\n\nexport function canonicalDistrictIDFromNumber(districtID: string, n: number): string\n{\n let a = reNumeric.exec(districtID);\n if (a && a.length == 4)\n {\n a[2] = String(n);\n districtID = `${a[1]}${a[2]}${a[3]}`;\n }\n else\n districtID = String(n);\n return districtID;\n}\n\n// Numbers start at 1\nexport type DistrictOrder = { [districtID: string]: number };\n\nexport function canonicalDistrictIDOrdering(order: DistrictOrder): DistrictOrder\n{\n let keys = Object.keys(order);\n let i: number;\n let a: any = [];\n let template: string = undefined;\n\n keys = keys.map((s: string) => canonicalSortingDistrictID(s));\n keys.sort();\n order = {};\n for (i = 0; i < keys.length; i++)\n order[canonicalDistrictID(keys[i])] = i+1;\n\n // Remove water districts\n if (order['ZZZ']) delete order['ZZZ'];\n if (order['ZZ']) delete order['ZZ'];\n\n return order;\n}\n\n\nexport interface OneCSVLine\n{\n geoid: string;\n districtID: string;\n}\n\nlet reArray = [\n /^(\\d\\d[^\\s,\"']*)[\\s]*,[\\s]*([^\\s'\"]+)[\\s]*$/,\n /^[\"'](\\d\\d[^\"']*)[\"'][\\s]*,[\\s]*[\"']([^\"']*)[\"'][\\s]*$/,\n /^(\\d\\d[^\\s,]*)[\\s]*,[\\s]*[\"']([^\"']*)[\"'][\\s]*$/,\n /^[\"'](\\d\\d[^\"']*)[\"'][\\s]*,[\\s]*([^\\s]+)[\\s]*$/,\n ];\n\nexport function parseCSVLine(line: string): OneCSVLine\n{\n if (line == null || line == '') return null;\n for (let i: number = 0; i < reArray.length; i++)\n {\n let a = reArray[i].exec(line);\n if (a && a.length === 3)\n return { geoid: a[1], districtID: a[2] };\n }\n return null;\n}\n\nexport interface ConvertResult\n{\n inBlockMap: BlockMapping;\n inStateMap: BlockMapping;\n outValid: boolean;\n outState: string;\n outMap: BlockMapping;\n outOrder: DistrictOrder;\n outDistrictToSplit: DistrictToSplitBlock;\n}\n\nexport function blockmapToState(blockMap: BlockMapping): string\n{\n for (var id in blockMap) if (blockMap.hasOwnProperty(id))\n return geoidToState(id);\n return null;\n}\n\n// blockToVTD:\n// Take BlockMapping (simple map of GEOID to districtID) and a per-state map of block-level GEOID to VTD\n// and return the output mapping of VTD to districtID, as well a data structure that describes any VTD's\n// that need to be split between districtIDs. Also returns the DistrictOrder structure that defines the\n// districtIDs that were used by the file.\n//\n// The state (as specified by the first two digits of the GEOID) is also determined. If the GEOID's do\n// not all specify the same state, the mapping is considered invalid and the outValid flag is set to false.\n//\n\nexport function blockmapToVTDmap(blockMap: BlockMapping, stateMap: BlockMapping): ConvertResult\n{\n let res: ConvertResult = {\n inBlockMap: blockMap,\n inStateMap: stateMap,\n outValid: true,\n outState: null,\n outMap: {},\n outOrder: {},\n outDistrictToSplit: {}\n };\n\n let bmGather: { [geoid: string]: { [district: string]: { [blockid: string]: boolean } } } = {};\n let revMap: BlockMapping = {};\n let id: string;\n\n if (stateMap)\n for (id in stateMap) if (stateMap.hasOwnProperty(id))\n revMap[stateMap[id]] = null;\n\n // First aggregate into features across all the blocks\n for (id in blockMap) if (blockMap.hasOwnProperty(id))\n {\n let state = geoidToState(id);\n if (res.outState == null)\n res.outState = state;\n else if (res.outState !== state)\n {\n res.outValid = false;\n break;\n }\n\n let districtID: string = canonicalDistrictID(blockMap[id]);\n\n // Just ignore ZZZ (water) blocks\n if (districtID === 'ZZZ')\n continue;\n\n let n: number = id.length;\n let geoid: string;\n\n // Simple test for block id (vs. voting district or block group) id\n if (n >= 15)\n {\n if (stateMap && stateMap[id] !== undefined)\n geoid = stateMap[id];\n else\n {\n geoid = id.substr(0, 12); // heuristic for mapping blockID to blockgroupID\n if (revMap[geoid] === undefined)\n {\n res.outValid = false;\n break;\n }\n }\n }\n else\n geoid = id;\n\n if (res.outOrder[districtID] === undefined)\n res.outOrder[districtID] = 0;\n\n let districtToBlocks: { [districtID: string]: { [blockid: string]: boolean } } = bmGather[geoid];\n if (districtToBlocks === undefined)\n bmGather[geoid] = { [districtID]: { [id]: true } };\n else\n {\n let thisDistrict: { [blockid: string]: boolean } = districtToBlocks[districtID];\n if (thisDistrict === undefined)\n {\n thisDistrict = { };\n districtToBlocks[districtID] = thisDistrict;\n }\n thisDistrict[id] = true;\n }\n }\n\n // Now determine actual mapping of blocks to features, looking for split features\n for (let geoid in bmGather) if (bmGather.hasOwnProperty(geoid))\n {\n let districtToBlocks = bmGather[geoid];\n if (Util.countKeys(districtToBlocks) == 1)\n {\n res.outMap[geoid] = Util.nthKey(districtToBlocks);\n }\n else\n {\n for (let districtID in districtToBlocks) if (districtToBlocks.hasOwnProperty(districtID))\n {\n let split: SplitBlock = { state: '', datasource: '', geoid: geoid, blocks: Object.keys(districtToBlocks[districtID]) };\n let splits = res.outDistrictToSplit[districtID];\n if (splits === undefined)\n {\n splits = [];\n res.outDistrictToSplit[districtID] = splits;\n }\n splits.push(split);\n }\n }\n }\n\n res.outOrder = canonicalDistrictIDOrdering(res.outOrder);\n\n return res;\n}\n\nexport const GEOIDToState: any = {\n '01': 'AL',\n '02': 'AK',\n '04': 'AZ',\n '05': 'AR',\n '06': 'CA',\n '08': 'CO',\n '09': 'CT',\n '10': 'DE',\n '12': 'FL',\n '13': 'GA',\n '15': 'HI',\n '16': 'ID',\n '17': 'IL',\n '18': 'IN',\n '19': 'IA',\n '20': 'KS',\n '21': 'KY',\n '22': 'LA',\n '23': 'ME',\n '24': 'MD',\n '25': 'MA',\n '26': 'MI',\n '27': 'MN',\n '28': 'MS',\n '29': 'MO',\n '30': 'MT',\n '31': 'NE',\n '32': 'NV',\n '33': 'NH',\n '34': 'NJ',\n '35': 'NM',\n '36': 'NY',\n '37': 'NC',\n '38': 'ND',\n '39': 'OH',\n '40': 'OK',\n '41': 'OR',\n '42': 'PA',\n '44': 'RI',\n '45': 'SC',\n '46': 'SD',\n '47': 'TN',\n '48': 'TX',\n '49': 'UT',\n '50': 'VT',\n '51': 'VA',\n '53': 'WA',\n '54': 'WV',\n '55': 'WI',\n '56': 'WY',\n};\n\nexport const StateToGEOID: any = {\n 'AL': '01',\n 'AK': '02',\n 'AZ': '04',\n 'AR': '05',\n 'CA': '06',\n 'CO': '08',\n 'CT': '09',\n 'DE': '10',\n 'FL': '12',\n 'GA': '13',\n 'HI': '15',\n 'ID': '16',\n 'IL': '17',\n 'IN': '18',\n 'IA': '19',\n 'KS': '20',\n 'KY': '21',\n 'LA': '22',\n 'ME': '23',\n 'MD': '24',\n 'MA': '25',\n 'MI': '26',\n 'MN': '27',\n 'MS': '28',\n 'MO': '29',\n 'MT': '30',\n 'NE': '31',\n 'NV': '32',\n 'NH': '33',\n 'NJ': '34',\n 'NM': '35',\n 'NY': '36',\n 'NC': '37',\n 'ND': '38',\n 'OH': '39',\n 'OK': '40',\n 'OR': '41',\n 'PA': '42',\n 'RI': '44',\n 'SC': '45',\n 'SD': '46',\n 'TN': '47',\n 'TX': '48',\n 'UT': '49',\n 'VT': '50',\n 'VA': '51',\n 'WA': '53',\n 'WV': '54',\n 'WI': '55',\n 'WY': '56',\n};\n\nexport function geoidToState(geoid: string): string\n{\n let re = /^(..).*$/;\n\n let a = re.exec(geoid);\n if (a == null || a.length != 2) return null;\n return GEOIDToState[a[1]];\n}\n","module.exports = require(\"@dra2020/util\");","module.exports = require(\"object-hash\");"],"sourceRoot":""}
package/lib/dra-types.ts CHANGED
@@ -1,5 +1,12 @@
1
1
  // Public libraries
2
2
  import * as Hash from 'object-hash';
3
+ import * as Util from '@dra2020/util';
4
+
5
+ // Used internally to index into District Properties Array
6
+ export type BlockMap = { [id: string]: number };
7
+
8
+ // Used more generically and allows string districtIDs
9
+ export type BlockMapping = { [id: string]: string };
3
10
 
4
11
  // Type for single comment
5
12
  export interface Comment
@@ -225,8 +232,283 @@ export function canonicalDistrictIDOrdering(order: DistrictOrder): DistrictOrder
225
232
  order[canonicalDistrictID(keys[i])] = i+1;
226
233
 
227
234
  // Remove water districts
228
- if (order['ZZZ'])
229
- delete order['ZZZ'];
235
+ if (order['ZZZ']) delete order['ZZZ'];
236
+ if (order['ZZ']) delete order['ZZ'];
230
237
 
231
238
  return order;
232
239
  }
240
+
241
+
242
+ export interface OneCSVLine
243
+ {
244
+ geoid: string;
245
+ districtID: string;
246
+ }
247
+
248
+ let reArray = [
249
+ /^(\d\d[^\s,"']*)[\s]*,[\s]*([^\s'"]+)[\s]*$/,
250
+ /^["'](\d\d[^"']*)["'][\s]*,[\s]*["']([^"']*)["'][\s]*$/,
251
+ /^(\d\d[^\s,]*)[\s]*,[\s]*["']([^"']*)["'][\s]*$/,
252
+ /^["'](\d\d[^"']*)["'][\s]*,[\s]*([^\s]+)[\s]*$/,
253
+ ];
254
+
255
+ export function parseCSVLine(line: string): OneCSVLine
256
+ {
257
+ if (line == null || line == '') return null;
258
+ for (let i: number = 0; i < reArray.length; i++)
259
+ {
260
+ let a = reArray[i].exec(line);
261
+ if (a && a.length === 3)
262
+ return { geoid: a[1], districtID: a[2] };
263
+ }
264
+ return null;
265
+ }
266
+
267
+ export interface ConvertResult
268
+ {
269
+ inBlockMap: BlockMapping;
270
+ inStateMap: BlockMapping;
271
+ outValid: boolean;
272
+ outState: string;
273
+ outMap: BlockMapping;
274
+ outOrder: DistrictOrder;
275
+ outDistrictToSplit: DistrictToSplitBlock;
276
+ }
277
+
278
+ export function blockmapToState(blockMap: BlockMapping): string
279
+ {
280
+ for (var id in blockMap) if (blockMap.hasOwnProperty(id))
281
+ return geoidToState(id);
282
+ return null;
283
+ }
284
+
285
+ // blockToVTD:
286
+ // Take BlockMapping (simple map of GEOID to districtID) and a per-state map of block-level GEOID to VTD
287
+ // and return the output mapping of VTD to districtID, as well a data structure that describes any VTD's
288
+ // that need to be split between districtIDs. Also returns the DistrictOrder structure that defines the
289
+ // districtIDs that were used by the file.
290
+ //
291
+ // The state (as specified by the first two digits of the GEOID) is also determined. If the GEOID's do
292
+ // not all specify the same state, the mapping is considered invalid and the outValid flag is set to false.
293
+ //
294
+
295
+ export function blockmapToVTDmap(blockMap: BlockMapping, stateMap: BlockMapping): ConvertResult
296
+ {
297
+ let res: ConvertResult = {
298
+ inBlockMap: blockMap,
299
+ inStateMap: stateMap,
300
+ outValid: true,
301
+ outState: null,
302
+ outMap: {},
303
+ outOrder: {},
304
+ outDistrictToSplit: {}
305
+ };
306
+
307
+ let bmGather: { [geoid: string]: { [district: string]: { [blockid: string]: boolean } } } = {};
308
+ let revMap: BlockMapping = {};
309
+ let id: string;
310
+
311
+ if (stateMap)
312
+ for (id in stateMap) if (stateMap.hasOwnProperty(id))
313
+ revMap[stateMap[id]] = null;
314
+
315
+ // First aggregate into features across all the blocks
316
+ for (id in blockMap) if (blockMap.hasOwnProperty(id))
317
+ {
318
+ let state = geoidToState(id);
319
+ if (res.outState == null)
320
+ res.outState = state;
321
+ else if (res.outState !== state)
322
+ {
323
+ res.outValid = false;
324
+ break;
325
+ }
326
+
327
+ let districtID: string = canonicalDistrictID(blockMap[id]);
328
+
329
+ // Just ignore ZZZ (water) blocks
330
+ if (districtID === 'ZZZ')
331
+ continue;
332
+
333
+ let n: number = id.length;
334
+ let geoid: string;
335
+
336
+ // Simple test for block id (vs. voting district or block group) id
337
+ if (n >= 15)
338
+ {
339
+ if (stateMap && stateMap[id] !== undefined)
340
+ geoid = stateMap[id];
341
+ else
342
+ {
343
+ geoid = id.substr(0, 12); // heuristic for mapping blockID to blockgroupID
344
+ if (revMap[geoid] === undefined)
345
+ {
346
+ res.outValid = false;
347
+ break;
348
+ }
349
+ }
350
+ }
351
+ else
352
+ geoid = id;
353
+
354
+ if (res.outOrder[districtID] === undefined)
355
+ res.outOrder[districtID] = 0;
356
+
357
+ let districtToBlocks: { [districtID: string]: { [blockid: string]: boolean } } = bmGather[geoid];
358
+ if (districtToBlocks === undefined)
359
+ bmGather[geoid] = { [districtID]: { [id]: true } };
360
+ else
361
+ {
362
+ let thisDistrict: { [blockid: string]: boolean } = districtToBlocks[districtID];
363
+ if (thisDistrict === undefined)
364
+ {
365
+ thisDistrict = { };
366
+ districtToBlocks[districtID] = thisDistrict;
367
+ }
368
+ thisDistrict[id] = true;
369
+ }
370
+ }
371
+
372
+ // Now determine actual mapping of blocks to features, looking for split features
373
+ for (let geoid in bmGather) if (bmGather.hasOwnProperty(geoid))
374
+ {
375
+ let districtToBlocks = bmGather[geoid];
376
+ if (Util.countKeys(districtToBlocks) == 1)
377
+ {
378
+ res.outMap[geoid] = Util.nthKey(districtToBlocks);
379
+ }
380
+ else
381
+ {
382
+ for (let districtID in districtToBlocks) if (districtToBlocks.hasOwnProperty(districtID))
383
+ {
384
+ let split: SplitBlock = { state: '', datasource: '', geoid: geoid, blocks: Object.keys(districtToBlocks[districtID]) };
385
+ let splits = res.outDistrictToSplit[districtID];
386
+ if (splits === undefined)
387
+ {
388
+ splits = [];
389
+ res.outDistrictToSplit[districtID] = splits;
390
+ }
391
+ splits.push(split);
392
+ }
393
+ }
394
+ }
395
+
396
+ res.outOrder = canonicalDistrictIDOrdering(res.outOrder);
397
+
398
+ return res;
399
+ }
400
+
401
+ export const GEOIDToState: any = {
402
+ '01': 'AL',
403
+ '02': 'AK',
404
+ '04': 'AZ',
405
+ '05': 'AR',
406
+ '06': 'CA',
407
+ '08': 'CO',
408
+ '09': 'CT',
409
+ '10': 'DE',
410
+ '12': 'FL',
411
+ '13': 'GA',
412
+ '15': 'HI',
413
+ '16': 'ID',
414
+ '17': 'IL',
415
+ '18': 'IN',
416
+ '19': 'IA',
417
+ '20': 'KS',
418
+ '21': 'KY',
419
+ '22': 'LA',
420
+ '23': 'ME',
421
+ '24': 'MD',
422
+ '25': 'MA',
423
+ '26': 'MI',
424
+ '27': 'MN',
425
+ '28': 'MS',
426
+ '29': 'MO',
427
+ '30': 'MT',
428
+ '31': 'NE',
429
+ '32': 'NV',
430
+ '33': 'NH',
431
+ '34': 'NJ',
432
+ '35': 'NM',
433
+ '36': 'NY',
434
+ '37': 'NC',
435
+ '38': 'ND',
436
+ '39': 'OH',
437
+ '40': 'OK',
438
+ '41': 'OR',
439
+ '42': 'PA',
440
+ '44': 'RI',
441
+ '45': 'SC',
442
+ '46': 'SD',
443
+ '47': 'TN',
444
+ '48': 'TX',
445
+ '49': 'UT',
446
+ '50': 'VT',
447
+ '51': 'VA',
448
+ '53': 'WA',
449
+ '54': 'WV',
450
+ '55': 'WI',
451
+ '56': 'WY',
452
+ };
453
+
454
+ export const StateToGEOID: any = {
455
+ 'AL': '01',
456
+ 'AK': '02',
457
+ 'AZ': '04',
458
+ 'AR': '05',
459
+ 'CA': '06',
460
+ 'CO': '08',
461
+ 'CT': '09',
462
+ 'DE': '10',
463
+ 'FL': '12',
464
+ 'GA': '13',
465
+ 'HI': '15',
466
+ 'ID': '16',
467
+ 'IL': '17',
468
+ 'IN': '18',
469
+ 'IA': '19',
470
+ 'KS': '20',
471
+ 'KY': '21',
472
+ 'LA': '22',
473
+ 'ME': '23',
474
+ 'MD': '24',
475
+ 'MA': '25',
476
+ 'MI': '26',
477
+ 'MN': '27',
478
+ 'MS': '28',
479
+ 'MO': '29',
480
+ 'MT': '30',
481
+ 'NE': '31',
482
+ 'NV': '32',
483
+ 'NH': '33',
484
+ 'NJ': '34',
485
+ 'NM': '35',
486
+ 'NY': '36',
487
+ 'NC': '37',
488
+ 'ND': '38',
489
+ 'OH': '39',
490
+ 'OK': '40',
491
+ 'OR': '41',
492
+ 'PA': '42',
493
+ 'RI': '44',
494
+ 'SC': '45',
495
+ 'SD': '46',
496
+ 'TN': '47',
497
+ 'TX': '48',
498
+ 'UT': '49',
499
+ 'VT': '50',
500
+ 'VA': '51',
501
+ 'WA': '53',
502
+ 'WV': '54',
503
+ 'WI': '55',
504
+ 'WY': '56',
505
+ };
506
+
507
+ export function geoidToState(geoid: string): string
508
+ {
509
+ let re = /^(..).*$/;
510
+
511
+ let a = re.exec(geoid);
512
+ if (a == null || a.length != 2) return null;
513
+ return GEOIDToState[a[1]];
514
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/dra-types",
3
- "version": "1.0.18",
3
+ "version": "1.2.0",
4
4
  "description": "Shared types used between client and server.",
5
5
  "main": "dist/dra-types.js",
6
6
  "types": "./dist/all.d.ts",
@@ -33,6 +33,7 @@
33
33
  "webpack-cli": "^3.3.9"
34
34
  },
35
35
  "dependencies": {
36
+ "@dra2020/util": "^1.0.38",
36
37
  "object-hash": "^2.0.0"
37
38
  }
38
39
  }
package/webpack.config.js CHANGED
@@ -10,6 +10,12 @@ fs.readdirSync('node_modules')
10
10
  nodeModules[mod] = 'commonjs ' + mod;
11
11
  });
12
12
 
13
+ fs.readdirSync('node_modules/@dra2020')
14
+ .forEach((mod) => {
15
+ mod = '@dra2020/' + mod;
16
+ nodeModules[mod] = 'commonjs ' + mod;
17
+ });
18
+
13
19
  var libConfig = {
14
20
  entry: {
15
21
  library: './lib/all.ts'