Skip to content

Commit aaf0228

Browse files
authored
Merge pull request #205 from MihaMi27/TCX-GPX-Refactoring
TCX/GPX Manipulation Refactorings
2 parents c1c96ba + 2f5bc2e commit aaf0228

33 files changed

+309
-114
lines changed

README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,11 @@ from sport_activities_features.tcx_manipulation import TCXFile
154154

155155
# Class for reading TCX files
156156
tcx_file=TCXFile()
157-
data = tcx_file.read_one_file("path_to_the_file") # Represents data as dictionary of lists
157+
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
158+
data = tcx_file.extract_activity_data(tcx_exercise) # Represents data as dictionary of lists
158159

159160
# Alternative choice
160-
data = tcx_file.read_one_file("path_to_the_file", numpy_array= True) # Represents data as dictionary of numpy.arrays
161+
data = tcx_file.extract_activity_data(tcx_exercise, numpy_array= True) # Represents data as dictionary of numpy.arrays
161162

162163
```
163164

@@ -169,10 +170,11 @@ from sport_activities_features.gpx_manipulation import GPXFile
169170
gpx_file=GPXFile()
170171

171172
# Read the file and generate a dictionary with
172-
data = gpx_file.read_one_file("path_to_the_file") # Represents data as dictionary of lists
173+
gpx_exercise = gpx_file.read_one_file("path_to_the_file")
174+
data = gpx_file.extract_activity_data(gpx_exercise) # Represents data as dictionary of lists
173175

174176
# Alternative choice
175-
data = gpx_file.read_one_file("path_to_the_file", numpy_array= True) # Represents data as dictionary of numpy.arrays
177+
data = gpx_file.extract_activity_data(gpx_exercise, numpy_array= True) # Represents data as dictionary of numpy.arrays
176178

177179
```
178180

@@ -185,7 +187,8 @@ from sport_activities_features.plot_data import PlotData
185187

186188
# Read TCX file
187189
tcx_file = TCXFile()
188-
activity = tcx_file.read_one_file("path_to_the_file")
190+
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
191+
activity = tcx_file.extract_activity_data(tcx_exercise)
189192

190193
# Detect hills in data
191194
Hill = HillIdentification(activity['altitudes'], 30)
@@ -211,7 +214,8 @@ from sport_activities_features.tcx_manipulation import TCXFile
211214

212215
# Reading the TCX file
213216
tcx_file = TCXFile()
214-
activity = tcx_file.read_one_file("path_to_the_data")
217+
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
218+
activity = tcx_file.extract_activity_data(tcx_exercise)
215219

216220
# Identifying the intervals in the activity by power
217221
Intervals = IntervalIdentificationByPower(activity["distances"], activity["timestamps"], activity["altitudes"], 70)
@@ -231,7 +235,8 @@ from sport_activities_features import TCXFile
231235

232236
# Read TCX file
233237
tcx_file = TCXFile()
234-
tcx_data = tcx_file.read_one_file("path_to_file")
238+
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
239+
tcx_data = tcx_file.extract_activity_data(tcx_exercise)
235240

236241
# Configure visual crossing api key
237242
visual_crossing_api_key = "weather_api_key" # https://www.visualcrossing.com/weather-api
@@ -285,8 +290,8 @@ from sport_activities_features.tcx_manipulation import TCXFile
285290

286291
# Read TCX file
287292
tcx_file = TCXFile()
288-
289-
integral_metrics = tcx_file.extract_integral_metrics("path_to_the_file")
293+
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
294+
integral_metrics = tcx_file.extract_integral_metrics(tcx_exercise)
290295

291296
print(integral_metrics)
292297

@@ -299,7 +304,9 @@ from sport_activities_features.tcx_manipulation import TCXFile
299304

300305
#read TCX file
301306
tcx_file = TCXFile()
302-
tcx_data = tcx_file.read_one_file("path_to_the_file")
307+
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
308+
tcx_data = tcx_file.extract_activity_data(tcx_exercise)
309+
303310

304311
#configure visual crossing api key
305312
visual_crossing_api_key = "API_KEY" # https://www.visualcrossing.com/weather-api
@@ -351,7 +358,8 @@ from sport_activities_features.tcx_manipulation import TCXFile
351358

352359
# Reading the TCX file.
353360
tcx_file = TCXFile()
354-
activity = tcx_file.read_one_file('path_to_the_data')
361+
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
362+
activity = tcx_file.extract_activity_data(tcx_exercise)
355363

356364
# Converting the read data to arrays.
357365
positions = np.array([*activity['positions']])
@@ -381,7 +389,8 @@ Identify interruption events from a TCX or GPX file.
381389

382390
# read TCX file (also works with GPX files)
383391
tcx_file = TCXFile()
384-
tcx_data = tcx_file.read_one_file("path_to_the_data")
392+
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
393+
tcx_data = tcx_file.extract_activity_data(tcx_exercise)
385394

