-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmanager_tests.py
executable file
·101 lines (75 loc) · 2.94 KB
/
manager_tests.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#! /usr/bin/env python
import MapGardening
import optparse
usage = "usage: %prog [options]"
p = optparse.OptionParser(usage)
p.add_option('--place', '-p',
default="all"
)
p.add_option('--type', '-t',
default="raster",
help="type of analysis, 'raster' or 'proximity' (or 'all' for all types)"
)
p.add_option('--resolution', '-r',
default="all",
help="analysis resolution in metres (or 'all' for all resolutions)"
)
options, arguments = p.parse_args()
if options.place == "all":
places = MapGardening.get_all_places()
else:
placename = options.place
place = MapGardening.get_place(placename)
places = {placename: place}
# TODO: query the BlankSpotTableManager to see which types are present
possible_types = [
'raster',
'proximity',
]
if options.type == "all":
runtypes = possible_types
else:
runtypes = [options.type]
# TODO: query the BlankSpotTableManager to see which resolutions are present
possible_resolutions = [
#'250',
#'500',
'100',
'1000',
]
if options.resolution == "all":
resolutions = possible_resolutions
else:
resolutions = [options.resolution]
MapGardening.init_logging()
for placename in sorted(places.keys()):
#print "testing BlankSpotTableManager for", placename
print placename
MapGardening.init_db(places[placename]['dbname'])
bstm = MapGardening.BlankSpotTableManager()
#print "creating manager table"
#bstm.create_manager_table()
for runtype in runtypes:
for resolution in resolutions:
params = {
'runtype': runtype,
'resolution': resolution
}
#print "creating blankspot table"
#bst_obj = bstm.create_new_blankspot_table({'runtype': "raster", 'resolution': 250})
#print bst_obj.getTableName()
#print "fetching existing blankspot table", params['resolution'], params['runtype']
bst_objs = bstm.get_existing_blankspot_tables(params)
if len(bst_objs) > 0:
for bst_obj in bst_objs:
tablename = bst_obj.getTableName().strip()
blankcount = bst_obj.getBlankCount()
print '\t'.join((tablename, str(blankcount), str(bst_obj.run_start), str(bst_obj.run_finish)))
if blankcount <= 0:
print "deleting", tablename
bstm.remove_blankspot_table(bst_obj)
else:
print "existing table not found for", params['resolution'], params['runtype']
# end for resolutions
# end for runtypes
MapGardening.disconnect_db()