-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_db.py
591 lines (477 loc) · 28.6 KB
/
query_db.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
import psycopg2
import csv
import os
import sys
import traceback
from pprint import pprint as pp
import numpy as np
#
from logger_setup import logger
from database import login_info
import load_test_tables
if True: # constants, globals used for source code folding only
#used to initialize np array
NP_ROWS=1179 * 1179 #origin, dest pairs
NP_COLS=30 #aggregate columns required for each income group
#set to 'WARN' to capure only data loading issues. 'DEBUG' is verbose.
LOG_LEVEL='INFO'
#switches to limit queries for testing
LIMIT_ON = 10 #arbitrary, small >=1
LIMIT_OFF= 100000000 #arbitrary, large
LIMIT_STG = ' LIMIT {}'
TEST=True
if TEST:
NP_ROWS=4 #conforms to 'test' database
db='test'
prefix='test_' #used only for testing don't want to drop 'real' tables ;-)
load_test_tables.create_test_tables (create_single_scenario=True)
else:
prefix=''
conn = psycopg2.connect(database= db,
user=login_info['user'],
password=login_info['password']
)
curs = conn.cursor()
if True: #column and table name components (stiched together to id columns)
scenarios=['yesred_nohwy', 'yesred_yeshwy', 'nored_nohwy', 'nored_nohwy']
incomes=['inc1', 'inc2', 'inc3', 'inc4', 'inc5']
rail_modes=['wrail', 'wcrail', 'drail', 'dcrail']
bus_modes=['wexpbus', 'wbus', 'dexpbus', 'dbus']
drive_modes=['da', 'sr2', 'sr3']
purposes_pk=['hbw', 'nhbw']
purposes_op=['obo', 'hbs', 'hbo']
purposes = purposes_pk + purposes_op
#Some trip purposes inherently involve a round trip, others one way.
# Home-based trips are assumed round-trip
purposes_round_trip=['hbw', 'hbo', 'hbs']
purposes_one_way=['obo', 'nhbw']
#transit metrics. These exclude fares (picked up from fares_fares table)
transit_time_metrics=['xferwaittime', 'walktime', 'railtime', 'initialwaittime', 'bustime', 'autotime']
transit_other_metrics=['autodistance']
transit_metrics=transit_time_metrics + transit_other_metrics
occupancy_hwy_loaded=['hov', 'sov']
occupancy_hwy_tod=['sov', 'hov2', 'hov3']
tod_hwy_loaded = ['am', 'pm', 'md', 'nt']
tod_transit_times=['pk', 'op']
tod_fares=tod_transit_times
metrics=['toll', 'time', 'distance']
#mappings
purpose_peak_flag={} #mapped to abbreviations in tables
for p in purposes_pk:
purpose_peak_flag[p] = 'pk'
for p in purposes_op:
purpose_peak_flag[p] = 'op'
def aggregate_bus_rail_fares(scenario=None,
income=None,
purposes=purposes,
purposes_round_trip=purposes_round_trip,
#purpose_peak_flag=purpose_peak_flag,
bus_modes=bus_modes,
rail_modes=rail_modes,
np_rows=NP_ROWS):
" rail/bus costs = SUM((peak trips * peak fare) + (op trips * op fare))"
"""
The main assumption is that work-related trips are on peak, and others are off. Here are the mappings:
purposes_pk=[('hbw', 1), ('nhbw', 2)]
purposes_op=[('obo', 3), ('hbs', 4), ('hbo', 5)]
The mode_choice_od table disaggregates to income, mode, purpose. For instance, we have data for
trips from home to work, walking to the express bus, on-peak for each OD pair. From the fares_fares table,
we know the fare for the express bus on-peak.
So we can simply aggregate across all the mode choice/purpose pairs to capture all trips associated with some
income group and assign the correct fair to each.
We do this by coming up with a bunch of SELECT statements like this pair:
'--adding bus_rail_fares for hbw. wexpbus - outbound leg
SELECT DISTINCT
test_fares_fares.origin,
test_fares_fares.dest,
test_yesred_nohwy_mode_choice_od.hbw_inc1_wexpbus * test_fares_fares.wexpbus_pk
FROM
test_yesred_nohwy_mode_choice_od , test_fares_fares
WHERE
test_yesred_nohwy_mode_choice_od.origin=test_fares_fares.origin AND
test_fares_fares.dest=test_yesred_nohwy_mode_choice_od.dest
ORDER BY
test_fares_fares.origin, test_fares_fares.dest
--adding bus_rail_fares for hbw. wexpbus - return leg
SELECT DISTINCT
test_fares_fares.origin,
test_fares_fares.dest,
test_yesred_nohwy_mode_choice_od.hbw_inc1_wexpbus * test_fares_fares.wexpbus_pk
FROM
test_yesred_nohwy_mode_choice_od , test_fares_fares
WHERE
test_yesred_nohwy_mode_choice_od.dest=test_fares_fares.origin AND
test_yesred_nohwy_mode_choice_od.origin=test_fares_fares.dest
ORDER BY
test_fares_fares.origin, test_fares_fares.dest
"""
#general info for this metric
topic = 'bus_rail_fares'
trips_table = '{}mode_choice_od'.format(scenario)
metrics_table= '{}fares_fares'.format(prefix)
logger.info('Beginning aggregation of {} data'.format(topic))
#initialize null np array
npa=np.zeros(((np_rows-1)**2, 3)) #orig, dest, value
fresh_npa_array=True
for purpose in purposes:
#peak or off peak as f(purpose)
pk_flag=purpose_peak_flag[purpose]
#round trip of one-way (round trip for home based journeys)?
trip_legs=['outbound']
if purpose in purposes_round_trip:
trip_legs.append('return')
#calculate each leg of the trip separately
for trip_leg in trip_legs:
#loop thru appropriate modes (no fares w/ auto) and compose SELECT
for mode in bus_modes+rail_modes:
# --adding {topic} for {purpose}. {mode} - {trip_leg} leg\n'
select= '--adding {} for {}. {} - {} leg\n'.format(topic, purpose, mode, trip_leg)
# SELECT DISTINCT
select += 'SELECT DISTINCT\n '
# {metrics_table}.origin
select += '\t{}.origin,\n'.format(metrics_table)
# {metrics_table}.dest
select += '\t{}.dest,\n'.format(metrics_table)
# '{trips_table}.{purpose}_{income}_{mode} * {metrics_table}.{mode}_{pk_flag} '
stmt= '\t{}.{}_{}_{} * {}.{}_{}\n '
select+= stmt.format(trips_table, purpose, income, mode, metrics_table, mode, pk_flag)
# FROM {trips_table} , {metrics_table}
select += 'FROM \n\t {} , {} \n '.format( trips_table, metrics_table)
if trip_leg== 'outbound':
#use OD pairs from trip table same as metric table's
# WHERE {trips_table}.origin={metrics_table}.origin AND
select +='WHERE \n\t{}.origin={}.origin AND \n'.format( trips_table, metrics_table)
# {metrics_table}.dest={metrics_table}.dest)
select +='\t{}.dest={}.dest \n'.format(metrics_table, trips_table)
else:
#use transposed OD pairs from trip table (origin = metrics.dest, dest=metrics.origin)
# WHERE {trips_table}.dest={metrics_table}.origin AND
select +='WHERE \n\t{}.dest={}.origin AND \n'.format( trips_table, metrics_table)
# {metrics_table}.origin={metrics_table}.dest)
select +='\t{}.origin={}.dest \n'.format(trips_table, metrics_table)
# ORDER BY {metrics_table}.origin, {metrics_table}.dest
select +='ORDER BY \n\t{}.origin, {}.dest\n\n'.format( metrics_table, metrics_table)
logger.debug('executing:\n' + select)
#some queries can't succeed because there are not tables to support them e.g., autodistance for wexpbus mode
good_table=True
try:
curs.execute(select)
except:
msg = '--Nevermind. NOT adding {} for {}. {} - {} leg - no table to support it\n'
logger.debug(msg.format(topic, purpose, mode, trip_leg))
good_table=False
break
if good_table:
res=np.array(curs.fetchall())
#add the results to the last column of the aggregation array
#grab the OD columns for the first result
if fresh_npa_array:
npa=res
fresh_npa_array=False
#add only the last column of subsequent ones
else:
npa[:,-1]+=res[:,-1]
logger.info('writing data for {} {} for {}: {} {} {}'.format(pk_flag, topic, scenario, income, purpose, mode))
logger.debug('executing {}\n'.format(select))
return npa
def aggregate_transit_metrics(scenario=None,
income=None,
purposes=purposes,
purposes_round_trip=purposes_round_trip,
bus_modes=bus_modes,
rail_modes=rail_modes,
np_rows=NP_ROWS,
topic=None):
"""Aggregate time costs for mass transit. Roll up topics over purpose and mode.
Cf aggregate_bus_rail_fares() for more verbose documentation."""
"""Keeps topics (initialwaittime, bustime, etc.) separate for now. For final analysis it may makes sense to consolodate
waiting: initialwaittime, transfertime
bus time: wexpbus, dexpbus, wbus, dbus
train time: wrail, wcrail, drail, dcrail
... but it's easier to combine later than have to separate."""
"""Typical SELECTS
--adding xferwaittime for hbw. wbus - outbound leg
SELECT DISTINCT
test_yesred_nohwy_transit_od_timecost.origin,
test_yesred_nohwy_transit_od_timecost.dest,
test_yesred_nohwy_mode_choice_od.hbw_inc1_wbus * test_yesred_nohwy_transit_od_timecost.pk_wbus_xferwaittime
FROM
test_yesred_nohwy_mode_choice_od , test_yesred_nohwy_transit_od_timecost
WHERE
test_yesred_nohwy_mode_choice_od.origin=test_yesred_nohwy_transit_od_timecost.origin AND
test_yesred_nohwy_transit_od_timecost.dest=test_yesred_nohwy_mode_choice_od.dest
ORDER BY
test_yesred_nohwy_transit_od_timecost.origin, test_yesred_nohwy_transit_od_timecost.dest
--adding xferwaittime for hbw. wbus - return leg
SELECT DISTINCT
test_yesred_nohwy_transit_od_timecost.origin,
test_yesred_nohwy_transit_od_timecost.dest,
test_yesred_nohwy_mode_choice_od.hbw_inc1_wbus * test_yesred_nohwy_transit_od_timecost.pk_wbus_xferwaittime
--adding xferwaittime for hbw. wbus - return leg
SELECT DISTINCT
test_yesred_nohwy_transit_od_timecost.origin,
test_yesred_nohwy_transit_od_timecost.dest,
test_yesred_nohwy_mode_choice_od.hbw_inc1_wbus * test_yesred_nohwy_transit_od_timecost.pk_wbus_xferwaittime
FROM
test_yesred_nohwy_mode_choice_od , test_yesred_nohwy_transit_od_timecost
WHERE
test_yesred_nohwy_mode_choice_od.dest=test_yesred_nohwy_transit_od_timecost.origin AND
test_yesred_nohwy_mode_choice_od.origin=test_yesred_nohwy_transit_od_timecost.dest
ORDER BY
test_yesred_nohwy_transit_od_timecost.origin, test_yesred_nohwy_transit_od_timecost.dest
"""
#general info for this metric
trips_table = '{}mode_choice_od'.format(scenario)
metrics_table= '{}transit_od_timecost'.format(scenario)
logger.info('Beginning aggregation of {} data'.format(topic))
#initialize null np array
npa=np.zeros(((np_rows-1)**2, 3)) #orig, dest, value
fresh_npa_array=True
for purpose in purposes:
#peak or off peak as f(purpose)
pk_flag=purpose_peak_flag[purpose]
#round trip of one-way (round trip for home based journeys)?
trip_legs=['outbound']
if purpose in purposes_round_trip:
trip_legs.append('return')
#calculate each leg of the trip separately
for trip_leg in trip_legs:
#loop thru appropriate modes (no fares w/ auto) and compose SELECT
for mode in bus_modes+rail_modes:
# --adding {topic} for {purpose}. {mode} - {trip_leg} leg\n'
select= '--adding {} for {}. {} - {} leg\n'.format(topic, purpose, mode, trip_leg)
# SELECT DISTINCT
select += 'SELECT DISTINCT\n '
# {metrics_table}.origin
select += '\t{}.origin,\n'.format(metrics_table)
# {metrics_table}.dest
select += '\t{}.dest,\n'.format(metrics_table)
# '{trips_table}.{purpose}_{income}_{mode} * {metrics_table}.{pk_flag}_{mode}_{topic} '
stmt= '\t{}.{}_{}_{} * {}.{}_{}_{}\n '
select+= stmt.format(trips_table, purpose, income, mode, metrics_table, pk_flag, mode, topic)
#print(select)
# FROM {trips_table} , {metrics_table}
select += 'FROM \n\t {} , {} \n '.format( trips_table, metrics_table)
if trip_leg== 'outbound':
#use OD pairs from trip table same as metric table's
# WHERE {trips_table}.origin={metrics_table}.origin AND
select +='WHERE \n\t{}.origin={}.origin AND \n'.format( trips_table, metrics_table)
# {metrics_table}.dest={metrics_table}.dest)
select +='\t{}.dest={}.dest \n'.format(metrics_table, trips_table)
else:
#use transposed OD pairs from trip table (origin = metrics.dest, dest=metrics.origin)
# WHERE {trips_table}.dest={metrics_table}.origin AND
select +='WHERE \n\t{}.dest={}.origin AND \n'.format( trips_table, metrics_table)
# {metrics_table}.origin={metrics_table}.dest)
select +='\t{}.origin={}.dest \n'.format(trips_table, metrics_table)
# ORDER BY {metrics_table}.origin, {metrics_table}.dest
select +='ORDER BY \n\t{}.origin, {}.dest\n\n'.format( metrics_table, metrics_table)
logger.debug('executing:\n' +select)
#some queries can't succeed because there are not tables to support them e.g., autodistance for wexpbus mode
good_table=True
try:
curs.execute(select)
except:
msg = '--Nevermind. NOT adding {} for {}. {} - {} leg - no table to support it\n'
logger.debug(msg.format(topic, purpose, mode, trip_leg))
good_table=False
break
if good_table:
res=np.array(curs.fetchall())
#add the results to the last column of the aggregation array
#grab the OD columns for the first result
if fresh_npa_array:
npa=res
fresh_npa_array=False
#add only the last column of subsequent ones
else:
npa[:,-1]+=res[:,-1]
logger.info('writing data for {} {} for {}: {} {} {}'.format(pk_flag, topic, scenario, income, purpose, mode))
logger.debug('executing {}\n'.format(select))
a=1
return npa
def aggregate_hwy_costs(scenario=None,
income=None,
purposes=purposes,
purposes_round_trip=purposes_round_trip,
bus_modes=bus_modes,
rail_modes=rail_modes,
np_rows=NP_ROWS,
topic=None,
occupancy=None):
"""Aggregate costs for highway-only travel. Roll up topics over purpose, tod.
Keeps occupancies (sov, hov2, hov3) and costs (time, distance, toll) separate"""
"""Typical SELECTS
"""
"""
# hwy_toll_hov_am
# hbo_inc1_md_hov3"""
#general info for this metric
trips_table = '{}trips_purpose_income_tod_occ'.format(scenario)
metrics_table= '{}loaded_hwy_od_timecost'.format(scenario)
logger.info('Beginning aggregation of {} data'.format(topic))
#initialize null np array
npa=np.zeros(((np_rows-1)**2, 3)) #orig, dest, value
fresh_npa_array=True
for purpose in purposes:
#peak or off peak as f(purpose)
#pk_flag=purpose_peak_flag[purpose]
#round trip of one-way (round trip for home based journeys)?
trip_legs=['outbound']
if purpose in purposes_round_trip:
trip_legs.append('return')
#calculate each leg of the trip separately
for trip_leg in trip_legs:
#loop thru appropriate modes and compose SELECT
for mode in drive_modes:
for tod in tod_hwy_loaded:
# --adding {topic} for {purpose} {mode} {occupancy}- {trip_leg} leg\n'
select= '--adding {} for {} {} {} - {} leg\n'.format(topic, purpose, mode, occupancy, trip_leg)
# SELECT DISTINCT
select += 'SELECT DISTINCT\n '
# {metrics_table}.origin
select += '\t{}.origin,\n'.format(metrics_table)
# {metrics_table}.dest
select += '\t{}.dest,\n'.format(metrics_table)
if occupancy == 'hov2' or occupancy=='hov3':
occ_for_loaded = 'hov'
else:
occ_for_loaded='sov'
# '{trips_table}.{purpose}_{income}_{tod}_{occ} * {metrics_table}.hwy_{topic}_{occupancy}_{tod} '
stmt= '\t{}.{}_{}_{}_{} * {}.hwy_{}_{}_{}\n '
select+= stmt.format(trips_table, purpose, income, tod, occupancy, \
metrics_table, topic, occ_for_loaded, tod)
# FROM {trips_table} , {metrics_table}
select += 'FROM \n\t {} , {} \n '.format( trips_table, metrics_table)
if trip_leg== 'outbound':
#use OD pairs from trip table same as metric table's
# WHERE {trips_table}.origin={metrics_table}.origin AND
select +='WHERE \n\t{}.origin={}.origin AND \n'.format( trips_table, metrics_table)
# {metrics_table}.dest={metrics_table}.dest)
select +='\t{}.dest={}.dest \n'.format(metrics_table, trips_table)
else:
#use transposed OD pairs from trip table (origin = metrics.dest, dest=metrics.origin)
# WHERE {trips_table}.dest={metrics_table}.origin AND
select +='WHERE \n\t{}.dest={}.origin AND \n'.format( trips_table, metrics_table)
# {metrics_table}.origin={metrics_table}.dest)
select +='\t{}.origin={}.dest \n'.format(trips_table, metrics_table)
# ORDER BY {metrics_table}.origin, {metrics_table}.dest
select +='ORDER BY \n\t{}.origin, {}.dest\n\n'.format( metrics_table, metrics_table)
logger.debug('executing:\n' +select)
#some queries can't succeed because there are not tables to support them e.g., autodistance for wexpbus mode
good_table=True
try:
print(select)
curs.execute('END')
curs.execute(select)
conn.commit()
except :
exc_type, exc_value, exc_traceback = sys.exc_info()
msg = '--Nevermind. NOT adding {} for {}. {} - {} leg - no table to support it\n'
logger.debug(msg.format(topic, purpose, mode, trip_leg))
good_table=False
break
if good_table:
res=np.array(curs.fetchall())
#add the results to the last column of the aggregation array
#grab the OD columns for the first result
if fresh_npa_array:
npa=res
fresh_npa_array=False
#add only the last column of subsequent ones
else:
npa[:,-1]+=res[:,-1]
logger.info('writing data for {} {} for {}: {} {} {}'.format(occupancy, topic, scenario, income, purpose, mode))
logger.debug('executing {}\n'.format(select))
return npa
def add_to_master(npa=None, master_npa=None, master_col=None, include_od_cols=False):
"adds newly-acquired data column to the master array"
if include_od_cols:
#if we're going to add OD columns, that implies a new master, so override initialization
master_npa=np.zeros((len(npa), NP_COLS))
#load all three columns
for col in range(0, 3):
master_npa[:,col]=npa[:,col]
else:
#just load the values
master_npa[:,master_col]+=npa[:,-1]
return master_npa
def make_rollup_tables():
for scenario in scenarios:
scenario=prefix + scenario+'_'
for income in incomes:
#initialize np array
master_npa=np.zeros(((NP_ROWS-1)**2, NP_COLS))
master_col =0 #numpy column index
master_headers=['origin', 'dest']
#************** bus/rail fares **************#
#add orig, dest columns to master_npa, since this is the first one loaded
col_name = 'bus_rail_fares' #column name in master_npa array
routine=aggregate_bus_rail_fares #the method run to process this
#add orig, dest columns to master_npa, since this is the first one loaded
master_npa = add_to_master( master_npa=master_npa,
npa=routine(scenario=scenario, income=income),
master_col=master_col,
include_od_cols=True)
master_headers.append(col_name)
master_col +=3 #accounts for addition of od cols
logger.info('done rolling up {} {} {}'.format(scenario, income, col_name))
#**************bus/ time time, distance**************#
#create an aggregate across all puropses, times,
routine=aggregate_transit_metrics
for metric in transit_metrics: #walktime, etc.
col_name=metric
master_npa = add_to_master( master_npa=master_npa,
npa=routine(scenario=scenario, income=income, topic = metric),
master_col=master_col,
include_od_cols=False
)
master_headers.append(col_name)
master_col +=1
logger.info('done rolling up {} {} {}'.format(scenario, income, col_name))
#**************highway distance/time**************#
#create an aggregate across all puropses, times,
routine=aggregate_hwy_costs
for metric in metrics: #toll, distance, time
for occupancy in occupancy_hwy_tod: #sov, hov2, hov3
col_name=metric+ '_' +occupancy
master_npa = add_to_master( master_npa=master_npa,
npa=routine(scenario=scenario, income=income, topic = metric, occupancy=occupancy),
master_col=master_col,
include_od_cols=False
)
master_headers.append(col_name)
master_col +=1
logger.info('done rolling up {} {} {}'.format(scenario, income, col_name))
db_table_name='aggregated_{}_{}' .format(scenario, income)
create_db_table(tname=db_table_name, scenario=scenario, income=income,
data=master_npa, master_headers=master_headers)
logger.debug('Success in creating aggregate db table for {} {}'.format(scenario, income))
a=1
def create_db_table(tname=None, scenario=None, income=None, master_headers=None, data=None):
"creates a new table for this income group and scenario"
curs.execute('END')
sql = 'DROP TABLE IF EXISTS {}'.format(tname)
curs.execute(sql)
logger.debug('dropping table {}'.format(tname))
sql='CREATE TABLE IF NOT EXISTS {} ('.format(tname)
for col in master_headers:
sql+=' {} float,'.format(str(col))
sql = sql[:-1] + ');' #
print(sql)
curs.execute(sql)
conn.commit()
##TODO: should be a clever way simply to load the array (alt: dump file and load; also could just do INSERTs)
#for line in data:
#sql="INSERT INTO {} (".format(tname)
#for col in master_headers:
#sql+=' {}, '.format(col)
#sql=sql[:-2] + ") VALUES ("
#for value in line.split(','):
#sql+=' {},'.format(value)
#sql=sql[:-2] + ") "
#print(sql)
#curs.execute(sql)
pass
if __name__=='__main__':
make_rollup_tables()