Skip to content

Commit

Permalink
Merge pull request #205 from MihaMi27/TCX-GPX-Refactoring
Browse files Browse the repository at this point in the history
TCX/GPX Manipulation Refactorings
  • Loading branch information
firefly-cpp authored Dec 15, 2024
2 parents c1c96ba + 2f5bc2e commit aaf0228
Show file tree
Hide file tree
Showing 33 changed files with 309 additions and 114 deletions.
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,11 @@ from sport_activities_features.tcx_manipulation import TCXFile

# Class for reading TCX files
tcx_file=TCXFile()
data = tcx_file.read_one_file("path_to_the_file") # Represents data as dictionary of lists
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
data = tcx_file.extract_activity_data(tcx_exercise) # Represents data as dictionary of lists

# Alternative choice
data = tcx_file.read_one_file("path_to_the_file", numpy_array= True) # Represents data as dictionary of numpy.arrays
data = tcx_file.extract_activity_data(tcx_exercise, numpy_array= True) # Represents data as dictionary of numpy.arrays

```

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

# Read the file and generate a dictionary with
data = gpx_file.read_one_file("path_to_the_file") # Represents data as dictionary of lists
gpx_exercise = gpx_file.read_one_file("path_to_the_file")
data = gpx_file.extract_activity_data(gpx_exercise) # Represents data as dictionary of lists

# Alternative choice
data = gpx_file.read_one_file("path_to_the_file", numpy_array= True) # Represents data as dictionary of numpy.arrays
data = gpx_file.extract_activity_data(gpx_exercise, numpy_array= True) # Represents data as dictionary of numpy.arrays

```

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

# Read TCX file
tcx_file = TCXFile()
activity = tcx_file.read_one_file("path_to_the_file")
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
activity = tcx_file.extract_activity_data(tcx_exercise)

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

# Reading the TCX file
tcx_file = TCXFile()
activity = tcx_file.read_one_file("path_to_the_data")
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
activity = tcx_file.extract_activity_data(tcx_exercise)

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

# Read TCX file
tcx_file = TCXFile()
tcx_data = tcx_file.read_one_file("path_to_file")
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
tcx_data = tcx_file.extract_activity_data(tcx_exercise)

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

# Read TCX file
tcx_file = TCXFile()

integral_metrics = tcx_file.extract_integral_metrics("path_to_the_file")
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
integral_metrics = tcx_file.extract_integral_metrics(tcx_exercise)

print(integral_metrics)

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

#read TCX file
tcx_file = TCXFile()
tcx_data = tcx_file.read_one_file("path_to_the_file")
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
tcx_data = tcx_file.extract_activity_data(tcx_exercise)


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

# Reading the TCX file.
tcx_file = TCXFile()
activity = tcx_file.read_one_file('path_to_the_data')
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
activity = tcx_file.extract_activity_data(tcx_exercise)

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

# read TCX file (also works with GPX files)
tcx_file = TCXFile()
tcx_data = tcx_file.read_one_file("path_to_the_data")
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
tcx_data = tcx_file.extract_activity_data(tcx_exercise)

"""
Time interval = time before and after the start of an event
Expand Down Expand Up @@ -434,7 +443,8 @@ from sport_activities_features import ElevationIdentification
from sport_activities_features import TCXFile

tcx_file = TCXFile()
tcx_data = tcx_file.read_one_file('path_to_file')
tcx_exercise = tcx_file.read_one_file("path_to_the_file")
tcx_data = tcx_file.extract_activity_data(tcx_exercise)

elevations = ElevationIdentification(tcx_data['positions'])
"""Adds tcx_data['elevation'] = eg. [124, 21, 412] for each position"""
Expand Down
3 changes: 2 additions & 1 deletion examples/calculate_training_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

# Reading a TCX file.
tcx_file = TCXFile()
activity = tcx_file.read_one_file('../datasets/15.tcx')
tcx_exercise = tcx_file.read_one_file('../datasets/15.tcx')
activity = tcx_file.extract_activity_data(tcx_exercise)

timestamps = activity['timestamps']
heart_rates = activity['heartrates']
Expand Down
5 changes: 3 additions & 2 deletions examples/convert_gpx_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
output_file = 'path_to_output_file'

# Read GPX file
data = gpx_file.read_one_file(
input_file,
gpx_exercise = gpx_file.read_one_file(input_file)
data = gpx_file.extract_activity_data(
gpx_exercise,
) # Represents data as dictionary of lists

# Convert dictionary of lists to pandas DataFrame
Expand Down
5 changes: 3 additions & 2 deletions examples/convert_tcx_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
output_file = 'path_to_output_file'

# Read TCX file
data = tcx_file.read_one_file(
input_file,
tcx_exercise = tcx_file.read_one_file(input_file)
data = tcx_file.extract_activity_data(
tcx_exercise,
) # Represents data as dictionary of lists

# Convert dictionary of lists to pandas DataFrame
Expand Down
3 changes: 2 additions & 1 deletion examples/dead_end_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

# Reading the TCX file.
tcx_file = TCXFile()
activity = tcx_file.read_one_file('path_to_the_file')
tcx_exercise = tcx_file.read_one_file('path_to_the_file')
activity = tcx_file.extract_activity_data(tcx_exercise)

# Converting the read data to the array.
positions = np.array([*activity['positions']])
Expand Down
3 changes: 2 additions & 1 deletion examples/draw_map_with_identified_hills.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# read TCX file
tcx_file = TCXFile()

data = tcx_file.read_one_file('path_to_the_data')
tcx_exercise = tcx_file.read_one_file('path_to_the_data')
data = tcx_file.extract_activity_data(tcx_exercise)

# detect hills in data
Hill = HillIdentification(data['altitudes'], 30)
Expand Down
3 changes: 2 additions & 1 deletion examples/draw_map_with_identified_intervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# Reading the TCX file
tcx_file = TCXFile()
tcx_exercise = tcx_file.read_one_file('path_to_the_data')
(
activity_type,
positions,
Expand All @@ -17,7 +18,7 @@
timestamps,
heartrates,
speeds,
) = tcx_file.read_one_file('path_to_the_data').values()
) = tcx_file.extract_activity_data(tcx_exercise).values()

# Identifying the intervals in the activity by power and drawing the map
Intervals = IntervalIdentificationByPower(distances, timestamps, altitudes, 70)
Expand Down
3 changes: 2 additions & 1 deletion examples/extract_data_inside_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
# Reading all files in filder.
for file in all_files:
print('\rProgress: ', int(progress), '%', end='')
activity = tcx_file.read_one_file(file)
tcx_exercise = tcx_file.read_one_file(file)
activity = tcx_file.extract_activity_data(tcx_exercise)

# Converting the read data to arrays.
positions = np.array([*activity['positions']])
Expand Down
3 changes: 2 additions & 1 deletion examples/hill_data_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

# read TCX file
tcx_file = TCXFile()
activity = tcx_file.read_one_file('path_to_the_data')
tcx_exercise = tcx_file.read_one_file('path_to_the_data')
activity = tcx_file.extract_activity_data(tcx_exercise)

# detect hills in data
Hill = HillIdentification(activity['altitudes'], 30)
Expand Down
3 changes: 2 additions & 1 deletion examples/identify_interruptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

# read TCX file (also works with GPX files)
tcx_file = TCXFile()
tcx_data = tcx_file.read_one_file('path_to_the_data')
tcx_exercise = tcx_file.read_one_file('path_to_the_data')
tcx_data = tcx_file.extract_activity_data(tcx_exercise)

"""
Time interval = time before and after the start of an event
Expand Down
3 changes: 2 additions & 1 deletion examples/integral_metrics_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# read TCX file
tcx_file = TCXFile()
# extract integral metrics ans store it in dictionary
integral_metrics = tcx_file.extract_integral_metrics('path_to_the_file')
tcx_exercise = tcx_file.read_one_file('path_to_the_file')
integral_metrics = tcx_file.extract_integral_metrics(tcx_exercise)

