Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Andrew Friedman
/
Fairly Draw Election Districts
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0122466b
authored
Mar 13, 2017
by
Anne Rogers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updating
parent
226c625d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
57 deletions
reading_shapes/get_combined.py
reading_shapes/location_api.py
reading_shapes/get_combined.py
View file @
0122466b
...
...
@@ -3,8 +3,6 @@ import json
import
ast
from
util
import
create_json_file
,
recover_json
# shapefile_path = "test_files/s_11au16.shp"
shapefile_path
=
"Census_tract/Tract_2010Census_DP1.shp"
def
get_shapeRecs
(
shapefile_path
):
...
...
@@ -12,32 +10,6 @@ def get_shapeRecs(shapefile_path):
shapeRecs
=
sf
.
shapeRecords
()
return
shapeRecs
# def get_coordinates_connects(shapeRecs):
# sf_connect = set()
# sf_dict = {}
# sf_state = {}
# # add state loop in
# # set_states
# for num in range(74002):
# # rec = int(shapeRecs[num].record[2])
# # print(shapeRecs[num].record)
# rec = shapeRecs[num].record[0]
# points = shapeRecs[num].shape.points
# # if rec in sf_state:
# #
# for point in points:
# if point in sf_dict:
# list_num = sf_dict[point]
# for past_num in list_num:
# if not past_num in sf_dict and not (past_num == rec):
# # if not past_num in sf_dict and (past_num-rec):
# sf_connect.add((rec,past_num))
# sf_connect.add((past_num,rec))
# sf_dict[point] += [rec]
# elif point not in sf_dict:
# sf_dict[point] = [rec]
# return sf_connect
def
get_states_connects
(
shapeRecs
,
state_set
):
sf_connects
=
set
()
dict_points
=
{}
...
...
@@ -73,12 +45,6 @@ def get_connects_traits(sf_connect):
dict_traits
[
sh_num1
]
.
append
(
sh_num2
)
return
dict_traits
# def get_connects(shapeRecs):
# dict_connect = get_coordinates_connects(shapeRecs)
# dict_tracts = get_connects_traits(dict_tracts)
# return dict_tracts
def
get_full_connects_state
(
shapeRecs
,
state_set
):
dict_connect
=
get_states_connects
(
shapeRecs
,
state_set
)
dict_tracts
=
get_connects_traits
(
dict_connect
)
...
...
@@ -154,9 +120,11 @@ def race_RD(record):
return
percent_RD
def
gender_RD
(
record
):
total_population
=
record
[
6
]
weight_R
=
0
weight_D
=
0
...
...
@@ -168,18 +136,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
):
...
...
@@ -223,22 +195,6 @@ def get_populations_RD(shapeRecs, connect_tracts, state_set):
# Needs fixing:
# Set instead of dictionary
# Sizes
# def create_tract(shapeRecs):
# connect_tracts = get_connects(shapeRecs)
# print("done with get connects")
# dict_tracts = get_populations_RD(shapeRecs,connect_tracts)
# print("done with get tracts")
# create_json_file(dict_tracts, "tracts" + "_run_1")
# print("json created")
# return dict_tracts
def
create_state_tracts
(
shapeRecs
):
state_tracts
=
{}
state_dict_of_sets
=
recover_json
(
"state_set_json_files/"
+
"Master_tract_sets.json"
)
...
...
@@ -276,4 +232,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
\ No newline at end of file
reading_shapes/location_api.py
View file @
0122466b
...
...
@@ -63,8 +63,7 @@ def hard_code(output=False):
"11001009700"
:
"District of Columbia"
,
"15009990200"
:
"Hawaii"
,
"23005990000"
:
"Maine"
,
"26001990000"
:
"Michigan"
,
"26001990000"
:
"Michigan"
,
"26009990000"
:
"Michigan"
,
"26157990000"
:
"Michigan"
,
"28047990000"
:
"Mississippi"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment