Commit 95670f2c by Anne Rogers

a

parent 485d1ad9
Showing with 39 additions and 45 deletions
Please run git fetch
Before Preceeding Please run:
git fetch - all
sudo pip3 install pyshp
algorithms directory:
algorithms.py contains all the functions for constructing district plans by utilizing
......@@ -21,15 +22,17 @@ reading_shapes directory:
location_api.py uses the GPS coordinates of census tracts to determine which state they are in
and sorts them accordingly, using the LocationIQ API
RUN: [1] get_shapeRecs(shapefile_path), [2] create_state_tracts(shapeRecs)
state_set_json_files contains the partially completed tracts as dictionaries created by
location_api.py
state_set_json_files contains the sets of all items in a state
state_tracts_full_json_files contains the completed tract dictionaries created by get_combined.py
state_num.csv contains the state and number of districts
States.csv
states.json
tract.py - example of tract dict
util.py - contains helper functions for reading and writing CSVs, JSON, and pickle files
tracts1.json JSON file for helping location_api.py fun
tract.py example of tract dict
util.py contains helper functions for reading and writing CSVs, JSON, and pickle files
state_runs contains the partially completed tracts as dictionaries created by
location_api.py
Census_tract contains Census tract files
test_files contains files orginally used for testing
......
......@@ -728,9 +728,6 @@ def unused_tract_mapping(used_tracts, districts_dict, all_tracts, max_pop, min_p
Returns: a dictionary of dictionaries containing a tract plans in the state
'''
unused_tracts = get_unused_set(all_tracts, used_tracts)
while unused_tracts:
put_unused_in_district_plan(used_tracts, unused_tracts,
......@@ -952,24 +949,6 @@ def completed_result(state, initial_percent_of_people=60, goal=5,
return districts_dict
def all_states_result(initial_percent_of_people, special_name=''):
'''
Gets the final districts plan for a every state and outputs all district plans.
Inputs:
initial_percent_of_people: the percent of people used for drawing (a interger)
special_name: specialized names for district plan output file (a string)
Returns: nothing
'''
master_tracts = set_tracts()
for state in master_tracts:
print(state)
completed_result(state, initial_percent_of_people, special_name=special_name)
def district_plan_add_sets(districts_plan):
'''
Makes district value of the "tracts", key, into a set from a list.
......@@ -993,7 +972,8 @@ def district_plan_add_sets(districts_plan):
if __name__=="__main__":
num_args = len(sys.argv)
if num_args == 3:
# Demo code - Not longer Runable
if num_args == 0:
double_word = {"West_Virginia": "West Virginia",
"South_Carolina": "South Carolina",
"North_Dakota": "North_Dakota",
......@@ -1011,18 +991,21 @@ if __name__=="__main__":
sys.argv[1] = double_word[sys.argv[1]]
#print(sys.argv[1], sys.argv[2])
results = percents_countdown(sys.argv[1], int(sys.argv[2]))
district_plan = results[2]
# state_tracts, num_districts = set_tracts(state=sys.argv[1])
district_plan = recover_json("Dicts/" + sys.argv[1] +".json")
Strings = recover_json("Strings/" + sys.argv[1] +".json")
results_gap = calculate_efficiency_gap_from_dict(district_plan)
tracts, districts = set_tracts(state=sys.argv[1])
if results_gap < 0:
party = "Democrats"
else:
party = "Republicans"
advantage = abs(results_gap * districts)
print("The efficiency gap for this plan of {} is {}, which indicates that {} receive a districting advantage of {} seats.".format(sys.argv[1], results_gap, party, advantage))
create_json_file(district_plan,"district_plans/" + sys.argv[1])
#print(results_gap)
create_json_file(district_plan, sys.argv[1])
if num_args == 4:
if num_args > 1:
double_word = {"West_Virginia": "West Virginia",
"South_Carolina": "South Carolina",
"North_Dakota": "North_Dakota",
......@@ -1037,12 +1020,19 @@ if __name__=="__main__":
"District_of_Columbia": "District of Columbia"}
if sys.argv[1] in double_word:
sys.argv[1] = double_word[sys.argv[1]]
state = double_word[sys.argv[1]]
elif sys.argv[1] not in double_word:
state = sys.argv[1]
initial_percent_of_people=60
goal=5
special_name=''
better=False
district_plan = completed_result(state, initial_percent_of_people=60, goal=5,special_name='', better=False)
#print(sys.argv[1], sys.argv[2])
# state_tracts, num_districts = set_tracts(state=sys.argv[1])
district_plan = recover_json("Dicts/" + sys.argv[1] +".json")
Strings = recover_json("Strings/" + sys.argv[1] +".json")
results_gap = calculate_efficiency_gap_from_dict(district_plan)
tracts, districts = set_tracts(state=sys.argv[1])
if results_gap < 0:
......@@ -1052,6 +1042,7 @@ if __name__=="__main__":
advantage = abs(results_gap * districts)
# print(results_gap)
#print(district_plan)
print("The efficiency gap for this plan of {} is {}, which indicates that {} receive a districting advantage of {} seats.".format(sys.argv[1], results_gap, party, advantage))
......
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