386395
"""
387396
Time interval = time before and after the start of an event
@@ -434,7 +443,8 @@ from sport_activities_features import ElevationIdentification
434443
from sport_activities_features import TCXFile
435444

436445
tcx_file = TCXFile()
437-
tcx_data = tcx_file.read_one_file('path_to_file')
446+
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
447+
tcx_data = tcx_file.extract_activity_data(tcx_exercise)
438448

439449
elevations = ElevationIdentification(tcx_data['positions'])
440450
"""Adds tcx_data['elevation'] = eg. [124, 21, 412] for each position"""

examples/calculate_training_load.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
# Reading a TCX file.
1313
tcx_file = TCXFile()
14-
activity = tcx_file.read_one_file('../datasets/15.tcx')
14+
tcx_exercise = tcx_file.read_one_file('../datasets/15.tcx')
15+
activity = tcx_file.extract_activity_data(tcx_exercise)
1516

1617
timestamps = activity['timestamps']
1718
heart_rates = activity['heartrates']

examples/convert_gpx_to_csv.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
output_file = 'path_to_output_file'
1313

1414
# Read GPX file
15-
data = gpx_file.read_one_file(
16-
input_file,
15+
gpx_exercise = gpx_file.read_one_file(input_file)
16+
data = gpx_file.extract_activity_data(
17+
gpx_exercise,
1718
) # Represents data as dictionary of lists
1819

1920
# Convert dictionary of lists to pandas DataFrame

examples/convert_tcx_to_csv.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
output_file = 'path_to_output_file'
1313

1414
# Read TCX file
15-
data = tcx_file.read_one_file(
16-
input_file,
15+
tcx_exercise = tcx_file.read_one_file(input_file)
16+
data = tcx_file.extract_activity_data(
17+
tcx_exercise,
1718
) # Represents data as dictionary of lists
1819

1920
# Convert dictionary of lists to pandas DataFrame

examples/dead_end_extraction.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
# Reading the TCX file.
1010
tcx_file = TCXFile()
11-
activity = tcx_file.read_one_file('path_to_the_file')
11+
tcx_exercise = tcx_file.read_one_file('path_to_the_file')
12+
activity = tcx_file.extract_activity_data(tcx_exercise)
1213

1314
# Converting the read data to the array.
1415
positions = np.array([*activity['positions']])

examples/draw_map_with_identified_hills.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
# read TCX file
77
tcx_file = TCXFile()
88

9-
data = tcx_file.read_one_file('path_to_the_data')
9+
tcx_exercise = tcx_file.read_one_file('path_to_the_data')
10+
data = tcx_file.extract_activity_data(tcx_exercise)
1011

1112
# detect hills in data
1213
Hill = HillIdentification(data['altitudes'], 30)

examples/draw_map_with_identified_intervals.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
# Reading the TCX file
1010
tcx_file = TCXFile()
11+
tcx_exercise = tcx_file.read_one_file('path_to_the_data')
1112
(
1213
activity_type,
1314
positions,
@@ -17,7 +18,7 @@
1718
timestamps,
1819
heartrates,
1920
speeds,
20-
) = tcx_file.read_one_file('path_to_the_data').values()
21+
) = tcx_file.extract_activity_data(tcx_exercise).values()
2122

2223
# Identifying the intervals in the activity by power and drawing the map
2324
Intervals = IntervalIdentificationByPower(distances, timestamps, altitudes, 70)

examples/extract_data_inside_area.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
# Reading all files in filder.
1717
for file in all_files:
1818
print('\rProgress: ', int(progress), '%', end='')
19-
activity = tcx_file.read_one_file(file)
19+
tcx_exercise = tcx_file.read_one_file(file)
20+
activity = tcx_file.extract_activity_data(tcx_exercise)
2021

2122
# Converting the read data to arrays.
2223
positions = np.array([*activity['positions']])

examples/hill_data_extraction.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
# read TCX file
66
tcx_file = TCXFile()
7-
activity = tcx_file.read_one_file('path_to_the_data')
7+
tcx_exercise = tcx_file.read_one_file('path_to_the_data')
8+
activity = tcx_file.extract_activity_data(tcx_exercise)
89

910
# detect hills in data
1011
Hill = HillIdentification(activity['altitudes'], 30)

examples/identify_interruptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
# read TCX file (also works with GPX files)
1111
tcx_file = TCXFile()
12-
tcx_data = tcx_file.read_one_file('path_to_the_data')
12+
tcx_exercise = tcx_file.read_one_file('path_to_the_data')
13+
tcx_data = tcx_file.extract_activity_data(tcx_exercise)
1314

1415
"""
1516
Time interval = time before and after the start of an event

0 commit comments

Comments
 (0)