@dra2020/district-analytics 17.0.2 → 17.1.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 +13 -7
- package/dist/_api.d.ts +5 -29
- package/dist/_data.d.ts +2 -67
- package/dist/analyze.d.ts +1 -3
- package/dist/cohesive.d.ts +2 -3
- package/dist/compact.d.ts +0 -2
- package/dist/data.d.ts +60 -16
- package/dist/district-analytics.js +1368 -1979
- package/dist/district-analytics.js.map +1 -1
- package/dist/equal.d.ts +0 -3
- package/dist/index.d.ts +2 -2
- package/dist/legacy-types.d.ts +1 -3
- package/dist/minority.d.ts +0 -6
- package/dist/preprocess.d.ts +1 -1
- package/dist/requirements.d.ts +12 -0
- package/dist/results.d.ts +0 -50
- package/dist/rpv.d.ts +2 -2
- package/dist/score.d.ts +3 -4
- package/dist/settings.d.ts +0 -1
- package/dist/src/_api.d.ts +5 -29
- package/dist/src/_data.d.ts +2 -67
- package/dist/src/analyze.d.ts +1 -3
- package/dist/src/cohesive.d.ts +2 -3
- package/dist/src/compact.d.ts +0 -2
- package/dist/src/data.d.ts +60 -16
- package/dist/src/equal.d.ts +0 -3
- package/dist/src/index.d.ts +2 -2
- package/dist/src/legacy-types.d.ts +1 -3
- package/dist/src/minority.d.ts +0 -6
- package/dist/src/preprocess.d.ts +1 -1
- package/dist/src/requirements.d.ts +12 -0
- package/dist/src/results.d.ts +0 -50
- package/dist/src/rpv.d.ts +2 -2
- package/dist/src/score.d.ts +3 -4
- package/dist/src/settings.d.ts +0 -1
- package/dist/src/types.d.ts +86 -42
- package/dist/src/utils.d.ts +8 -5
- package/dist/src/valid.d.ts +0 -5
- package/dist/types.d.ts +86 -42
- package/dist/utils.d.ts +8 -5
- package/dist/valid.d.ts +0 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# District Analytics
|
|
2
2
|
|
|
3
|
-
A layer between dra-client and fn-all (scoring lambda)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
A layer between `dra-client` and `fn-all` (the scoring lambda), on the one hand, and `dra-analytics`, on the other,
|
|
4
|
+
that knows enough about DRA and the analytics proper in `dra-analytics` to take data in, compose the various lower-level
|
|
5
|
+
analytics calls, and make the various artifacts: scorecard, ratings, requirements checklist, etc. This allows the callers
|
|
6
|
+
to remain high-level and agnostic of the analytics specifics and the analytics proper to no nothing about DRA.
|
|
7
7
|
|
|
8
8
|
## Build Status
|
|
9
9
|
|
|
@@ -14,6 +14,8 @@ DRA, on the other.
|
|
|
14
14
|
```javascript
|
|
15
15
|
import * as DA from 'district-analytics';
|
|
16
16
|
|
|
17
|
+
// Create a session request
|
|
18
|
+
|
|
17
19
|
let sr = {} as DA.SessionRequest;
|
|
18
20
|
sr['title'] = "NC 2020 Congress";
|
|
19
21
|
sr['stateXX'] = "NC";
|
|
@@ -26,16 +28,20 @@ sr['graph'] = graph as T.ContiguityGraph;
|
|
|
26
28
|
sr['plan'] = planByGeoID as DA.PlanByGeoID;
|
|
27
29
|
sr['districtShapes'] = districtShapes as T.GeoFeatureCollection;
|
|
28
30
|
sr['aggregates'] = aggregates as PF.PackedFields[];
|
|
29
|
-
sr['datasetsMeta'] = datasetsMeta as DT.DatasetsMeta;
|
|
30
31
|
sr['config'] = config as T.Dict;
|
|
31
32
|
|
|
33
|
+
// Create an analytics session
|
|
34
|
+
|
|
32
35
|
let s = new DA.AnalyticsSession(sr);
|
|
33
36
|
|
|
37
|
+
// Run the analytics
|
|
38
|
+
|
|
34
39
|
let bLog = false;
|
|
35
40
|
s.analyzePlan(bLog);
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
// Retrieve the artifacts
|
|
43
|
+
|
|
38
44
|
const scorecard: DA.Scorecard = s.getPlanScorecard();
|
|
39
45
|
const ratings: DA.Ratings = s.getRatings();
|
|
46
|
+
const requirements: DA.RequirementsChecklist = s.getRequirementsChecklist();
|
|
40
47
|
```
|
|
41
|
-
|
package/dist/_api.d.ts
CHANGED
|
@@ -1,40 +1,16 @@
|
|
|
1
|
-
import { DT, PF } from '@dra2020/dra-types';
|
|
2
1
|
import { Types } from '@dra2020/dra-analytics';
|
|
3
|
-
import
|
|
4
|
-
import { DistrictStatistics } from './results';
|
|
5
|
-
import * as D from './_data';
|
|
2
|
+
import * as D from './data';
|
|
6
3
|
import * as T from './types';
|
|
7
4
|
import * as L from './legacy-types';
|
|
8
5
|
export declare class AnalyticsSession {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
config: T.Dict;
|
|
12
|
-
bOneTimeProcessingDone: boolean;
|
|
13
|
-
bPlanAnalyzed: boolean;
|
|
14
|
-
bPostProcessingDone: boolean;
|
|
15
|
-
tests: T.TestEntries;
|
|
16
|
-
_profile?: L.Profile;
|
|
17
|
-
_scorecard?: L.Scorecard;
|
|
18
|
-
state: D.State;
|
|
19
|
-
counties: D.Counties;
|
|
20
|
-
graph: D.GraphClass;
|
|
21
|
-
features: D.Features;
|
|
22
|
-
plan: D.Plan;
|
|
23
|
-
districts: D.Districts;
|
|
24
|
-
aggregates: PF.PackedFields[];
|
|
25
|
-
datasetsMeta: DT.DatasetsMeta;
|
|
26
|
-
repsByDistrict?: number[];
|
|
6
|
+
data: D.SessionData;
|
|
7
|
+
bLog: boolean;
|
|
27
8
|
constructor(SessionRequest: T.SessionRequest);
|
|
28
|
-
processConfig(config: T.Dict): T.Dict;
|
|
29
9
|
analyzePlan(bLog?: boolean, overridesJSON?: any): boolean;
|
|
30
|
-
getGoodShapes(): T.GeoFeatureCollection;
|
|
31
10
|
analyzeRacialPolarization(districtID: number, groups: Types.MinorityFilter, bLog?: boolean): Types.RPVAnalysis | undefined;
|
|
32
|
-
getDistrictStatistics(bLog?: boolean): DistrictStatistics;
|
|
33
11
|
getPlanProfile(bLog?: boolean): L.Profile;
|
|
34
12
|
getPlanScorecard(bLog?: boolean): L.Scorecard;
|
|
35
13
|
getRatings(bLog?: boolean): T.Ratings;
|
|
36
|
-
getRequirementsChecklist(bLog?: boolean): RequirementsChecklist;
|
|
37
|
-
|
|
38
|
-
getTest(testID: T.Test): T.TestEntry;
|
|
39
|
-
populationDeviationThreshold(): number;
|
|
14
|
+
getRequirementsChecklist(bLog?: boolean): T.RequirementsChecklist;
|
|
15
|
+
getDistrictStatistics(bLog?: boolean): T.DistrictStatistics;
|
|
40
16
|
}
|
package/dist/_data.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Types } from '@dra2020/dra-analytics';
|
|
2
1
|
import * as T from './types';
|
|
2
|
+
export * from './data';
|
|
3
3
|
import { AnalyticsSession } from './_api';
|
|
4
4
|
export type TransposedTable = {
|
|
5
5
|
totalPop: number[];
|
|
@@ -32,7 +32,7 @@ export type TransposedTable = {
|
|
|
32
32
|
asianPct: number[];
|
|
33
33
|
nativePct: number[];
|
|
34
34
|
};
|
|
35
|
-
export declare class
|
|
35
|
+
export declare class LegacyDistricts {
|
|
36
36
|
_session: AnalyticsSession;
|
|
37
37
|
_shapes: T.GeoFeatureCollection;
|
|
38
38
|
_geoProperties: T.DistrictProperties;
|
|
@@ -48,69 +48,4 @@ export declare class Districts {
|
|
|
48
48
|
recalcStatistics(bLog?: boolean): void;
|
|
49
49
|
extractDistrictShapeProperties(bLog?: boolean): void;
|
|
50
50
|
getCountyIndex(geoID: string): number;
|
|
51
|
-
extractVotesByDemographic(districtID: number, groups: Types.MinorityFilter, bLog?: boolean): Types.DemographicVotingByFeature | undefined;
|
|
52
|
-
}
|
|
53
|
-
export declare function inferSelectedMinority(groups: Types.MinorityFilter): string;
|
|
54
|
-
export declare class Features {
|
|
55
|
-
_session: AnalyticsSession;
|
|
56
|
-
_data: T.GeoFeatureCollection;
|
|
57
|
-
_keys: T.DatasetKeys;
|
|
58
|
-
_featureIDs: T.FeaturesByGeoID;
|
|
59
|
-
constructor(s: AnalyticsSession, data: T.GeoFeatureCollection, keys: T.DatasetKeys);
|
|
60
|
-
nFeatures(): number;
|
|
61
|
-
featureByIndex(i: number): T.GeoFeature;
|
|
62
|
-
resetDataset(d: T.Dataset, k: string): void;
|
|
63
|
-
mapGeoIDsToFeatureIDs(): void;
|
|
64
|
-
featureID(i: string): number;
|
|
65
|
-
}
|
|
66
|
-
export declare function geoIDForFeature(f: any): string;
|
|
67
|
-
export declare function fieldForFeature(f: any, dk: string, ff: T.FeatureField): any;
|
|
68
|
-
export declare class Counties {
|
|
69
|
-
_session: AnalyticsSession;
|
|
70
|
-
_data: T.GeoFeatureCollection;
|
|
71
|
-
_countyNameLookup: T.FIPSCodeToCountyNameMap;
|
|
72
|
-
nCounties: number;
|
|
73
|
-
index: T.FIPSToOrdinalMap;
|
|
74
|
-
fips: T.OrdinalToFIPSlMap;
|
|
75
|
-
totalPopulation: number[];
|
|
76
|
-
constructor(s: AnalyticsSession, data: T.GeoFeatureCollection);
|
|
77
|
-
countyByIndex(i: number): T.GeoFeature;
|
|
78
|
-
propertyForCounty(f: any, pk: string): any;
|
|
79
|
-
mapFIPSToName(fips: string, name: string): void;
|
|
80
|
-
nameFromFIPS(fips: string): string;
|
|
81
|
-
indexFromFIPS(fips: string): number;
|
|
82
|
-
}
|
|
83
|
-
export declare class State {
|
|
84
|
-
_session: AnalyticsSession;
|
|
85
|
-
xx: string;
|
|
86
|
-
nDistricts: number;
|
|
87
|
-
nReps: number;
|
|
88
|
-
totalPop: number;
|
|
89
|
-
targetSize: number;
|
|
90
|
-
tooBigFIPS: string[];
|
|
91
|
-
tooBigName: string[];
|
|
92
|
-
singleCountyDistrictMax: number;
|
|
93
|
-
expectedSplits: number;
|
|
94
|
-
expectedAffected: number;
|
|
95
|
-
constructor(s: AnalyticsSession, xx: string, n: number);
|
|
96
|
-
}
|
|
97
|
-
export declare class Plan {
|
|
98
|
-
_session: AnalyticsSession;
|
|
99
|
-
_planByGeoID: T.PlanByGeoID;
|
|
100
|
-
_planByDistrictID: T.PlanByDistrictID;
|
|
101
|
-
districtIDs: number[];
|
|
102
|
-
constructor(s: AnalyticsSession, p: T.PlanByGeoID);
|
|
103
|
-
invertPlan(bLog?: boolean): void;
|
|
104
|
-
initializeDistrict(i: number): void;
|
|
105
|
-
byGeoID(): T.PlanByGeoID;
|
|
106
|
-
byDistrictID(): T.PlanByDistrictID;
|
|
107
|
-
districtForGeoID(i: string): number;
|
|
108
|
-
geoIDsForDistrictID(i: number): Set<string>;
|
|
109
|
-
}
|
|
110
|
-
export declare function invertPlan(plan: T.PlanByGeoID, s?: AnalyticsSession, bLog?: boolean): T.PlanByDistrictID;
|
|
111
|
-
export declare class GraphClass {
|
|
112
|
-
_session: AnalyticsSession;
|
|
113
|
-
_graph: T.ContiguityGraph;
|
|
114
|
-
constructor(s: AnalyticsSession, graph: T.ContiguityGraph);
|
|
115
|
-
peerNeighbors(node: string): string[];
|
|
116
51
|
}
|
package/dist/analyze.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
import { AnalyticsSession } from './_api';
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function doAnalyzePlan(s: AnalyticsSession, bLog?: boolean): void;
|
|
4
|
-
export declare function doDeriveSecondaryTests(s: AnalyticsSession, bLog?: boolean): void;
|
|
2
|
+
export declare function newAnalyzePlan(s: AnalyticsSession): boolean;
|
package/dist/cohesive.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import * as T from './types';
|
|
2
|
-
import
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function doFindSplitVTDs(s: AnalyticsSession, bLog?: boolean): T.TestEntry;
|
|
2
|
+
import * as D from './data';
|
|
3
|
+
export declare function findCountiesSplitUnexpectedly(container: D.SessionData, bLog?: boolean): T.TestEntry;
|
package/dist/compact.d.ts
CHANGED
package/dist/data.d.ts
CHANGED
|
@@ -1,37 +1,80 @@
|
|
|
1
|
+
import { PF } from '@dra2020/dra-types';
|
|
2
|
+
import { Types } from '@dra2020/dra-analytics';
|
|
1
3
|
import * as T from './types';
|
|
4
|
+
import * as L from './legacy-types';
|
|
5
|
+
import * as D from './data';
|
|
2
6
|
import { AnalyticsSession } from './_api';
|
|
3
|
-
export declare class
|
|
7
|
+
export declare class SessionData {
|
|
4
8
|
_session: AnalyticsSession;
|
|
9
|
+
profile?: L.Profile;
|
|
10
|
+
legacyScorecardAlt?: L.Scorecard;
|
|
11
|
+
newScorecard?: Types.Scorecard;
|
|
12
|
+
ratings?: T.Ratings;
|
|
13
|
+
checklist?: T.RequirementsChecklist;
|
|
14
|
+
statistics?: T.DistrictStatistics;
|
|
15
|
+
bOneTimeProcessingDone: boolean;
|
|
16
|
+
bPlanAnalyzed: boolean;
|
|
17
|
+
title: string;
|
|
18
|
+
legislativeDistricts: boolean;
|
|
19
|
+
repsByDistrict?: number[];
|
|
20
|
+
config: T.Dict;
|
|
21
|
+
state: State;
|
|
22
|
+
counties: Counties;
|
|
23
|
+
graph: T.ContiguityGraph;
|
|
24
|
+
features: Features;
|
|
25
|
+
plan: Plan;
|
|
26
|
+
districts: Districts;
|
|
27
|
+
aggregates: Aggregates;
|
|
28
|
+
CxD: number[][];
|
|
29
|
+
constructor(s: AnalyticsSession, SessionRequest: T.SessionRequest);
|
|
30
|
+
}
|
|
31
|
+
export declare class Aggregates {
|
|
32
|
+
_container: D.SessionData;
|
|
33
|
+
_aggregates: PF.PackedFields[];
|
|
34
|
+
unpacked: {
|
|
35
|
+
[key: string]: {
|
|
36
|
+
[key: string]: number[];
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
columns: {
|
|
40
|
+
[key: string]: any[];
|
|
41
|
+
};
|
|
42
|
+
constructor(container: D.SessionData, aggregates: PF.PackedFields[]);
|
|
43
|
+
process(): void;
|
|
44
|
+
transpose(): T.DistrictRow[];
|
|
45
|
+
private _unpack;
|
|
46
|
+
private _columnize;
|
|
47
|
+
private _checkReqs;
|
|
48
|
+
private _convert;
|
|
49
|
+
}
|
|
50
|
+
export declare class Districts {
|
|
51
|
+
_container: D.SessionData;
|
|
5
52
|
_shapes: T.GeoFeatureCollection;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
getDistrictShapes(): T.GeoFeatureCollection;
|
|
9
|
-
getDistrictShapeByID(id: number): T.GeoFeature | undefined;
|
|
10
|
-
getCountyIndex(geoID: string): number;
|
|
53
|
+
constructor(container: D.SessionData, ds: T.GeoFeatureCollection);
|
|
54
|
+
getShapes(): T.GeoFeatureCollection;
|
|
11
55
|
}
|
|
12
56
|
export declare class Features {
|
|
13
|
-
|
|
57
|
+
_container: D.SessionData;
|
|
14
58
|
_data: T.GeoFeatureCollection;
|
|
15
59
|
_keys: T.DatasetKeys;
|
|
16
60
|
_featureIDs: T.FeaturesByGeoID;
|
|
17
|
-
constructor(
|
|
61
|
+
constructor(container: D.SessionData, data: T.GeoFeatureCollection, keys: T.DatasetKeys);
|
|
18
62
|
nFeatures(): number;
|
|
19
63
|
featureByIndex(i: number): T.GeoFeature;
|
|
20
|
-
resetDataset(d: T.Dataset, k: string): void;
|
|
21
64
|
mapGeoIDsToFeatureIDs(): void;
|
|
22
65
|
featureID(i: string): number;
|
|
23
66
|
}
|
|
24
67
|
export declare function geoIDForFeature(f: any): string;
|
|
25
68
|
export declare function fieldForFeature(f: any, dk: string, ff: T.FeatureField): any;
|
|
26
69
|
export declare class Counties {
|
|
27
|
-
|
|
70
|
+
_container: D.SessionData;
|
|
28
71
|
_data: T.GeoFeatureCollection;
|
|
29
72
|
_countyNameLookup: T.FIPSCodeToCountyNameMap;
|
|
30
73
|
nCounties: number;
|
|
31
74
|
index: T.FIPSToOrdinalMap;
|
|
32
75
|
fips: T.OrdinalToFIPSlMap;
|
|
33
76
|
totalPopulation: number[];
|
|
34
|
-
constructor(
|
|
77
|
+
constructor(container: D.SessionData, data: T.GeoFeatureCollection);
|
|
35
78
|
countyByIndex(i: number): T.GeoFeature;
|
|
36
79
|
propertyForCounty(f: any, pk: string): any;
|
|
37
80
|
mapFIPSToName(fips: string, name: string): void;
|
|
@@ -39,7 +82,7 @@ export declare class Counties {
|
|
|
39
82
|
indexFromFIPS(fips: string): number;
|
|
40
83
|
}
|
|
41
84
|
export declare class State {
|
|
42
|
-
|
|
85
|
+
_container: D.SessionData;
|
|
43
86
|
xx: string;
|
|
44
87
|
nDistricts: number;
|
|
45
88
|
nReps: number;
|
|
@@ -50,14 +93,14 @@ export declare class State {
|
|
|
50
93
|
singleCountyDistrictMax: number;
|
|
51
94
|
expectedSplits: number;
|
|
52
95
|
expectedAffected: number;
|
|
53
|
-
constructor(
|
|
96
|
+
constructor(container: D.SessionData, xx: string, n: number);
|
|
54
97
|
}
|
|
55
98
|
export declare class Plan {
|
|
56
|
-
|
|
99
|
+
_container: D.SessionData;
|
|
57
100
|
_planByGeoID: T.PlanByGeoID;
|
|
58
101
|
_planByDistrictID: T.PlanByDistrictID;
|
|
59
102
|
districtIDs: number[];
|
|
60
|
-
constructor(
|
|
103
|
+
constructor(container: D.SessionData, p: T.PlanByGeoID);
|
|
61
104
|
invertPlan(bLog?: boolean): void;
|
|
62
105
|
initializeDistrict(i: number): void;
|
|
63
106
|
byGeoID(): T.PlanByGeoID;
|
|
@@ -65,4 +108,5 @@ export declare class Plan {
|
|
|
65
108
|
districtForGeoID(i: string): number;
|
|
66
109
|
geoIDsForDistrictID(i: number): Set<string>;
|
|
67
110
|
}
|
|
68
|
-
export declare function invertPlan(plan: T.PlanByGeoID,
|
|
111
|
+
export declare function invertPlan(plan: T.PlanByGeoID, container?: D.SessionData, bLog?: boolean): T.PlanByDistrictID;
|
|
112
|
+
export declare function processConfig(config: T.Dict): T.Dict;
|