@dra2020/district-analytics 1.0.7 → 1.0.8

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 (132) hide show
  1. package/README.md +5 -5
  2. package/dist/district-analytics.js +1315 -1205
  3. package/package.json +6 -3
  4. package/.prettierrc +0 -5
  5. package/dist/_api.d.ts +0 -27
  6. package/dist/_data.d.ts +0 -130
  7. package/dist/analyze.d.ts +0 -4
  8. package/dist/cli.js +0 -12091
  9. package/dist/cli.js.map +0 -1
  10. package/dist/cohesive.d.ts +0 -4
  11. package/dist/compact.d.ts +0 -5
  12. package/dist/constants.d.ts +0 -6
  13. package/dist/district-analytics.js.map +0 -1
  14. package/dist/equal.d.ts +0 -4
  15. package/dist/geofeature.d.ts +0 -3
  16. package/dist/index.d.ts +0 -2
  17. package/dist/minority.d.ts +0 -3
  18. package/dist/political.d.ts +0 -8
  19. package/dist/preprocess.d.ts +0 -2
  20. package/dist/report.d.ts +0 -15
  21. package/dist/settings.d.ts +0 -5
  22. package/dist/src/_api.d.ts +0 -27
  23. package/dist/src/_data.d.ts +0 -130
  24. package/dist/src/analyze.d.ts +0 -4
  25. package/dist/src/cohesive.d.ts +0 -4
  26. package/dist/src/compact.d.ts +0 -5
  27. package/dist/src/constants.d.ts +0 -6
  28. package/dist/src/equal.d.ts +0 -4
  29. package/dist/src/geofeature.d.ts +0 -3
  30. package/dist/src/index.d.ts +0 -2
  31. package/dist/src/minority.d.ts +0 -3
  32. package/dist/src/political.d.ts +0 -8
  33. package/dist/src/preprocess.d.ts +0 -2
  34. package/dist/src/report.d.ts +0 -15
  35. package/dist/src/settings.d.ts +0 -5
  36. package/dist/src/types.d.ts +0 -110
  37. package/dist/src/utils.d.ts +0 -28
  38. package/dist/src/valid.d.ts +0 -8
  39. package/dist/test/_cli.d.ts +0 -5
  40. package/dist/types.d.ts +0 -110
  41. package/dist/utils.d.ts +0 -28
  42. package/dist/valid.d.ts +0 -8
  43. package/jestconfig.json +0 -14
  44. package/lib/HelloWorld.d.ts +0 -3
  45. package/lib/HelloWorld.js +0 -11
  46. package/lib/_api.js +0 -91
  47. package/lib/_api.js.map +0 -1
  48. package/lib/_cli.js +0 -434
  49. package/lib/_cli.js.map +0 -1
  50. package/lib/_data.js +0 -425
  51. package/lib/_data.js.map +0 -1
  52. package/lib/analyze.d.ts +0 -3
  53. package/lib/analyze.js +0 -69
  54. package/lib/analyze.js.map +0 -1
  55. package/lib/api.d.ts +0 -34
  56. package/lib/api.js +0 -117
  57. package/lib/api.js.map +0 -1
  58. package/lib/cli.d.ts +0 -1
  59. package/lib/cli.js +0 -386
  60. package/lib/cli.js.map +0 -1
  61. package/lib/cohesive.d.ts +0 -4
  62. package/lib/cohesive.js +0 -132
  63. package/lib/cohesive.js.map +0 -1
  64. package/lib/compact.d.ts +0 -4
  65. package/lib/compact.js +0 -183
  66. package/lib/compact.js.map +0 -1
  67. package/lib/constants.js +0 -367
  68. package/lib/constants.js.map +0 -1
  69. package/lib/data.js +0 -188
  70. package/lib/data.js.map +0 -1
  71. package/lib/equal.d.ts +0 -4
  72. package/lib/equal.js +0 -59
  73. package/lib/equal.js.map +0 -1
  74. package/lib/features.js +0 -19
  75. package/lib/features.js.map +0 -1
  76. package/lib/geofeature.js +0 -112
  77. package/lib/geofeature.js.map +0 -1
  78. package/lib/index.d.ts +0 -5
  79. package/lib/index.js +0 -11
  80. package/lib/index.js.map +0 -1
  81. package/lib/minority.d.ts +0 -3
  82. package/lib/minority.js +0 -61
  83. package/lib/minority.js.map +0 -1
  84. package/lib/political.d.ts +0 -7
  85. package/lib/political.js +0 -88
  86. package/lib/political.js.map +0 -1
  87. package/lib/preprocess.d.ts +0 -4
  88. package/lib/preprocess.js +0 -101
  89. package/lib/preprocess.js.map +0 -1
  90. package/lib/report.d.ts +0 -14
  91. package/lib/report.js +0 -817
  92. package/lib/report.js.map +0 -1
  93. package/lib/sample.d.ts +0 -1
  94. package/lib/sample.js +0 -32
  95. package/lib/sample.js.map +0 -1
  96. package/lib/scorecard.d.ts +0 -4
  97. package/lib/scorecard.js +0 -237
  98. package/lib/scorecard.js.map +0 -1
  99. package/lib/settings.d.ts +0 -5
  100. package/lib/settings.js +0 -18
  101. package/lib/settings.js.map +0 -1
  102. package/lib/types.d.ts +0 -125
  103. package/lib/types.js +0 -7
  104. package/lib/types.js.map +0 -1
  105. package/lib/utils.d.ts +0 -20
  106. package/lib/utils.js +0 -223
  107. package/lib/utils.js.map +0 -1
  108. package/lib/valid.d.ts +0 -5
  109. package/lib/valid.js +0 -230
  110. package/lib/valid.js.map +0 -1
  111. package/main.js +0 -4
  112. package/src/_api.ts +0 -121
  113. package/src/_data.ts +0 -595
  114. package/src/analyze.ts +0 -92
  115. package/src/cohesive.ts +0 -156
  116. package/src/compact.ts +0 -208
  117. package/src/constants.ts +0 -371
  118. package/src/equal.ts +0 -75
  119. package/src/geofeature.ts +0 -138
  120. package/src/index.ts +0 -6
  121. package/src/minority.ts +0 -70
  122. package/src/political.ts +0 -114
  123. package/src/preprocess.ts +0 -132
  124. package/src/report.ts +0 -1022
  125. package/src/settings.ts +0 -20
  126. package/src/types.ts +0 -185
  127. package/src/utils.ts +0 -245
  128. package/src/valid.ts +0 -275
  129. package/tsconfig.json +0 -25
  130. package/tslint.json +0 -3
  131. package/types/polygon-clipping/index.d.ts +0 -1
  132. package/webpack.config.js +0 -73
