Skip to content

Commit 4c0be9e

Browse files
committed
Increased number of extracted fields (fixed lack of altitude or speed data in some conversion)
1. Increased number of fields extracted from FIT files to include power, temperature, enhanced_speed, and enhanced_altiture (some Garmin devices do not include the default speed and altitude fields, only recording to the enhanced versions of these fields) 2. In conversion of FIT files to GPX with data only in the enhanced speed/altitude fields, augment the default column with data from enhanced column
1 parent 3a58e1d commit 4c0be9e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/fit2gpx.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@ def __init__(self, status_msg: bool = False):
2121
such as number of files converted.
2222
"""
2323
self.status_msg = status_msg
24-
# The names of the columns we will use in our points and laps DataFrame
24+
# The names of the columns will be used in our points and laps DataFrame
2525
# (use the same name as the field names in FIT file to facilate parsing)
2626
self._colnames_points = [
2727
'latitude',
2828
'longitude',
2929
'lap',
30-
'altitude',
3130
'timestamp',
31+
'altitude',
32+
'enhanced_altitude',
33+
'temperature',
3234
'heart_rate',
3335
'cadence',
3436
'speed',
35-
'power'
37+
'enhanced_speed',
38+
'power',
3639
]
3740

3841
self._colnames_laps = [
@@ -203,7 +206,13 @@ def fit_to_gpx(self, f_in, f_out):
203206
# Step 1: Convert FIT to pd.DataFrame
204207
df_laps, df_points = self.fit_to_dataframes(f_in)
205208

206-
# Step 2: Convert pd.DataFrame to GPX
209+
# Step 2: Fill gaps in data if FIT file recorded data only in enhanced altitude/speed columns:
210+
enhanced_fields = ['altitude', 'speed']
211+
for field in enhanced_fields:
212+
if df_points[field].count() == 0 and df_points[f'enhanced_{field}'].count() > 0:
213+
df_points[field].fillna(df_points[f'enhanced_{field}'], inplace=True)
214+
215+
# Step 3: Convert pd.DataFrame to GPX
207216
gpx = self.dataframe_to_gpx(
208217
df_points=df_points,
209218
col_lat='latitude',

0 commit comments

Comments
 (0)