@dra2020/dra-types 1.4.9 → 1.4.10

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/all.d.ts CHANGED
@@ -3,3 +3,5 @@ export * from './schemas';
3
3
  export * from './bucketmap';
4
4
  export * from './colordata';
5
5
  export * from './gencolor';
6
+ export * from './vfeature';
7
+ export * from './csv';
package/dist/csv.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ import * as VF from './vfeature';
2
+ export declare type BlockMap = {
3
+ [id: string]: number;
4
+ };
5
+ export declare type BlockMapping = {
6
+ [id: string]: string;
7
+ };
8
+ export declare function canonicalDistrictID(districtID: string): string;
9
+ export declare function canonicalSortingDistrictID(districtID: string): string;
10
+ export declare function canonicalNumericFromDistrictID(districtID: string): number;
11
+ export declare function canonicalDistrictIDFromNumber(districtID: string, n: number): string;
12
+ export declare type DistrictOrder = {
13
+ [districtID: string]: number;
14
+ };
15
+ export declare function canonicalDistrictIDGapFill(keys: string[]): string[];
16
+ export declare function canonicalDistrictIDOrdering(order: DistrictOrder): DistrictOrder;
17
+ export interface OneCSVLine {
18
+ geoid: string;
19
+ districtID: string;
20
+ }
21
+ export declare function parseCSVLine(line: string): OneCSVLine;
22
+ export interface ConvertResult {
23
+ inBlockMap: BlockMapping;
24
+ inStateMap: BlockMapping;
25
+ outValid: boolean;
26
+ outState: string;
27
+ outMap: BlockMapping;
28
+ outOrder: DistrictOrder;
29
+ outDistrictToSplit: VF.DistrictToSplitBlock;
30
+ }
31
+ export declare function blockmapToState(blockMap: BlockMapping): string;
32
+ export declare function blockmapToVTDmap(blockMap: BlockMapping, stateMap: BlockMapping): ConvertResult;
33
+ export declare const GEOIDToState: any;
34
+ export declare const StateToGEOID: any;
35
+ export declare function geoidToState(geoid: string): string;
36
+ export declare type StateUrls = ('alabama' | 'alaska' | 'arizona' | 'arkansas' | 'california' | 'colorado' | 'connecticut' | 'delaware' | 'florida' | 'georgia' | 'hawaii' | 'idaho' | 'illinois' | 'indiana' | 'iowa' | 'kansas' | 'kentucky' | 'louisiana' | 'maine' | 'maryland' | 'massachusetts' | 'michigan' | 'minnesota' | 'mississippi' | 'missouri' | 'montana' | 'nebraska' | 'nevada' | 'new-hampshire' | 'new-jersey' | 'new-mexico' | 'new-york' | 'north-carolina' | 'north-dakota' | 'ohio' | 'oklahoma' | 'oregon' | 'pennsylvania' | 'rhode-island' | 'south-carolina' | 'south-dakota' | 'tennessee' | 'texas' | 'utah' | 'vermont' | 'virginia' | 'washington' | 'west-virginia' | 'wisconsin' | 'wyoming');
37
+ export declare type ValidStateUrlsType = {
38
+ readonly [stateUrl in StateUrls]: boolean;
39
+ };
40
+ export declare function isStateUrl(s: any): s is StateUrls;
@@ -1,9 +1,3 @@
1
- export declare type BlockMap = {
2
- [id: string]: number;
3
- };
4
- export declare type BlockMapping = {
5
- [id: string]: string;
6
- };
7
1
  export interface Comment {
8
2
  userid: string;
9
3
  text: string;
@@ -27,55 +21,3 @@ export interface UserLikes {
27
21
  id?: string;
28
22
  [aid: string]: Like | string;
29
23
  }
30
- export interface SplitBlock {
31
- id?: string;
32
- chunkKey?: string;
33
- chunk?: string;
34
- state: string;
35
- datasource: string;
36
- geoid: string;
37
- blocks: string[];
38
- }
39
- export declare type DistrictToSplitBlock = {
40
- [districtID: string]: SplitBlock[];
41
- };
42
- export declare function vgeoidToGeoid(vgeoid: string): string;
43
- export declare function vgeoidToChunk(vgeoid: string): string;
44
- export declare function vgeoidToHash(vgeoid: string): string;
45
- export declare function isVfeature(geoid: string): boolean;
46
- export declare function splitToCacheKey(s: SplitBlock): string;
47
- export declare function splitToChunkKey(s: SplitBlock): string;
48
- export declare function splitToPrefix(s: SplitBlock): string;
49
- export declare function cacheKeysToChunkHash(keys: string[]): string;
50
- export declare function canonicalDistrictID(districtID: string): string;
51
- export declare function canonicalSortingDistrictID(districtID: string): string;
52
- export declare function canonicalNumericFromDistrictID(districtID: string): number;
53
- export declare function canonicalDistrictIDFromNumber(districtID: string, n: number): string;
54
- export declare type DistrictOrder = {
55
- [districtID: string]: number;
56
- };
57
- export declare function canonicalDistrictIDOrdering(order: DistrictOrder): DistrictOrder;
58
- export interface OneCSVLine {
59
- geoid: string;
60
- districtID: string;
61
- }
62
- export declare function parseCSVLine(line: string): OneCSVLine;
63
- export interface ConvertResult {
64
- inBlockMap: BlockMapping;
65
- inStateMap: BlockMapping;
66
- outValid: boolean;
67
- outState: string;
68
- outMap: BlockMapping;
69
- outOrder: DistrictOrder;
70
- outDistrictToSplit: DistrictToSplitBlock;
71
- }
72
- export declare function blockmapToState(blockMap: BlockMapping): string;
73
- export declare function blockmapToVTDmap(blockMap: BlockMapping, stateMap: BlockMapping): ConvertResult;
74
- export declare const GEOIDToState: any;
75
- export declare const StateToGEOID: any;
76
- export declare function geoidToState(geoid: string): string;
77
- export declare type StateUrls = ('alabama' | 'alaska' | 'arizona' | 'arkansas' | 'california' | 'colorado' | 'connecticut' | 'delaware' | 'florida' | 'georgia' | 'hawaii' | 'idaho' | 'illinois' | 'indiana' | 'iowa' | 'kansas' | 'kentucky' | 'louisiana' | 'maine' | 'maryland' | 'massachusetts' | 'michigan' | 'minnesota' | 'mississippi' | 'missouri' | 'montana' | 'nebraska' | 'nevada' | 'new-hampshire' | 'new-jersey' | 'new-mexico' | 'new-york' | 'north-carolina' | 'north-dakota' | 'ohio' | 'oklahoma' | 'oregon' | 'pennsylvania' | 'rhode-island' | 'south-carolina' | 'south-dakota' | 'tennessee' | 'texas' | 'utah' | 'vermont' | 'virginia' | 'washington' | 'west-virginia' | 'wisconsin' | 'wyoming');
78
- export declare type ValidStateUrlsType = {
79
- readonly [stateUrl in StateUrls]: boolean;
80
- };
81
- export declare function isStateUrl(s: any): s is StateUrls;
package/dist/dra-types.js CHANGED
@@ -109,11 +109,12 @@ function __export(m) {
109
109
  for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
110
110
  }
111
111
  Object.defineProperty(exports, "__esModule", { value: true });
112
- __export(__webpack_require__(/*! ./dra-types */ "./lib/dra-types.ts"));
113
112
  __export(__webpack_require__(/*! ./schemas */ "./lib/schemas.ts"));
114
113
  __export(__webpack_require__(/*! ./bucketmap */ "./lib/bucketmap.ts"));
115
114
  __export(__webpack_require__(/*! ./colordata */ "./lib/colordata.ts"));
116
115
  __export(__webpack_require__(/*! ./gencolor */ "./lib/gencolor.ts"));
116
+ __export(__webpack_require__(/*! ./vfeature */ "./lib/vfeature.ts"));
117
+ __export(__webpack_require__(/*! ./csv */ "./lib/csv.ts"));
117
118
 
118
119
 
119
120
  /***/ }),
