-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord.py
36 lines (29 loc) · 863 Bytes
/
record.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
import sys
import re
received = r"^received"
receiver = r"^receiver"
pulse = r"^pulse:"
space = r"^space:"
lastword = ''
signals = []
for line in sys.stdin:
words = line.strip().split(' ')
if re.search(received, words[0]) or re.search(receiver, words[0]):
continue
words[1] = int(words[1])
if re.search(space, words[0]) and words[1] == 152917:
continue
word = re.sub(pulse, 'pulse', words[0])
word = re.sub(space, 'space', word)
if lastword == word:
item = signals.pop()
item[1] = item[1] + words[1]
signals.append(item)
elif lastword == '' and word == 'space':
continue
else:
signals.append([word, words[1]])
lastword = word
for i in range(len(signals)):
if i < len(signals) - 1 or signals[i][0] != 'space':
print("{} {}".format(*signals[i]))