@dra2020/dra-analytics 3.3.5 → 4.0.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/README.md +4 -0
- package/dist/dra-analytics.js +29 -2
- package/dist/dra-analytics.js.map +1 -1
- package/dist/lib/equal/population.d.ts +1 -1
- package/lib/equal/population.ts +32 -2
- package/lib/rate/dra-ratings.ts +1 -0
- package/lib/types/population.ts +0 -1
- package/package.json +1 -11
package/README.md
CHANGED
|
@@ -44,6 +44,10 @@ The analytics in DRA include metrics favored by [many scholars](./docs/attributi
|
|
|
44
44
|
|
|
45
45
|
A [command-line interface](./docs/cli.md) (CLI) was added in v3.
|
|
46
46
|
|
|
47
|
+
## Updates
|
|
48
|
+
|
|
49
|
+
- 12/18/21 -- Added multi-member district (MMD) support to makePopulationScorecard().
|
|
50
|
+
|
|
47
51
|
## Build status for master branch
|
|
48
52
|
|
|
49
53
|
[](https://circleci.com/gh/dra2020/dra-analytics)
|
package/dist/dra-analytics.js
CHANGED
|
@@ -849,6 +849,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
849
849
|
exports.makePopulationScorecard = exports.isRoughlyEqual = exports.calcPopulationDeviation = void 0;
|
|
850
850
|
const C = __importStar(__webpack_require__(/*! ../rate/dra-config */ "./lib/rate/dra-config.ts"));
|
|
851
851
|
const U = __importStar(__webpack_require__(/*! ../utils/all */ "./lib/utils/all.ts"));
|
|
852
|
+
// MMD - This is the same for SMD & MMD. It's the calculation of min, max, and target size that differs.
|
|
852
853
|
function calcPopulationDeviation(max, min, targetSize) {
|
|
853
854
|
return (max - min) / targetSize; // Don't trim the result here!
|
|
854
855
|
}
|
|
@@ -858,10 +859,35 @@ function isRoughlyEqual(devation, bLegislative) {
|
|
|
858
859
|
return (devation <= threshold) ? true : false;
|
|
859
860
|
}
|
|
860
861
|
exports.isRoughlyEqual = isRoughlyEqual;
|
|
861
|
-
|
|
862
|
-
|
|
862
|
+
// MMD
|
|
863
|
+
// - Add optional # of reps per district.
|
|
864
|
+
// - Assume targetSize has been calculated correctly per # of reps not districts.
|
|
865
|
+
// - If it exists, handle the MMD-specific calculations.
|
|
866
|
+
function makePopulationScorecard(totPopByDistrict, targetSize, bLegislative, repsByDistrict, bLog = false) {
|
|
867
|
+
const nDistricts = totPopByDistrict.length;
|
|
868
|
+
// MMD - Validate reps per district input
|
|
869
|
+
if (repsByDistrict) {
|
|
870
|
+
if (repsByDistrict.length != nDistricts)
|
|
871
|
+
throw new Error("Mismatched #'s of districts passed to makePopulationScorecard()!");
|
|
872
|
+
if (repsByDistrict.includes(0))
|
|
873
|
+
throw new Error("Zero reps for a district passed to makePopulationScorecard()!");
|
|
874
|
+
// Assume a positive integer # of reps per district
|
|
875
|
+
}
|
|
876
|
+
// MMD - Figure out the type of districts, SMD or MMD.
|
|
877
|
+
const nReps = (repsByDistrict) ? repsByDistrict.reduce((a, b) => a + b, 0) : nDistricts;
|
|
878
|
+
const bSMD = (!repsByDistrict || (nReps == nDistricts)) ? true : false;
|
|
879
|
+
// MMD - Generalize populations for non-empty districts
|
|
880
|
+
// const nonEmptyDistricts = totPopByDistrict.filter(x => x > 0);
|
|
881
|
+
let popPerRep = U.deepCopy(totPopByDistrict);
|
|
882
|
+
if (!bSMD && repsByDistrict) {
|
|
883
|
+
for (let i = 0; i < nDistricts; i += 1) {
|
|
884
|
+
popPerRep[i] = totPopByDistrict[i] / repsByDistrict[i];
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
const nonEmptyDistricts = popPerRep.filter(x => x > 0);
|
|
863
888
|
let min = 0;
|
|
864
889
|
let max = 0;
|
|
890
|
+
// MMD - This is already generalized, because nonEmptyDistricts is generalized.
|
|
865
891
|
if (nonEmptyDistricts.length > 1) {
|
|
866
892
|
min = U.minArray(nonEmptyDistricts);
|
|
867
893
|
max = U.maxArray(nonEmptyDistricts);
|
|
@@ -2883,6 +2909,7 @@ exports.adjustSplittingRating = exports.rateSplittingLegacy = exports.rateDistri
|
|
|
2883
2909
|
const C = __importStar(__webpack_require__(/*! ./dra-config */ "./lib/rate/dra-config.ts"));
|
|
2884
2910
|
const normalize_1 = __webpack_require__(/*! ../rate/normalize */ "./lib/rate/normalize.ts");
|
|
2885
2911
|
const method_1 = __webpack_require__(/*! ../partisan/method */ "./lib/partisan/method.ts");
|
|
2912
|
+
// MMD - This is already generalized, if deviations have been calculated based on # of reps instead of districts.
|
|
2886
2913
|
// RATE POPULATION DEVIATION
|
|
2887
2914
|
function ratePopulationDeviation(rawDeviation, bLegislative) {
|
|
2888
2915
|
const _normalizer = new normalize_1.Normalizer(rawDeviation);
|