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
e5e5d70c
authored
Mar 14, 2017
by
Isaac Wink
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of mit.cs.uchicago.edu:ajfriedman/election_district_drawing
parents
781ce5d6
21c370a4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
5 deletions
reading_shapes/util.py
reading_shapes/util.py
View file @
e5e5d70c
...
...
@@ -4,15 +4,18 @@ 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
)
def
recover_json
(
json_file
):
with
open
(
json_file
)
as
json_tracts
:
str_tracts
=
json
.
load
(
json_tracts
)
dict_tracts
=
ast
.
literal_eval
(
str_tracts
)
return
dict_tracts
with
open
(
json_file
)
as
json_tracts
:
str_tracts
=
json
.
load
(
json_tracts
)
dict_tracts
=
ast
.
literal_eval
(
str_tracts
)
return
dict_tracts
def
read_csv
(
path
,
file_name
):
with
open
(
path
+
file_name
)
as
csvfile
:
...
...
@@ -22,3 +25,13 @@ 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