@dra2020/dra-analytics 4.1.7 → 5.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 +3 -1
- package/cli/partisan.ts +5 -5
- package/dist/dra-analytics.js +130 -125
- package/dist/dra-analytics.js.map +1 -1
- package/dist/lib/partisan/bias.d.ts +0 -8
- package/dist/lib/types/partisan.d.ts +0 -7
- package/lib/partisan/all.ts +15 -14
- package/lib/partisan/bias.ts +117 -117
- package/lib/types/partisan.ts +8 -8
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -23,7 +23,9 @@ them for several elections, one at a time, and then generate statistics for them
|
|
|
23
23
|
This repo & package can be integrated into other tools.
|
|
24
24
|
The libraries here are normally included like this:
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
```TypeScript
|
|
27
|
+
import { Compactness, Equal, Graph, Minority, Partisan, Splitting } from '@dra2020/dra-analytics';
|
|
28
|
+
```
|
|
27
29
|
|
|
28
30
|
Then the various functions of the different sets are available under their appropriate symbol.
|
|
29
31
|
|
package/cli/partisan.ts
CHANGED
|
@@ -161,10 +161,10 @@ export function printPartisanDetailsRow(xx: string, name: string, N: number, Vf:
|
|
|
161
161
|
(s.bias.gamma) ? trim(s.bias.gamma) : s.bias.gamma,
|
|
162
162
|
|
|
163
163
|
trim(s.bias.deviation), // Simple deviation from best # of seats
|
|
164
|
-
// (s.experimental.lProp) ? trim(s.experimental.lProp) : s.experimental.lProp,
|
|
165
|
-
(s.experimental.lPropAlt) ? trim(s.experimental.lPropAlt) : s.experimental.lPropAlt,
|
|
166
|
-
// trim(s.impact.unearnedS),
|
|
167
|
-
(s.experimental.lUE) ? trim(s.experimental.lUE) : s.experimental.lUE
|
|
168
|
-
// (s.experimental.lSym) ? trim(s.experimental.lSym) : s.experimental.lSym,
|
|
164
|
+
// // (s.experimental.lProp) ? trim(s.experimental.lProp) : s.experimental.lProp,
|
|
165
|
+
// (s.experimental.lPropAlt) ? trim(s.experimental.lPropAlt) : s.experimental.lPropAlt,
|
|
166
|
+
// // trim(s.impact.unearnedS),
|
|
167
|
+
// (s.experimental.lUE) ? trim(s.experimental.lUE) : s.experimental.lUE
|
|
168
|
+
// // (s.experimental.lSym) ? trim(s.experimental.lSym) : s.experimental.lSym,
|
|
169
169
|
);
|
|
170
170
|
}
|
package/dist/dra-analytics.js
CHANGED
|
@@ -1844,11 +1844,11 @@ function makePartisanScorecard(Vf, VfArray, bLog = false) {
|
|
|
1844
1844
|
// distribution than Rd.
|
|
1845
1845
|
const cD = (0, responsiveness_1.estCompetitiveDistricts)(VfArray);
|
|
1846
1846
|
const cDf = (0, responsiveness_1.estCompetitiveDistrictsShare)(cD, N);
|
|
1847
|
-
// EXPERIMENTAL
|
|
1848
|
-
const lSym =
|
|
1849
|
-
const lProp =
|
|
1850
|
-
const lPropAlt =
|
|
1851
|
-
const lUE =
|
|
1847
|
+
// // EXPERIMENTAL
|
|
1848
|
+
// const lSym = estLocalAsymmetry(Vf, dSVpoints, rSVpoints);
|
|
1849
|
+
// const lProp = estLocalDisproportionality(Vf, dSVpoints);
|
|
1850
|
+
// const lPropAlt = estLocalDisproportionalityAlt(Vf, N, dSVpoints);
|
|
1851
|
+
// const lUE = estLocalUnearnedSeats(Vf, N, dSVpoints);
|
|
1852
1852
|
const biasMeasurements = {
|
|
1853
1853
|
bestS: bestS,
|
|
1854
1854
|
bestSf: bestSf,
|
|
@@ -1887,12 +1887,13 @@ function makePartisanScorecard(Vf, VfArray, bLog = false) {
|
|
|
1887
1887
|
const RWins = VfArray.filter(x => x <= 0.5); // Ties credited to R's
|
|
1888
1888
|
const averageDVf = (DWins.length > 0) ? U.avgArray(DWins) : undefined;
|
|
1889
1889
|
const averageRVf = (RWins.length > 0) ? U.avgArray(RWins) : undefined;
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1890
|
+
// // EXPERIMENTAL
|
|
1891
|
+
// const experimentalMetrics: T.Experimental = {
|
|
1892
|
+
// lSym: lSym,
|
|
1893
|
+
// lProp: lProp,
|
|
1894
|
+
// lPropAlt: lPropAlt,
|
|
1895
|
+
// lUE: lUE
|
|
1896
|
+
// };
|
|
1896
1897
|
const s = {
|
|
1897
1898
|
bias: biasMeasurements,
|
|
1898
1899
|
impact: impactMeasurements,
|
|
@@ -1901,7 +1902,7 @@ function makePartisanScorecard(Vf, VfArray, bLog = false) {
|
|
|
1901
1902
|
rSVpoints: rSVpoints,
|
|
1902
1903
|
averageDVf: averageDVf,
|
|
1903
1904
|
averageRVf: averageRVf,
|
|
1904
|
-
experimental: experimentalMetrics,
|
|
1905
|
+
// experimental: experimentalMetrics,
|
|
1905
1906
|
details: {}
|
|
1906
1907
|
};
|
|
1907
1908
|
return s;
|
|
@@ -1986,14 +1987,6 @@ exports.calcDisproportionality = calcDisproportionality;
|
|
|
1986
1987
|
exports.calcBigR = calcBigR;
|
|
1987
1988
|
exports.calcMinimalInverseResponsiveness = calcMinimalInverseResponsiveness;
|
|
1988
1989
|
exports.calcGamma = calcGamma;
|
|
1989
|
-
exports.estLocalAsymmetry = estLocalAsymmetry;
|
|
1990
|
-
exports.rangeAsymmetry = rangeAsymmetry;
|
|
1991
|
-
exports.estLocalDisproportionality = estLocalDisproportionality;
|
|
1992
|
-
exports.rangeDisproportionality = rangeDisproportionality;
|
|
1993
|
-
exports.estLocalDisproportionalityAlt = estLocalDisproportionalityAlt;
|
|
1994
|
-
exports.rangeDisproportionalityAlt = rangeDisproportionalityAlt;
|
|
1995
|
-
exports.estLocalUnearnedSeats = estLocalUnearnedSeats;
|
|
1996
|
-
exports.rangeUnearnedSeats = rangeUnearnedSeats;
|
|
1997
1990
|
const U = __importStar(__webpack_require__(/*! ../utils/all */ "./lib/utils/all.ts"));
|
|
1998
1991
|
const C = __importStar(__webpack_require__(/*! ../rate/dra-config */ "./lib/rate/dra-config.ts"));
|
|
1999
1992
|
const method_1 = __webpack_require__(/*! ./method */ "./lib/partisan/method.ts");
|
|
@@ -2353,111 +2346,123 @@ function calcGamma(Vf, Sf, r) {
|
|
|
2353
2346
|
const g = 0.5 + (r * (Vf - 0.5)) - Sf;
|
|
2354
2347
|
return g;
|
|
2355
2348
|
}
|
|
2356
|
-
// EXPERIMENTAL
|
|
2357
|
-
const pctWidth = 5;
|
|
2358
|
-
// Average local asymmetry
|
|
2359
|
-
function estLocalAsymmetry(Vf, dSVpoints, rSVpoints)
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
//
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
}
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
//
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
}
|
|
2413
|
-
//
|
|
2414
|
-
function
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
//
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
}
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
}
|
|
2442
|
-
//
|
|
2443
|
-
//
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
const
|
|
2349
|
+
// // EXPERIMENTAL
|
|
2350
|
+
// const pctWidth = 5; // The size in % points of the 'local' window to bracket <V>
|
|
2351
|
+
// // Average local asymmetry
|
|
2352
|
+
// export function estLocalAsymmetry(Vf: number, dSVpoints: T.SVpoint[], rSVpoints: T.SVpoint[]): number | undefined
|
|
2353
|
+
// {
|
|
2354
|
+
// try
|
|
2355
|
+
// {
|
|
2356
|
+
// const dPts = svPointRange(Vf, dSVpoints);
|
|
2357
|
+
// const rPts = svPointRange(Vf, rSVpoints);
|
|
2358
|
+
// if (!dPts || !rPts) return undefined;
|
|
2359
|
+
// const lSym: number = rangeAsymmetry(dPts, rPts);
|
|
2360
|
+
// return lSym;
|
|
2361
|
+
// }
|
|
2362
|
+
// catch (err)
|
|
2363
|
+
// {
|
|
2364
|
+
// console.log("Exception in estLocalAsymmetry ...");
|
|
2365
|
+
// return undefined;
|
|
2366
|
+
// }
|
|
2367
|
+
// }
|
|
2368
|
+
// export function rangeAsymmetry(dSVpoints: T.SVpoint[], rSVpoints: T.SVpoint[]): number
|
|
2369
|
+
// {
|
|
2370
|
+
// const ndPts: number = dSVpoints.length;
|
|
2371
|
+
// const nrPts: number = rSVpoints.length;
|
|
2372
|
+
// console.assert(ndPts == nrPts, "# of D & R points don't match: ", ndPts, nrPts);
|
|
2373
|
+
// let tot: number = 0.0;
|
|
2374
|
+
// for (let i in dSVpoints)
|
|
2375
|
+
// {
|
|
2376
|
+
// tot += calcGeometricSeatsBias(dSVpoints[i].s, rSVpoints[i].s);
|
|
2377
|
+
// }
|
|
2378
|
+
// return tot / ndPts;
|
|
2379
|
+
// }
|
|
2380
|
+
// // Average local disproportionality
|
|
2381
|
+
// export function estLocalDisproportionality(Vf: number, dSVpoints: T.SVpoint[]): number | undefined
|
|
2382
|
+
// {
|
|
2383
|
+
// try
|
|
2384
|
+
// {
|
|
2385
|
+
// const dPts = svPointRange(Vf, dSVpoints);
|
|
2386
|
+
// if (!dPts) return undefined;
|
|
2387
|
+
// const lProp: number = rangeDisproportionality(dPts);
|
|
2388
|
+
// return lProp;
|
|
2389
|
+
// }
|
|
2390
|
+
// catch (err)
|
|
2391
|
+
// {
|
|
2392
|
+
// console.log("Exception in estLocalDisproportionality ...");
|
|
2393
|
+
// return undefined;
|
|
2394
|
+
// }
|
|
2395
|
+
// }
|
|
2396
|
+
// export function rangeDisproportionality(dSVpoints: T.SVpoint[]): number
|
|
2397
|
+
// {
|
|
2398
|
+
// const ndPts: number = dSVpoints.length;
|
|
2399
|
+
// let tot: number = 0.0;
|
|
2400
|
+
// for (let i in dSVpoints)
|
|
2401
|
+
// {
|
|
2402
|
+
// tot += calcProp(dSVpoints[i].v, dSVpoints[i].s);
|
|
2403
|
+
// }
|
|
2404
|
+
// return tot / ndPts;
|
|
2405
|
+
// }
|
|
2406
|
+
// // Average local disproportionality from the best # of seats (closest to proportional)
|
|
2407
|
+
// export function estLocalDisproportionalityAlt(Vf: number, N: number, dSVpoints: T.SVpoint[]): number | undefined
|
|
2408
|
+
// {
|
|
2409
|
+
// const dPts = svPointRange(Vf, dSVpoints);
|
|
2410
|
+
// if (!dPts) return undefined;
|
|
2411
|
+
// const lPropAlt: number = rangeDisproportionalityAlt(N, dPts);
|
|
2412
|
+
// return lPropAlt;
|
|
2413
|
+
// }
|
|
2414
|
+
// // Dynamically calculate the best # seats, so this is a step function
|
|
2415
|
+
// export function rangeDisproportionalityAlt(N: number, dSVpoints: T.SVpoint[]): number
|
|
2416
|
+
// {
|
|
2417
|
+
// const ndPts: number = dSVpoints.length;
|
|
2418
|
+
// let tot: number = 0.0;
|
|
2419
|
+
// for (let i in dSVpoints)
|
|
2420
|
+
// {
|
|
2421
|
+
// const bestS = bestSeats(N, dSVpoints[i].v);
|
|
2422
|
+
// const bestSf = bestSeatShare(bestS, N);
|
|
2423
|
+
// tot += calcDisproportionalityFromBest(dSVpoints[i].s, bestSf);
|
|
2424
|
+
// }
|
|
2425
|
+
// return tot / ndPts;
|
|
2426
|
+
// }
|
|
2427
|
+
// // Average local unearned seats from the best # of seats (closest to proportional)
|
|
2428
|
+
// export function estLocalUnearnedSeats(Vf: number, N: number, dSVpoints: T.SVpoint[]): number | undefined
|
|
2429
|
+
// {
|
|
2430
|
+
// const dPts = svPointRange(Vf, dSVpoints);
|
|
2431
|
+
// if (!dPts) return undefined;
|
|
2432
|
+
// const lUE: number = rangeUnearnedSeats(N, dPts);
|
|
2433
|
+
// return lUE;
|
|
2434
|
+
// }
|
|
2435
|
+
// export function rangeUnearnedSeats(N: number, dSVpoints: T.SVpoint[]): number
|
|
2436
|
+
// {
|
|
2437
|
+
// const ndPts: number = dSVpoints.length;
|
|
2438
|
+
// let tot: number = 0.0;
|
|
2439
|
+
// for (let i in dSVpoints)
|
|
2440
|
+
// {
|
|
2441
|
+
// const estS: number = dSVpoints[i].s * N;
|
|
2442
|
+
// const bestS = bestSeats(N, dSVpoints[i].v);
|
|
2443
|
+
// tot += estUnearnedSeats(bestS, estS);
|
|
2444
|
+
// }
|
|
2445
|
+
// return tot / ndPts;
|
|
2446
|
+
// }
|
|
2447
|
+
// // Filter the full [0.25–0.75] range of S–V points down to the 'local' range.
|
|
2448
|
+
// // Make sure that range is w/in the full range.
|
|
2449
|
+
// function svPointRange(Vf: number, svPoints: T.SVpoint[]): T.SVpoint[] | undefined
|
|
2450
|
+
// {
|
|
2451
|
+
// const svRange: number[] = [0.25, 0.75]; // The range over which we infer the S–V curve points
|
|
2452
|
+
// const halfStep: number = (1 / 100) / 2; // The V point increments, i.e., every half a percent
|
|
2453
|
+
// const localWindow: number = pctWidth / 100; // # of % points wide as a fraction
|
|
2454
|
+
// const plusMinus: number = localWindow / 2; // +/– % as a fraction
|
|
2455
|
+
// const delta: number = plusMinus + (halfStep / 2); // +/– % plus half a half step to deal w/ floating point precision
|
|
2456
|
+
// if ((Vf < svRange[0]) || (Vf > svRange[1])) return undefined;
|
|
2457
|
+
// const bracketingVs: number[] = [
|
|
2458
|
+
// findBracketingLowerVf(Vf, svPoints).v,
|
|
2459
|
+
// findBracketingUpperVf(Vf, svPoints).v
|
|
2460
|
+
// ];
|
|
2461
|
+
// const localRange: number[] = [bracketingVs[0] - delta, bracketingVs[1] + delta];
|
|
2462
|
+
// const subsetPts: T.SVpoint[] = svPoints.filter(x => inRange(x, localRange));
|
|
2463
|
+
// return subsetPts;
|
|
2464
|
+
// }
|
|
2465
|
+
// const inRange = (pt: T.SVpoint, range: number[]): boolean => {return (pt.v >= range[0]) && (pt.v <= range[1]);}
|
|
2461
2466
|
|
|
2462
2467
|
|
|
2463
2468
|
/***/ }),
|