Skip to content

Commit

Permalink
Tried to translate all countries.
Browse files Browse the repository at this point in the history
  • Loading branch information
sahawut committed Mar 27, 2017
1 parent 741e6b7 commit 24c1ee1
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
64 changes: 64 additions & 0 deletions spew2synthia/county.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from datetime import datetime
import os
import sys

import aid
import conf
import spew
import us


def to_county_id(csv):
tokens = csv.split('/')
county = tokens[-1].split('_')[-1][:5]
return county


def translate(states):
path = 'logs/'
aid.mkdir(path)
with open(path + 'countries.' + str(datetime.now()), 'w') as common:
sys.stdout = common
sys.stderr = common
#print(states)
for state in states:
if state == 'input':
continue
aid.log_time('Translating ' + state)
try:
pp_csvs = spew.find_csvs(conf.pp_prefix, state)
countries = set([to_county_id(csv) for csv in pp_csvs])
print(countries, flush=True)
for county in countries:
try:
prefix = path + state + '/'+ county
stdout = prefix + '.out'
aid.mkdir(stdout)
if os.path.exists(stdout):
print(stdout, 'already exists. Delete it if you want to rerun.')
continue
aid.log_time('Translating ' + county)
sys.stdout = open(stdout, 'w')
sys.stderr = open(prefix + '.err', 'w')
us.translate(county)
except Exception as e:
aid.log_error(e)
finally:
aid.log_time()
sys.stdout = common
sys.stderr = common
except Exception as e:
aid.log_error(e)
finally:
aid.log_time()
sys.stdout = common
sys.stderr = common
aid.log_time('Done')


def test():
translate(['10'])


if __name__ == "__main__":
translate(os.listdir(conf.path_usa))
8 changes: 5 additions & 3 deletions spew2synthia/tests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import county
import us
import spew
import state


#us.test()
#spew.test()
state.test()
us.test()
spew.test()
state.test()
county.test()

0 comments on commit 24c1ee1

Please sign in to comment.