@dra2020/district-analytics 1.0.6 → 1.0.9

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.
Files changed (63) hide show
  1. package/README.md +5 -5
  2. package/dist/cli.js +2627 -2024
  3. package/dist/cli.js.map +1 -1
  4. package/dist/district-analytics.js +1316 -1156
  5. package/dist/district-analytics.js.map +1 -1
  6. package/dist/src/_api.d.ts +4 -4
  7. package/dist/src/_data.d.ts +4 -2
  8. package/dist/src/analyze.d.ts +1 -1
  9. package/dist/src/cohesive.d.ts +4 -2
  10. package/dist/src/equal.d.ts +2 -2
  11. package/dist/src/index.d.ts +1 -0
  12. package/dist/src/minority.d.ts +1 -1
  13. package/dist/src/political.d.ts +5 -5
  14. package/dist/src/preprocess.d.ts +1 -1
  15. package/dist/src/report.d.ts +0 -15
  16. package/dist/src/results.d.ts +141 -0
  17. package/dist/src/settings.d.ts +3 -0
  18. package/dist/src/types.d.ts +24 -11
  19. package/dist/src/utils.d.ts +4 -3
  20. package/dist/src/valid.d.ts +3 -3
  21. package/dist/test/_cli.d.ts +2 -0
  22. package/package.json +7 -4
  23. package/.prettierrc +0 -5
  24. package/dist/_api.d.ts +0 -27
  25. package/dist/_data.d.ts +0 -130
  26. package/dist/analyze.d.ts +0 -4
  27. package/dist/cohesive.d.ts +0 -4
  28. package/dist/compact.d.ts +0 -5
  29. package/dist/constants.d.ts +0 -6
  30. package/dist/equal.d.ts +0 -4
  31. package/dist/geofeature.d.ts +0 -3
  32. package/dist/index.d.ts +0 -2
  33. package/dist/minority.d.ts +0 -3
  34. package/dist/political.d.ts +0 -8
  35. package/dist/preprocess.d.ts +0 -2
  36. package/dist/report.d.ts +0 -15
  37. package/dist/settings.d.ts +0 -5
  38. package/dist/types.d.ts +0 -110
  39. package/dist/utils.d.ts +0 -28
  40. package/dist/valid.d.ts +0 -8
  41. package/jestconfig.json +0 -14
  42. package/main.js +0 -4
  43. package/src/_api.ts +0 -120
  44. package/src/_data.ts +0 -572
  45. package/src/analyze.ts +0 -92
  46. package/src/cohesive.ts +0 -156
  47. package/src/compact.ts +0 -208
  48. package/src/constants.ts +0 -371
  49. package/src/equal.ts +0 -75
  50. package/src/geofeature.ts +0 -138
  51. package/src/index.ts +0 -6
  52. package/src/minority.ts +0 -70
  53. package/src/political.ts +0 -114
  54. package/src/preprocess.ts +0 -132
  55. package/src/report.ts +0 -997
  56. package/src/settings.ts +0 -20
  57. package/src/types.ts +0 -185
  58. package/src/utils.ts +0 -245
  59. package/src/valid.ts +0 -275
  60. package/tsconfig.json +0 -25
  61. package/tslint.json +0 -3
  62. package/types/polygon-clipping/index.d.ts +0 -1
  63. package/webpack.config.js +0 -73
