@dra2020/district-analytics 11.1.1 → 11.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.
- package/LICENSE +1 -1
- package/dist/cli.js +283941 -0
- package/dist/cli.js.map +1 -0
- package/dist/district-analytics.js +84 -57
- package/dist/district-analytics.js.map +1 -1
- package/dist/src/_data.d.ts +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/utils.d.ts +1 -1
- package/package.json +7 -8
|
@@ -43,7 +43,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
43
43
|
};
|
|
44
44
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
45
45
|
exports.AnalyticsSession = void 0;
|
|
46
|
-
const
|
|
46
|
+
const baseclient_1 = __webpack_require__(/*! @dra2020/baseclient */ "@dra2020/baseclient");
|
|
47
47
|
const Score = __importStar(__webpack_require__(/*! @dra2020/dra-score */ "@dra2020/dra-score"));
|
|
48
48
|
const preprocess_1 = __webpack_require__(/*! ./preprocess */ "./src/preprocess.ts");
|
|
49
49
|
const analyze_1 = __webpack_require__(/*! ./analyze */ "./src/analyze.ts");
|
|
@@ -160,7 +160,7 @@ class AnalyticsSession {
|
|
|
160
160
|
// If a district has a shape & it is not contiguous, by definition,
|
|
161
161
|
// it will be a Multipolygon, i.e., it will have multiple pieces, some
|
|
162
162
|
// possibly embedded w/in other districts. Get & add all the pieces.
|
|
163
|
-
const districtParts = Poly.polyParts(poly);
|
|
163
|
+
const districtParts = baseclient_1.Poly.polyParts(poly);
|
|
164
164
|
discontiguousDistrictFeatures.features.push(...districtParts.features);
|
|
165
165
|
// discontiguousDistrictFeatures.features.push(poly);
|
|
166
166
|
}
|
|
@@ -231,7 +231,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
231
231
|
return result;
|
|
232
232
|
};
|
|
233
233
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
234
|
-
exports.Graph = exports.invertPlan = exports.Plan = exports.State = exports.Counties = exports.Features = exports.Districts = void 0;
|
|
234
|
+
exports.Graph = exports.invertPlan = exports.Plan = exports.State = exports.Counties = exports.inferSelectedMinority = exports.Features = exports.Districts = void 0;
|
|
235
235
|
const G = __importStar(__webpack_require__(/*! @dra2020/dra-graph */ "@dra2020/dra-graph"));
|
|
236
236
|
const U = __importStar(__webpack_require__(/*! ./utils */ "./src/utils.ts"));
|
|
237
237
|
const S = __importStar(__webpack_require__(/*! ./settings */ "./src/settings.ts"));
|
|
@@ -633,23 +633,9 @@ class Districts {
|
|
|
633
633
|
// let dataDump: any[] = []; // For testing
|
|
634
634
|
// Gather [demographic %, D %] points for the selected district ID
|
|
635
635
|
let i = districtID;
|
|
636
|
-
// HACK -
|
|
636
|
+
// HACK - For comparing a minority group to everyone else (vs. just White),
|
|
637
637
|
// infer the *single* minority group that has been selected.
|
|
638
|
-
|
|
639
|
-
if (groups.invertSelection) {
|
|
640
|
-
if (groups.hispanic)
|
|
641
|
-
compareTo = 'not-hispanic';
|
|
642
|
-
else if (groups.black)
|
|
643
|
-
compareTo = 'not-black';
|
|
644
|
-
else if (groups.pacific)
|
|
645
|
-
compareTo = 'not-pacific';
|
|
646
|
-
else if (groups.asian)
|
|
647
|
-
compareTo = 'not-asian';
|
|
648
|
-
else if (groups.native)
|
|
649
|
-
compareTo = 'not-native';
|
|
650
|
-
else if (groups.minority)
|
|
651
|
-
compareTo = 'not-minority'; // same as 'white'
|
|
652
|
-
}
|
|
638
|
+
const selectedMinority = inferSelectedMinority(groups);
|
|
653
639
|
// HACK - Because "this" gets ghosted inside the forEach loop below
|
|
654
640
|
let outerThis = this;
|
|
655
641
|
// Get the geoIDs assigned to the district
|
|
@@ -689,33 +675,33 @@ class Districts {
|
|
|
689
675
|
const pctMinority = minorityVAP / totalVAP;
|
|
690
676
|
let pctComparison = whiteVAP / totalVAP;
|
|
691
677
|
if (groups.invertSelection) {
|
|
692
|
-
switch (
|
|
693
|
-
case '
|
|
678
|
+
switch (selectedMinority) {
|
|
679
|
+
case 'Hispanic': {
|
|
694
680
|
pctComparison = (totalVAP - hispanicVAP) / totalVAP;
|
|
695
681
|
break;
|
|
696
682
|
}
|
|
697
|
-
case '
|
|
683
|
+
case 'Black': {
|
|
698
684
|
pctComparison = (totalVAP - blackVAP) / totalVAP;
|
|
699
685
|
break;
|
|
700
686
|
}
|
|
701
|
-
case '
|
|
687
|
+
case 'Pacific': {
|
|
702
688
|
pctComparison = (totalVAP - pacificVAP) / totalVAP;
|
|
703
689
|
break;
|
|
704
690
|
}
|
|
705
|
-
case '
|
|
691
|
+
case 'Asian': {
|
|
706
692
|
pctComparison = (totalVAP - asianVAP) / totalVAP;
|
|
707
693
|
break;
|
|
708
694
|
}
|
|
709
|
-
case '
|
|
695
|
+
case 'Native': {
|
|
710
696
|
pctComparison = (totalVAP - nativeVAP) / totalVAP;
|
|
711
697
|
break;
|
|
712
698
|
}
|
|
713
|
-
case '
|
|
699
|
+
case 'Minority': {
|
|
714
700
|
pctComparison = (totalVAP - minorityVAP) / totalVAP;
|
|
715
701
|
break;
|
|
716
702
|
}
|
|
717
703
|
default: {
|
|
718
|
-
console.log("
|
|
704
|
+
console.log("Selected minority not recognized!");
|
|
719
705
|
break;
|
|
720
706
|
}
|
|
721
707
|
}
|
|
@@ -836,6 +822,22 @@ class Features {
|
|
|
836
822
|
featureID(i) { return this._featureIDs[i]; }
|
|
837
823
|
}
|
|
838
824
|
exports.Features = Features;
|
|
825
|
+
function inferSelectedMinority(groups) {
|
|
826
|
+
if (groups.hispanic)
|
|
827
|
+
return 'Hispanic';
|
|
828
|
+
if (groups.black)
|
|
829
|
+
return 'Black';
|
|
830
|
+
if (groups.pacific)
|
|
831
|
+
return 'Pacific';
|
|
832
|
+
if (groups.asian)
|
|
833
|
+
return 'Asian';
|
|
834
|
+
if (groups.native)
|
|
835
|
+
return 'Native';
|
|
836
|
+
if (groups.minority)
|
|
837
|
+
return 'Minority';
|
|
838
|
+
return 'No minority selected!';
|
|
839
|
+
}
|
|
840
|
+
exports.inferSelectedMinority = inferSelectedMinority;
|
|
839
841
|
// NOTE - This accessor is cloned from fGetW() in dra-client/restrict.ts
|
|
840
842
|
// f is a direct GeoJSON feature
|
|
841
843
|
// p is a geoID
|
|
@@ -1280,7 +1282,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
1280
1282
|
};
|
|
1281
1283
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1282
1284
|
exports.scoreKIWYSICompactness = exports.extractDistrictProperties = void 0;
|
|
1283
|
-
const
|
|
1285
|
+
const baseclient_1 = __webpack_require__(/*! @dra2020/baseclient */ "@dra2020/baseclient");
|
|
1284
1286
|
const Compactness = __importStar(__webpack_require__(/*! @dra2020/compactness */ "@dra2020/compactness"));
|
|
1285
1287
|
const U = __importStar(__webpack_require__(/*! ./utils */ "./src/utils.ts"));
|
|
1286
1288
|
// HELPER TO EXTRACT PROPERTIES OF DISTRICT SHAPES
|
|
@@ -1290,9 +1292,9 @@ function extractDistrictProperties(s, bLog = false) {
|
|
|
1290
1292
|
const poly = s.districts.getDistrictShapeByID(i);
|
|
1291
1293
|
// Guard against no shape for empty districts AND null shapes
|
|
1292
1294
|
if (isAShape(poly)) {
|
|
1293
|
-
const area = Poly.polyAreaFlat(poly);
|
|
1294
|
-
const perimeter = Poly.polyPerimeterFlat(poly);
|
|
1295
|
-
const diameter = Poly.polyDiameterFlat(poly);
|
|
1295
|
+
const area = baseclient_1.Poly.polyAreaFlat(poly);
|
|
1296
|
+
const perimeter = baseclient_1.Poly.polyPerimeterFlat(poly);
|
|
1297
|
+
const diameter = baseclient_1.Poly.polyDiameterFlat(poly);
|
|
1296
1298
|
let props = [0, 0, 0];
|
|
1297
1299
|
props[0 /* Area */] = area;
|
|
1298
1300
|
props[1 /* Diameter */] = diameter;
|
|
@@ -1306,7 +1308,7 @@ exports.extractDistrictProperties = extractDistrictProperties;
|
|
|
1306
1308
|
function isAShape(poly) {
|
|
1307
1309
|
if (poly == null)
|
|
1308
1310
|
return false;
|
|
1309
|
-
if (Poly.polyNull(poly))
|
|
1311
|
+
if (baseclient_1.Poly.polyNull(poly))
|
|
1310
1312
|
return false;
|
|
1311
1313
|
return poly.geometry && poly.geometry.coordinates && !U.isArrayEmpty(poly.geometry.coordinates);
|
|
1312
1314
|
}
|
|
@@ -1320,7 +1322,7 @@ function scoreKIWYSICompactness(s, bLog = false) {
|
|
|
1320
1322
|
for (let i = 0; i < rawShapes.features.length; i++) {
|
|
1321
1323
|
const shape = rawShapes.features[i];
|
|
1322
1324
|
if (isAShape(shape)) {
|
|
1323
|
-
const d = Poly.polyDescribe(shape);
|
|
1325
|
+
const d = baseclient_1.Poly.polyDescribe(shape);
|
|
1324
1326
|
let f = {
|
|
1325
1327
|
type: 'Feature',
|
|
1326
1328
|
properties: { districtID: `${i + 1}` },
|
|
@@ -1437,9 +1439,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
1437
1439
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
1438
1440
|
};
|
|
1439
1441
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1442
|
+
exports.inferSelectedMinority = void 0;
|
|
1440
1443
|
__exportStar(__webpack_require__(/*! ./_api */ "./src/_api.ts"), exports);
|
|
1441
1444
|
__exportStar(__webpack_require__(/*! ./results */ "./src/results.ts"), exports);
|
|
1442
1445
|
__exportStar(__webpack_require__(/*! ./types */ "./src/types.ts"), exports);
|
|
1446
|
+
var _data_1 = __webpack_require__(/*! ./_data */ "./src/_data.ts");
|
|
1447
|
+
Object.defineProperty(exports, "inferSelectedMinority", ({ enumerable: true, get: function () { return _data_1.inferSelectedMinority; } }));
|
|
1443
1448
|
|
|
1444
1449
|
|
|
1445
1450
|
/***/ }),
|
|
@@ -1502,10 +1507,17 @@ function getVRASection5(s) {
|
|
|
1502
1507
|
exports.getVRASection5 = getVRASection5;
|
|
1503
1508
|
// RPV - pulled into a separate component 11-17-2020
|
|
1504
1509
|
function doAnalyzeRacialPolarization(s, districtID, groups, bLog = false) {
|
|
1505
|
-
//
|
|
1506
|
-
if (!(groups.black || groups.hispanic || groups.pacific || groups.asian || groups.native))
|
|
1510
|
+
// Make sure that a minority is specified
|
|
1511
|
+
if (!(groups.black || groups.hispanic || groups.pacific || groups.asian || groups.native || groups.minority))
|
|
1507
1512
|
return undefined;
|
|
1508
1513
|
const points = s.districts.extractVotesByDemographic(districtID, groups, bLog);
|
|
1514
|
+
// Make sure the district is not empty & there are enough points
|
|
1515
|
+
if (points === undefined)
|
|
1516
|
+
return undefined;
|
|
1517
|
+
if (points.comparison === undefined)
|
|
1518
|
+
return undefined;
|
|
1519
|
+
if (points.comparison.length <= 10)
|
|
1520
|
+
return undefined;
|
|
1509
1521
|
return RPV.analyzeRacialVoting(points, districtID, groups);
|
|
1510
1522
|
}
|
|
1511
1523
|
exports.doAnalyzeRacialPolarization = doAnalyzeRacialPolarization;
|
|
@@ -2393,14 +2405,39 @@ function deepCopy(src) {
|
|
|
2393
2405
|
return src;
|
|
2394
2406
|
}
|
|
2395
2407
|
exports.deepCopy = deepCopy;
|
|
2408
|
+
function depthof(a) {
|
|
2409
|
+
if (a === null || a === undefined)
|
|
2410
|
+
return 1;
|
|
2411
|
+
switch (typeof a) {
|
|
2412
|
+
default: return 1;
|
|
2413
|
+
case 'number': return 1;
|
|
2414
|
+
case 'boolean': return 1;
|
|
2415
|
+
case 'string': return 1;
|
|
2416
|
+
case 'object':
|
|
2417
|
+
{
|
|
2418
|
+
let d = 0;
|
|
2419
|
+
if (Array.isArray(a))
|
|
2420
|
+
return a.length > 0 ? (1 + depthof(a[0])) : 2; // still return 2 for empty array
|
|
2421
|
+
else if (Buffer && Buffer.isBuffer(a))
|
|
2422
|
+
return 2;
|
|
2423
|
+
else if (a.hasOwnProperty === undefined)
|
|
2424
|
+
return 1;
|
|
2425
|
+
else {
|
|
2426
|
+
for (var key in a)
|
|
2427
|
+
if (a.hasOwnProperty(key))
|
|
2428
|
+
return 1 + depthof(a[key]);
|
|
2429
|
+
return 2; // or 2 for empty object
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
exports.depthof = depthof;
|
|
2396
2435
|
/* TriState
|
|
2397
2436
|
export function mapBooleanToTriState(bool: boolean): T.TriState
|
|
2398
2437
|
{
|
|
2399
2438
|
return (bool) ? T.TriState.Green : T.TriState.Red;
|
|
2400
2439
|
}
|
|
2401
2440
|
*/
|
|
2402
|
-
var util_1 = __webpack_require__(/*! @dra2020/util */ "@dra2020/util");
|
|
2403
|
-
Object.defineProperty(exports, "depthof", ({ enumerable: true, get: function () { return util_1.depthof; } }));
|
|
2404
2441
|
|
|
2405
2442
|
|
|
2406
2443
|
/***/ }),
|
|
@@ -2617,6 +2654,16 @@ module.exports = JSON.parse("{\"AL\":\"all\",\"AK\":\"all\",\"AZ\":\"all\",\"CA\
|
|
|
2617
2654
|
|
|
2618
2655
|
/***/ }),
|
|
2619
2656
|
|
|
2657
|
+
/***/ "@dra2020/baseclient":
|
|
2658
|
+
/*!**************************************!*\
|
|
2659
|
+
!*** external "@dra2020/baseclient" ***!
|
|
2660
|
+
\**************************************/
|
|
2661
|
+
/***/ ((module) => {
|
|
2662
|
+
|
|
2663
|
+
module.exports = require("@dra2020/baseclient");;
|
|
2664
|
+
|
|
2665
|
+
/***/ }),
|
|
2666
|
+
|
|
2620
2667
|
/***/ "@dra2020/compactness":
|
|
2621
2668
|
/*!***************************************!*\
|
|
2622
2669
|
!*** external "@dra2020/compactness" ***!
|
|
@@ -2657,16 +2704,6 @@ module.exports = require("@dra2020/dra-types");;
|
|
|
2657
2704
|
|
|
2658
2705
|
/***/ }),
|
|
2659
2706
|
|
|
2660
|
-
/***/ "@dra2020/poly":
|
|
2661
|
-
/*!********************************!*\
|
|
2662
|
-
!*** external "@dra2020/poly" ***!
|
|
2663
|
-
\********************************/
|
|
2664
|
-
/***/ ((module) => {
|
|
2665
|
-
|
|
2666
|
-
module.exports = require("@dra2020/poly");;
|
|
2667
|
-
|
|
2668
|
-
/***/ }),
|
|
2669
|
-
|
|
2670
2707
|
/***/ "@dra2020/racial-voting":
|
|
2671
2708
|
/*!*****************************************!*\
|
|
2672
2709
|
!*** external "@dra2020/racial-voting" ***!
|
|
@@ -2675,16 +2712,6 @@ module.exports = require("@dra2020/poly");;
|
|
|
2675
2712
|
|
|
2676
2713
|
module.exports = require("@dra2020/racial-voting");;
|
|
2677
2714
|
|
|
2678
|
-
/***/ }),
|
|
2679
|
-
|
|
2680
|
-
/***/ "@dra2020/util":
|
|
2681
|
-
/*!********************************!*\
|
|
2682
|
-
!*** external "@dra2020/util" ***!
|
|
2683
|
-
\********************************/
|
|
2684
|
-
/***/ ((module) => {
|
|
2685
|
-
|
|
2686
|
-
module.exports = require("@dra2020/util");;
|
|
2687
|
-
|
|
2688
2715
|
/***/ })
|
|
2689
2716
|
|
|
2690
2717
|
/******/ });
|