@dra2020/district-analytics 16.1.4 → 16.1.5
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/district-analytics.js +25 -130
- package/dist/district-analytics.js.map +1 -1
- package/dist/src/types.d.ts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +3 -3
|
@@ -538,6 +538,7 @@ class Districts {
|
|
|
538
538
|
// if (bLog) console.log("Statistics: Skipping water-only feature in district statistics:", geoID);
|
|
539
539
|
// }
|
|
540
540
|
});
|
|
541
|
+
console.log(`totalVAP: ${totalVAP}, whitePop: ${whitePop}, blackPop: ${blackPop}`);
|
|
541
542
|
// COMPUTE DERIVED VALUES
|
|
542
543
|
// MMD - Generalized the per-district population deviations's for MMD's with variable #'s of reps per district.
|
|
543
544
|
// - The real districts are indexed 1–N.
|
|
@@ -977,54 +978,11 @@ function geoIDForFeature(f) {
|
|
|
977
978
|
}
|
|
978
979
|
exports.geoIDForFeature = geoIDForFeature;
|
|
979
980
|
function fieldForFeature(f, dk /* dt: T.Dataset */, ff) {
|
|
980
|
-
//
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
// 10-27-2020 - Enabling a 'Tot' result for PVI, now that we're reporting 'Other'
|
|
986
|
-
switch (fk) {
|
|
987
|
-
case 'D': {
|
|
988
|
-
result = (_getFeatures(f, dk, 'D12') + _getFeatures(f, dk, 'D16')) / 2;
|
|
989
|
-
break;
|
|
990
|
-
}
|
|
991
|
-
case 'R': {
|
|
992
|
-
result = (_getFeatures(f, dk, 'R12') + _getFeatures(f, dk, 'R16')) / 2;
|
|
993
|
-
break;
|
|
994
|
-
}
|
|
995
|
-
case 'Tot': {
|
|
996
|
-
result = (_getFeatures(f, dk, 'D12') + _getFeatures(f, dk, 'D16') + _getFeatures(f, dk, 'R12') + _getFeatures(f, dk, 'R16')) / 2;
|
|
997
|
-
break;
|
|
998
|
-
}
|
|
999
|
-
default: {
|
|
1000
|
-
console.log("Field not recognized.");
|
|
1001
|
-
break;
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
// result = (_getFeatures(f, dk, (fk === 'D' ? 'D12' : 'R12')) + _getFeatures(f, dk, (fk === 'D' ? 'D16' : 'R16'))) / 2;
|
|
1005
|
-
}
|
|
1006
|
-
else if (dk === 'P20GPR') {
|
|
1007
|
-
switch (fk) {
|
|
1008
|
-
case 'D': {
|
|
1009
|
-
result = (_getFeatures(f, 'E16GPR', 'D') + _getFeatures(f, 'E20GPR', 'D')) / 2;
|
|
1010
|
-
break;
|
|
1011
|
-
}
|
|
1012
|
-
case 'R': {
|
|
1013
|
-
result = (_getFeatures(f, 'E16GPR', 'R') + _getFeatures(f, 'E20GPR', 'R')) / 2;
|
|
1014
|
-
break;
|
|
1015
|
-
}
|
|
1016
|
-
case 'Tot': {
|
|
1017
|
-
result = (_getFeatures(f, 'E16GPR', 'D') + _getFeatures(f, 'E20GPR', 'D') + _getFeatures(f, 'E16GPR', 'R') + _getFeatures(f, 'E20GPR', 'R')) / 2;
|
|
1018
|
-
break;
|
|
1019
|
-
}
|
|
1020
|
-
default: {
|
|
1021
|
-
console.log("Field not recognized.");
|
|
1022
|
-
break;
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
else
|
|
1027
|
-
result = _getFeatures(f, dk, fk);
|
|
981
|
+
// Multiple keys to transparently handle NH and non-NH (e.g. Bl vs BlC) keyed fields
|
|
982
|
+
// One of the values will always be missing and hence zero.
|
|
983
|
+
const keys = T.fieldsFromFeatureField(dk, ff);
|
|
984
|
+
let result = 0;
|
|
985
|
+
keys.forEach(key => { result += _getFeatures(f, dk, key); });
|
|
1028
986
|
return result;
|
|
1029
987
|
}
|
|
1030
988
|
exports.fieldForFeature = fieldForFeature;
|
|
@@ -1034,8 +992,10 @@ exports.fieldForFeature = fieldForFeature;
|
|
|
1034
992
|
function _getFeatures(f, datasetKey, p) {
|
|
1035
993
|
if (!f.properties)
|
|
1036
994
|
return 0;
|
|
995
|
+
// This is actual path
|
|
1037
996
|
if (f.properties.getDatasetField)
|
|
1038
997
|
return f.properties.getDatasetField(f, datasetKey, p);
|
|
998
|
+
// This is old path looking through full dataset property structure
|
|
1039
999
|
if (!f.properties.datasets)
|
|
1040
1000
|
return 0;
|
|
1041
1001
|
if (datasetKey && !f.properties.datasets[datasetKey])
|
|
@@ -1043,71 +1003,6 @@ function _getFeatures(f, datasetKey, p) {
|
|
|
1043
1003
|
let n = datasetKey ? f.properties.datasets[datasetKey][p] : f.properties[p];
|
|
1044
1004
|
return !n || isNaN(n) ? 0 : n;
|
|
1045
1005
|
}
|
|
1046
|
-
/* 01-04-22 -- Replaced with the above
|
|
1047
|
-
function _getFeatures(f: any, datasetKey: string, p: string): any
|
|
1048
|
-
{
|
|
1049
|
-
// Shim to load sample data2.json from disk for command-line scaffolding
|
|
1050
|
-
if (f.properties && f.properties['datasets'])
|
|
1051
|
-
{
|
|
1052
|
-
if (!f.properties['datasets'][datasetKey])
|
|
1053
|
-
{
|
|
1054
|
-
// Feature is missing the dataset
|
|
1055
|
-
nMissingDataset += 1;
|
|
1056
|
-
// console.log(`${nMissingDataset}: Data ${datasetKey} missing for feature ${f} Returning zero.`);
|
|
1057
|
-
|
|
1058
|
-
return 0;
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
return f.properties['datasets'][datasetKey][p];
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
// NOTE - The fGetW() code from dra-client below here ...
|
|
1065
|
-
|
|
1066
|
-
// Direct property?
|
|
1067
|
-
if (f.properties && f.properties[p] !== undefined)
|
|
1068
|
-
{
|
|
1069
|
-
return f.properties[p];
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
|
-
// Joined property?
|
|
1073
|
-
let a: any[] = _fGetJoined(f);
|
|
1074
|
-
if (a)
|
|
1075
|
-
{
|
|
1076
|
-
for (let i: number = 0; i < a.length; i++)
|
|
1077
|
-
{
|
|
1078
|
-
let o: any = a[i];
|
|
1079
|
-
if (!datasetKey)
|
|
1080
|
-
{
|
|
1081
|
-
if (o[p] !== undefined)
|
|
1082
|
-
{
|
|
1083
|
-
return o[p];
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
else
|
|
1087
|
-
{
|
|
1088
|
-
if (o['datasets'] && o['datasets'][datasetKey])
|
|
1089
|
-
{
|
|
1090
|
-
let v = (o['datasets'][datasetKey][p]);
|
|
1091
|
-
if ((!(v == null)) && (!(v == undefined)))
|
|
1092
|
-
{
|
|
1093
|
-
return o['datasets'][datasetKey][p];
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
// Feature is missing the property
|
|
1101
|
-
nMissingProperty += 1;
|
|
1102
|
-
// console.log(`${nMissingProperty}: ${p} value undefined for ${f.properties['GEOID10']}. Returning zero.`);
|
|
1103
|
-
|
|
1104
|
-
return 0;
|
|
1105
|
-
// return undefined;
|
|
1106
|
-
}
|
|
1107
|
-
*/
|
|
1108
|
-
function _fGetJoined(f) {
|
|
1109
|
-
return (f.properties && f.properties.joined) ? f.properties.joined : undefined;
|
|
1110
|
-
}
|
|
1111
1006
|
// Wrap data by county, to abstract the specifics of the internal structure
|
|
1112
1007
|
class Counties {
|
|
1113
1008
|
constructor(s, data) {
|
|
@@ -2505,23 +2400,23 @@ exports.OUT_OF_STATE = "OUT_OF_STATE";
|
|
|
2505
2400
|
// TYPE DEFINITIONS
|
|
2506
2401
|
//
|
|
2507
2402
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
2508
|
-
exports.
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
}
|
|
2524
|
-
exports.
|
|
2403
|
+
exports.fieldsFromFeatureField = void 0;
|
|
2404
|
+
const FieldsByFeatureField = [
|
|
2405
|
+
["Tot"],
|
|
2406
|
+
["Wh"],
|
|
2407
|
+
["Bl", "BlC"],
|
|
2408
|
+
["His"],
|
|
2409
|
+
["Asn", "AsnC"],
|
|
2410
|
+
["Pac", "PacC"],
|
|
2411
|
+
["Nat", "NatC"],
|
|
2412
|
+
["D"],
|
|
2413
|
+
["R"],
|
|
2414
|
+
["Tot"]
|
|
2415
|
+
];
|
|
2416
|
+
function fieldsFromFeatureField(ds, ff) {
|
|
2417
|
+
return FieldsByFeatureField[ff];
|
|
2418
|
+
}
|
|
2419
|
+
exports.fieldsFromFeatureField = fieldsFromFeatureField;
|
|
2525
2420
|
|
|
2526
2421
|
|
|
2527
2422
|
/***/ }),
|