diff --git a/logos/uasquare.xcf b/logos/uasquare.xcf new file mode 100644 index 00000000..2490f755 Binary files /dev/null and b/logos/uasquare.xcf differ diff --git a/rowers/templates/export.html b/rowers/templates/export.html index fb62a190..e4eab5e2 100644 --- a/rowers/templates/export.html +++ b/rowers/templates/export.html @@ -111,6 +111,24 @@ {% endif %} + {% if workout.uploadedtounderarmour == 0 %} + {% if user.rower.underarmourtoken == None or user.rower.underarmourtoken == '' %} +
+ + Underarmour icon +
+ {% else %} +
+ Underarmour icon +
+ {% endif %} + {% else %} +
+ + Underarmour icon +
+ {% endif %} + @@ -138,8 +156,11 @@
-
-

connect with RunKeeper

+
+

connect with Runkeeper

+
+
+

connect with Under Armour

diff --git a/rowers/underarmourstuff.py b/rowers/underarmourstuff.py index 83733089..98607567 100644 --- a/rowers/underarmourstuff.py +++ b/rowers/underarmourstuff.py @@ -211,6 +211,8 @@ def createunderarmourworkoutdata(w): duration += w.duration.minute*60 duration += w.duration.second duration += +1.0e-6*w.duration.microsecond + name = w.name + notes = w.notes # adding diff, trying to see if this is valid #t = row.df.ix[:,'TimeStamp (sec)'].values-10*row.df.ix[0,'TimeStamp (sec)'] @@ -235,61 +237,68 @@ def createunderarmourworkoutdata(w): except KeyError: haslatlon = 0 + # short for debugging +# t = t[:3] +# d = d[:3] + # lat = lat[:3] + # hr = hr[:3] + # lon = lon[:3] + # spm = spm[:3] + # path data if haslatlon: locdata = [] for e in zip(t,lat,lon): - point = {'timestamp':e[0], - 'latitude':e[1], - 'longitude':e[2], - 'altitude':0, - "type":"gps"} - locdata.append(point) + point = { + 'lat':e[1], + 'lng':e[2], + 'elevation':0, + } + locdata.append([e[0],point]) hrdata = [] for e in zip(t,hr): - point = {'timestamp':e[0], - 'heart_rate':e[1] - } + point = [e[0], + e[1] + ] hrdata.append(point) distancedata = [] for e in zip(t,d): - point = {'timestamp':e[0], - 'distance':e[1] - } + point = [e[0], + e[1] + ] distancedata.append(point) - start_time = w.startdatetime.strftime("%a, %d %b %Y %H:%M:%S") + spmdata = [] + for e in zip(t,spm): + spmdata.append([e[0],e[1]]) - if haslatlon: - data = { - "type": "Rowing", - "start_time": start_time, - "total_distance": int(w.distance), - "duration": duration, - "notes": w.notes, - "average_heart_rate": averagehr, - "path": locdata, - "distance": distancedata, - "heart_rate": hrdata, - "post_to_twitter":"false", - "post_to_facebook":"false", - } - else: - data = { - "type": "Rowing", - "start_time": start_time, - "total_distance": int(w.distance), - "duration": duration, - "notes": w.notes, - "avg_heartrate": averagehr, - "distance": distancedata, - "heart_rate": hrdata, - "post_to_twitter":"false", - "post_to_facebook":"false", - } + start_time = w.startdatetime.isoformat() + timeseries = { + "distance": distancedata, + "heartrate": hrdata, + "cadence": spmdata, + } + + aggregrates = { + "elapsed_time_total": duration, + "distance_total": max(d), + "heartrate_avg": averagehr, + } + +# if haslatlon: +# timeseries["position"] = locdata + + data = { + "name": name, + "start_datetime": start_time, + "time_series": timeseries, + "start_locale_timezone": "Etc/UTC", + "activity_type": "/v7.1/activity_type/128/", + "notes": notes, + } return data diff --git a/rowers/urls.py b/rowers/urls.py index 05a6ade2..8fe5c55d 100644 --- a/rowers/urls.py +++ b/rowers/urls.py @@ -237,6 +237,7 @@ urlpatterns = [ url(r'^workout/(\d+)/recalcsummary/$',views.workout_recalcsummary_view), url(r'^workout/(\d+)/sporttracksuploadw/$',views.workout_sporttracks_upload_view), url(r'^workout/(\d+)/runkeeperuploadw/$',views.workout_runkeeper_upload_view), + url(r'^workout/(\d+)/underarmouruploadw/$',views.workout_underarmour_upload_view), url(r'^multi-compare$',views.multi_compare_view), url(r'^me/teams/c/(?P\w+.*)/s/(?P\w+.*)$',views.rower_teams_view), url(r'^me/teams/s/(?P\w+.*)$',views.rower_teams_view), diff --git a/rowers/views.py b/rowers/views.py index 46e55611..da37dbea 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -1430,6 +1430,72 @@ def workout_runkeeper_upload_view(request,id=0): return HttpResponseRedirect(url) +# Upload workout to Underarmour +@login_required() +def workout_underarmour_upload_view(request,id=0): + message = "" + try: + w = Workout.objects.get(id=id) + r = w.user + except Workout.DoesNotExist: + raise Http404("Workout doesn't exist") + + try: + thetoken = underarmour_open(r.user) + except UnderarmourNoTokenError: + return HttpResponseRedirect("/rowers/me/underarmourauthorize/") + + # ready to upload. Hurray + + if (checkworkoutuser(request.user,w)): + data = underarmourstuff.createunderarmourworkoutdata(w) +# return HttpResponse(json.dumps(data)) + if not data: + message = "Data error" + url = reverse(workout_export_view, + kwargs = { + 'message':str(message), + 'id':str(w.id), + }) + return HttpResponseRedirect(url) + + authorizationstring = str('Bearer ' + thetoken) + headers = {'Authorization': authorizationstring, + 'Api-Key': UNDERARMOUR_CLIENT_KEY, + 'user-agent': 'sanderroosendaal', + 'Content-Type': 'application/json', + } + + import urllib + url = "https://api.ua.com/v7.1/workout/" + response = requests.post(url,headers=headers,data=json.dumps(data)) + + # check for duplicate error first + if (response.status_code == 409 ): + message = "Duplicate error" + w.uploadedtounderarmour = -1 + w.save() + elif (response.status_code == 201 or response.status_code==200): + underarmourid = underarmourstuff.getidfromresponse(response) + w.uploadedtounderarmour = underarmourid + w.save() + url = "/rowers/workout/"+str(w.id)+"/export" + return HttpResponseRedirect(url) + else: + s = response + message = "Something went wrong in workout_underarmour_upload_view: %s - %s" % (s.reason,s.text) + + else: + message = "You are not authorized to upload this workout" + + url = reverse(workout_export_view, + kwargs = { + 'message':str(message), + 'id':str(w.id), + }) + + return HttpResponseRedirect(url) + # Upload workout to SportTracks @login_required() def workout_sporttracks_upload_view(request,id=0): diff --git a/static/img/uachecked.png b/static/img/uachecked.png new file mode 100644 index 00000000..4a445ab0 Binary files /dev/null and b/static/img/uachecked.png differ diff --git a/static/img/uagray.png b/static/img/uagray.png new file mode 100644 index 00000000..42fe929e Binary files /dev/null and b/static/img/uagray.png differ diff --git a/static/img/uasquare.png b/static/img/uasquare.png new file mode 100644 index 00000000..6e6cf69c Binary files /dev/null and b/static/img/uasquare.png differ