@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
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { PopulationScorecard } from '../types/all';
|
|
2
2
|
export declare function calcPopulationDeviation(max: number, min: number, targetSize: number): number;
|
|
3
3
|
export declare function isRoughlyEqual(devation: number, bLegislative: boolean): boolean;
|
|
4
|
-
export declare function makePopulationScorecard(totPopByDistrict: number[], targetSize: number, bLegislative: boolean, bLog?: boolean): PopulationScorecard;
|
|
4
|
+
export declare function makePopulationScorecard(totPopByDistrict: number[], targetSize: number, bLegislative: boolean, repsByDistrict?: number[], bLog?: boolean): PopulationScorecard;
|
package/lib/equal/population.ts
CHANGED
|
@@ -9,6 +9,7 @@ import * as T from '../types/all';
|
|
|
9
9
|
import * as U from '../utils/all';
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
// MMD - This is the same for SMD & MMD. It's the calculation of min, max, and target size that differs.
|
|
12
13
|
export function calcPopulationDeviation(max: number, min: number, targetSize: number): number
|
|
13
14
|
{
|
|
14
15
|
return (max - min) / targetSize; // Don't trim the result here!
|
|
@@ -21,13 +22,42 @@ export function isRoughlyEqual(devation: number, bLegislative: boolean): boolean
|
|
|
21
22
|
return (devation <= threshold) ? true : false;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
// MMD
|
|
26
|
+
// - Add optional # of reps per district.
|
|
27
|
+
// - Assume targetSize has been calculated correctly per # of reps not districts.
|
|
28
|
+
// - If it exists, handle the MMD-specific calculations.
|
|
29
|
+
export function makePopulationScorecard(totPopByDistrict: number[], targetSize: number, bLegislative: boolean, repsByDistrict?: number[], bLog: boolean = false): PopulationScorecard
|
|
25
30
|
{
|
|
26
|
-
const
|
|
31
|
+
const nDistricts = totPopByDistrict.length;
|
|
32
|
+
|
|
33
|
+
// MMD - Validate reps per district input
|
|
34
|
+
if (repsByDistrict)
|
|
35
|
+
{
|
|
36
|
+
if (repsByDistrict.length != nDistricts) throw new Error("Mismatched #'s of districts passed to makePopulationScorecard()!");
|
|
37
|
+
if (repsByDistrict.includes(0)) throw new Error("Zero reps for a district passed to makePopulationScorecard()!");
|
|
38
|
+
// Assume a positive integer # of reps per district
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// MMD - Figure out the type of districts, SMD or MMD.
|
|
42
|
+
const nReps = (repsByDistrict) ? repsByDistrict.reduce((a, b) => a + b, 0) : nDistricts;
|
|
43
|
+
const bSMD = (!repsByDistrict || (nReps == nDistricts)) ? true : false;
|
|
44
|
+
|
|
45
|
+
// MMD - Generalize populations for non-empty districts to be per rep.
|
|
46
|
+
// const nonEmptyDistricts = totPopByDistrict.filter(x => x > 0);
|
|
47
|
+
let popPerRep: number[] = U.deepCopy(totPopByDistrict);
|
|
48
|
+
if (!bSMD && repsByDistrict)
|
|
49
|
+
{
|
|
50
|
+
for (let i = 0; i < nDistricts; i += 1)
|
|
51
|
+
{
|
|
52
|
+
popPerRep[i] = totPopByDistrict[i] / repsByDistrict[i];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const nonEmptyDistricts = popPerRep.filter(x => x > 0);
|
|
27
56
|
|
|
28
57
|
let min = 0;
|
|
29
58
|
let max = 0;
|
|
30
59
|
|
|
60
|
+
// MMD - This is already generalized, because nonEmptyDistricts is generalized.
|
|
31
61
|
if (nonEmptyDistricts.length > 1)
|
|
32
62
|
{
|
|
33
63
|
min = U.minArray(nonEmptyDistricts);
|
package/lib/rate/dra-ratings.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {avgSVError} from '../partisan/method';
|
|
|
8
8
|
import * as T from '../types/all'
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
// MMD - This is already generalized, if deviations have been calculated based on # of reps instead of districts.
|
|
11
12
|
// RATE POPULATION DEVIATION
|
|
12
13
|
|
|
13
14
|
export function ratePopulationDeviation(rawDeviation: number, bLegislative: boolean): number
|
package/lib/types/population.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dra2020/dra-analytics",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "DRA analytics",
|
|
5
5
|
"main": "dist/dra-analytics.js",
|
|
6
6
|
"types": "./dist/lib/all/all.d.ts",
|
|
@@ -30,16 +30,6 @@
|
|
|
30
30
|
"bugs": {
|
|
31
31
|
"url": "https://github.com/dra2020/dra-analytics/issues"
|
|
32
32
|
},
|
|
33
|
-
"jest": {
|
|
34
|
-
"moduleFileExtensions": [
|
|
35
|
-
"js",
|
|
36
|
-
"jsx"
|
|
37
|
-
],
|
|
38
|
-
"moduleDirectories": [
|
|
39
|
-
"node_modules",
|
|
40
|
-
"shared"
|
|
41
|
-
]
|
|
42
|
-
},
|
|
43
33
|
"homepage": "https://github.com/dra2020/dra-analytics#readme",
|
|
44
34
|
"devDependencies": {
|
|
45
35
|
"@types/geojson": "^7946.0.8",
|