@dra2020/dra-types 1.8.91 → 1.8.93
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/alldt.d.ts +1 -0
- package/dist/datasets.d.ts +46 -0
- package/dist/dra-types.js +167 -86
- package/dist/dra-types.js.map +1 -1
- package/dist/packedfields.d.ts +24 -28
- package/lib/alldt.ts +1 -0
- package/lib/colormgr.ts +6 -6
- package/lib/datasets.ts +55 -0
- package/lib/packedfields.ts +155 -74
- package/package.json +1 -1
package/dist/alldt.d.ts
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export interface DatasetField {
|
|
2
|
+
shortCaption: string;
|
|
3
|
+
longCaption: string;
|
|
4
|
+
order?: number;
|
|
5
|
+
isCombo?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function sortFields(f1: DatasetField, f2: DatasetField): number;
|
|
8
|
+
export type DatasetFields = {
|
|
9
|
+
[key: string]: DatasetField;
|
|
10
|
+
};
|
|
11
|
+
export interface DatasetMeta {
|
|
12
|
+
type: string;
|
|
13
|
+
year: number;
|
|
14
|
+
title: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
office?: string;
|
|
17
|
+
subtype?: string;
|
|
18
|
+
votingAge?: boolean;
|
|
19
|
+
nhAlone?: boolean;
|
|
20
|
+
privateKey?: string;
|
|
21
|
+
members?: {
|
|
22
|
+
[key: number]: string;
|
|
23
|
+
};
|
|
24
|
+
fields?: DatasetFields;
|
|
25
|
+
}
|
|
26
|
+
export type DatasetsMeta = {
|
|
27
|
+
[dataset: string]: DatasetMeta;
|
|
28
|
+
};
|
|
29
|
+
export interface Dataset {
|
|
30
|
+
id: string;
|
|
31
|
+
name?: string;
|
|
32
|
+
description?: string;
|
|
33
|
+
createdBy?: string;
|
|
34
|
+
createTime?: string;
|
|
35
|
+
modifyTime?: string;
|
|
36
|
+
deleted?: boolean;
|
|
37
|
+
published?: string;
|
|
38
|
+
official?: boolean;
|
|
39
|
+
state?: string;
|
|
40
|
+
datasource?: string;
|
|
41
|
+
dotmap?: boolean;
|
|
42
|
+
meta?: DatasetsMeta;
|
|
43
|
+
}
|
|
44
|
+
export type DatasetIndex = {
|
|
45
|
+
[id: string]: Dataset;
|
|
46
|
+
};
|
package/dist/dra-types.js
CHANGED
|
@@ -47,6 +47,7 @@ __exportStar(__webpack_require__(/*! ./landmark */ "./lib/landmark.ts"), exports
|
|
|
47
47
|
__exportStar(__webpack_require__(/*! ./splittogeofeature */ "./lib/splittogeofeature.ts"), exports);
|
|
48
48
|
__exportStar(__webpack_require__(/*! ./reverse */ "./lib/reverse.ts"), exports);
|
|
49
49
|
__exportStar(__webpack_require__(/*! ./groups */ "./lib/groups.ts"), exports);
|
|
50
|
+
__exportStar(__webpack_require__(/*! ./datasets */ "./lib/datasets.ts"), exports);
|
|
50
51
|
__exportStar(__webpack_require__(/*! ./precincts */ "./lib/precincts.ts"), exports);
|
|
51
52
|
|
|
52
53
|
|
|
@@ -256,7 +257,7 @@ exports.ethnicBackgroundColor = ethnicBackgroundColor;
|
|
|
256
257
|
function ToAllEthnicColor(agg, dc, pd) {
|
|
257
258
|
// Use VAP/CVAP if it exists
|
|
258
259
|
const dataset = dc.primeVDS ? dc.primeVDS : dc.primeDDS;
|
|
259
|
-
return AggregateEthnicColor(PF.ToGetter(agg, dc, dataset), pd, dataset.endsWith('NH'));
|
|
260
|
+
return AggregateEthnicColor(PF.ToGetter(agg, dc, '', dataset), pd, dataset.endsWith('NH'));
|
|
260
261
|
}
|
|
261
262
|
exports.ToAllEthnicColor = ToAllEthnicColor;
|
|
262
263
|
function ToPartisanColorStr(agg, dc, pd) {
|
|
@@ -269,21 +270,21 @@ function ToPartisanDistrictColor(agg, dc, pd) {
|
|
|
269
270
|
exports.ToPartisanDistrictColor = ToPartisanDistrictColor;
|
|
270
271
|
function ToPartisanColor(agg, dc, stops) {
|
|
271
272
|
if (dc.primeEDS === PF.DS_PVI2020) {
|
|
272
|
-
const getter16 = PF.ToGetter(agg, dc, PF.DS_PRES2016);
|
|
273
|
-
const getter20 = PF.ToGetter(agg, dc, PF.DS_PRES2020);
|
|
273
|
+
const getter16 = PF.ToGetter(agg, dc, '', PF.DS_PRES2016);
|
|
274
|
+
const getter20 = PF.ToGetter(agg, dc, '', PF.DS_PRES2020);
|
|
274
275
|
const pviRaw = PF.calcRaw2020Pvi(getter16, getter20);
|
|
275
276
|
const color = ColorFromRGBPcts((1 - pviRaw / 100), 0, pviRaw / 100, stops);
|
|
276
277
|
//console.log('Pvi (r, d, color): (' + (1 - pviRaw/100) + ', ' + pviRaw/100 + ', ' + color + ')');
|
|
277
278
|
return color;
|
|
278
279
|
}
|
|
279
280
|
else if (dc.primeEDS === PF.DS_PVI2016) {
|
|
280
|
-
const getter = PF.ToGetter(agg, dc, dc.primeEDS);
|
|
281
|
+
const getter = PF.ToGetter(agg, dc, '', dc.primeEDS);
|
|
281
282
|
const pviRaw = PF.calcRawPvi(getter);
|
|
282
283
|
const color = ColorFromRGBPcts((1 - pviRaw / 100), 0, pviRaw / 100, stops);
|
|
283
284
|
return color;
|
|
284
285
|
}
|
|
285
286
|
else {
|
|
286
|
-
const getter = PF.ToGetter(agg, dc, dc.primeEDS);
|
|
287
|
+
const getter = PF.ToGetter(agg, dc, '', dc.primeEDS);
|
|
287
288
|
return AggregatePartisanColorStr(getter, stops);
|
|
288
289
|
}
|
|
289
290
|
}
|
|
@@ -345,7 +346,7 @@ function ToEthnicColorStr(agg, dc, pd, detail) {
|
|
|
345
346
|
break;
|
|
346
347
|
default: break;
|
|
347
348
|
}
|
|
348
|
-
const getter = PF.ToGetter(agg, dc, dataset);
|
|
349
|
+
const getter = PF.ToGetter(agg, dc, '', dataset);
|
|
349
350
|
let den = getter(total);
|
|
350
351
|
let num = getter(ethnic);
|
|
351
352
|
if (den === undefined || isNaN(den) || num === undefined || isNaN(num))
|
|
@@ -1242,6 +1243,23 @@ exports.StateNameMap = {
|
|
|
1242
1243
|
};
|
|
1243
1244
|
|
|
1244
1245
|
|
|
1246
|
+
/***/ }),
|
|
1247
|
+
|
|
1248
|
+
/***/ "./lib/datasets.ts":
|
|
1249
|
+
/*!*************************!*\
|
|
1250
|
+
!*** ./lib/datasets.ts ***!
|
|
1251
|
+
\*************************/
|
|
1252
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
1253
|
+
|
|
1254
|
+
|
|
1255
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1256
|
+
exports.sortFields = void 0;
|
|
1257
|
+
function sortFields(f1, f2) {
|
|
1258
|
+
return (f1.order || 0) - (f2.order || 0);
|
|
1259
|
+
}
|
|
1260
|
+
exports.sortFields = sortFields;
|
|
1261
|
+
|
|
1262
|
+
|
|
1245
1263
|
/***/ }),
|
|
1246
1264
|
|
|
1247
1265
|
/***/ "./lib/dra-types.ts":
|
|
@@ -1359,34 +1377,8 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
1359
1377
|
|
|
1360
1378
|
|
|
1361
1379
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1362
|
-
exports.pvi2020Str = exports.calcRaw2020Pvi = exports.pviStr = exports.calcRawPvi = exports.calcShift = exports.ToGetterPvi20 = exports.ToGetterPvi16 = exports.ToGetter = exports.findPackedField = exports.getPackedField = exports.diffPackedFields = exports.aggregatePackedFields = exports.packedCopy = exports.zeroPackedCopy = exports.zeroPackedFields = exports.retrievePackedFields = exports.setPackedFields = exports.hasPackedFields = exports.computePackedFields = exports.computeMetaIndex = exports.fGet = exports.fGetJoined = exports.
|
|
1380
|
+
exports.pvi2020Str = exports.calcRaw2020Pvi = exports.pviStr = exports.calcRawPvi = exports.calcShift = exports.ToGetterPvi20 = exports.ToGetterPvi16 = exports.ToGetter = exports.fieldGetterNotLoaded = exports.findPackedField = exports.getPackedField = exports.diffPackedFields = exports.decrementPackedFields = exports.aggregateCount = exports.aggregatePackedFields = exports.packedCopy = exports.zeroPackedCopy = exports.zeroPackedFields = exports.retrievePackedFields = exports.pushedExtPackedFields = exports.featurePushedExtPackedFields = exports.featurePushExtPackedFields = exports.isExtDataset = exports.setPackedFields = exports.hasPackedFields = exports.computePackedFields = exports.computeMetaIndex = exports.fGet = exports.fGetJoined = exports.DS_PRES2016 = exports.DS_PRES2020 = exports.DS_PVI2016 = exports.PVI2020_Title = exports.DS_PVI2020 = exports.DATASET_TYPE_OTHER = exports.DATASET_TYPE_PVI = exports.DATASET_TYPE_ELECTION = exports.DATASET_TYPE_DEMOGRAPHIC = exports.AGG_pvi = exports.AGG_pres2016 = exports.AGG_pres2008 = exports.AGG_DEMOGRAPHIC18 = exports.AGG_DEMOGRAPHIC = void 0;
|
|
1363
1381
|
const baseclient_1 = __webpack_require__(/*! @dra2020/baseclient */ "@dra2020/baseclient");
|
|
1364
|
-
// **** Dataset Codes Explained ****
|
|
1365
|
-
// Elections:
|
|
1366
|
-
// EYYGCC, where YY = year and CC = contest [PR, SE, GO, AG]
|
|
1367
|
-
// C16GCO = composite (spans number of years)
|
|
1368
|
-
// PYYGPR = PVI, where YY is year [16, 20]
|
|
1369
|
-
// Census/ACS:
|
|
1370
|
-
// DYYF = Census/ACS Total Pop, where YY = year [10, 18, 19, 20]
|
|
1371
|
-
// DYYT = Census/ACS VAP/CVAP, where YY = year [10, 18, 19, 20]
|
|
1372
|
-
// D20FA = Census 2020 Total Prisoner-Adjusted Pop
|
|
1373
|
-
// D20TNH = Census 2020 VAP with Non-Hispanic Alone Race fields
|
|
1374
|
-
// **** Dataset Fields Explained ****
|
|
1375
|
-
// Elections:
|
|
1376
|
-
// D: Democratic
|
|
1377
|
-
// R: Republican
|
|
1378
|
-
// Tot (Total R + D + Other)
|
|
1379
|
-
// Census/ACS/VAP/CVAP:
|
|
1380
|
-
// Tot: total
|
|
1381
|
-
// Wh: White alone, not Hispanic
|
|
1382
|
-
// His: All Hispanics
|
|
1383
|
-
// Bl: Black alone, not Hispanic; BlC: Black combo, incl Hispanic
|
|
1384
|
-
// Asn: Asian alone, not Hispanic; AsnC: Asian combo, incl Hispanic
|
|
1385
|
-
// Nat: Native alone, not Hispanic; NatC: Native combo, incl Hispanic
|
|
1386
|
-
// Pac (also PI): Pacific alone, not Hispanic; PacC: Pacific combo, incl Hispanic
|
|
1387
|
-
// OthAl: Other alone, not Hispanic; Oth: Other + Two or more races, incl Hispanic
|
|
1388
|
-
// Mix: Two or more races, not Hispanic
|
|
1389
|
-
// AsnPI: Asian + Pacific, not Hispanic
|
|
1390
1382
|
exports.AGG_DEMOGRAPHIC = 'demographic';
|
|
1391
1383
|
exports.AGG_DEMOGRAPHIC18 = 'demographic18';
|
|
1392
1384
|
exports.AGG_pres2008 = 'pres2008';
|
|
@@ -1395,13 +1387,12 @@ exports.AGG_pvi = 'pvi';
|
|
|
1395
1387
|
exports.DATASET_TYPE_DEMOGRAPHIC = 'demographic';
|
|
1396
1388
|
exports.DATASET_TYPE_ELECTION = 'election';
|
|
1397
1389
|
exports.DATASET_TYPE_PVI = 'pvi';
|
|
1390
|
+
exports.DATASET_TYPE_OTHER = 'other';
|
|
1398
1391
|
exports.DS_PVI2020 = 'P20GPR';
|
|
1399
1392
|
exports.PVI2020_Title = 'PVI 2016/2020';
|
|
1400
1393
|
exports.DS_PVI2016 = 'P16GPR';
|
|
1401
1394
|
exports.DS_PRES2020 = 'E20GPR';
|
|
1402
1395
|
exports.DS_PRES2016 = 'E16GPR';
|
|
1403
|
-
function fieldGetterNotLoaded(f) { return undefined; }
|
|
1404
|
-
exports.fieldGetterNotLoaded = fieldGetterNotLoaded;
|
|
1405
1396
|
function fGetJoined(f) {
|
|
1406
1397
|
return (f.properties && f.properties.joined) ? f.properties.joined : undefined;
|
|
1407
1398
|
}
|
|
@@ -1445,7 +1436,7 @@ function fGetW(f, datasetKey, p) {
|
|
|
1445
1436
|
}
|
|
1446
1437
|
return undefined;
|
|
1447
1438
|
}
|
|
1448
|
-
function computeMetaIndex(meta) {
|
|
1439
|
+
function computeMetaIndex(datasetid, meta) {
|
|
1449
1440
|
if (meta == null)
|
|
1450
1441
|
return null;
|
|
1451
1442
|
let offset = 1; // first entry is count of aggregates
|
|
@@ -1458,26 +1449,27 @@ function computeMetaIndex(meta) {
|
|
|
1458
1449
|
});
|
|
1459
1450
|
index.fields[datasetKey] = fieldsIndex;
|
|
1460
1451
|
});
|
|
1452
|
+
let groupindex = { [datasetid]: index };
|
|
1461
1453
|
index.length = offset;
|
|
1462
1454
|
index.getDatasetField = (f, dataset, field) => {
|
|
1463
1455
|
let pf = retrievePackedFields(f);
|
|
1464
|
-
return getPackedField(
|
|
1456
|
+
return getPackedField(groupindex, pf, datasetid, dataset, field);
|
|
1465
1457
|
};
|
|
1466
1458
|
return index;
|
|
1467
1459
|
}
|
|
1468
1460
|
exports.computeMetaIndex = computeMetaIndex;
|
|
1469
1461
|
let nAlloc = 0;
|
|
1470
|
-
function
|
|
1462
|
+
function allocPackedFieldsArray(length) {
|
|
1471
1463
|
let ab = new ArrayBuffer(8 * length);
|
|
1472
1464
|
let af = new Float64Array(ab);
|
|
1473
1465
|
nAlloc++;
|
|
1474
|
-
//if ((nAlloc % 10000) == 0) console.log(`
|
|
1466
|
+
//if ((nAlloc % 10000) == 0) console.log(`allocPackedFieldsArray: ${nAlloc} allocs`);
|
|
1475
1467
|
return af;
|
|
1476
1468
|
}
|
|
1477
1469
|
function computePackedFields(f, index) {
|
|
1478
1470
|
if (f.properties.packedFields)
|
|
1479
1471
|
return f.properties.packedFields;
|
|
1480
|
-
let af =
|
|
1472
|
+
let af = allocPackedFieldsArray(index.length);
|
|
1481
1473
|
af[0] = 0; // count of number of aggregates
|
|
1482
1474
|
Object.keys(index.fields).forEach((dataset) => {
|
|
1483
1475
|
let fields = index.fields[dataset];
|
|
@@ -1488,11 +1480,11 @@ function computePackedFields(f, index) {
|
|
|
1488
1480
|
af[fields[field]] = n;
|
|
1489
1481
|
});
|
|
1490
1482
|
});
|
|
1491
|
-
f.properties.packedFields = af; // cache here
|
|
1483
|
+
f.properties.packedFields = { ['']: af }; // cache here
|
|
1492
1484
|
f.properties.getDatasetField = index.getDatasetField;
|
|
1493
1485
|
// Major memory savings to delete this after packing
|
|
1494
1486
|
delete f.properties.datasets;
|
|
1495
|
-
return
|
|
1487
|
+
return f.properties.packedFields;
|
|
1496
1488
|
}
|
|
1497
1489
|
exports.computePackedFields = computePackedFields;
|
|
1498
1490
|
function hasPackedFields(f) {
|
|
@@ -1506,6 +1498,58 @@ function setPackedFields(f, pf, fIndex) {
|
|
|
1506
1498
|
f.properties.getDatasetField = fIndex.properties.getDatasetField;
|
|
1507
1499
|
}
|
|
1508
1500
|
exports.setPackedFields = setPackedFields;
|
|
1501
|
+
const reExtDataset = /^.*\.ds$/;
|
|
1502
|
+
function isExtDataset(did) {
|
|
1503
|
+
return did && reExtDataset.test(did);
|
|
1504
|
+
}
|
|
1505
|
+
exports.isExtDataset = isExtDataset;
|
|
1506
|
+
function featurePushExtPackedFields(f, datasetid, data, card) {
|
|
1507
|
+
var _a;
|
|
1508
|
+
let blocks = ((_a = f === null || f === void 0 ? void 0 : f.properties) === null || _a === void 0 ? void 0 : _a.blocks) || (card.has(f.properties.id) ? [f.properties.id] : null);
|
|
1509
|
+
if (!blocks)
|
|
1510
|
+
return;
|
|
1511
|
+
if (!f.properties.packedFields)
|
|
1512
|
+
throw ('pushExtPackedFields: base datasets should be pushed first');
|
|
1513
|
+
if (card.size != data[0])
|
|
1514
|
+
throw ('pushExtPackedFields: packed fields and block cardinality do not match');
|
|
1515
|
+
if (f.properties.packedFields[datasetid])
|
|
1516
|
+
return; // already pushed
|
|
1517
|
+
let nfields = data[1];
|
|
1518
|
+
let pfa = allocPackedFieldsArray(nfields + 1); // field count
|
|
1519
|
+
pfa[0] = 0;
|
|
1520
|
+
for (let j = 0; j < nfields; j++)
|
|
1521
|
+
pfa[j] = 0;
|
|
1522
|
+
blocks.forEach((blockid) => {
|
|
1523
|
+
if (!card.has(blockid))
|
|
1524
|
+
throw (`pushExtPackedFields: missing blockid ${blockid} in cardinality set`);
|
|
1525
|
+
let x = 2 + (nfields * card.get(blockid));
|
|
1526
|
+
for (let i = 1; i <= nfields; i++)
|
|
1527
|
+
pfa[i] += data[x++];
|
|
1528
|
+
});
|
|
1529
|
+
f.properties.packedFields[datasetid] = pfa;
|
|
1530
|
+
}
|
|
1531
|
+
exports.featurePushExtPackedFields = featurePushExtPackedFields;
|
|
1532
|
+
function featurePushedExtPackedFields(f, datasetid, card) {
|
|
1533
|
+
var _a;
|
|
1534
|
+
if (!f)
|
|
1535
|
+
return true;
|
|
1536
|
+
if (f.features)
|
|
1537
|
+
return featurePushedExtPackedFields(f.features[0], datasetid, card);
|
|
1538
|
+
if (!((_a = f === null || f === void 0 ? void 0 : f.properties) === null || _a === void 0 ? void 0 : _a.blocks) && !card.has(f.properties.id))
|
|
1539
|
+
return true;
|
|
1540
|
+
if (!f.properties.packedFields)
|
|
1541
|
+
return true;
|
|
1542
|
+
return !!f.properties.packedFields[datasetid];
|
|
1543
|
+
}
|
|
1544
|
+
exports.featurePushedExtPackedFields = featurePushedExtPackedFields;
|
|
1545
|
+
function pushedExtPackedFields(pf, datasetids) {
|
|
1546
|
+
if (pf && datasetids)
|
|
1547
|
+
for (let i = 0; i < datasetids.length; i++)
|
|
1548
|
+
if (!pf[datasetids[i]])
|
|
1549
|
+
return false;
|
|
1550
|
+
return !!pf;
|
|
1551
|
+
}
|
|
1552
|
+
exports.pushedExtPackedFields = pushedExtPackedFields;
|
|
1509
1553
|
function retrievePackedFields(f) {
|
|
1510
1554
|
if (f.properties.packedFields === undefined)
|
|
1511
1555
|
throw 'Feature should have pre-computed packed fields';
|
|
@@ -1517,84 +1561,121 @@ exports.retrievePackedFields = retrievePackedFields;
|
|
|
1517
1561
|
let abZero = new ArrayBuffer(8);
|
|
1518
1562
|
let afZero = new Float64Array(abZero);
|
|
1519
1563
|
afZero[0] = 0;
|
|
1564
|
+
let pfZero = { ['']: afZero };
|
|
1520
1565
|
function zeroPackedFields(index) {
|
|
1521
1566
|
if (index == null)
|
|
1522
|
-
return
|
|
1523
|
-
let
|
|
1524
|
-
|
|
1525
|
-
af
|
|
1526
|
-
|
|
1567
|
+
return pfZero;
|
|
1568
|
+
let pf = {};
|
|
1569
|
+
Object.keys(index).forEach(datasetid => {
|
|
1570
|
+
let af = allocPackedFieldsArray(index[datasetid].length);
|
|
1571
|
+
for (let i = 0; i < af.length; i++)
|
|
1572
|
+
af[i] = 0;
|
|
1573
|
+
pf[datasetid] = af;
|
|
1574
|
+
});
|
|
1575
|
+
return pf;
|
|
1527
1576
|
}
|
|
1528
1577
|
exports.zeroPackedFields = zeroPackedFields;
|
|
1529
1578
|
function zeroPackedCopy(pf) {
|
|
1530
1579
|
if (pf == null)
|
|
1531
|
-
return
|
|
1532
|
-
let
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1580
|
+
return pfZero;
|
|
1581
|
+
let copy = {};
|
|
1582
|
+
Object.keys(pf).forEach(datasetid => {
|
|
1583
|
+
let cf = allocPackedFieldsArray(pf[datasetid].length);
|
|
1584
|
+
for (let i = 0; i < cf.length; i++)
|
|
1585
|
+
cf[i] = 0;
|
|
1586
|
+
copy[datasetid] = cf;
|
|
1587
|
+
});
|
|
1588
|
+
return copy;
|
|
1536
1589
|
}
|
|
1537
1590
|
exports.zeroPackedCopy = zeroPackedCopy;
|
|
1538
1591
|
function packedCopy(pf) {
|
|
1539
1592
|
if (pf == null)
|
|
1540
1593
|
return null;
|
|
1541
|
-
let
|
|
1542
|
-
|
|
1543
|
-
af
|
|
1544
|
-
|
|
1594
|
+
let copy = {};
|
|
1595
|
+
Object.keys(pf).forEach(datasetid => {
|
|
1596
|
+
let af = pf[datasetid];
|
|
1597
|
+
let cf = allocPackedFieldsArray(af.length);
|
|
1598
|
+
for (let i = 0; i < af.length; i++)
|
|
1599
|
+
cf[i] = af[i];
|
|
1600
|
+
copy[datasetid] = cf;
|
|
1601
|
+
});
|
|
1602
|
+
return copy;
|
|
1545
1603
|
}
|
|
1546
1604
|
exports.packedCopy = packedCopy;
|
|
1547
1605
|
function aggregatePackedFields(agg, pf) {
|
|
1548
1606
|
if (agg == null || pf == null)
|
|
1549
1607
|
return agg;
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1608
|
+
Object.keys(agg).forEach(datasetid => {
|
|
1609
|
+
let af = agg[datasetid];
|
|
1610
|
+
let sf = pf[datasetid];
|
|
1611
|
+
if (sf && sf.length == af.length) {
|
|
1612
|
+
let n = af.length;
|
|
1613
|
+
for (let i = 1; i < n; i++)
|
|
1614
|
+
af[i] += sf[i];
|
|
1615
|
+
af[0]++; // count of aggregates
|
|
1616
|
+
}
|
|
1617
|
+
});
|
|
1558
1618
|
return agg;
|
|
1559
1619
|
}
|
|
1560
1620
|
exports.aggregatePackedFields = aggregatePackedFields;
|
|
1621
|
+
function aggregateCount(agg) {
|
|
1622
|
+
if (!agg || !agg[''])
|
|
1623
|
+
return 0;
|
|
1624
|
+
return agg[''][0];
|
|
1625
|
+
}
|
|
1626
|
+
exports.aggregateCount = aggregateCount;
|
|
1627
|
+
function decrementPackedFields(agg, pf) {
|
|
1628
|
+
if (agg == null || pf == null)
|
|
1629
|
+
return agg;
|
|
1630
|
+
Object.keys(agg).forEach(datasetid => {
|
|
1631
|
+
let af = agg[datasetid];
|
|
1632
|
+
let sf = pf[datasetid];
|
|
1633
|
+
if (sf && sf.length == af.length) {
|
|
1634
|
+
let n = af.length;
|
|
1635
|
+
for (let i = 1; i < n; i++)
|
|
1636
|
+
af[i] -= sf[i];
|
|
1637
|
+
af[0]++; // count of aggregates
|
|
1638
|
+
}
|
|
1639
|
+
});
|
|
1640
|
+
return agg;
|
|
1641
|
+
}
|
|
1642
|
+
exports.decrementPackedFields = decrementPackedFields;
|
|
1561
1643
|
function diffPackedFields(main, parts) {
|
|
1562
1644
|
main = packedCopy(retrievePackedFields(main));
|
|
1563
1645
|
if (main == null || parts == null || parts.length == 0)
|
|
1564
1646
|
return null;
|
|
1565
1647
|
parts = parts.map(retrievePackedFields);
|
|
1566
|
-
parts.forEach((pf) =>
|
|
1567
|
-
for (let i = 0; i < main.length; i++)
|
|
1568
|
-
main[i] -= pf[i];
|
|
1569
|
-
});
|
|
1648
|
+
parts.forEach((pf) => decrementPackedFields(main, pf));
|
|
1570
1649
|
return main;
|
|
1571
1650
|
}
|
|
1572
1651
|
exports.diffPackedFields = diffPackedFields;
|
|
1573
|
-
function getPackedField(index, pf, dataset, field) {
|
|
1574
|
-
if (index
|
|
1652
|
+
function getPackedField(index, pf, datasetid, dataset, field) {
|
|
1653
|
+
if (!index || !pf || !index[datasetid] || !pf[datasetid])
|
|
1575
1654
|
return 0;
|
|
1576
|
-
let fields = index.fields[dataset];
|
|
1577
|
-
return fields ? (fields[field] !== undefined ? pf[fields[field]] : 0) : 0;
|
|
1655
|
+
let fields = index[datasetid].fields[dataset];
|
|
1656
|
+
return fields ? (fields[field] !== undefined ? pf[datasetid][fields[field]] : 0) : 0;
|
|
1578
1657
|
}
|
|
1579
1658
|
exports.getPackedField = getPackedField;
|
|
1580
|
-
function findPackedField(index, pf, dataset, field) {
|
|
1581
|
-
let fields = index.fields[dataset];
|
|
1659
|
+
function findPackedField(index, pf, datasetid, dataset, field) {
|
|
1660
|
+
let fields = index[datasetid].fields[dataset];
|
|
1582
1661
|
return fields ? (fields[field] !== undefined ? fields[field] : -1) : -1;
|
|
1583
1662
|
}
|
|
1584
1663
|
exports.findPackedField = findPackedField;
|
|
1585
|
-
function
|
|
1586
|
-
|
|
1664
|
+
function fieldGetterNotLoaded(f) { return undefined; }
|
|
1665
|
+
exports.fieldGetterNotLoaded = fieldGetterNotLoaded;
|
|
1666
|
+
function ToGetter(agg, dc, datasetid, datasetKey) {
|
|
1667
|
+
return (field) => { return getPackedField(dc.dsIndex, agg, datasetid, datasetKey, field); };
|
|
1587
1668
|
}
|
|
1588
1669
|
exports.ToGetter = ToGetter;
|
|
1589
1670
|
function ToGetterPvi16(agg, dc, datasetKey) {
|
|
1590
1671
|
return (field) => {
|
|
1591
1672
|
if (field === 'R')
|
|
1592
|
-
return Math.round((getPackedField(dc.dsIndex, agg, datasetKey, 'R12') + getPackedField(dc.dsIndex, agg, datasetKey, 'R16')) / 2);
|
|
1673
|
+
return Math.round((getPackedField(dc.dsIndex, agg, '', datasetKey, 'R12') + getPackedField(dc.dsIndex, agg, '', datasetKey, 'R16')) / 2);
|
|
1593
1674
|
if (field === 'D')
|
|
1594
|
-
return Math.round((getPackedField(dc.dsIndex, agg, datasetKey, 'D12') + getPackedField(dc.dsIndex, agg, datasetKey, 'D16')) / 2);
|
|
1675
|
+
return Math.round((getPackedField(dc.dsIndex, agg, '', datasetKey, 'D12') + getPackedField(dc.dsIndex, agg, '', datasetKey, 'D16')) / 2);
|
|
1595
1676
|
if (field === 'Tot')
|
|
1596
|
-
return Math.round((getPackedField(dc.dsIndex, agg, datasetKey, 'R12') + getPackedField(dc.dsIndex, agg, datasetKey, 'R16') +
|
|
1597
|
-
getPackedField(dc.dsIndex, agg, datasetKey, 'D12') + getPackedField(dc.dsIndex, agg, datasetKey, 'D16')) / 2);
|
|
1677
|
+
return Math.round((getPackedField(dc.dsIndex, agg, '', datasetKey, 'R12') + getPackedField(dc.dsIndex, agg, '', datasetKey, 'R16') +
|
|
1678
|
+
getPackedField(dc.dsIndex, agg, '', datasetKey, 'D12') + getPackedField(dc.dsIndex, agg, '', datasetKey, 'D16')) / 2);
|
|
1598
1679
|
return 0;
|
|
1599
1680
|
};
|
|
1600
1681
|
}
|
|
@@ -1602,12 +1683,12 @@ exports.ToGetterPvi16 = ToGetterPvi16;
|
|
|
1602
1683
|
function ToGetterPvi20(agg, dc) {
|
|
1603
1684
|
return (field) => {
|
|
1604
1685
|
if (field === 'R')
|
|
1605
|
-
return Math.round((getPackedField(dc.dsIndex, agg, exports.DS_PRES2016, 'R') + getPackedField(dc.dsIndex, agg, exports.DS_PRES2020, 'R')) / 2);
|
|
1686
|
+
return Math.round((getPackedField(dc.dsIndex, agg, '', exports.DS_PRES2016, 'R') + getPackedField(dc.dsIndex, agg, '', exports.DS_PRES2020, 'R')) / 2);
|
|
1606
1687
|
if (field === 'D')
|
|
1607
|
-
return Math.round((getPackedField(dc.dsIndex, agg, exports.DS_PRES2016, 'D') + getPackedField(dc.dsIndex, agg, exports.DS_PRES2020, 'D')) / 2);
|
|
1688
|
+
return Math.round((getPackedField(dc.dsIndex, agg, '', exports.DS_PRES2016, 'D') + getPackedField(dc.dsIndex, agg, '', exports.DS_PRES2020, 'D')) / 2);
|
|
1608
1689
|
if (field === 'Tot')
|
|
1609
|
-
return Math.round((getPackedField(dc.dsIndex, agg, exports.DS_PRES2016, 'R') + getPackedField(dc.dsIndex, agg, exports.DS_PRES2020, 'R') +
|
|
1610
|
-
getPackedField(dc.dsIndex, agg, exports.DS_PRES2016, 'D') + getPackedField(dc.dsIndex, agg, exports.DS_PRES2020, 'D')) / 2);
|
|
1690
|
+
return Math.round((getPackedField(dc.dsIndex, agg, '', exports.DS_PRES2016, 'R') + getPackedField(dc.dsIndex, agg, '', exports.DS_PRES2020, 'R') +
|
|
1691
|
+
getPackedField(dc.dsIndex, agg, '', exports.DS_PRES2016, 'D') + getPackedField(dc.dsIndex, agg, '', exports.DS_PRES2020, 'D')) / 2);
|
|
1611
1692
|
return 0;
|
|
1612
1693
|
};
|
|
1613
1694
|
}
|
|
@@ -1617,12 +1698,12 @@ function calcShift(agg, dc, datasetOld, datasetNew) {
|
|
|
1617
1698
|
ToGetterPvi16(agg, dc, datasetOld) :
|
|
1618
1699
|
datasetOld === exports.DS_PVI2020 ?
|
|
1619
1700
|
ToGetterPvi20(agg, dc) :
|
|
1620
|
-
ToGetter(agg, dc, datasetOld);
|
|
1701
|
+
ToGetter(agg, dc, '', datasetOld);
|
|
1621
1702
|
const getterNew = datasetNew === exports.DS_PVI2016 ?
|
|
1622
1703
|
ToGetterPvi16(agg, dc, datasetNew) :
|
|
1623
1704
|
datasetNew === exports.DS_PVI2020 ?
|
|
1624
1705
|
ToGetterPvi20(agg, dc) :
|
|
1625
|
-
ToGetter(agg, dc, datasetNew);
|
|
1706
|
+
ToGetter(agg, dc, '', datasetNew);
|
|
1626
1707
|
// Calc two-party Swing
|
|
1627
1708
|
const repOld = getterOld('R');
|
|
1628
1709
|
const demOld = getterOld('D');
|