generated from edgi-govdata-archiving/Template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
check_AllPrograms.py
73 lines (60 loc) · 2.07 KB
/
check_AllPrograms.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
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# coding: utf-8
import pdb
import sys, argparse
import sqlite3
from Region import Region
from csv import reader
def main(argv):
parser = argparse.ArgumentParser(
prog="check_AllPrograms.py",
description="Check active facilities for each region against"
" previous for gross discrepancies.",
)
parser.add_argument("-d", "--cds_file", required=True, help="The CDs to work with")
my_args = parser.parse_args()
found_errors = False
### While working through errors, return successful code
return found_errors
cds_filename = my_args.cds_file
state_cds = []
with open(cds_filename, "r") as read_obj:
csv_reader = reader(read_obj)
raw_state_cds = list(map(tuple, csv_reader))
state_cds = []
for state, cd in raw_state_cds:
cd = int(cd)
state_cds.append((state, cd))
conn = sqlite3.connect( "region.db" )
cursor = conn.cursor()
# if abs(current-previous)/previous > threshold
# declare a problem.
threshold = 0.4
problem_text = '{} - {} - {} - previous={} - current={} '
programs = ('CWA','CAA','RCRA')
for state, cd in state_cds:
if cd is None:
type = 'State'
else:
type = 'Congressional District'
region = Region( type=type, value=cd, state=state )
for program in programs:
current = region.get_active_facilities( program )
previous = region.get_active_facilities( program,
'active_facilities_previous' )
if previous < 30:
continue
if previous != 0:
if abs( current - previous ) / previous > threshold:
print( problem_text.format( state, cd, program, previous, current ))
found_errors = True
print ( "Found errors? {}".format(found_errors))
sys.exit(found_errors)
def usage():
print("Usage: check_AllPrograms.py -c -d cds_todo.csv ")
exit
if __name__ == "__main__":
if len(sys.argv) < 2:
usage()
else:
main(sys.argv[1])