-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
69 lines (53 loc) · 2.23 KB
/
main.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
69
import sys
import os
from parser.tcx import getMarker
from classes.tcxclasses import Course
course = Course();
#read
with open(sys.argv[1], "r") as file_input:
for line in file_input:
marker = str(getMarker(line))
if( marker != "" ):
course.update(marker, line)
course.finish();
is_header = True;
lap_count = 0;
lap = course.getLap(0)
tp_count = -1;
tp = 0;
#write
path = sys.argv[1]
path = os.path.normpath(path)
tokens = path.split(os.sep)
tokens[-1] = "fixed_"+tokens[-1]
tokens[0] = "/"+tokens[0]
path = os.path.join(*tokens)
with open(sys.argv[1], "r") as file_input:
with open(path, "w") as file_output:
for line in file_input:
if is_header :
if line.lstrip().startswith("<Trackpoint>"):
is_header = False
tp_count = tp_count + 1
tp = lap.getTrackPoint(tp_count);
if line.lstrip().startswith("<DistanceMeters>"):
line = "\t\t\t\t<DistanceMeters>"+str(lap.tot_dist)+"</DistanceMeters>\n"
if line.lstrip().startswith("<MaximumSpeed>"):
line = "\t\t\t\t<MaximumSpeed>"+str(lap.max_speed)+"</MaximumSpeed>\n"
else:
if line.lstrip().startswith("<Lap StartTime"):
lap_count = lap_count + 1;
lap = course.getLap(lap_count);
is_header = True;
tp_count = -1;
if line.lstrip().startswith("<Trackpoint>"):
tp_count = tp_count + 1
tp = lap.getTrackPoint(tp_count);
if line.lstrip().startswith("<DistanceMeters>"): #TrackPoint
course.dist += tp.speed
line = "\t\t\t\t\t\t<DistanceMeters>"+str(course.dist)+"</DistanceMeters>\n"
if line.lstrip().startswith("<ns3:Speed>"):
line = "\t\t\t\t\t\t\t<ns3:Speed>"+str(tp.speed)+"</ns3:Speed>\n"
if line.lstrip().startswith("<ns3:AvgSpeed>"):
line = "\t\t\t\t\t\t<ns3:AvgSpeed>"+str(lap.avg_speed)+"</ns3:AvgSpeed>\n"
file_output.write(line)