@dra2020/dra-types 1.4.8 → 1.5.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 +3 -0
- package/dist/csv.d.ts +40 -0
- package/dist/dra-types.d.ts +0 -58
- package/dist/dra-types.js +290 -80
- package/dist/dra-types.js.map +1 -1
- package/dist/stats.d.ts +45 -0
- package/dist/vfeature.d.ts +20 -0
- package/lib/all.ts +3 -0
- package/lib/bucketmap.ts +5 -0
- package/lib/csv.ts +515 -0
- package/lib/dra-types.ts +0 -592
- package/lib/schemas.ts +2 -0
- package/lib/stats.ts +203 -0
- package/lib/vfeature.ts +105 -0
- package/package.json +4 -4
package/dist/all.d.ts
CHANGED
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;
|
package/dist/dra-types.d.ts
CHANGED
|
@@ -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,13 @@ 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"));
|
|
118
|
+
__export(__webpack_require__(/*! ./stats */ "./lib/stats.ts"));
|
|
117
119
|
|
|
118
120
|
|
|
119
121
|
/***/ }),
|
|
@@ -135,8 +137,11 @@ exports.BucketMap = {
|
|
|
135
137
|
'state': 'dra-us-west-2-723398989493',
|
|
136
138
|
'state-dev': 'dev-dra-us-west-2-723398989493',
|
|
137
139
|
'logs': 'dra-uswest-logs',
|
|
140
|
+
'logs-dev': 'dra-uswest-logs',
|
|
138
141
|
'memsqs': 'dra-uswest-memsqs',
|
|
142
|
+
'memsqs-dev': 'dra-uswest-memsqs',
|
|
139
143
|
'images': 'dra-uswest-images',
|
|
144
|
+
'images-dev': 'dra-uswest-images',
|
|
140
145
|
'data': 'dra-us-west-datafiles',
|
|
141
146
|
'data-dev': 'dra-us-west-datafiles-dev',
|
|
142
147
|
'splits': 'dra-block-cache',
|
|
@@ -147,6 +152,8 @@ exports.BucketMap = {
|
|
|
147
152
|
'geojson-dev': 'dra-uswest-geojson',
|
|
148
153
|
'transfers': 'dra-transfers',
|
|
149
154
|
'transfers-dev': 'dra-transfers-dev',
|
|
155
|
+
'downloads': 'dra-uswest-downloads',
|
|
156
|
+
'downloads-dev': 'dra-uswest-downloads',
|
|
150
157
|
};
|
|
151
158
|
|
|
152
159
|
|
|
@@ -473,10 +480,10 @@ lum.forEach((n) => { exports.IntensityBackgroundColor.push(`rgba(${n}, ${n}, ${n
|
|
|
473
480
|
|
|
474
481
|
/***/ }),
|
|
475
482
|
|
|
476
|
-
/***/ "./lib/
|
|
477
|
-
|
|
478
|
-
!*** ./lib/
|
|
479
|
-
|
|
483
|
+
/***/ "./lib/csv.ts":
|
|
484
|
+
/*!********************!*\
|
|
485
|
+
!*** ./lib/csv.ts ***!
|
|
486
|
+
\********************/
|
|
480
487
|
/*! no static exports found */
|
|
481
488
|
/***/ (function(module, exports, __webpack_require__) {
|
|
482
489
|
|
|
@@ -484,82 +491,7 @@ lum.forEach((n) => { exports.IntensityBackgroundColor.push(`rgba(${n}, ${n}, ${n
|
|
|
484
491
|
|
|
485
492
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
486
493
|
// Public libraries
|
|
487
|
-
const Hash = __webpack_require__(/*! object-hash */ "object-hash");
|
|
488
494
|
const Util = __webpack_require__(/*! @dra2020/util */ "@dra2020/util");
|
|
489
|
-
// Canonical hashing of splitblock data
|
|
490
|
-
function hash(o) {
|
|
491
|
-
return Hash(o, { respectType: false,
|
|
492
|
-
unorderedArrays: true,
|
|
493
|
-
unorderedObjects: true,
|
|
494
|
-
excludeKeys: (k) => (k === 'id' || k === 'chunk')
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
function vgeoidToGeoid(vgeoid) {
|
|
498
|
-
let re = /vfeature_([^_]*)_.*/;
|
|
499
|
-
let a = re.exec(vgeoid);
|
|
500
|
-
if (a == null || a.length != 2)
|
|
501
|
-
return '';
|
|
502
|
-
else
|
|
503
|
-
return a[1];
|
|
504
|
-
}
|
|
505
|
-
exports.vgeoidToGeoid = vgeoidToGeoid;
|
|
506
|
-
function vgeoidToChunk(vgeoid) {
|
|
507
|
-
// vgeoid is string of form: "vfeature_[geoid]_[chunkid]_[hash]"
|
|
508
|
-
// the contents are chunked into a file of form "vfeature_chunk_[chunkid]"
|
|
509
|
-
// So extract the chunk ID and download that.
|
|
510
|
-
let re = /vfeature_([^_]*)_([^_*])_(.*)/;
|
|
511
|
-
let a = re.exec(vgeoid);
|
|
512
|
-
if (a && a.length == 4)
|
|
513
|
-
vgeoid = `vfeature_chunk_${a[2]}`;
|
|
514
|
-
else
|
|
515
|
-
vgeoid = null;
|
|
516
|
-
return vgeoid;
|
|
517
|
-
}
|
|
518
|
-
exports.vgeoidToChunk = vgeoidToChunk;
|
|
519
|
-
function vgeoidToHash(vgeoid) {
|
|
520
|
-
// vgeoid is string of form: "vfeature_[geoid]_[chunkid]_[hash]"
|
|
521
|
-
let re = /vfeature_([^_]*)_([^_*])_(.*)/;
|
|
522
|
-
let a = re.exec(vgeoid);
|
|
523
|
-
if (a && a.length == 4)
|
|
524
|
-
vgeoid = a[3];
|
|
525
|
-
else
|
|
526
|
-
vgeoid = null;
|
|
527
|
-
return vgeoid;
|
|
528
|
-
}
|
|
529
|
-
exports.vgeoidToHash = vgeoidToHash;
|
|
530
|
-
function isVfeature(geoid) {
|
|
531
|
-
return geoid.indexOf('vfeature') === 0;
|
|
532
|
-
}
|
|
533
|
-
exports.isVfeature = isVfeature;
|
|
534
|
-
function splitToCacheKey(s) {
|
|
535
|
-
if (s.id === undefined)
|
|
536
|
-
s.id = hash(s);
|
|
537
|
-
if (s.chunk === undefined)
|
|
538
|
-
s.chunk = "0";
|
|
539
|
-
return `_${s.state}_${s.datasource}_vfeature_${s.geoid}_${s.chunk}_${s.id}.geojson`;
|
|
540
|
-
}
|
|
541
|
-
exports.splitToCacheKey = splitToCacheKey;
|
|
542
|
-
function splitToChunkKey(s) {
|
|
543
|
-
if (s.chunk === undefined)
|
|
544
|
-
s.chunk = "0";
|
|
545
|
-
return `_${s.state}_${s.datasource}_vfeature_chunk_${s.chunk}.geojson`;
|
|
546
|
-
}
|
|
547
|
-
exports.splitToChunkKey = splitToChunkKey;
|
|
548
|
-
function splitToPrefix(s) {
|
|
549
|
-
if (s.blocks === undefined) {
|
|
550
|
-
let re = /_([^_]*)_(.*)_vfeature.*\.geojson$/;
|
|
551
|
-
let a = re.exec(s.id);
|
|
552
|
-
if (a && a.length == 3)
|
|
553
|
-
return `_${a[1]}_${a[2]}`;
|
|
554
|
-
return s.id;
|
|
555
|
-
}
|
|
556
|
-
return `_${s.state}_${s.datasource}`;
|
|
557
|
-
}
|
|
558
|
-
exports.splitToPrefix = splitToPrefix;
|
|
559
|
-
function cacheKeysToChunkHash(keys) {
|
|
560
|
-
return hash(keys);
|
|
561
|
-
}
|
|
562
|
-
exports.cacheKeysToChunkHash = cacheKeysToChunkHash;
|
|
563
495
|
let reNumeric = /^(\D*)(\d*)(\D*)$/;
|
|
564
496
|
let reDistrictNumber = /^\d+$/;
|
|
565
497
|
let reDistrictNumeric = /^\d/;
|
|
@@ -575,6 +507,8 @@ function canonicalDistrictID(districtID) {
|
|
|
575
507
|
}
|
|
576
508
|
exports.canonicalDistrictID = canonicalDistrictID;
|
|
577
509
|
// Normalize any numeric part to have four digits with padded leading zeros
|
|
510
|
+
// so alphabetic sorting will result in correct numeric sort for mixed alphanumber
|
|
511
|
+
// district labels.
|
|
578
512
|
function canonicalSortingDistrictID(districtID) {
|
|
579
513
|
let a = reNumeric.exec(districtID);
|
|
580
514
|
if (a && a.length == 4) {
|
|
@@ -620,12 +554,34 @@ function canonicalDistrictIDFromNumber(districtID, n) {
|
|
|
620
554
|
return districtID;
|
|
621
555
|
}
|
|
622
556
|
exports.canonicalDistrictIDFromNumber = canonicalDistrictIDFromNumber;
|
|
557
|
+
// If purely numeric districtIDs and we are missing some number of IDs less than
|
|
558
|
+
function canonicalDistrictIDGapFill(keys) {
|
|
559
|
+
if (keys == null || keys.length == 0)
|
|
560
|
+
return keys;
|
|
561
|
+
let nonNumeric = keys.find((s) => !reDistrictNumber.test(s)) !== undefined;
|
|
562
|
+
if (nonNumeric)
|
|
563
|
+
return keys;
|
|
564
|
+
let max = Number(keys[keys.length - 1]);
|
|
565
|
+
if (max == keys.length || (max - keys.length) > keys.length)
|
|
566
|
+
return keys; // no gaps or too many gaps
|
|
567
|
+
// OK, finally going to fill some gaps
|
|
568
|
+
for (let i = 0; i < keys.length; i++) {
|
|
569
|
+
let here = Number(keys[i]);
|
|
570
|
+
while (here > i + 1) {
|
|
571
|
+
keys.splice(i, 0, canonicalSortingDistrictID(String(i + 1)));
|
|
572
|
+
i++;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return keys;
|
|
576
|
+
}
|
|
577
|
+
exports.canonicalDistrictIDGapFill = canonicalDistrictIDGapFill;
|
|
623
578
|
function canonicalDistrictIDOrdering(order) {
|
|
624
579
|
let keys = Object.keys(order);
|
|
625
580
|
let i;
|
|
626
581
|
let a = [];
|
|
627
582
|
let template = undefined;
|
|
628
583
|
keys = keys.map((s) => canonicalSortingDistrictID(s));
|
|
584
|
+
keys = canonicalDistrictIDGapFill(keys);
|
|
629
585
|
keys.sort();
|
|
630
586
|
order = {};
|
|
631
587
|
for (i = 0; i < keys.length; i++)
|
|
@@ -1070,9 +1026,263 @@ exports.Schemas = {
|
|
|
1070
1026
|
'likes': {},
|
|
1071
1027
|
'comments': {},
|
|
1072
1028
|
'stats': {},
|
|
1029
|
+
'livestats': {},
|
|
1073
1030
|
};
|
|
1074
1031
|
|
|
1075
1032
|
|
|
1033
|
+
/***/ }),
|
|
1034
|
+
|
|
1035
|
+
/***/ "./lib/stats.ts":
|
|
1036
|
+
/*!**********************!*\
|
|
1037
|
+
!*** ./lib/stats.ts ***!
|
|
1038
|
+
\**********************/
|
|
1039
|
+
/*! no static exports found */
|
|
1040
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
1041
|
+
|
|
1042
|
+
"use strict";
|
|
1043
|
+
|
|
1044
|
+
// In constrast to logging, the stats manager is responsible for tracking live server status.
|
|
1045
|
+
// The results are stored in a compact database record which can be easily queried for current
|
|
1046
|
+
// status. Each server instance maintains its own field in the overall "values" record in the
|
|
1047
|
+
// stats database. The reporting tool aggregates all instances to report overall server activity.
|
|
1048
|
+
//
|
|
1049
|
+
// There are basically three kinds of values:
|
|
1050
|
+
// Sum - we want to sum the value across all server instances (e.g. number of connnected clients)
|
|
1051
|
+
// Avg - we just take average across all server instances (e.g. memory heap size)
|
|
1052
|
+
// Rate - we want to track the rate of some activity over some time period
|
|
1053
|
+
//
|
|
1054
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1055
|
+
exports.ValTypeSum = 0;
|
|
1056
|
+
exports.ValTypeAvg = 1;
|
|
1057
|
+
exports.ValTypeRate = 2;
|
|
1058
|
+
const ExpiryAge = 1000 * 60 * 60 * 24; // throw away instance record after this time period
|
|
1059
|
+
function statExpiryTime() {
|
|
1060
|
+
let time = new Date();
|
|
1061
|
+
time.setTime(time.getTime() + ExpiryAge);
|
|
1062
|
+
return time.toJSON();
|
|
1063
|
+
}
|
|
1064
|
+
exports.statExpiryTime = statExpiryTime;
|
|
1065
|
+
// Aggregate running value. This applies both in memory (logging multiple times before
|
|
1066
|
+
// saving to database) as well as aggregating into an instance structure in the DB.
|
|
1067
|
+
function statValueRecord(sv, cur, valType) {
|
|
1068
|
+
if (sv === undefined)
|
|
1069
|
+
sv = {};
|
|
1070
|
+
if (sv.min === undefined || cur < sv.min)
|
|
1071
|
+
sv.min = cur;
|
|
1072
|
+
if (sv.max === undefined || cur > sv.max)
|
|
1073
|
+
sv.max = cur;
|
|
1074
|
+
sv.cur = cur;
|
|
1075
|
+
sv.valType = valType;
|
|
1076
|
+
return sv;
|
|
1077
|
+
}
|
|
1078
|
+
exports.statValueRecord = statValueRecord;
|
|
1079
|
+
function statRateIncr(sr, incr = 1) {
|
|
1080
|
+
if (sr == null)
|
|
1081
|
+
sr = {};
|
|
1082
|
+
sr.valType = exports.ValTypeRate;
|
|
1083
|
+
sr.thisMin = sr.thisMin === undefined ? incr : sr.thisMin + incr;
|
|
1084
|
+
sr.thisHour = sr.thisHour === undefined ? incr : sr.thisHour + incr;
|
|
1085
|
+
sr.thisDay = sr.thisDay === undefined ? incr : sr.thisDay + incr;
|
|
1086
|
+
return sr;
|
|
1087
|
+
}
|
|
1088
|
+
exports.statRateIncr = statRateIncr;
|
|
1089
|
+
exports.OneMinute = 1000 * 60;
|
|
1090
|
+
exports.OneHour = exports.OneMinute * 60;
|
|
1091
|
+
exports.OneDay = exports.OneHour * 24;
|
|
1092
|
+
function statRateRollover(sr, period) {
|
|
1093
|
+
if ((period % exports.OneMinute) == 0) {
|
|
1094
|
+
sr.lastMin = sr.thisMin;
|
|
1095
|
+
sr.thisMin = 0;
|
|
1096
|
+
}
|
|
1097
|
+
if ((period % exports.OneHour) == 0) {
|
|
1098
|
+
sr.lastHour = sr.thisHour;
|
|
1099
|
+
sr.thisHour = 0;
|
|
1100
|
+
}
|
|
1101
|
+
if ((period % exports.OneDay) == 0) {
|
|
1102
|
+
sr.lastDay = sr.thisDay;
|
|
1103
|
+
sr.thisDay = 0;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
exports.statRateRollover = statRateRollover;
|
|
1107
|
+
function statEntryIndexMerge(accum, si) {
|
|
1108
|
+
if (accum == null)
|
|
1109
|
+
accum = {};
|
|
1110
|
+
// We just discard and replace old rate information
|
|
1111
|
+
Object.keys(accum).forEach((p) => { if (accum[p].valType == exports.ValTypeRate)
|
|
1112
|
+
delete accum[p]; });
|
|
1113
|
+
// But merge in all the other values
|
|
1114
|
+
Object.keys(si).forEach((p) => {
|
|
1115
|
+
let se = si[p];
|
|
1116
|
+
if (se.valType == exports.ValTypeRate)
|
|
1117
|
+
accum[p] = se;
|
|
1118
|
+
else {
|
|
1119
|
+
let sv = se;
|
|
1120
|
+
accum[p] = statValueRecord(se, sv.cur, sv.valType);
|
|
1121
|
+
}
|
|
1122
|
+
});
|
|
1123
|
+
return accum;
|
|
1124
|
+
}
|
|
1125
|
+
exports.statEntryIndexMerge = statEntryIndexMerge;
|
|
1126
|
+
function statEntryIndexRollover(si, period) {
|
|
1127
|
+
Object.keys(si).forEach((p) => {
|
|
1128
|
+
let se = si[p];
|
|
1129
|
+
if (se.valType == exports.ValTypeRate)
|
|
1130
|
+
statRateRollover(se, period);
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
exports.statEntryIndexRollover = statEntryIndexRollover;
|
|
1134
|
+
function statRecordMerge(accum, si) {
|
|
1135
|
+
if (accum == null)
|
|
1136
|
+
accum = { id: si.id, production: si.production, time: si.time, expires: si.expires, index: {} };
|
|
1137
|
+
accum.expires = si.expires;
|
|
1138
|
+
accum.time = si.time;
|
|
1139
|
+
statEntryIndexMerge(accum.index, si.index);
|
|
1140
|
+
return accum;
|
|
1141
|
+
}
|
|
1142
|
+
exports.statRecordMerge = statRecordMerge;
|
|
1143
|
+
// Accumulate a set of values together (e.g. from multiple running instances)
|
|
1144
|
+
// for reporting current state.
|
|
1145
|
+
//
|
|
1146
|
+
function statValueAccum(accum, sv) {
|
|
1147
|
+
if (accum == null) {
|
|
1148
|
+
accum = {};
|
|
1149
|
+
accum.valType = sv.valType;
|
|
1150
|
+
}
|
|
1151
|
+
if (accum.min === undefined || sv.min < accum.min)
|
|
1152
|
+
accum.min = sv.min;
|
|
1153
|
+
if (accum.max === undefined || sv.max > accum.max)
|
|
1154
|
+
accum.max = sv.max;
|
|
1155
|
+
if (accum.valType === undefined)
|
|
1156
|
+
accum.valType = sv.valType;
|
|
1157
|
+
if (accum.valType == exports.ValTypeSum)
|
|
1158
|
+
accum.cur = (accum.cur === undefined ? sv.cur : accum.cur + sv.cur);
|
|
1159
|
+
else if (accum.valType == exports.ValTypeAvg) {
|
|
1160
|
+
accum.tot = (accum.tot === undefined ? 0 : accum.tot) + sv.cur;
|
|
1161
|
+
accum.cnt = (accum.cnt === undefined ? 0 : accum.cnt) + 1;
|
|
1162
|
+
accum.cur = accum.tot / accum.cnt;
|
|
1163
|
+
}
|
|
1164
|
+
return accum;
|
|
1165
|
+
}
|
|
1166
|
+
exports.statValueAccum = statValueAccum;
|
|
1167
|
+
function statRateAccum(accum, sr) {
|
|
1168
|
+
if (accum == null) {
|
|
1169
|
+
accum = {};
|
|
1170
|
+
accum.valType = sr.valType;
|
|
1171
|
+
}
|
|
1172
|
+
accum.thisMin = accum.thisMin === undefined ? sr.thisMin : (accum.thisMin + (sr.thisMin === undefined ? 0 : sr.thisMin));
|
|
1173
|
+
accum.lastMin = accum.lastMin === undefined ? sr.lastMin : (accum.lastMin + (sr.lastMin === undefined ? 0 : sr.lastMin));
|
|
1174
|
+
accum.thisHour = accum.thisHour === undefined ? sr.thisHour : (accum.thisHour + (sr.thisHour === undefined ? 0 : sr.thisHour));
|
|
1175
|
+
accum.lastHour = accum.lastHour === undefined ? sr.lastHour : (accum.lastHour + (sr.lastHour === undefined ? 0 : sr.lastHour));
|
|
1176
|
+
accum.thisDay = accum.thisDay === undefined ? sr.thisDay : (accum.thisDay + (sr.thisDay === undefined ? 0 : sr.thisDay));
|
|
1177
|
+
accum.lastDay = accum.lastDay === undefined ? sr.lastDay : (accum.lastDay + (sr.lastDay === undefined ? 0 : sr.lastDay));
|
|
1178
|
+
return accum;
|
|
1179
|
+
}
|
|
1180
|
+
exports.statRateAccum = statRateAccum;
|
|
1181
|
+
function statIndexAccum(accum, si) {
|
|
1182
|
+
if (accum == null)
|
|
1183
|
+
accum = {};
|
|
1184
|
+
Object.keys(si).forEach((p) => {
|
|
1185
|
+
let se = si[p];
|
|
1186
|
+
if (se.valType == exports.ValTypeRate)
|
|
1187
|
+
accum[p] = statRateAccum(accum[p], se);
|
|
1188
|
+
else
|
|
1189
|
+
accum[p] = statValueAccum(accum[p], se);
|
|
1190
|
+
});
|
|
1191
|
+
return accum;
|
|
1192
|
+
}
|
|
1193
|
+
exports.statIndexAccum = statIndexAccum;
|
|
1194
|
+
|
|
1195
|
+
|
|
1196
|
+
/***/ }),
|
|
1197
|
+
|
|
1198
|
+
/***/ "./lib/vfeature.ts":
|
|
1199
|
+
/*!*************************!*\
|
|
1200
|
+
!*** ./lib/vfeature.ts ***!
|
|
1201
|
+
\*************************/
|
|
1202
|
+
/*! no static exports found */
|
|
1203
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
1204
|
+
|
|
1205
|
+
"use strict";
|
|
1206
|
+
|
|
1207
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1208
|
+
// Public libraries
|
|
1209
|
+
const Hash = __webpack_require__(/*! object-hash */ "object-hash");
|
|
1210
|
+
// Canonical hashing of splitblock data
|
|
1211
|
+
function hash(o) {
|
|
1212
|
+
return Hash(o, { respectType: false,
|
|
1213
|
+
unorderedArrays: true,
|
|
1214
|
+
unorderedObjects: true,
|
|
1215
|
+
excludeKeys: (k) => (k === 'id' || k === 'chunk')
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
function vgeoidToGeoid(vgeoid) {
|
|
1219
|
+
let re = /vfeature_([^_]*)_.*/;
|
|
1220
|
+
let a = re.exec(vgeoid);
|
|
1221
|
+
if (a == null || a.length != 2)
|
|
1222
|
+
return '';
|
|
1223
|
+
else
|
|
1224
|
+
return a[1];
|
|
1225
|
+
}
|
|
1226
|
+
exports.vgeoidToGeoid = vgeoidToGeoid;
|
|
1227
|
+
function vgeoidToChunk(vgeoid) {
|
|
1228
|
+
// vgeoid is string of form: "vfeature_[geoid]_[chunkid]_[hash]"
|
|
1229
|
+
// the contents are chunked into a file of form "vfeature_chunk_[chunkid]"
|
|
1230
|
+
// So extract the chunk ID and download that.
|
|
1231
|
+
let re = /vfeature_([^_]*)_([^_*])_(.*)/;
|
|
1232
|
+
let a = re.exec(vgeoid);
|
|
1233
|
+
if (a && a.length == 4)
|
|
1234
|
+
vgeoid = `vfeature_chunk_${a[2]}`;
|
|
1235
|
+
else
|
|
1236
|
+
vgeoid = null;
|
|
1237
|
+
return vgeoid;
|
|
1238
|
+
}
|
|
1239
|
+
exports.vgeoidToChunk = vgeoidToChunk;
|
|
1240
|
+
function vgeoidToHash(vgeoid) {
|
|
1241
|
+
// vgeoid is string of form: "vfeature_[geoid]_[chunkid]_[hash]"
|
|
1242
|
+
let re = /vfeature_([^_]*)_([^_*])_(.*)/;
|
|
1243
|
+
let a = re.exec(vgeoid);
|
|
1244
|
+
if (a && a.length == 4)
|
|
1245
|
+
vgeoid = a[3];
|
|
1246
|
+
else
|
|
1247
|
+
vgeoid = null;
|
|
1248
|
+
return vgeoid;
|
|
1249
|
+
}
|
|
1250
|
+
exports.vgeoidToHash = vgeoidToHash;
|
|
1251
|
+
function isVfeature(geoid) {
|
|
1252
|
+
return geoid.indexOf('vfeature') === 0;
|
|
1253
|
+
}
|
|
1254
|
+
exports.isVfeature = isVfeature;
|
|
1255
|
+
function splitToCacheKey(s) {
|
|
1256
|
+
if (s.id === undefined)
|
|
1257
|
+
s.id = hash(s);
|
|
1258
|
+
if (s.chunk === undefined)
|
|
1259
|
+
s.chunk = "0";
|
|
1260
|
+
return `_${s.state}_${s.datasource}_vfeature_${s.geoid}_${s.chunk}_${s.id}.geojson`;
|
|
1261
|
+
}
|
|
1262
|
+
exports.splitToCacheKey = splitToCacheKey;
|
|
1263
|
+
function splitToChunkKey(s) {
|
|
1264
|
+
if (s.chunk === undefined)
|
|
1265
|
+
s.chunk = "0";
|
|
1266
|
+
return `_${s.state}_${s.datasource}_vfeature_chunk_${s.chunk}.geojson`;
|
|
1267
|
+
}
|
|
1268
|
+
exports.splitToChunkKey = splitToChunkKey;
|
|
1269
|
+
function splitToPrefix(s) {
|
|
1270
|
+
if (s.blocks === undefined) {
|
|
1271
|
+
let re = /_([^_]*)_(.*)_vfeature.*\.geojson$/;
|
|
1272
|
+
let a = re.exec(s.id);
|
|
1273
|
+
if (a && a.length == 3)
|
|
1274
|
+
return `_${a[1]}_${a[2]}`;
|
|
1275
|
+
return s.id;
|
|
1276
|
+
}
|
|
1277
|
+
return `_${s.state}_${s.datasource}`;
|
|
1278
|
+
}
|
|
1279
|
+
exports.splitToPrefix = splitToPrefix;
|
|
1280
|
+
function cacheKeysToChunkHash(keys) {
|
|
1281
|
+
return hash(keys);
|
|
1282
|
+
}
|
|
1283
|
+
exports.cacheKeysToChunkHash = cacheKeysToChunkHash;
|
|
1284
|
+
|
|
1285
|
+
|
|
1076
1286
|
/***/ }),
|
|
1077
1287
|
|
|
1078
1288
|
/***/ "@dra2020/util":
|