-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetadata.py
268 lines (245 loc) · 10.1 KB
/
metadata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# data dirs
class DataDirs():
def __init__(self):
self.BASE = 'data'
self.GEN = 'gen'
self.ACW = 'acw'
self.CENSUS = 'census'
self.NO_SMALL = 'noSmall'
self.SMALL_3 = 'small3'
self.SMALL_4 = 'small4'
self.SMALL_5 = 'small5'
# data files
class DataFiles():
def __init__(self):
data_dirs = DataDirs()
# source files
self.THE_ONE_RING = f'{data_dirs.BASE}/theOneRing.csv'
self.SWALLOWED_VOTE_2020 = f'{data_dirs.BASE}/swallowedVoteSampler2020.csv'
self.TOTALS_BY_YEAR = f'{data_dirs.BASE}/totalsByYear.csv'
self.CENSUS_DIFF_2020 = f'{data_dirs.BASE}/censusDiff2020.csv'
# generated files
self.STATE_VOTE_WEIGHTS_PIVOT = 'stateVoteWeightsPivot.csv'
self.STATE_SWING_WEIGHTS_PIVOT = 'stateSwingWeightsPivot.csv'
self.GROUP_AGG_WEIGHTS_PIVOT = 'groupAggWeightsPivot.csv'
self.CENSUS_DIFF_2020_PIVOT = 'censusDiff2020Pivot.csv'
# columns in data files
class Columns():
def __init__(self):
self.ABBREV = 'Abbrev'
self.STATE = 'State'
self.ACW_GROUP = 'Civil War Grouping'
self.CENSUS_GROUP = 'Census Grouping'
self.GROUP = 'Group'
self.YEAR = 'Year'
self.EC_VOTES = 'EC votes'
self.EC_VOTES_NORM = 'EC votes normalized'
self.LOG_EC_VOTES = 'EC votes (log)'
self.EC_VOTES_FROM_POP = 'EC votes from pop vote'
self.VOTES_COUNTED = 'Votes counted'
self.VOTES_COUNTED_NORM = 'Votes counted normalized'
self.VOTES_COUNTED_PCT = 'Votes counted %'
self.VOTE_WEIGHT = 'Vote weight'
self.LOG_VOTE_WEIGHT = 'Vote weight (log)'
self.AVG_WEIGHT = 'Average weight'
self.VOTE_MARGIN = 'Vote margin'
self.SWING_WEIGHT = 'Swing weight'
self.PARTY = 'Party'
self.POP_PER_EC = 'Pop vote per EC vote'
# self.POP_PER_EC_SHORT = 'Pop per EC vote'
self.VOTES_COUNTED_PCT_TOTAL_POP = 'Votes counted as % of total population'
self.TOTAL_POP = 'Total population'
self.STATE_COUNT = 'State count'
self.STATES_IN_GROUP = 'States in group'
self.STATES_USING_POP = 'States using popular vote'
self.MOST_EC_VOTES = 'Most EC votes'
# figure dimensions
class FigDimensions():
def __init__(self):
self.MD5 = 650
self.MD6 = 788
self.MD7 = 924
self.MD8 = 1080
self.MD12 = 1610
def square(self, width):
return width
def crt(self, width):
return width * .75
def wide_door(self, width):
return width * 1.25
def narrow_door(self, width):
return width * 1.5
data_dirs = DataDirs()
cols = Columns()
# state groupings
ACW_GROUPS = ['Union', 'Confederate', 'Border', 'Postbellum']
CENSUS_GROUPS = ['Northeast', 'South', 'Midwest', 'West']
GROUP_LABEL_SMALL_3 = 'Small (3 ECV)'
GROUP_LABEL_SMALL_4 = 'Small (3-4 ECV)'
GROUP_LABEL_SMALL_5 = 'Small (3-5 ECV)'
GROUP_LABEL_SMALL_EQ4 = 'Small (4 ECV)'
GROUP_LABEL_SMALL_EQ5 = 'Small (5 ECV)'
DATA_DIR_TO_SMALL_GROUP_LABELS = {
data_dirs.SMALL_3: GROUP_LABEL_SMALL_3,
data_dirs.SMALL_4: GROUP_LABEL_SMALL_4,
data_dirs.SMALL_5: GROUP_LABEL_SMALL_5
}
GROUPS_FOR_DIR = {
data_dirs.ACW: ACW_GROUPS,
data_dirs.CENSUS: CENSUS_GROUPS
}
GROUPS_COL_FOR_DIR = {
data_dirs.ACW: cols.ACW_GROUP,
data_dirs.CENSUS: cols.CENSUS_GROUP
}
GROUP_COLORS = {
# ACW
'Union': '#5378BE',
'Confederate': '#E3B061',
'Border': '#69B190',
'Postbellum': '#DC5A48',
# Census
'Northeast': '#19D3F3',
'South': '#FFA15A',
'Midwest': '#00CC96',
'West': '#EB637A',
# Slave/Free
# 'Free (Union)': '#5378BE',
# 'Slave (Confederate)': '#E3B061',
# 'Slave (Border)': '#69B190',
'Free': '#A092FF',
'Slave': '#FFB6C1',
# Small
GROUP_LABEL_SMALL_3: '#A0A0A0',
GROUP_LABEL_SMALL_4: '#A0A0A0',
GROUP_LABEL_SMALL_5: '#A0A0A0',
# GROUP_LABEL_SMALL_3: '#6d7473',
# GROUP_LABEL_SMALL_4: '#6d7473',
# GROUP_LABEL_SMALL_5: '#6d7473',
# GROUP_LABEL_SMALL_EQ4: '#C0C0C0',
GROUP_LABEL_SMALL_EQ4: '#6d7473',
# GROUP_LABEL_SMALL_EQ5: '#E0E0E0',
GROUP_LABEL_SMALL_EQ5: '#61928f',
'3 ECV': '#2a2e2e',
# 'Small (3 ECV)': '#404d4c',
'4-5 ECV': '#6d7473',
# 'Small (4-5 ECV)': '#6d7473',
'6-8 ECV': '#61928f',
'9-13 ECV': '#57c8c3',
'14-19 ECV': '#43ded8',
'20+ ECV': '#2ffcf5',
# Nat'l
'Nat\'l Average': '#444444',
}
GROUP_ALT_COLORS = {
# ACW
'Union0': '#27408B',
'Union1': '#62B1F6',
'Union2': '#0276FD',
'Confederate0': '#B58517',
'Confederate1': '#FCB000',
'Confederate2': '#F99B36',
'Border0': '#98FB98',
'Border1': '#3CB371',
'Border2': '#ADFF2F',
'Postbellum0': '#FA8072',
'Postbellum1': '#8B0000',
'Postbellum2': '#DC143C',
# Census
'Northeast0': '#22316C',
'Northeast1': '#62B1F6',
'Northeast2': '#0276FD',
'South0': '#B58517',
'South1': '#FCB000',
'South2': '#F99B36',
'Midwest0': '#98FB98',
'Midwest1': '#3CB371',
'Midwest2': '#ADFF2F',
'West0': '#FA8072',
'West1': '#8B0000',
'West2': '#DC143C',
# Small
"Small0": '#9C9C9C',
"Small1": '#6A6A6A',
"Small2": '#888888',
}
# parties
PARTIES = ['Democrat', 'Republican', 'Whig', 'Whig-Harrison', 'Whig-White', 'Whig-Webster', 'National Republican',
'Anti-Masonic', 'Constitutional Union', 'American', 'Democrat-Breckenridge', 'Democrat-Douglas',
'Democrat-Unpledged', 'Populist', 'Progressive', 'Dixiecrat', 'American Independent', 'split']
PARTY_COLORS = {
'Democrat': 'Blue',
'Republican': 'Red',
'Biden': 'Blue',
'Trump': 'Red',
'Whig': 'Orange',
'Whig-Harrison': 'OrangeRed',
'Whig-White': 'Tomato',
'Whig-Webster': 'DarkOrange',
'National Republican': 'Crimson',
'Anti-Masonic': 'ForestGreen',
'Constitutional Union': 'Green',
'American': 'SpringGreen',
'Democrat-Breckenridge': 'LightBlue',
'Democrat-Douglas': 'DodgerBlue',
'Democrat-Unpledged': 'Cyan',
'Populist': 'SeaGreen',
'Progressive': 'DarkGreen',
'Dixiecrat': 'DarkTurquoise',
'American Independent': 'LightSkyBlue',
'split': 'Gray'
}
# just here for reference
COLORS_PLOTLY = ['#636EFA', '#FECB52', '#00CC96', '#AB63FA', '#FFA15A', '#19D3F3', '#FF6692', '#B6E880', '#FF97FF', '#EF553B']
# years
YEAR_0 = 1800
YEAR_N = 2020
# animations
FRAME_RATE = 1000
# historical events/eras/descriptions
EVENTS = [
{'year': 1788, 'name': 'First presidential election', 'desc': 'State legislatures/property-owning white males can vote'},
# {'year': 1800, 'name': 'Jeffersonian democracy'},
{'year': 1828, 'name': 'Jacksonian democracy begins', 'desc': 'Most tax/property-based voting restrictions eliminated'},
# {'year': 1857, 'name': 'Dred Scott v Sandford'},
{'year': 1861, 'name': '11 of 15 slave states secede, Civil War begins'},
# {'year': 1863, 'name': 'Emancipation Proclamation'},
{'year': 1865, 'name': 'Civil War ends, 13th Amendment', 'desc': 'Slavery abolished'},
# {'year': 1868, 'name': '14th Amendment'},
{'year': 1870, 'name': '15th Amendment', 'desc': 'Black male suffrage'},
{'year': 1877, 'name': 'Compromise of 1877', 'desc': 'Federal troops leave South, \'Redeemer\' govts take power'},
{'year': 1883, 'name': 'United States v. Stanley', 'desc': 'Civil Rights Act of 1875 deemed unconstitutional'},
# {'year': 1887, 'name': 'Dawes Act', 'desc': 'Suffrage to Native Americans who leave tribes'},
{'year': 1890, 'name': '\'Mississippi Plan\' begins', 'desc': 'Voting laws rewritten in Southern state constitutions'},
{'year': 1896, 'name': 'Plessy v Ferguson:', 'desc': '\'Separate but equal\' segregation is law of the land'},
# {'year': 1890, 'name': '\'Mississippi Plan\' concludes', 'desc': 'Georgia is final Southern state to rewrite constitution'},
{'year': 1903, 'name': 'Giles v Harris', 'desc': 'Alabama constitution\'s discriminatory voting requirements upheld'},
# {'year': 1909, 'name': 'NAACP founded'},
# {'year': 1912, 'name': 'First Internat\'l Eugenics Conference', 'desc': 'Internat\'l Federation of Eugenics Orgs founded'},
# {'year': 1915, 'name': 'Second KKK reborn in Georgia'},
{'year': 1920, 'name': '19th Amendment', 'desc': 'Women\'s suffrage'},
# {'year': 1921, 'name': 'Tulsa race massacre'},
{'year': 1924, 'name': 'Indian Citizenship Act', 'desc': 'Suffrage to Native Americans'},
# {'year': 1925, 'name': 'KKK peak membership at 4-5 million', 'desc': '15% of eligible population in KKK'},
# {'year': 1932, 'name': 'Tuskegee Syphilis Study'},
{'year': 1943, 'name': 'Magnuson Act', 'desc': 'Suffrage to Chinese immigrants'},
{'year': 1954, 'name': 'Brown v Board of Education', 'desc': 'Segregated public schools unconstitutional'},
# {'year': 1955, 'name': 'Emmett Till lynching, Montgomery bus boycott'},
# {'year': 1957, 'name': 'Civil Rights Act of 1957'},
# {'year': 1960, 'name': 'Civil Rights Act of 1960, Sit-ins'},
# {'year': 1961, 'name': '23rd Amendment', 'desc': 'Washington DC citizens can vote for President'},
# {'year': 1964, 'name': 'Civil Rights Act of 1964, 24th Amendment abolishes poll taxes'},
{'year': 1965, 'name': 'Voting Rights Act', 'desc': 'Voting protections for racial minorities'},
{'year': 1971, 'name': '26th Amendment', 'desc': 'Suffrage extended to 18-year-olds'},
{'year': 2006, 'name': 'Voting Rights Act extended for last time'},
{'year': 2013, 'name': 'Shelby County v Holder', 'desc': 'Voting Rights Act loses oversight power'},
]
ERAS = [
{'begin': 1788, 'end': 1861, 'name': 'Antebellum Period', 'color': '#4CF3CE'},
{'begin': 1861, 'end': 1865, 'name': 'Civil War', 'color': '#FFFF4D'},
{'begin': 1865, 'end': 1877, 'name': 'Reconstruction', 'color': '#ADFF2F'},
{'begin': 1877, 'end': 1896, 'name': 'Redemption', 'color': '#4CF3CE'},
{'begin': 1896, 'end': 1954, 'name': 'Jim Crow Era', 'color': '#FFFF4D'},
{'begin': 1954, 'end': 1968, 'name': 'Civil Rights Era', 'color': '#ADFF2F'},
{'begin': 1968, 'end': YEAR_N, 'name': 'Post Civil Rights Era', 'color': '#4CF3CE'},
]