@dra2020/district-analytics 1.0.1 → 1.0.4
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/src/_api.d.ts +27 -0
- package/dist/src/_data.d.ts +130 -0
- package/dist/src/analyze.d.ts +4 -0
- package/dist/src/cohesive.d.ts +4 -0
- package/dist/src/compact.d.ts +5 -0
- package/dist/src/constants.d.ts +6 -0
- package/dist/src/equal.d.ts +4 -0
- package/dist/src/geofeature.d.ts +3 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/minority.d.ts +3 -0
- package/dist/src/political.d.ts +8 -0
- package/dist/src/preprocess.d.ts +2 -0
- package/dist/src/report.d.ts +15 -0
- package/dist/src/settings.d.ts +5 -0
- package/dist/src/types.d.ts +110 -0
- package/dist/src/utils.d.ts +28 -0
- package/dist/src/valid.d.ts +8 -0
- package/package.json +9 -7
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Scorecard } from './report';
|
|
2
|
+
import * as D from './_data';
|
|
3
|
+
import * as T from './types';
|
|
4
|
+
export declare class AnalyticsSession {
|
|
5
|
+
title: string;
|
|
6
|
+
legislativeDistricts: boolean;
|
|
7
|
+
config: T.Dict;
|
|
8
|
+
bOneTimeProcessingDone: boolean;
|
|
9
|
+
bPlanAnalyzed: boolean;
|
|
10
|
+
bPostProcessingDone: boolean;
|
|
11
|
+
testScales: T.TestScales;
|
|
12
|
+
tests: T.TestEntries;
|
|
13
|
+
scorecard: Scorecard;
|
|
14
|
+
state: D.State;
|
|
15
|
+
counties: D.Counties;
|
|
16
|
+
graph: D.Graph;
|
|
17
|
+
features: D.Features;
|
|
18
|
+
plan: D.Plan;
|
|
19
|
+
districts: D.Districts;
|
|
20
|
+
constructor(SessionRequest: T.SessionRequest);
|
|
21
|
+
processConfig(config: T.Dict): T.Dict;
|
|
22
|
+
analyzePlan(bLog?: boolean): boolean;
|
|
23
|
+
getTest(testID: T.Test): T.TestEntry;
|
|
24
|
+
prepareScorecard(): any;
|
|
25
|
+
prepareTestLog(): any;
|
|
26
|
+
populationDeviationThreshold(): number;
|
|
27
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import * as T from './types';
|
|
2
|
+
import { AnalyticsSession } from './_api';
|
|
3
|
+
export declare enum DistrictField {
|
|
4
|
+
TotalPop = 0,
|
|
5
|
+
PopDevPct = 1,
|
|
6
|
+
bEqualPop = 2,
|
|
7
|
+
bNotEmpty = 3,
|
|
8
|
+
bContiguous = 4,
|
|
9
|
+
bNotEmbedded = 5,
|
|
10
|
+
CountySplits = 6,
|
|
11
|
+
DemVotes = 7,
|
|
12
|
+
RepVotes = 8,
|
|
13
|
+
TwoPartyVote = 9,
|
|
14
|
+
DemPct = 10,
|
|
15
|
+
RepPct = 11,
|
|
16
|
+
DemSeat = 12,
|
|
17
|
+
TotalVAP = 13,
|
|
18
|
+
MinorityPop = 14,
|
|
19
|
+
WhitePop = 15,
|
|
20
|
+
BlackPop = 16,
|
|
21
|
+
HispanicPop = 17,
|
|
22
|
+
PacificPop = 18,
|
|
23
|
+
AsianPop = 19,
|
|
24
|
+
NativePop = 20,
|
|
25
|
+
WhitePct = 21,
|
|
26
|
+
MinorityPct = 22,
|
|
27
|
+
BlackPct = 23,
|
|
28
|
+
HispanicPct = 24,
|
|
29
|
+
PacificPct = 25,
|
|
30
|
+
AsianPct = 26,
|
|
31
|
+
NativePct = 27
|
|
32
|
+
}
|
|
33
|
+
export declare const DisplayFields: DistrictField[];
|
|
34
|
+
export declare class Districts {
|
|
35
|
+
_session: AnalyticsSession;
|
|
36
|
+
_shapes: T.GeoFeatureCollection;
|
|
37
|
+
_geoProperties: T.DistrictProperties;
|
|
38
|
+
statistics: any[][];
|
|
39
|
+
constructor(s: AnalyticsSession, ds: T.GeoFeatureCollection);
|
|
40
|
+
getShape(i: number): T.GeoFeature;
|
|
41
|
+
getGeoProperties(i: number): any;
|
|
42
|
+
setGeoProperties(i: number, p: T.DistrictShapeProperties): void;
|
|
43
|
+
numberOfColumns(): number;
|
|
44
|
+
numberOfRows(): number;
|
|
45
|
+
numberOfWorkingDistricts(): number;
|
|
46
|
+
initStatistics(): any[][];
|
|
47
|
+
recalcStatistics(bLog?: boolean): void;
|
|
48
|
+
extractDistrictShapeProperties(bLog?: boolean): void;
|
|
49
|
+
getCountyIndex(geoID: string): number;
|
|
50
|
+
}
|
|
51
|
+
export declare const enum Dataset {
|
|
52
|
+
CENSUS = "CENSUS",
|
|
53
|
+
VAP = "VAP",
|
|
54
|
+
ELECTION = "ELECTION"
|
|
55
|
+
}
|
|
56
|
+
export declare type DatasetKeys = {
|
|
57
|
+
CENSUS: string;
|
|
58
|
+
VAP: string;
|
|
59
|
+
ELECTION: string;
|
|
60
|
+
};
|
|
61
|
+
export declare const DatasetDescriptions: any;
|
|
62
|
+
export declare const enum FeatureField {
|
|
63
|
+
TotalPop = "Tot",
|
|
64
|
+
WhitePop = "Wh",
|
|
65
|
+
BlackPop = "BlC",
|
|
66
|
+
HispanicPop = "His",
|
|
67
|
+
AsianPop = "AsnC",
|
|
68
|
+
PacificPop = "PacC",
|
|
69
|
+
NativePop = "NatC",
|
|
70
|
+
DemVotes = "D",
|
|
71
|
+
RepVotes = "R",
|
|
72
|
+
TotalVotes = "Tot"
|
|
73
|
+
}
|
|
74
|
+
export declare class Features {
|
|
75
|
+
_session: AnalyticsSession;
|
|
76
|
+
_data: T.GeoFeatureCollection;
|
|
77
|
+
_keys: DatasetKeys;
|
|
78
|
+
_featureIDs: T.FeaturesByGeoID;
|
|
79
|
+
constructor(s: AnalyticsSession, data: T.GeoFeatureCollection, keys: DatasetKeys);
|
|
80
|
+
nFeatures(): number;
|
|
81
|
+
featureByIndex(i: number): T.GeoFeature;
|
|
82
|
+
geoIDForFeature(f: any): string;
|
|
83
|
+
fieldForFeature(f: any, dt: Dataset, fk: string): any;
|
|
84
|
+
resetDataset(d: Dataset, k: string): void;
|
|
85
|
+
mapGeoIDsToFeatureIDs(): void;
|
|
86
|
+
featureID(i: string): number;
|
|
87
|
+
}
|
|
88
|
+
export declare class Counties {
|
|
89
|
+
_session: AnalyticsSession;
|
|
90
|
+
_data: T.GeoFeatureCollection;
|
|
91
|
+
_countyNameLookup: T.FIPSCodeToCountyNameMap;
|
|
92
|
+
nCounties: number;
|
|
93
|
+
index: T.FIPSToOrdinalMap;
|
|
94
|
+
constructor(s: AnalyticsSession, data: T.GeoFeatureCollection);
|
|
95
|
+
countyByIndex(i: number): T.GeoFeature;
|
|
96
|
+
propertyForCounty(f: any, pk: string): any;
|
|
97
|
+
mapFIPSToName(fips: string, name: string): void;
|
|
98
|
+
nameFromFIPS(fips: string): string;
|
|
99
|
+
indexFromFIPS(fips: string): number;
|
|
100
|
+
}
|
|
101
|
+
export declare class State {
|
|
102
|
+
_session: AnalyticsSession;
|
|
103
|
+
xx: string;
|
|
104
|
+
nDistricts: number;
|
|
105
|
+
totalPop: number;
|
|
106
|
+
tooBigFIPS: string[];
|
|
107
|
+
tooBigName: string[];
|
|
108
|
+
expectedSplits: number;
|
|
109
|
+
expectedAffected: number;
|
|
110
|
+
constructor(s: AnalyticsSession, xx: string, n: number);
|
|
111
|
+
}
|
|
112
|
+
export declare class Plan {
|
|
113
|
+
_session: AnalyticsSession;
|
|
114
|
+
_planByGeoID: T.PlanByGeoID;
|
|
115
|
+
_planByDistrictID: T.PlanByDistrictID;
|
|
116
|
+
districtIDs: number[];
|
|
117
|
+
constructor(s: AnalyticsSession, p: T.PlanByGeoID);
|
|
118
|
+
invertPlan(): void;
|
|
119
|
+
initializeDistrict(i: number): void;
|
|
120
|
+
byGeoID(): T.PlanByGeoID;
|
|
121
|
+
byDistrictID(): T.PlanByDistrictID;
|
|
122
|
+
districtForGeoID(i: string): number;
|
|
123
|
+
geoIDsForDistrictID(i: number): Set<string>;
|
|
124
|
+
}
|
|
125
|
+
export declare class Graph {
|
|
126
|
+
_session: AnalyticsSession;
|
|
127
|
+
_graph: T.ContiguityGraph;
|
|
128
|
+
constructor(s: AnalyticsSession, graph: T.ContiguityGraph);
|
|
129
|
+
peerNeighbors(node: string): string[];
|
|
130
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AnalyticsSession } from './_api';
|
|
2
|
+
export declare function doAnalyzeDistricts(s: AnalyticsSession, bLog?: boolean): void;
|
|
3
|
+
export declare function doAnalyzePlan(s: AnalyticsSession, bLog?: boolean): void;
|
|
4
|
+
export declare function doDeriveSecondaryTests(s: AnalyticsSession): void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as T from './types';
|
|
2
|
+
import { AnalyticsSession } from './_api';
|
|
3
|
+
export declare function doReock(s: AnalyticsSession, bLog?: boolean): T.TestEntry;
|
|
4
|
+
export declare function doPolsbyPopper(s: AnalyticsSession, bLog?: boolean): T.TestEntry;
|
|
5
|
+
export declare function extractDistrictProperties(s: AnalyticsSession, bLog?: boolean): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const StateXXToName: any;
|
|
2
|
+
export declare const StateRequirements: any;
|
|
3
|
+
export declare const MinorityDemographicDefns: any;
|
|
4
|
+
export declare const VRASection5Preclearance: any;
|
|
5
|
+
export declare const MajorityMinorityDistricts: any;
|
|
6
|
+
export declare const StateMinorityContacts: any;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as T from './types';
|
|
2
|
+
import { AnalyticsSession } from './_api';
|
|
3
|
+
export declare function doSeatsBias(s: AnalyticsSession): T.TestEntry;
|
|
4
|
+
export declare function doVotesBias(s: AnalyticsSession): T.TestEntry;
|
|
5
|
+
export declare function doResponsiveness(s: AnalyticsSession): T.TestEntry;
|
|
6
|
+
export declare function doResponsiveDistricts(s: AnalyticsSession): T.TestEntry;
|
|
7
|
+
export declare function doEfficiencyGap(s: AnalyticsSession): T.TestEntry;
|
|
8
|
+
export declare function fptpWin(demPct: number): number;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as T from './types';
|
|
2
|
+
import { AnalyticsSession } from './_api';
|
|
3
|
+
export declare type Scorecard = {
|
|
4
|
+
[category: number]: ScorecardCategoryEntry;
|
|
5
|
+
};
|
|
6
|
+
declare type ScorecardCategoryEntry = {
|
|
7
|
+
catName: string;
|
|
8
|
+
catScore?: number | boolean;
|
|
9
|
+
catTests: T.TestEntries;
|
|
10
|
+
};
|
|
11
|
+
export declare function doConfigureScales(s: AnalyticsSession): void;
|
|
12
|
+
export declare function doAnalyzePostProcessing(s: AnalyticsSession): void;
|
|
13
|
+
export declare function doPrepareScorecard(s: AnalyticsSession): any;
|
|
14
|
+
export declare function doPrepareTestLog(s: AnalyticsSession): any;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import * as geojson from 'geojson';
|
|
2
|
+
export declare const enum Suite {
|
|
3
|
+
Legal = 0,
|
|
4
|
+
Fair = 1,
|
|
5
|
+
Best = 2
|
|
6
|
+
}
|
|
7
|
+
export declare type SessionRequest = {
|
|
8
|
+
title: string;
|
|
9
|
+
stateXX: string;
|
|
10
|
+
nDistricts: number;
|
|
11
|
+
legislativeDistricts: boolean;
|
|
12
|
+
plan: PlanByGeoID;
|
|
13
|
+
data: GeoFeatureCollection;
|
|
14
|
+
districtShapes: GeoFeatureCollection;
|
|
15
|
+
districtProperties: DistrictProperties;
|
|
16
|
+
graph: ContiguityGraph;
|
|
17
|
+
countyNameLookup: FIPSCodeToCountyNameMap;
|
|
18
|
+
counties: GeoFeatureCollection;
|
|
19
|
+
config: {};
|
|
20
|
+
};
|
|
21
|
+
export declare type PlanByGeoID = {
|
|
22
|
+
[geoID: string]: number;
|
|
23
|
+
};
|
|
24
|
+
export declare type PlanByDistrictID = {
|
|
25
|
+
[districtID: number]: Set<string>;
|
|
26
|
+
};
|
|
27
|
+
export declare type FeaturesByGeoID = {
|
|
28
|
+
[geoID: string]: number;
|
|
29
|
+
};
|
|
30
|
+
export declare type FIPSCodeToCountyNameMap = {
|
|
31
|
+
[FIPSCode: string]: string;
|
|
32
|
+
};
|
|
33
|
+
export declare type FIPSToOrdinalMap = {
|
|
34
|
+
[FIPSCode: string]: number;
|
|
35
|
+
};
|
|
36
|
+
export declare type GeoFeature = geojson.Feature;
|
|
37
|
+
export declare type GeoFeatureArray = GeoFeature[];
|
|
38
|
+
export declare type GeoFeatureCollection = geojson.FeatureCollection;
|
|
39
|
+
export interface GeoFeatureMap {
|
|
40
|
+
[geoID: string]: GeoFeature;
|
|
41
|
+
}
|
|
42
|
+
export declare type ContiguityGraph = {
|
|
43
|
+
[geoID: string]: Neighbors;
|
|
44
|
+
};
|
|
45
|
+
export declare type Neighbors = {
|
|
46
|
+
[geoID: string]: number;
|
|
47
|
+
};
|
|
48
|
+
export declare type VoteTriple = [number, number, number];
|
|
49
|
+
export declare const enum VoteType {
|
|
50
|
+
Democratic = 0,
|
|
51
|
+
Republican = 1,
|
|
52
|
+
Total = 2
|
|
53
|
+
}
|
|
54
|
+
export declare type TestScale = {
|
|
55
|
+
testScale: Array<number>;
|
|
56
|
+
testInvertp: boolean;
|
|
57
|
+
};
|
|
58
|
+
export declare type TestScales = {
|
|
59
|
+
[test: number]: TestScale;
|
|
60
|
+
};
|
|
61
|
+
export declare type TestEntry = {
|
|
62
|
+
score?: number | boolean;
|
|
63
|
+
details: Dict;
|
|
64
|
+
normalizedScore?: number;
|
|
65
|
+
};
|
|
66
|
+
export declare type DistrictWIP = {
|
|
67
|
+
[districtID: number]: any;
|
|
68
|
+
};
|
|
69
|
+
export declare const enum Test {
|
|
70
|
+
Complete = 0,
|
|
71
|
+
Contiguous = 1,
|
|
72
|
+
FreeOfHoles = 2,
|
|
73
|
+
EqualPopulation = 3,
|
|
74
|
+
PopulationDeviation = 4,
|
|
75
|
+
Reock = 5,
|
|
76
|
+
PolsbyPopper = 6,
|
|
77
|
+
CountySplits = 7,
|
|
78
|
+
Complexity = 8,
|
|
79
|
+
SeatsBias = 9,
|
|
80
|
+
VotesBias = 10,
|
|
81
|
+
Responsiveness = 11,
|
|
82
|
+
ResponsiveDistricts = 12,
|
|
83
|
+
EfficiencyGap = 13,
|
|
84
|
+
MajorityMinorityDistricts = 14
|
|
85
|
+
}
|
|
86
|
+
export declare type TestEntries = {
|
|
87
|
+
[test: number]: TestEntry;
|
|
88
|
+
};
|
|
89
|
+
export declare type DistrictProperties = {
|
|
90
|
+
[districtID: number]: any;
|
|
91
|
+
};
|
|
92
|
+
export declare type DistrictShapeProperties = [number, number, number];
|
|
93
|
+
export declare const enum DistrictShapeProperty {
|
|
94
|
+
Area = 0,
|
|
95
|
+
Diameter = 1,
|
|
96
|
+
Perimeter = 2
|
|
97
|
+
}
|
|
98
|
+
export declare type GeoIDParts = {
|
|
99
|
+
state?: string;
|
|
100
|
+
county?: string;
|
|
101
|
+
tract?: string;
|
|
102
|
+
bg?: string;
|
|
103
|
+
block?: string;
|
|
104
|
+
};
|
|
105
|
+
export declare type GeoIDTotal = {
|
|
106
|
+
[geoID: string]: number;
|
|
107
|
+
};
|
|
108
|
+
export declare type Dict = {
|
|
109
|
+
[key: string]: any;
|
|
110
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as T from './types';
|
|
2
|
+
export declare function isInState(geoID: string): boolean;
|
|
3
|
+
export declare function isOutOfState(geoID: string): boolean;
|
|
4
|
+
export declare function getDistrict(plan: T.PlanByGeoID, geoID: string): number | undefined;
|
|
5
|
+
export declare function invertPlan(plan: T.PlanByGeoID): T.PlanByDistrictID;
|
|
6
|
+
export declare function parseGeoID(geoID: string): T.GeoIDParts;
|
|
7
|
+
export declare function getFIPSFromCountyGeoID(geoID: string): string;
|
|
8
|
+
export declare function normalize(rawScore: number, scale: Array<number>, invertp?: boolean): number;
|
|
9
|
+
export declare function trim(fullFraction: number): number;
|
|
10
|
+
export declare function sumArray(arr: number[]): number;
|
|
11
|
+
export declare function avgArray(arr: number[]): number;
|
|
12
|
+
export declare function minArray(arr: number[]): number;
|
|
13
|
+
export declare function maxArray(arr: number[]): number;
|
|
14
|
+
export declare function initArray(n: number, value: any): any[];
|
|
15
|
+
export declare function andArray(arr: boolean[]): boolean;
|
|
16
|
+
export declare function keyExists(k: string, o: object): boolean;
|
|
17
|
+
export declare function isObjectEmpty(o: object): boolean;
|
|
18
|
+
export declare function isSetEmpty(s: any): boolean;
|
|
19
|
+
export declare function isArrayEmpty(a: any[]): boolean;
|
|
20
|
+
export declare function getObjectKeys(o: object): string[];
|
|
21
|
+
export declare function getNumericObjectKeys(o: object): number[];
|
|
22
|
+
export declare function getSelectObjectKeys(o: T.Dict, v: any[]): string[];
|
|
23
|
+
export declare function arrayContains(a: any[], item: any): boolean;
|
|
24
|
+
export declare function objectContains(o: object, key: any): boolean;
|
|
25
|
+
export declare function countEnumValues(enumName: any): number;
|
|
26
|
+
export declare function shallowCopy(src: any): any;
|
|
27
|
+
export declare function deepCopy(src: any): any;
|
|
28
|
+
export { depthof } from '@dra2020/util';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as T from './types';
|
|
2
|
+
import * as D from './_data';
|
|
3
|
+
import { AnalyticsSession } from './_api';
|
|
4
|
+
export declare function doIsComplete(s: AnalyticsSession): T.TestEntry;
|
|
5
|
+
export declare function doIsContiguous(s: AnalyticsSession): T.TestEntry;
|
|
6
|
+
export declare function isConnected(districtGeos: Set<string>, graph: D.Graph): boolean;
|
|
7
|
+
export declare function doIsFreeOfHoles(s: AnalyticsSession): T.TestEntry;
|
|
8
|
+
export declare function isEmbedded(districtID: number, geoIDs: Set<string>, plan: D.Plan, graph: D.Graph): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dra2020/district-analytics",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "District analytics TypeScript package",
|
|
5
5
|
"main": "dist/district-analytics.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,22 +12,24 @@
|
|
|
12
12
|
"prepare": "npm run build",
|
|
13
13
|
"webpack": "node_modules/.bin/webpack"
|
|
14
14
|
},
|
|
15
|
-
"files": [
|
|
16
|
-
"lib/**/*"
|
|
17
|
-
],
|
|
18
15
|
"repository": {
|
|
19
16
|
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/
|
|
17
|
+
"url": "git+https://github.com/dra2020/district-analytics.git"
|
|
21
18
|
},
|
|
19
|
+
"files": [
|
|
20
|
+
"*/src/*",
|
|
21
|
+
"*/dist/*.*",
|
|
22
|
+
"*/dist/*/*.*"
|
|
23
|
+
],
|
|
22
24
|
"keywords": [
|
|
23
25
|
"Typescript"
|
|
24
26
|
],
|
|
25
27
|
"author": "Alec Ramsay",
|
|
26
28
|
"license": "MIT",
|
|
27
29
|
"bugs": {
|
|
28
|
-
"url": "https://github.com/
|
|
30
|
+
"url": "https://github.com/dra2020/district-analytics/issues"
|
|
29
31
|
},
|
|
30
|
-
"homepage": "https://github.com/
|
|
32
|
+
"homepage": "https://github.com/dra2020/district-analytics#readme",
|
|
31
33
|
"devDependencies": {
|
|
32
34
|
"@types/geojson": "^7946.0.7",
|
|
33
35
|
"@types/jest": "^24.0.17",
|