-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeFilt.py
40 lines (37 loc) · 967 Bytes
/
timeFilt.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
import csv
import sys
if len(sys.argv) != 2:
print("Usage: %s maxGap" % sys.argv[0])
fields = None
csvFile = sys.stdin
reader = csv.reader(csvFile)
count = 0
lastrow = None
rows = []
watchout = -1
for idx, row in enumerate(reader):
if idx == 0:
fields = row
print(",".join(row))
elif idx == 1:
rows.append(row)
lastrow = row
else:
unixtime = fields.index("unixtime")
tid = fields.index("TripID")
if row[tid] == watchout:
lastrow = row
continue
if (lastrow[tid] == row[tid]):
if int(row[unixtime]) - int(lastrow[unixtime]) <= int(sys.argv[1]):
rows.append(row)
lastrow = row
else:
while rows[-1][tid] == row[tid]:
rows.pop()
watchout = row[tid]
lastrow = row
else:
lastrow = row
for r in rows:
print(",".join(r))