-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTimesProcessor.py
More file actions
96 lines (73 loc) · 1.88 KB
/
TimesProcessor.py
File metadata and controls
96 lines (73 loc) · 1.88 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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import csv
import sys
"""
Function: writeTimes
Writes a list of lists of swim meet data to a csv.
Input: (str) filename, (list of lists) alltimes
"""
def writeTimes(csvname, alltimes) :
with open(csvname, "wb") as csvfile:
w = csv.writer(csvfile, delimiter=",")
#print len(alltimes)
#print alltimes[33]
#print alltimes[34]
for ea in alltimes:
ea = ea.split(',')
#print ea
w.writerow(ea)
return
""" UNUSED
Function: toSeconds
Converts a string of time into a float
(e.g. "45.62" -> 45.62, "1:03.74" -> 63.74)
Input: (str) time
Output: (float) converted
"""
def toSeconds(time):
converted = 0
time = time[:-1]
timeList = time.split(".")
if ":" in timeList[0]:
minutes = timeList[0].split(":")
converted += (int(minutes[0]) * 60)
converted += float(minutes[1])
else:
converted += float(time)
return converted
"""
Function: readTextData
Read a HY-TEK text file and converts it to a list of lists.
Input: (str) filename
Output: (list of lists) results
"""
def readTextData(filename):
results = []
with open(filename, "rb") as txtfile:
t = txtfile.read()
t = t.split('\n')
for ea in t:
ea = ' '.join(ea.split())
ea = ','.join(ea.split())
results.append(ea)
return results
def main():
#toSeconds("56.50")
############################
# OPTION: take filename as a Python input
"""
filename = raw_input("Enter filename (must be .txt): ")
csvname = filename.split(".")[0] + ".csv"
print "Data from " + filename + " will be written to " + csvname
"""
############################
# OPTION: take filename as a command line argument
filename = sys.argv[1]
if (".txt" not in filename):
print "ERROR: file must be .txt"
csvname = filename.split(".")[0] + ".csv"
print "Data from " + filename + " will be written to " + csvname
alltimes = readTextData(filename)
writeTimes(csvname, alltimes)
return
if __name__ == "__main__":
main()