forked from cfpb/zip-backfill
/
test.py
63 lines (42 loc) · 2.18 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import argparse
import os
import random
import pick_rand
import Zip_Backfill
import Self_Check
import Google_Check
#command line parser
parser = argparse.ArgumentParser(description = 'Tests zip_backfill accuraccy on a number of rows randomly selected from every file, choose one flag')
parser.add_argument('input', help = 'OpenAddresses file to take rows from')
parser.add_argument('output', help = 'a file to write results to')
parser.add_argument('shape_file', help = 'a census ZCTA shape file')
parser.add_argument('number', help = 'the number of rows to test')
parser.add_argument('-g', '--google', help = 'use google geocode search, attach a file with a google API key')
parser.add_argument('-r', '--reverse', help = 'use a reverse google geocode search, attach a file with a google API key')
parser.add_argument('-z', '--zip', help = 'search google with zip code, attach a file with a google API key')
parser.add_argument('-m', '--mapbox', help = 'reverse geocode from the mapbox API, attach a file with a mapbox API key')
parser.add_argument('-o', '--openaddresses', help = 'check against zips in openaddresses, use a file with zips as input', action = 'store_true')
args = parser.parse_args()
#check that a flag is picked
#create temp file for storing data
temp_rand = random.randint(1000000,9999999)
print 'picks rows'
#open temp file and write in random rows
pick_rand.write_rows(args.input, temp_rand, args.number)
print 'load poly'
#load shape file
zips_load = Zip_Backfill.import_zip(args.shape_file)
if args.openaddresses:
print 'run test'
Self_Check.write_openaddresses_test(temp_rand, args.output, zips_load[0], zips_load[1])
else:
temp_backfill = random.randint(10000000,99999999)
print 'backfill'
Zip_Backfill.write_zip(temp_rand, temp_backfill, zips_load[0], zips_load[1])
print 'run test'
if args.google: write_test(temp_backfill, args.output, args.google, False, False, False)
if args.reverse: write_test(temp_backfill, args.output, args.reverse, True, False, False)
if args.zip: write_test(temp_backfill, args.output, args.zip, False, True, False)
if args.mapbox: write_test(temp_backfill, args.output, args.mapbox, False, False, True)
os.remove(temp_backfill)
os.remove(temp_rand)