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
ed56d080
authored
Mar 14, 2017
by
Anne Rogers
Browse files
Options
Browse Files
Download
Plain Diff
one last merge
parents
5042bba6
e5e5d70c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
2 deletions
README.txt
reading_shapes/util.py
README.txt
View file @
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
...
...
reading_shapes/util.py
View file @
ed56d080
...
...
@@ -4,7 +4,10 @@ import csv
def
create_json_file
(
dictionary
,
path_file_name
):
tract_str
=
str
(
dictionary
)
if
type
(
dictionary
)
!=
str
:
tract_str
=
str
(
dictionary
)
if
type
(
dictionary
)
==
str
:
tract_str
=
dictionary
with
open
(
path_file_name
+
".json"
,
'w'
)
as
json_file
:
json
.
dump
(
tract_str
,
json_file
)
...
...
@@ -22,4 +25,14 @@ def read_csv(path, file_name):
num_districts_states
[
row
[
'state'
]]
=
row
[
'num'
]
return
num_districts_states
def
color_csv
(
path
,
file_name
):
with
open
(
path
+
file_name
)
as
csvfile
:
colors_dict
=
{}
reader
=
csv
.
DictReader
(
csvfile
)
count
=
1
for
row
in
reader
:
colors_dict
[
count
]
=
row
[
'colors'
]
count
+=
1
return
colors_dict
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