Commit 814d9f16 by Anne Rogers

updating

parent ed56d080
Showing with 40 additions and 26 deletions
......@@ -355,9 +355,13 @@ def countdown(tracts, num_districts, initial_percent_of_people, difference, tota
def percents_countdown(state_tract, num_districts, initial_percent_of_people, total_population):
def percents_countdown(state_tract, num_districts, initial_percent_of_people,
total_population):
'''
Purpose
For the purposes of the demo for the presentation. Finds a district_plan
and using the initial_percent_of_people of people, if there is none with
that percent, "initial_percent_of_people" - "difference" replaces the
"initial_percent_of_people" and the process keeps going till it finds one.
Inputs:
tracts:
......@@ -373,7 +377,6 @@ def percents_countdown(state_tract, num_districts, initial_percent_of_people, to
'''
percent_of_people = initial_percent_of_people
count_passed = 0
percent_greater_3 = False
passed_percent_of_people = None
passed_count = None
passed_district = None
......@@ -402,9 +405,13 @@ def percents_countdown(state_tract, num_districts, initial_percent_of_people, to
return passed_district, passed_district_id
def demo_countdown(tracts, num_districts, initial_percent_of_people, difference, total_population):
def demo_countdown(tracts, num_districts, initial_percent_of_people,
difference, total_population):
'''
Purpose
For the purposes of the demo for the presentation. Finds a district_plan
and using the initial_percent_of_people of people, if there is none with
that percent, "initial_percent_of_people" - "difference" replaces the
"initial_percent_of_people" and the process keeps going till it finds one.
Inputs:
tracts:
......@@ -420,7 +427,6 @@ def demo_countdown(tracts, num_districts, initial_percent_of_people, difference,
'''
percent_of_people = initial_percent_of_people
count_passed = 0
percent_greater_3 = False
passed_percent_of_people = None
passed_count = None
passed_district = None
......@@ -828,6 +834,7 @@ def find_largest_wasted(district_plan):
district_plan: a dictionary of dictionaries containing a tract plans in the state
Returns:
a interger, district number of the highest wasted district
'''
highest_wasted_num = 0
......@@ -859,25 +866,25 @@ def find_largest_wasted(district_plan):
return highest_wasted_district
def make_gap_lower(districts_dict, all_tracts, num_districts, used_tracts, goal, min_pop, max_pop):
def make_gap_lower(districts_dict, all_tracts, num_districts, used_tracts,
goal, min_pop, max_pop):
'''
Use the efficiency gap to construct an optimal district plan for a state that incorporates
a percentage of the population greater than or equal to the percent_of_people argument
If it is impossible to construct a district plan that meets the population threshold, return 0.
Use the efficiency gap to construct an optimal district plan using
the entire population. It looks through districts randomly to find
a district under "goal" or stops if has looked at districts 4500 times.
Inputs:
districts_dict
all_tracts
num_districts
used_tracts
goal
min_pop
max_pop
districts_dict: a dictionary of dictionaries containing a tract plans in the state
all_tracts: a dictionary of dictionaries containing the data on all tracts in the state
num_districts: an integer indicating the total number of districts to be constructed
used_tracts: a dictionary containing a geoid id, a string and it's district placeement, a interger
goal: a interger, the percent of the aimed efficiency_gap
min_pop: a interger, minimum population for a district
max_pop: a interger, maximum population for a district
Returns:
a dictionary of dictionaries containing a tract plans in the state
a interger,
'''
count = 0
gap = calculate_efficiency_gap_from_dict(districts_dict)
......@@ -943,16 +950,13 @@ def make_gap_lower(districts_dict, all_tracts, num_districts, used_tracts, goal,
printer.append(calculate_efficiency_gap_from_dict(districts_dict))
print(printer)
return districts_dict, count
return districts_dict
def completed_result(state, initial_percent_of_people=60, goal=5, special_name=''):
def completed_result(state, initial_percent_of_people=60, goal=5,
special_name=''):
'''
Gets the final districts plan for a entire state's population
and outputs district plan to a file.
......@@ -960,6 +964,7 @@ def completed_result(state, initial_percent_of_people=60, goal=5, special_name='
Inputs:
state: a string, state name captalized
initial_percent_of_people: a interger, the percent of people used for drawing
goal: a interger, the percent of the aimed efficiency_gap
special_name: a string, specialized names for district plan output file
Returns: a dictionary of dictionaries containing a tract plans in the state
......@@ -1008,7 +1013,6 @@ 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:
state: state name captalized (a string)
initial_percent_of_people: the percent of people used for drawing (a interger)
special_name: specialized names for district plan output file (a string)
......@@ -1020,6 +1024,16 @@ def all_states_result(initial_percent_of_people, special_name=''):
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.
Inputs:
districts_plan: a dictionary of dictionaries containing a tract plans in the state
Returns: a dictionary of dictionaries containing a tract plans in the state
'''
for num in districts_plan:
set_tracts = set(districts_plan[num]["tracts"])
......
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