Commit 9e7d47e3 by Garrett Johnson

Merge branch 'master' of mit.cs.uchicago.edu:ajfriedman/election_district_drawing

parents 562daf7d ed56d080
algorithms directory:
algorithms.py contains all the functions for constructing district plans by utilizing
the efficiency gap
drawing.py (must be run using Python2) creates a basemap of the United States and maps color-
coded tracts (the color corresponding to their district) onto the basemap using Networkx
reading_shapes directory:
get_combined.py contains functions to convert shapefiles of census tracts, determine which tracts
are connected to each other, and analyze demographic data to estimate the number of Republicans and Democrats in each district
location_api.py uses the GPS coordinates of census tracts to determine which state they are in
and sorts them accordingly
and sorts them accordingly, using the LocationIQ API
state_set_json_files contains the partially completed tracts as dictionaries created by
location_api.py
state_tracts_full_json_files contains the completed tract dictionaries created by get_combined.py
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,8 +3,6 @@ import json
import ast
from util import create_json_file, recover_json
shapefile_path = "Census_tract/Tract_2010Census_DP1.shp"
def get_shapeRecs(shapefile_path):
......@@ -46,7 +44,7 @@ def get_connects_tracts(sf_connect):
dict_tracts = {}
for sh_num1, sh_num2 in sf_connect:
if sh_num1 not in dict_tracts:
dict_traics[sh_num1] = [sh_num2]
dict_tracts[sh_num1] = [sh_num2]
count += 1
if sh_num1 in dict_tracts:
if sh_num2 not in dict_tracts[sh_num1]:
......@@ -149,6 +147,8 @@ def gender_RD(record):
2012 exit poll data, found here: http://www.cnn.com/election/2012/results/race/president/
'''
total_population = record[6]
weight_R = 0
weight_D = 0
......@@ -160,18 +160,22 @@ def gender_RD(record):
weight_D += pop_female * -0.12
total_population_above_16 = pop_female + pop_male
if not total_population_above_16:
return 0.0
population_change = 1 - (total_population_above_16/total_population) + 1
weight_D = weight_D * population_change
weight_R = weight_R * population_change
add_weights = weight_R + weight_D
if not add_weights:
return 0.0
percent_RD =((add_weights)/(abs(weight_D)+weight_R))
return percent_RD
percent_RD =( (add_weights)/(abs(weight_D)+weight_R))
return percent_RD
def get_populations_RD(shapeRecs, connect_tracts, state_set):
......@@ -219,7 +223,6 @@ def get_populations_RD(shapeRecs, connect_tracts, state_set):
def create_state_tracts(shapeRecs):
'''
Recover the json files created in location_api.py that have sorted tracts by state
......@@ -261,4 +264,5 @@ def state_tracts_hard_coded(Master_tract_dicts):
Master_tract_dicts[state][new_connection]["connections"].append(tract)
single_state_dict = Master_tract_dicts[state]
create_json_file(single_state_dict, "state_tracts_full_json_files/" + state + "tract_dict")
return Master_tract_dicts
\ No newline at end of file
return Master_tract_dicts
......@@ -68,8 +68,7 @@ def hard_code(output=False):
"11001009700": "District of Columbia",
"15009990200": "Hawaii",
"23005990000": "Maine",
"26001990000":"Michigan",
"26001990000": "Michigan",
"26009990000": "Michigan",
"26157990000": "Michigan",
"28047990000": "Mississippi",
......
......@@ -35,3 +35,4 @@ def color_csv(path, file_name):
count += 1
return colors_dict
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment