-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpace-adjust.py
30 lines (23 loc) · 905 Bytes
/
pace-adjust.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 re
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename()
temp_file_path = file_path.replace(".tcx", "_corrected.tcx")
correct_distance = float(input('What is the shown distance on your treadmill (the correct one)?\n'))
wrong_distance = float(input('What is the shown distance on your smartwatch (the wrong one)?\n'))
correction_ratio = correct_distance / wrong_distance
file1 = open(file_path, 'r')
file2 = open(temp_file_path, 'w')
for line in file1:
if re.match(" <DistanceMeters>", line):
distance=re.findall(r'\d+\.\d+', line)
distance1=str(float(distance[0]))
distance_corrected=float(distance[0])*correction_ratio
distance2=str(distance_corrected)
file2.write(line.replace(distance1, distance2))
else:
file2.write(line)
file1.close()
file2.close()