@dra2020/dra-analytics 3.2.0 → 3.3.3
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/cli/partisan.ts +21 -21
- package/dist/dra-analytics.js +19 -7
- package/dist/dra-analytics.js.map +1 -1
- package/dist/lib/all/types.d.ts +1 -1
- package/dist/lib/partisan/bias.d.ts +3 -2
- package/lib/all/types.ts +4 -1
- package/lib/partisan/all.ts +1 -1
- package/lib/partisan/bias.ts +20 -6
- package/package.json +10 -10
package/dist/lib/all/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Scorecard, PopulationScorecard, PartisanScorecard, MinorityScorecard, CompactnessScorecard, SplittingScorecard, Dict, PCAModel, MinorityFilter, dictPoint, DemographicVotingByFeature, RPVFactor, RPVAnalysis } from '../types/all';
|
|
1
|
+
export { Scorecard, PopulationScorecard, PartisanScorecard, MinorityScorecard, CompactnessScorecard, SplittingScorecard, Dict, VfArray, SVpoint, rVpoints, PCAModel, MinorityFilter, dictPoint, DemographicVotingByFeature, RPVFactor, RPVAnalysis } from '../types/all';
|
|
@@ -12,6 +12,7 @@ export declare function estGeometricSeatsBias(Vf: number, dSVpoints: T.SVpoint[]
|
|
|
12
12
|
export declare function inferGeometricSeatsBiasPoints(dSVpoints: T.SVpoint[], rSVpoints: T.SVpoint[]): T.SVpoint[];
|
|
13
13
|
export declare function invertSVPoints(inferredSVpoints: T.SVpoint[]): T.SVpoint[];
|
|
14
14
|
export declare function calcEfficiencyGap(Vf: number, Sf: number, shareType?: T.Party): number;
|
|
15
|
+
export declare function calcEfficiencyGapPrime(Vf: number, Sf: number, R: number | undefined): number | undefined;
|
|
15
16
|
export declare function calcMeanMedianDifference(VfArray: T.VfArray, Vf?: number): number;
|
|
16
17
|
export declare function keyRVpoints(VfArray: T.VfArray): T.rVpoints;
|
|
17
18
|
export declare function isASweep(Sf: number, nDistricts: number): boolean;
|
|
@@ -29,5 +30,5 @@ export declare function estLocalDisproportionality(Vf: number, dSVpoints: T.SVpo
|
|
|
29
30
|
export declare function rangeDisproportionality(dSVpoints: T.SVpoint[]): number;
|
|
30
31
|
export declare function estLocalDisproportionalityAlt(Vf: number, N: number, dSVpoints: T.SVpoint[]): number | undefined;
|
|
31
32
|
export declare function rangeDisproportionalityAlt(N: number, dSVpoints: T.SVpoint[]): number;
|
|
32
|
-
export declare function estLocalUnearnedSeats(Vf: number, N: number,
|
|
33
|
-
export declare function rangeUnearnedSeats(N: number,
|
|
33
|
+
export declare function estLocalUnearnedSeats(Vf: number, N: number, dSVpoints: T.SVpoint[]): number | undefined;
|
|
34
|
+
export declare function rangeUnearnedSeats(N: number, dSVpoints: T.SVpoint[]): number;
|
package/lib/all/types.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
export
|
|
4
4
|
{
|
|
5
|
-
// Scorecards
|
|
5
|
+
// Scorecards
|
|
6
6
|
Scorecard,
|
|
7
7
|
PopulationScorecard,
|
|
8
8
|
PartisanScorecard,
|
|
@@ -11,6 +11,9 @@ export
|
|
|
11
11
|
SplittingScorecard,
|
|
12
12
|
Dict,
|
|
13
13
|
|
|
14
|
+
// Subordinate types
|
|
15
|
+
VfArray, SVpoint, rVpoints,
|
|
16
|
+
|
|
14
17
|
// For legacy KIWYSI compactness calculations
|
|
15
18
|
PCAModel,
|
|
16
19
|
|
package/lib/partisan/all.ts
CHANGED
|
@@ -109,7 +109,7 @@ export function makePartisanScorecard(Vf: number, VfArray: T.VfArray, bLog: bool
|
|
|
109
109
|
const lSym = estLocalAsymmetry(Vf, dSVpoints, rSVpoints);
|
|
110
110
|
const lProp = estLocalDisproportionality(Vf, dSVpoints);
|
|
111
111
|
const lPropAlt = estLocalDisproportionalityAlt(Vf, N, dSVpoints);
|
|
112
|
-
const lUE = estLocalUnearnedSeats(Vf, N,
|
|
112
|
+
const lUE = estLocalUnearnedSeats(Vf, N, dSVpoints);
|
|
113
113
|
|
|
114
114
|
const biasMeasurements: T.Bias = {
|
|
115
115
|
bestS: bestS,
|
package/lib/partisan/bias.ts
CHANGED
|
@@ -262,6 +262,21 @@ export function calcEfficiencyGap(Vf: number, Sf: number, shareType = T.Party.De
|
|
|
262
262
|
return efficiencyGap;
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
+
// For illustration purposes only
|
|
266
|
+
// Assumes Democratic vote shares
|
|
267
|
+
// Alternate specification with winner's bonus (R) heuristic built in:
|
|
268
|
+
// - By convention, '+' = R bias; '-' = D bias
|
|
269
|
+
// - If 1 <= R <= 2, EG is undefined (no/acceptable bias).
|
|
270
|
+
export function calcEfficiencyGapPrime(Vf: number, Sf: number, R: number | undefined): number | undefined
|
|
271
|
+
{
|
|
272
|
+
let EG = undefined;
|
|
273
|
+
|
|
274
|
+
if (R && ((R > 2) || (R < 1)))
|
|
275
|
+
EG = (2.0 * (Vf - 0.5)) - (Sf - 0.5);
|
|
276
|
+
|
|
277
|
+
return EG;
|
|
278
|
+
}
|
|
279
|
+
|
|
265
280
|
// MEAN–MEDIAN DIFFERENCE
|
|
266
281
|
//
|
|
267
282
|
// From PlanScore.org: "The mean-median difference is a party’s median vote share
|
|
@@ -409,7 +424,7 @@ export function calcLopsidedOutcomes(VfArray: T.VfArray): number | undefined
|
|
|
409
424
|
//
|
|
410
425
|
// * gSym is the area of asymmetry between the two curves.
|
|
411
426
|
// * The choice of what base to normalize it by is somewhat arbitrary.
|
|
412
|
-
// * We actually only infer the S–V
|
|
427
|
+
// * We actually only infer the S–V curve over the range [0.25–0.75] <<< 101 points (not 100!)
|
|
413
428
|
// * But dividing by 100 normalizes the area of asymmetry to the area of the SxV unit square.
|
|
414
429
|
export function calcGlobalSymmetry(dSVpoints: T.SVpoint[], rSVpoints: T.SVpoint[], S50V: number): number
|
|
415
430
|
{
|
|
@@ -610,20 +625,18 @@ export function rangeDisproportionalityAlt(N: number, dSVpoints: T.SVpoint[]): n
|
|
|
610
625
|
}
|
|
611
626
|
|
|
612
627
|
// Average local unearned seats from the best # of seats (closest to proportional)
|
|
613
|
-
export function estLocalUnearnedSeats(Vf: number, N: number,
|
|
628
|
+
export function estLocalUnearnedSeats(Vf: number, N: number, dSVpoints: T.SVpoint[]): number | undefined
|
|
614
629
|
{
|
|
615
630
|
const dPts = svPointRange(Vf, dSVpoints);
|
|
616
631
|
|
|
617
632
|
if (!dPts) return undefined;
|
|
618
633
|
|
|
619
|
-
const
|
|
620
|
-
|
|
621
|
-
const lUE: number = rangeUnearnedSeats(N, estS, dPts);
|
|
634
|
+
const lUE: number = rangeUnearnedSeats(N, dPts);
|
|
622
635
|
|
|
623
636
|
return lUE;
|
|
624
637
|
}
|
|
625
638
|
|
|
626
|
-
export function rangeUnearnedSeats(N: number,
|
|
639
|
+
export function rangeUnearnedSeats(N: number, dSVpoints: T.SVpoint[]): number
|
|
627
640
|
{
|
|
628
641
|
const ndPts: number = dSVpoints.length;
|
|
629
642
|
|
|
@@ -631,6 +644,7 @@ export function rangeUnearnedSeats(N: number, estS: number, dSVpoints: T.SVpoint
|
|
|
631
644
|
|
|
632
645
|
for (let i in dSVpoints)
|
|
633
646
|
{
|
|
647
|
+
const estS: number = dSVpoints[i].s * N;
|
|
634
648
|
const bestS = bestSeats(N, dSVpoints[i].v);
|
|
635
649
|
|
|
636
650
|
tot += estUnearnedSeats(bestS, estS);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dra2020/dra-analytics",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.3",
|
|
4
4
|
"description": "DRA analytics",
|
|
5
5
|
"main": "dist/dra-analytics.js",
|
|
6
6
|
"types": "./dist/lib/all/all.d.ts",
|
|
@@ -43,27 +43,27 @@
|
|
|
43
43
|
"homepage": "https://github.com/dra2020/dra-analytics#readme",
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/geojson": "^7946.0.8",
|
|
46
|
-
"@types/jest": "^27.0.
|
|
46
|
+
"@types/jest": "^27.0.3",
|
|
47
47
|
"@types/node": "^12.20.20",
|
|
48
48
|
"@types/yargs": "^16.0.4",
|
|
49
49
|
"csv-parse": "^4.16.0",
|
|
50
|
-
"jest": "^27.
|
|
50
|
+
"jest": "^27.4.3",
|
|
51
51
|
"json-loader": "^0.5.7",
|
|
52
52
|
"prettier": "^2.3.2",
|
|
53
53
|
"shapefile": "^0.6.6",
|
|
54
54
|
"source-map-loader": "^3.0.0",
|
|
55
|
-
"ts-jest": "^27.
|
|
56
|
-
"ts-loader": "^9.2.
|
|
55
|
+
"ts-jest": "^27.1.1",
|
|
56
|
+
"ts-loader": "^9.2.6",
|
|
57
57
|
"tsify": "^5.0.4",
|
|
58
58
|
"tslint": "^6.1.3",
|
|
59
59
|
"tslint-config-prettier": "^1.18.0",
|
|
60
|
-
"typescript": "^4.
|
|
61
|
-
"webpack": "^5.
|
|
62
|
-
"webpack-cli": "^4.
|
|
60
|
+
"typescript": "^4.5.2",
|
|
61
|
+
"webpack": "^5.65.0",
|
|
62
|
+
"webpack-cli": "^4.9.1",
|
|
63
63
|
"yargs": "^17.1.1"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@dra2020/baseclient": "^1.0.
|
|
66
|
+
"@dra2020/baseclient": "^1.0.67",
|
|
67
67
|
"geojson": "^0.5.0"
|
|
68
68
|
}
|
|
69
|
-
}
|
|
69
|
+
}
|