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