-
Notifications
You must be signed in to change notification settings - Fork 0
/
SecuenceRecorder.py
30 lines (28 loc) · 1022 Bytes
/
SecuenceRecorder.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
import functools
def recordSecuences (newSecuences, fileName):
f = open(fileName, "w")
halfParsed = list(map( lambda sec: list(map(lambda instr: str(instr[0]) + '-' + str(round(instr[1])),sec)),newSecuences))
fullParsed = list(map(lambda hsec:functools.reduce(lambda b,x:b + ',' + x,hsec),halfParsed))
for i in fullParsed:
f.write(i)
f.write('\n')
f.close()
def readInstructions(fileName):
instructions = []
archivo = open(fileName, "r")
for line in archivo:
instructions.append(line)
archivo.close()
#Remove ending '\n' from strings
for i in range(0,len(instructions)):
instructions[i] = instructions[i].replace('\n', '')
#Parse lines of instructions to list of list of tuples with motor and velocity
parsedInstructions = []
for i in instructions:
velocitySeries = []
splitbycomma = i.split(',')
for j in splitbycomma:
splitbydash = j.split('-')
velocitySeries.append((int((splitbydash[0])), int(splitbydash[1])))
parsedInstructions.append(velocitySeries)
return parsedInstructions