print(integral_metrics)
3 changes: 2 additions & 1 deletion examples/interval_data_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

# Reading the TCX file
tcx_file = TCXFile()
activity = tcx_file.read_one_file('path_to_the_data')
tcx_exercise = tcx_file.read_one_file('path_to_the_data')
activity = tcx_file.extract_activity_data(tcx_exercise)

# Identifying the intervals in the activity by power
Intervals = IntervalIdentificationByPower(
Expand Down
3 changes: 2 additions & 1 deletion examples/missing_elevation_data_extraction.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from sport_activities_features import ElevationIdentification, TCXFile

tcx_file = TCXFile()
tcx_data = tcx_file.read_one_file('path_to_the_data')
tcx_exercise = tcx_file.read_one_file('path_to_the_data')
tcx_data = tcx_file.extract_activity_data(tcx_exercise)

elevations = ElevationIdentification(tcx_data['positions'])
"""Adds tcx_data['elevation'] = eg. [124, 21, 412] for each position"""
Expand Down
5 changes: 3 additions & 2 deletions examples/read_all_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
# Extracting the data of all files
activities = []
for file in all_files:
tcx_exercise = tcx_file.read_one_file(file)
activity = {'ID': os.path.splitext(os.path.split(file)[-1])[0]}
activity.update(tcx_file.read_one_file(file))
activity.update(tcx_file.extract_integral_metrics(file))
activity.update(tcx_file.extract_activity_data(tcx_exercise))
activity.update(tcx_file.extract_integral_metrics(tcx_exercise))

# Hills
Hill = HillIdentification(activity['altitudes'], 30)
Expand Down
3 changes: 2 additions & 1 deletion examples/read_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

# iterate through files and print total distance of activities
for i in range(len(all_files)):
activity = tcx_file.read_one_file(all_files[i])
tcx_exercise = tcx_file.read_one_file(all_files[i])
activity = tcx_file.extract_activity_data(tcx_exercise)
print('total distance: ', activity['total_distance'] / 1000)
3 changes: 2 additions & 1 deletion examples/read_gpx_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

# read GPX file
gpx_file = GPXFile()
data = gpx_file.read_one_file('path_to_the_file')
gpx_exercise = gpx_file.read_one_file('path_to_the_file')
data = gpx_file.extract_activity_data(gpx_exercise)
3 changes: 2 additions & 1 deletion examples/read_tcx_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

# read TCX file
tcx_file = TCXFile()
data = tcx_file.read_one_file('path_to_the_file')
tcx_exercise = tcx_file.read_one_file('path_to_the_file')
data = tcx_file.extract_activity_data(tcx_exercise)
3 changes: 2 additions & 1 deletion examples/weather_data_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# Read TCX file
tcx_file = TCXFile()
tcx_data = tcx_file.read_one_file('path_to_the_file')
tcx_exercise = tcx_file.read_one_file('path_to_the_file')
tcx_data = tcx_file.extract_activity_data(tcx_exercise)

# Configure visual crossing api key
# https://www.visualcrossing.com/weather-api
Expand Down
Loading

0 comments on commit aaf0228

Please sign in to comment.