-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreformat_ant_choices.py
68 lines (59 loc) · 1.79 KB
/
reformat_ant_choices.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
import pandas as pd
import datetime
import numpy as np
from sys import argv
import argparse
IN_DIR = 'datasets/csv'
OUT_DIR = 'datasets/reformated_csv'
def reformat_counts(label, delim=None):
fname = 'counts%s.csv' % label
in_file = open('%s/%s' % (IN_DIR, fname))
out_file = open('%s/reformated_%s' % (OUT_DIR, fname), 'a')
split_func = None
if delim == None:
split_func = lambda x : x.split()
else:
split_func = lambda x : x.split(delim)
for line in in_file:
line = line.strip('\n')
line = line.split(',')
if line[0] == 'Year':
continue
#print line
year = int(line[0])
day = int(line[1])
hour = int(line[2])
minute = int(line[3])
second = float(line[4])
dt = datetime.datetime(int(line[0]), 1, 1)
delta = datetime.timedelta(days=day, hours=hour, minutes=minute, seconds=second)
dt += delta
dt = str(dt)
edge = None
for entry in line[5:]:
#entry = entry.split('-')
#entry = entry.split()
entry = split_func(entry)
#print entry
if len(entry) == 2 and entry[0] != '':
edge = entry
break
if edge == None:
continue
source = edge[0].strip()
dest = edge[1].strip()
out_file.write('%s, %s, %s\n' % (source, dest, dt))
in_file.close()
out_file.close()
def main():
parser = argparse.ArgumentParser()
parser.add_argument('labels', nargs='+')
parser.add_argument('-d', '--delim', default=None)
args = parser.parse_args()
labels = args.labels
delim = args.delim
for label in labels:
print label
reformat_counts(label, delim)
if __name__ == '__main__':
main()