Private
Public Access
1
0

small improvement tcx and fit detection

This commit is contained in:
Sander Roosendaal
2020-07-09 16:43:46 +02:00
parent 60e85c2876
commit ecb49a580e

View File

@@ -1535,38 +1535,36 @@ def handle_nonpainsled(f2, fileformat, summary=''):
# This routine should be used everywhere in views.py and mailprocessing.py
# Currently there is code duplication
def get_workouttype_from_fit(filename):
def get_workouttype_from_fit(filename,workouttype='water'):
fitfile = FitFile(filename,check_crc=False)
records = fitfile.messages
fittype = 'rowing'
workouttype = 'water'
for record in records:
if record.name == 'sport':
fittype = record.get_values()['sport'].lower()
try:
workouttype = mytypes.fitmappinginv[fittype]
except KeyError:
workouttype = 'other'
return workouttype
return workouttype
import rowingdata.tcxtools as tcxtools
def get_workouttype_from_tcx(filename):
def get_workouttype_from_tcx(filename,workouttype='water'):
d = tcxtools.tcx_getdict(filename)
tcxtype = 'rowing'
workouttype = 'water'
try:
tcxtype = d['Activities']['Activity']['@Sport'].lower()
if tcxtype == 'other':
tcxtype = 'rowing'
except KeyError:
tcxtype = 'rowing'
return workouttype
try:
workouttype = mytypes.garminmappinginv[tcxtype.upper()]
except KeyError:
workouttype = 'water'
return workouttype
return workouttype
@@ -1665,9 +1663,9 @@ def new_workout_from_file(r, f2,
# Get workout type from fit & tcx
if (fileformat == 'fit'):
workouttype = get_workouttype_from_fit(f2)
workouttype = get_workouttype_from_fit(f2,workouttype=workouttype)
if (fileformat == 'tcx'):
workouttype = get_workouttype_from_tcx(f2)
workouttype = get_workouttype_from_tcx(f2,workouttype=workouttype)
# handle non-Painsled by converting it to painsled compatible CSV
if (fileformat != 'csv'):