-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadd_timing.py
More file actions
39 lines (37 loc) · 1.03 KB
/
add_timing.py
File metadata and controls
39 lines (37 loc) · 1.03 KB
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
#! /usr/bin/env python
import sys, csv, bz2#, os
def main(argv=None):
# dir_path = os.path.dirname(os.getcwd())
#print dir_path
if argv is None:
argv = sys.argv
argv.pop(0)
f = bz2.BZ2File(argv.pop(0), 'r')
print "reading bz2 timing file"
indb = csv.DictReader(f, dialect='excel-tab')
ns = indb.fieldnames[-14:]
idref = {}
for x in indb:
idref[x['NiteID']] = dict(zip(ns, [x[k] for k in ns]))
f.close()
print "reading databse"
f = open(argv.pop(0), 'rb')
indb = csv.DictReader(f, dialect='excel-tab')
col = argv.pop(0)
print "target column: "+col
ncols = [col + '_' + k for k in ns]
fn = indb.fieldnames + ncols
try:
out = open(argv.pop(0),'w')
except IndexError:
out = sys.stdout
outdb = csv.DictWriter(out, fieldnames=fn, dialect='excel-tab')
outdb.writeheader()
print "writing timing info to database"
for x in indb:
cdata = idref.get(x[col], {})
x.update(zip(ncols, [cdata.get(k, '') for k in ns]))
outdb.writerow(x)
f.close()
if __name__ == '__main__':
main()