package/lib/preprocess.js DELETED
@@ -1,101 +0,0 @@
1
- "use strict";
2
- //
3
- // PREPROCESS DATA
4
- //
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const U = require("./utils");
7
- // NOTE - Do preprocessing separately, so the constructor returns quickly.
8
- function doPreprocessData(s) {
9
- // If necessary, do one-time preprocessing
10
- if (!s.bOneTimeProcessingDone) {
11
- doPreprocessCountyFeatures(s);
12
- doPreprocessCensus(s);
13
- doPreprocessElection(s);
14
- s.bOneTimeProcessingDone = true;
15
- }
16
- // Invert the plan by district ID
17
- s.plan.invertPlan();
18
- // Create a map of geoIDs to feature IDs
19
- s.features.mapGeoIDsToFeatureIDs();
20
- }
21
- exports.doPreprocessData = doPreprocessData;
22
- // CREATE A FIPS CODE TO COUNTY NAME LOOKUP
23
- function doPreprocessCountyFeatures(s) {
24
- for (let i = 0; i < s.counties.nCounties; i++) {
25
- let county = s.counties.countyByIndex(i);
26
- let fips = s.counties.propertyForCounty(county, 'COUNTYFP');
27
- let name = s.counties.propertyForCounty(county, 'NAME');
28
- s.counties.mapFIPSToName(fips, name);
29
- }
30
- }
31
- // ANALYZE THE CENSUS BY COUNTY
32
- function doPreprocessCensus(s) {
33
- // The county-splitting analytic needs the following info, using NC as an example:
34
- // '_stateTotal' = The total state population, e.g., 9,535,483 for NC's 2010 Census
35
- // 'totalByCounty' = The total population by county FIPS code
36
- let totalByCounty = {};
37
- // NOTE - This works w/o GEOIDs, because you're looping over all features.
38
- for (let i = 0; i < s.features.nFeatures(); i++) {
39
- let f = s.features.featureByIndex(i);
40
- let geoID = s.features.geoIDForFeature(f);
41
- let value = s.features.fieldForFeature(f, "CENSUS" /* CENSUS */, "Tot" /* TotalPop */);
42
- // Sum total population across the state
43
- s.state.totalPop += value;
44
- // Get the county FIPS code for the feature
45
- let county = U.parseGeoID(geoID)['county'];
46
- let countyFIPS = U.getFIPSFromCountyGeoID(county);
47
- // If a subtotal for the county doesn't exist, initialize one
48
- if (!(U.keyExists(countyFIPS, totalByCounty))) {
49
- totalByCounty[countyFIPS] = 0;
50
- }
51
- // Sum total population by county
52
- totalByCounty[countyFIPS] += value;
53
- }
54
- // NOTE - The above could be replaced, if I got totals on county.geojson.
55
- // 'target_size': 733499, # calc as total / districts
56
- let targetSize = Math.round(s.state.totalPop / s.state.nDistricts);
57
- // Find counties that are bigger than the target district size.
58
- // 'too_big' = The counties that are bigger than a district, e.g., ['Mecklenburg', 'Wake']
59
- // 'too_big_fips' = Their FIPS codes, e.g., ['119', '183']
60
- // 'expected_splits' = The # of counties that are bigger than a single district, e.g., 2
61
- // 'expected_affected' = The # of people whose district must be split, e.g., 353,623
62
- let tooBigFIPS = [];
63
- let tooBigName = [];
64
- let expectedSplits = 0;
65
- let expectedAffected = 0;
66
- // Create a FIPS code-ordinal map
67
- // Get the county FIPS codes
68
- let fipsCodes = U.getObjectKeys(totalByCounty);
69
- // Sort the results
70
- fipsCodes = fipsCodes.sort();
71
- // Create the ID-ordinal map
72
- for (let i in fipsCodes) {
73
- s.counties.index[fipsCodes[i]] = Number(i);
74
- }
75
- // Loop over the counties
76
- for (let county in fipsCodes) {
77
- let fipsCode = fipsCodes[county];
78
- let countyAffected = 0;
79
- // Find the number of required splits, assuming target district size.
80
- let rawQuotient = totalByCounty[fipsCode] / (targetSize + 1);
81
- let remainder = rawQuotient % 1;
82
- let quotient = rawQuotient - remainder;
83
- let countySplits = quotient;
84
- if (countySplits > 0) {
85
- countyAffected = totalByCounty[fipsCode] % targetSize;
86
- tooBigFIPS.push(fipsCode);
87
- tooBigName.push(s.counties.nameFromFIPS(fipsCode));
88
- }
89
- expectedSplits += countySplits;
90
- expectedAffected += countyAffected;
91
- }
92
- s.state.tooBigFIPS = tooBigFIPS;
93
- s.state.tooBigName = tooBigName;
94
- s.state.expectedSplits = expectedSplits;
95
- s.state.expectedAffected = expectedAffected;
96
- }
97
- // PREPROCESS ELECTION RESULTS
98
- function doPreprocessElection(s) {
99
- console.log("TODO - Preprocessing election data ...");
100
- }
101
- //# sourceMappingURL=preprocess.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"preprocess.js","sourceRoot":"","sources":["../src/preprocess.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,kBAAkB;AAClB,EAAE;;AAGF,6BAA6B;AAO7B,0EAA0E;AAC1E,SAAgB,gBAAgB,CAAC,CAAmB;IAClD,0CAA0C;IAC1C,IAAI,CAAC,CAAC,CAAC,sBAAsB,EAAE;QAC7B,0BAA0B,CAAC,CAAC,CAAC,CAAC;QAC9B,kBAAkB,CAAC,CAAC,CAAC,CAAC;QACtB,oBAAoB,CAAC,CA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IAAI,SAAS,EAAE;QAC5B,IAAI,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,cAAc,GAAG,CAAC,CAAC;QAEvB,qEAAqE;QACrE,IAAI,WAAW,GAAG,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;QAC7D,IAAI,SAAS,GAAG,WAAW,GAAG,CAAC,CAAC;QAChC,IAAI,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAC;QACvC,IAAI,YAAY,GAAG,QAAQ,CAAC;QAE5B,IAAI,YAAY,GAAG,CAAC,EAAE;YACpB,cAAc,GAAG,aAAa,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC;YACtD,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC1B,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;SACpD;QAED,cAAc,IAAI,YAAY,CAAC;QAC/B,gBAAgB,IAAI,cAAc,CAAC;KACpC;IAED,CAAC,CAAC,KAAK,CAAC,UAAU,GAAG,UAAU,CAAC;IAChC,CAAC,CAAC,KAAK,CAAC,UAAU,GAAG,UAAU,CAAC;IAChC,CAAC,CAAC,KAAK,CAAC,cAAc,GAAG,cAAc,CAAC;IACxC,CAAC,CAAC,KAAK,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;AAC9C,CAAC;AAGD,8BAA8B;AAE9B,SAAS,oBAAoB,CAAC,CAAmB;IAC/C,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;AACxD,CAAC"}
package/lib/report.d.ts DELETED
@@ -1,14 +0,0 @@
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 doPrepareScorecard(s: AnalyticsSession): any;
13
- export declare function doPrepareTestLog(s: AnalyticsSession): any;
14
- export {};