diff --git a/rowers/c2stuff.py b/rowers/c2stuff.py index 5f5979bc..4da51ef2 100644 --- a/rowers/c2stuff.py +++ b/rowers/c2stuff.py @@ -6,7 +6,7 @@ from rowers.imports import * import datetime from requests import Request, Session - +import mytypes from rowers.mytypes import otwtypes from iso8601 import ParseError @@ -428,7 +428,7 @@ def createc2workoutdata(w): startdate = datetime.datetime.combine(w.date,datetime.time()) data = { - "type": workouttype, + "type": mytypes.c2mapping[workouttype], "date": w.startdatetime.isoformat(), "timezone": w.timezone, "distance": int(w.distance), @@ -684,6 +684,9 @@ def process_callback(request): # Uploading workout def workout_c2_upload(user,w): message = 'trying C2 upload' + if mytypes.c2mapping[w.workouttype] is None: + return "This workout type cannot be uploaded to Concept2",0 + thetoken = c2_open(user) r = Rower.objects.get(user=user) @@ -755,7 +758,7 @@ def add_workout_from_data(user,importid,data,strokedata, source='c2',splitdata=None, workoutsource='concept2'): try: - workouttype = data['type'] + workouttype = mytypes.c2mappinginv[data['type']] except KeyError: workouttype = 'rower' diff --git a/rowers/mytypes.py b/rowers/mytypes.py index f86dfc6f..76163587 100644 --- a/rowers/mytypes.py +++ b/rowers/mytypes.py @@ -41,6 +41,52 @@ workouttypes = ( ('other','Other'), ) +c2mapping = { + 'water':'water', + 'rower':'rower', + 'skierg':'skierg', + 'bike':'bike', + 'dynamic':'dynamic', + 'slides':'slides', + 'paddle':'paddle', + 'snow':'snow', + 'coastal':'water', + 'c-boat':'water', + 'churchboat':'water', + 'Ride':'bike', + 'Kitesurf':None, + 'Run':None, + 'NordicSki':'snow', + 'Swim':None, + 'RockClimbing':None, + 'Hike':None, + 'RollerSki':'snow', + 'Walk':None, + 'AlpineSki':None, + 'Snowboard':None, + 'BackcountrySki':'snow', + 'Snowshoe':'snow', + 'Canoeing':'paddle', + 'StairStepper':None, + 'Crossfit':None, + 'StandUpPaddling':None, + 'EBikeRide':None, + 'Surfing':None, + 'Elliptical':None, + 'VirtualRide':None, + 'IceSkate':None, + 'WeightTraining':None, + 'InlineSkate':None, + 'Windsurf':None, + 'Kayaking':None, + 'Workout':None, + 'Yoga':None, + 'other':None, + + } + +c2mappinginv = {value:key for key,value in c2mapping.iteritems() if value is not None} + otwtypes = ( 'water', 'coastal', diff --git a/rowers/views.py b/rowers/views.py index e5997a68..a2f4f729 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -10822,7 +10822,7 @@ def workout_getimportview(request,externalid,source = 'c2'): if strokedata.empty: distance = data['distance'] c2id = data['id'] - workouttype = data['type'] + workouttype = mytypes.c2mappinginv[data['type']] verified = data['verified'] startdatetime = iso8601.parse_date(data['date']) weightclass = data['weight_class']