@dra2020/district-analytics 8.0.1 → 8.1.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/dist/cli.js +78 -3
- package/dist/cli.js.map +1 -1
- package/dist/district-analytics.js +78 -3
- package/dist/district-analytics.js.map +1 -1
- package/dist/src/_data.d.ts +4 -28
- package/dist/src/types.d.ts +24 -0
- package/dist/src/utils.d.ts +3 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -103415,6 +103415,41 @@ class Districts {
|
|
|
103415
103415
|
}
|
|
103416
103416
|
}
|
|
103417
103417
|
exports.Districts = Districts;
|
|
103418
|
+
// CLASSES, ETC. FOR FEATURE & COUNTY DATA
|
|
103419
|
+
// Types of datasets by feature
|
|
103420
|
+
/* 08-13-2020 - Moved to types.ts
|
|
103421
|
+
export const enum Dataset
|
|
103422
|
+
{
|
|
103423
|
+
SHAPES = "SHAPES",
|
|
103424
|
+
CENSUS = "CENSUS",
|
|
103425
|
+
VAP = "VAP",
|
|
103426
|
+
ELECTION = "ELECTION"
|
|
103427
|
+
}
|
|
103428
|
+
*/
|
|
103429
|
+
/* 08-13-2020 - Moved to types.ts
|
|
103430
|
+
export type DatasetKeys = {
|
|
103431
|
+
SHAPES: string; // A shapefile
|
|
103432
|
+
CENSUS: string; // A total population Census dataset
|
|
103433
|
+
VAP: string; // A voting age (or citizen voting age) dataset
|
|
103434
|
+
ELECTION: string; // An election dataset
|
|
103435
|
+
}
|
|
103436
|
+
*/
|
|
103437
|
+
// Identifiers of fields for each feature in the datasets
|
|
103438
|
+
/* 08-13-2020 - Moved to types.ts
|
|
103439
|
+
export const enum FeatureField
|
|
103440
|
+
{
|
|
103441
|
+
TotalPop = "Tot",
|
|
103442
|
+
WhitePop = "Wh",
|
|
103443
|
+
BlackPop = "BlC",
|
|
103444
|
+
HispanicPop = "His",
|
|
103445
|
+
AsianPop = "AsnC",
|
|
103446
|
+
PacificPop = "PacC",
|
|
103447
|
+
NativePop = "NatC",
|
|
103448
|
+
DemVotes = "D",
|
|
103449
|
+
RepVotes = "R",
|
|
103450
|
+
TotalVotes = "Tot"
|
|
103451
|
+
}
|
|
103452
|
+
*/
|
|
103418
103453
|
// Wrap data by feature, to abstract the specifics of the internal structure
|
|
103419
103454
|
class Features {
|
|
103420
103455
|
constructor(s, data, keys) {
|
|
@@ -104723,14 +104758,31 @@ function parseGeoID(geoID) {
|
|
|
104723
104758
|
return parts;
|
|
104724
104759
|
}
|
|
104725
104760
|
exports.parseGeoID = parseGeoID;
|
|
104726
|
-
|
|
104727
|
-
|
|
104761
|
+
// 08-13-2020 - Enhanced completeness checking.
|
|
104762
|
+
function isWaterOnly(geoID, s) {
|
|
104763
|
+
const waterOnlySignature = 'ZZZZZZ';
|
|
104728
104764
|
if (geoID.indexOf(waterOnlySignature) >= 0)
|
|
104729
104765
|
return true;
|
|
104766
|
+
if (s) {
|
|
104767
|
+
// If called with a session, get the feature ...
|
|
104768
|
+
const featureID = s.features.featureID(geoID);
|
|
104769
|
+
const f = s.features.featureByIndex(featureID);
|
|
104770
|
+
// ... and also check the 'ALAND' property
|
|
104771
|
+
const bNoLand = ((f.properties['ALAND10'] !== undefined) && (f.properties['ALAND10'] == 0)) ? true : false;
|
|
104772
|
+
return bNoLand;
|
|
104773
|
+
}
|
|
104730
104774
|
else
|
|
104731
104775
|
return false;
|
|
104732
104776
|
}
|
|
104733
104777
|
exports.isWaterOnly = isWaterOnly;
|
|
104778
|
+
function isUninhabited(geoID, s) {
|
|
104779
|
+
const featureID = s.features.featureID(geoID);
|
|
104780
|
+
const f = s.features.featureByIndex(featureID);
|
|
104781
|
+
const totalPop = s.features.fieldForFeature(f, "CENSUS" /* CENSUS */, "Tot" /* TotalPop */);
|
|
104782
|
+
const bUninhabited = (totalPop > 0) ? false : true;
|
|
104783
|
+
return bUninhabited;
|
|
104784
|
+
}
|
|
104785
|
+
exports.isUninhabited = isUninhabited;
|
|
104734
104786
|
// NORMALIZING RESULTS
|
|
104735
104787
|
function normalize(rawScore, testScale) {
|
|
104736
104788
|
let rangeMin = testScale.scale[0];
|
|
@@ -104940,10 +104992,26 @@ function doIsComplete(s, bLog = false) {
|
|
|
104940
104992
|
// Check the dummy district that holds any unassigned features.
|
|
104941
104993
|
let unassignedFeatures = [];
|
|
104942
104994
|
let bAllAssigned = (!bNotEmptyByDistrict[S.NOT_ASSIGNED]);
|
|
104995
|
+
let bAllNonWaterOnlyAssigned = bAllAssigned ? true : false;
|
|
104943
104996
|
if (!bAllAssigned) {
|
|
104944
104997
|
let unassignedDistrict = s.plan.geoIDsForDistrictID(S.NOT_ASSIGNED);
|
|
104945
104998
|
unassignedFeatures = Array.from(unassignedDistrict);
|
|
104946
104999
|
// unassignedFeatures = unassignedFeatures.slice(0, S.NUMBER_OF_ITEMS_TO_REPORT);
|
|
105000
|
+
// 08-13-2020 - Enhanced completeness checking.
|
|
105001
|
+
// Are any of the unassigned features not water-only -or- inhabited?
|
|
105002
|
+
// Check the official congressional maps for CT, KY, IL, and MI.
|
|
105003
|
+
bAllNonWaterOnlyAssigned = !unassignedFeatures.some(function (geoID) {
|
|
105004
|
+
if (U.isWaterOnly(geoID, s)) {
|
|
105005
|
+
console.log("Unassigned water-only feature ignored in completeness check: ", geoID);
|
|
105006
|
+
return false;
|
|
105007
|
+
}
|
|
105008
|
+
if (U.isUninhabited(geoID, s)) {
|
|
105009
|
+
console.log("Uninhabited feature ignored in completeness check: ", geoID);
|
|
105010
|
+
return false;
|
|
105011
|
+
}
|
|
105012
|
+
// Not water-only and inhabited
|
|
105013
|
+
return true;
|
|
105014
|
+
});
|
|
104947
105015
|
}
|
|
104948
105016
|
// Do all real districts have at least one feature assigned to them?
|
|
104949
105017
|
let emptyDistricts = [];
|
|
@@ -104967,7 +105035,14 @@ function doIsComplete(s, bLog = false) {
|
|
|
104967
105035
|
// Note, this can happen if a district is created, and then all features
|
|
104968
105036
|
// are removed from it (in DRA).
|
|
104969
105037
|
// Populate the test entry
|
|
104970
|
-
|
|
105038
|
+
// 08-13-2020 - Revised completeness check:
|
|
105039
|
+
// A plan is complete if:
|
|
105040
|
+
// * All inhabited, not water-only districts are assigned to districts.
|
|
105041
|
+
// * No districts are empty, i.e., each has one or more geos assigned to them.
|
|
105042
|
+
// Note: We're not checking (in _data.ts) whether those geos are water-only
|
|
105043
|
+
// or have any population, but that's a real edge case.
|
|
105044
|
+
test['score'] = bAllNonWaterOnlyAssigned && bNoneEmpty;
|
|
105045
|
+
// test['score'] = bAllAssigned && bNoneEmpty;
|
|
104971
105046
|
if (!bAllAssigned) {
|
|
104972
105047
|
test['details']['unassignedFeatures'] = unassignedFeatures;
|
|
104973
105048
|
}
|