@@ -1,5 +0,0 @@
1
- export declare const PRECISION: number;
2
- export declare const NORMALIZED_RANGE: number;
3
- export declare const NOT_ASSIGNED: number;
4
- export declare const NUMBER_OF_ITEMS_TO_REPORT: number;
5
- export declare const OUT_OF_STATE: string;
package/dist/types.d.ts DELETED
@@ -1,110 +0,0 @@
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
- };
package/dist/utils.d.ts DELETED
@@ -1,28 +0,0 @@
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';
package/dist/valid.d.ts DELETED
@@ -1,8 +0,0 @@
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/jestconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "transform": {
3
- "^.+\\.(t|j)sx?$": "ts-jest"
4
- },
5
- "testRegex": "(/_tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
6
- "moduleFileExtensions": [
7
- "ts",
8
- "tsx",
9
- "js",
10
- "jsx",
11
- "json",
12
- "node"
13
- ]
14
- }
package/main.js DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // Invoke the CLI
4
- var run = require('./dist/cli.js');
package/src/_api.ts DELETED
@@ -1,120 +0,0 @@
1
- //
2
- // THE NODE PACKAGE API
3
- //
4
-
5
- import { doPreprocessData } from './preprocess'
6
- import { doAnalyzePlan, doAnalyzeDistricts } from './analyze'
7
- import {
8
- doConfigureScales, doAnalyzePostProcessing, doPrepareScorecard,
9
- doPrepareTestLog, Scorecard
10
- } from './report'
11
-
12
- import * as D from './_data';
13
- import * as T from './types'
14
- import * as U from './utils';
15
- import * as S from './settings';
16
-
17
- export class AnalyticsSession {
18
- title: string;
19
- legislativeDistricts: boolean;
20
- config: T.Dict = {};
21
-
22
- bOneTimeProcessingDone = false;
23
- bPlanAnalyzed = false;
24
- bPostProcessingDone = false;
25
- testScales = {} as T.TestScales;
26
- tests = {} as T.TestEntries;
27
- scorecard = {} as Scorecard;
28
-
29
- state: D.State;
30
- counties: D.Counties;
31
- graph: D.Graph;
32
- features: D.Features;
33
- plan: D.Plan;
34
- districts: D.Districts;
35
-
36
- constructor(SessionRequest: T.SessionRequest) {
37
- this.title = SessionRequest['title'];
38
- this.legislativeDistricts = SessionRequest['legislativeDistricts'];
39
- this.config = this.processConfig(SessionRequest['config'])
40
-
41
- this.state = new D.State(this, SessionRequest['stateXX'], SessionRequest['nDistricts']);
42
- this.counties = new D.Counties(this, SessionRequest['counties']);
43
- this.graph = new D.Graph(this, SessionRequest['graph']);
44
- this.features = new D.Features(this, SessionRequest['data'], this.config['datasets']);
45
- this.plan = new D.Plan(this, SessionRequest['plan']);
46
- this.districts = new D.Districts(this, SessionRequest['districtShapes']);
47
-
48
- // NOTE: I've pulled these out of the individual analytics to here. Eventually,
49
- // we could want them to passed into an analytics session as data, along with
50
- // everything else. For now, this keeps branching out of the main code.
51
- doConfigureScales(this);
52
- }
53
- processConfig(config: T.Dict): T.Dict {
54
- // NOTE - Session settings are required:
55
- // - Analytics suites can be defaulted to all with [], but
56
- // - Dataset keys must be explicitly specified with 'dataset'
57
-
58
- let defaultSuites = [T.Suite.Legal, T.Suite.Fair, T.Suite.Best];
59
-
60
- // If the config passed in has no suites = [], use the default suites
61
- if (U.isArrayEmpty(config['suites'])) {
62
- config['suites'] = defaultSuites;
63
- }
64
-
65
- // Default the Census & redistricting cycle to 2010
66
- if (!(U.keyExists('cycle', config))) config['cycle'] = 2010;
67
-
68
- return config;
69
- }
70
-
71
- // Using the the data in the analytics session, calculate all the
72
- // analytics & validations, saving/updating the individual test results.
73
- analyzePlan(bLog: boolean = false): boolean {
74
- try {
75
- doPreprocessData(this);
76
- doAnalyzeDistricts(this, bLog);
77
- doAnalyzePlan(this, bLog);
78
- doAnalyzePostProcessing(this);
79
- }
80
- catch {
81
- return false;
82
- }
83
-
84
- return true;
85
- }
86
-
87
- // Get an individual test, so you can drive UI with the results.
88
- getTest(testID: T.Test): T.TestEntry {
89
- // Get the existing test entries
90
- // T.Test is a numeric enum, so convert the string keys to numbers
91
- let testValues = U.getNumericObjectKeys(this.tests);
92
-
93
- // If there's no entry for this test, create & initialize one
94
- if (!(testValues.includes(testID))) {
95
- this.tests[testID] = {} as T.TestEntry;
96
- this.tests[testID]['score'] = undefined;
97
- this.tests[testID]['details'] = {};
98
- }
99
-
100
- // Return a pointer to the the test entry for this test
101
- return this.tests[testID];
102
- }
103
-
104
- // Prepare a scorecard for rendering
105
- // NOTE - This assumes that analyzePlan() has been run!
106
- prepareScorecard(): any {
107
- return doPrepareScorecard(this);
108
- }
109
-
110
- // Prepare test results for rendering
111
- // NOTE - This assumes that analyzePlan() has been run!
112
- prepareTestLog(): any {
113
- return doPrepareTestLog(this);
114
- }
115
-
116
- populationDeviationThreshold(): number {
117
- return 1 - this.testScales[T.Test.PopulationDeviation]['testScale'][0];
118
- }
119
- }
120
-