Private
Public Access
1
0

solve #564 adding fit and tcx tests

This commit is contained in:
Sander Roosendaal
2020-07-09 14:39:44 +02:00
parent 1a74291543
commit 60e85c2876
3 changed files with 84 additions and 1 deletions

View File

@@ -70,6 +70,7 @@ import zipfile
import pandas as pd
import numpy as np
import itertools
from fitparse import FitFile
import math
from rowers.tasks import (
handle_sendemail_unrecognized, handle_sendemail_breakthrough,
@@ -94,6 +95,7 @@ queuehigh = django_rq.get_queue('default')
from rowsandall_app.settings import SITE_URL
from rowers.mytypes import otwtypes,otetypes
from rowers import mytypes
from rowers.database import *
from rowers.opaque import encoder
@@ -1533,6 +1535,40 @@ 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):
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
import rowingdata.tcxtools as tcxtools
def get_workouttype_from_tcx(filename):
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'
try:
workouttype = mytypes.garminmappinginv[tcxtype.upper()]
except KeyError:
workouttype = 'water'
return workouttype
def new_workout_from_file(r, f2,
workouttype='rower',
@@ -1554,6 +1590,8 @@ def new_workout_from_file(r, f2,
summary = ''
oarlength = 2.89
inboard = 0.88
# Save zip files to email box for further processing
if len(fileformat) == 3 and fileformat[0] == 'zip':
uploadoptions['fromuploadform'] = True
bodyyaml = yaml.safe_dump(uploadoptions,default_flow_style=False)
@@ -1625,6 +1663,12 @@ def new_workout_from_file(r, f2,
# email attachment which can safely be ignored
return (0, '', f2)
# Get workout type from fit & tcx
if (fileformat == 'fit'):
workouttype = get_workouttype_from_fit(f2)
if (fileformat == 'tcx'):
workouttype = get_workouttype_from_tcx(f2)
# handle non-Painsled by converting it to painsled compatible CSV
if (fileformat != 'csv'):
f2, summary, oarlength, inboard, fileformat, impeller = handle_nonpainsled(
@@ -1636,6 +1680,8 @@ def new_workout_from_file(r, f2,
message = 'Something went wrong'
return (0, message, '')
dosummary = (fileformat != 'fit' and 'speedcoach2' not in fileformat)
dosummary = dosummary or summary == ''