@@ -135,8 +136,11 @@ exports.BucketMap = {
135
136
  'state': 'dra-us-west-2-723398989493',
136
137
  'state-dev': 'dev-dra-us-west-2-723398989493',
137
138
  'logs': 'dra-uswest-logs',
139
+ 'logs-dev': 'dra-uswest-logs',
138
140
  'memsqs': 'dra-uswest-memsqs',
141
+ 'memsqs-dev': 'dra-uswest-memsqs',
139
142
  'images': 'dra-uswest-images',
143
+ 'images-dev': 'dra-uswest-images',
140
144
  'data': 'dra-us-west-datafiles',
141
145
  'data-dev': 'dra-us-west-datafiles-dev',
142
146
  'splits': 'dra-block-cache',
@@ -475,10 +479,10 @@ lum.forEach((n) => { exports.IntensityBackgroundColor.push(`rgba(${n}, ${n}, ${n
475
479
 
476
480
  /***/ }),
477
481
 
478
- /***/ "./lib/dra-types.ts":
479
- /*!**************************!*\
480
- !*** ./lib/dra-types.ts ***!
481
- \**************************/
482
+ /***/ "./lib/csv.ts":
483
+ /*!********************!*\
484
+ !*** ./lib/csv.ts ***!
485
+ \********************/
482
486
  /*! no static exports found */
483
487
  /***/ (function(module, exports, __webpack_require__) {
484
488
 
@@ -486,82 +490,7 @@ lum.forEach((n) => { exports.IntensityBackgroundColor.push(`rgba(${n}, ${n}, ${n
486
490
 
487
491
  Object.defineProperty(exports, "__esModule", { value: true });
488
492
  // Public libraries
489
- const Hash = __webpack_require__(/*! object-hash */ "object-hash");
490
493
  const Util = __webpack_require__(/*! @dra2020/util */ "@dra2020/util");
491
- // Canonical hashing of splitblock data
492
- function hash(o) {
493
- return Hash(o, { respectType: false,
494
- unorderedArrays: true,
495
- unorderedObjects: true,
496
- excludeKeys: (k) => (k === 'id' || k === 'chunk')
497
- });
498
- }
499
- function vgeoidToGeoid(vgeoid) {
500
- let re = /vfeature_([^_]*)_.*/;
501
- let a = re.exec(vgeoid);
502
- if (a == null || a.length != 2)
503
- return '';
504
- else
505
- return a[1];
506
- }
507
- exports.vgeoidToGeoid = vgeoidToGeoid;
508
- function vgeoidToChunk(vgeoid) {
509
- // vgeoid is string of form: "vfeature_[geoid]_[chunkid]_[hash]"
510
- // the contents are chunked into a file of form "vfeature_chunk_[chunkid]"
511
- // So extract the chunk ID and download that.
512
- let re = /vfeature_([^_]*)_([^_*])_(.*)/;
513
- let a = re.exec(vgeoid);
514
- if (a && a.length == 4)
515
- vgeoid = `vfeature_chunk_${a[2]}`;
516
- else
517
- vgeoid = null;
518
- return vgeoid;
519
- }
520
- exports.vgeoidToChunk = vgeoidToChunk;
521
- function vgeoidToHash(vgeoid) {
522
- // vgeoid is string of form: "vfeature_[geoid]_[chunkid]_[hash]"
523
- let re = /vfeature_([^_]*)_([^_*])_(.*)/;
524
- let a = re.exec(vgeoid);
525
- if (a && a.length == 4)
526
- vgeoid = a[3];
527
- else
528
- vgeoid = null;
529
- return vgeoid;
530
- }
531
- exports.vgeoidToHash = vgeoidToHash;
532
- function isVfeature(geoid) {
533
- return geoid.indexOf('vfeature') === 0;
534
- }
535
- exports.isVfeature = isVfeature;
536
- function splitToCacheKey(s) {
537
- if (s.id === undefined)
538
- s.id = hash(s);
539
- if (s.chunk === undefined)
540
- s.chunk = "0";
541
- return `_${s.state}_${s.datasource}_vfeature_${s.geoid}_${s.chunk}_${s.id}.geojson`;
542
- }
543
- exports.splitToCacheKey = splitToCacheKey;
544
- function splitToChunkKey(s) {
545
- if (s.chunk === undefined)
546
- s.chunk = "0";
547
- return `_${s.state}_${s.datasource}_vfeature_chunk_${s.chunk}.geojson`;
548
- }
549
- exports.splitToChunkKey = splitToChunkKey;
550
- function splitToPrefix(s) {
551
- if (s.blocks === undefined) {
552
- let re = /_([^_]*)_(.*)_vfeature.*\.geojson$/;
553
- let a = re.exec(s.id);
554
- if (a && a.length == 3)
555
- return `_${a[1]}_${a[2]}`;
556
- return s.id;
557
- }
558
- return `_${s.state}_${s.datasource}`;
559
- }
560
- exports.splitToPrefix = splitToPrefix;
561
- function cacheKeysToChunkHash(keys) {
562
- return hash(keys);
563
- }
564
- exports.cacheKeysToChunkHash = cacheKeysToChunkHash;
565
494
  let reNumeric = /^(\D*)(\d*)(\D*)$/;
566
495
  let reDistrictNumber = /^\d+$/;
567
496
  let reDistrictNumeric = /^\d/;
@@ -577,6 +506,8 @@ function canonicalDistrictID(districtID) {
577
506
  }
578
507
  exports.canonicalDistrictID = canonicalDistrictID;
579
508
  // Normalize any numeric part to have four digits with padded leading zeros
509
+ // so alphabetic sorting will result in correct numeric sort for mixed alphanumber
510
+ // district labels.
580
511
  function canonicalSortingDistrictID(districtID) {
581
512
  let a = reNumeric.exec(districtID);
582
513
  if (a && a.length == 4) {
@@ -622,12 +553,34 @@ function canonicalDistrictIDFromNumber(districtID, n) {
622
553
  return districtID;
623
554
  }
624
555
  exports.canonicalDistrictIDFromNumber = canonicalDistrictIDFromNumber;
556
+ // If purely numeric districtIDs and we are missing some number of IDs less than
557
+ function canonicalDistrictIDGapFill(keys) {
558
+ if (keys == null || keys.length == 0)
559
+ return keys;
560
+ let nonNumeric = keys.find((s) => !reDistrictNumber.test(s)) !== undefined;
561
+ if (nonNumeric)
562
+ return keys;
563
+ let max = Number(keys[keys.length - 1]);
564
+ if (max == keys.length || (max - keys.length) > keys.length)
565
+ return keys; // no gaps or too many gaps
566
+ // OK, finally going to fill some gaps
567
+ for (let i = 0; i < keys.length; i++) {
568
+ let here = Number(keys[i]);
569
+ while (here > i + 1) {
570
+ keys.splice(i, 0, canonicalSortingDistrictID(String(i + 1)));
571
+ i++;
572
+ }
573
+ }
574
+ return keys;
575
+ }
576
+ exports.canonicalDistrictIDGapFill = canonicalDistrictIDGapFill;
625
577
  function canonicalDistrictIDOrdering(order) {
626
578
  let keys = Object.keys(order);
627
579
  let i;
628
580
  let a = [];
629
581
  let template = undefined;
630
582
  keys = keys.map((s) => canonicalSortingDistrictID(s));
583
+ keys = canonicalDistrictIDGapFill(keys);
631
584
  keys.sort();
632
585
  order = {};
633
586
  for (i = 0; i < keys.length; i++)
@@ -1075,6 +1028,96 @@ exports.Schemas = {
1075
1028
  };
1076
1029
 
1077
1030
 
1031
+ /***/ }),
1032
+
1033
+ /***/ "./lib/vfeature.ts":
1034
+ /*!*************************!*\
1035
+ !*** ./lib/vfeature.ts ***!
1036
+ \*************************/
1037
+ /*! no static exports found */
1038
+ /***/ (function(module, exports, __webpack_require__) {
1039
+
1040
+ "use strict";
1041
+
1042
+ Object.defineProperty(exports, "__esModule", { value: true });
1043
+ // Public libraries
1044
+ const Hash = __webpack_require__(/*! object-hash */ "object-hash");
1045
+ // Canonical hashing of splitblock data
1046
+ function hash(o) {
1047
+ return Hash(o, { respectType: false,
1048
+ unorderedArrays: true,
1049
+ unorderedObjects: true,
1050
+ excludeKeys: (k) => (k === 'id' || k === 'chunk')
1051
+ });
1052
+ }
1053
+ function vgeoidToGeoid(vgeoid) {
1054
+ let re = /vfeature_([^_]*)_.*/;
1055
+ let a = re.exec(vgeoid);
1056
+ if (a == null || a.length != 2)
1057
+ return '';
1058
+ else
1059
+ return a[1];
1060
+ }
1061
+ exports.vgeoidToGeoid = vgeoidToGeoid;
1062
+ function vgeoidToChunk(vgeoid) {
1063
+ // vgeoid is string of form: "vfeature_[geoid]_[chunkid]_[hash]"
1064
+ // the contents are chunked into a file of form "vfeature_chunk_[chunkid]"
1065
+ // So extract the chunk ID and download that.
1066
+ let re = /vfeature_([^_]*)_([^_*])_(.*)/;
1067
+ let a = re.exec(vgeoid);
1068
+ if (a && a.length == 4)
1069
+ vgeoid = `vfeature_chunk_${a[2]}`;
1070
+ else
1071
+ vgeoid = null;
1072
+ return vgeoid;
1073
+ }
1074
+ exports.vgeoidToChunk = vgeoidToChunk;
1075
+ function vgeoidToHash(vgeoid) {
1076
+ // vgeoid is string of form: "vfeature_[geoid]_[chunkid]_[hash]"
1077
+ let re = /vfeature_([^_]*)_([^_*])_(.*)/;
1078
+ let a = re.exec(vgeoid);
1079
+ if (a && a.length == 4)
1080
+ vgeoid = a[3];
1081
+ else
1082
+ vgeoid = null;
1083
+ return vgeoid;
1084
+ }
1085
+ exports.vgeoidToHash = vgeoidToHash;
1086
+ function isVfeature(geoid) {
1087
+ return geoid.indexOf('vfeature') === 0;
1088
+ }
1089
+ exports.isVfeature = isVfeature;
1090
+ function splitToCacheKey(s) {
1091
+ if (s.id === undefined)
1092
+ s.id = hash(s);
1093
+ if (s.chunk === undefined)
1094
+ s.chunk = "0";
1095
+ return `_${s.state}_${s.datasource}_vfeature_${s.geoid}_${s.chunk}_${s.id}.geojson`;
1096
+ }
1097
+ exports.splitToCacheKey = splitToCacheKey;
1098
+ function splitToChunkKey(s) {
1099
+ if (s.chunk === undefined)
1100
+ s.chunk = "0";
1101
+ return `_${s.state}_${s.datasource}_vfeature_chunk_${s.chunk}.geojson`;
1102
+ }
1103
+ exports.splitToChunkKey = splitToChunkKey;
1104
+ function splitToPrefix(s) {
1105
+ if (s.blocks === undefined) {
1106
+ let re = /_([^_]*)_(.*)_vfeature.*\.geojson$/;
1107
+ let a = re.exec(s.id);
1108
+ if (a && a.length == 3)
1109
+ return `_${a[1]}_${a[2]}`;
1110
+ return s.id;
1111
+ }
1112
+ return `_${s.state}_${s.datasource}`;
1113
+ }
1114
+ exports.splitToPrefix = splitToPrefix;
1115
+ function cacheKeysToChunkHash(keys) {
1116
+ return hash(keys);
1117
+ }
1118
+ exports.cacheKeysToChunkHash = cacheKeysToChunkHash;
1119
+
1120
+
1078
1121
  /***/ }),
1079
1122
 
1080
1123
  /***/ "@dra2020/util":