upload works partially
This commit is contained in:
BIN
logos/uasquare.xcf
Normal file
BIN
logos/uasquare.xcf
Normal file
Binary file not shown.
@@ -111,6 +111,24 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if workout.uploadedtounderarmour == 0 %}
|
||||||
|
{% if user.rower.underarmourtoken == None or user.rower.underarmourtoken == '' %}
|
||||||
|
<div class="grid_1">
|
||||||
|
<a href="/rowers/me/underarmourauthorize">
|
||||||
|
<img src="/static/img/uagray.png" alt="Underarmour icon" width="60" height="60"></a>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="grid_1">
|
||||||
|
<a href="/rowers/workout/{{ workout.id }}/underarmouruploadw"><img src="/static/img/uasquare.png" alt="Underarmour icon" width="60" height="60"></a>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
<div class="grid_1">
|
||||||
|
<a href="https://underarmour.com/fitnessActivity/{{ workout.uploadedtounderarmour }}">
|
||||||
|
<img src="/static/img/uachecked.png" alt="Underarmour icon" width="60" height="60"></a>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -138,8 +156,11 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="grid_6">
|
<div class="grid_6">
|
||||||
<div class="grid_2 alpha suffix_4">
|
<div class="grid_2 alpha">
|
||||||
<p><a href="/rowers/me/runkeeperauthorize/"><img src="/static/img/rk-logo.png" alt="connect with RunKeeper" width="120"></a></p>
|
<p><a href="/rowers/me/runkeeperauthorize/"><img src="/static/img/rk-logo.png" alt="connect with Runkeeper" width="120"></a></p>
|
||||||
|
</div>
|
||||||
|
<div class="grid_2">
|
||||||
|
<p><a href="/rowers/me/underarmourauthorize/"><img src="/static/img/UAbtn.png" alt="connect with Under Armour" width="120"></a></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -211,6 +211,8 @@ def createunderarmourworkoutdata(w):
|
|||||||
duration += w.duration.minute*60
|
duration += w.duration.minute*60
|
||||||
duration += w.duration.second
|
duration += w.duration.second
|
||||||
duration += +1.0e-6*w.duration.microsecond
|
duration += +1.0e-6*w.duration.microsecond
|
||||||
|
name = w.name
|
||||||
|
notes = w.notes
|
||||||
|
|
||||||
# adding diff, trying to see if this is valid
|
# adding diff, trying to see if this is valid
|
||||||
#t = row.df.ix[:,'TimeStamp (sec)'].values-10*row.df.ix[0,'TimeStamp (sec)']
|
#t = row.df.ix[:,'TimeStamp (sec)'].values-10*row.df.ix[0,'TimeStamp (sec)']
|
||||||
@@ -235,61 +237,68 @@ def createunderarmourworkoutdata(w):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
haslatlon = 0
|
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
|
# path data
|
||||||
if haslatlon:
|
if haslatlon:
|
||||||
locdata = []
|
locdata = []
|
||||||
for e in zip(t,lat,lon):
|
for e in zip(t,lat,lon):
|
||||||
point = {'timestamp':e[0],
|
point = {
|
||||||
'latitude':e[1],
|
'lat':e[1],
|
||||||
'longitude':e[2],
|
'lng':e[2],
|
||||||
'altitude':0,
|
'elevation':0,
|
||||||
"type":"gps"}
|
}
|
||||||
locdata.append(point)
|
locdata.append([e[0],point])
|
||||||
|
|
||||||
hrdata = []
|
hrdata = []
|
||||||
for e in zip(t,hr):
|
for e in zip(t,hr):
|
||||||
point = {'timestamp':e[0],
|
point = [e[0],
|
||||||
'heart_rate':e[1]
|
e[1]
|
||||||
}
|
]
|
||||||
hrdata.append(point)
|
hrdata.append(point)
|
||||||
|
|
||||||
distancedata = []
|
distancedata = []
|
||||||
for e in zip(t,d):
|
for e in zip(t,d):
|
||||||
point = {'timestamp':e[0],
|
point = [e[0],
|
||||||
'distance':e[1]
|
e[1]
|
||||||
}
|
]
|
||||||
distancedata.append(point)
|
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:
|
start_time = w.startdatetime.isoformat()
|
||||||
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",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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
|
return data
|
||||||
|
|
||||||
|
|||||||
@@ -237,6 +237,7 @@ urlpatterns = [
|
|||||||
url(r'^workout/(\d+)/recalcsummary/$',views.workout_recalcsummary_view),
|
url(r'^workout/(\d+)/recalcsummary/$',views.workout_recalcsummary_view),
|
||||||
url(r'^workout/(\d+)/sporttracksuploadw/$',views.workout_sporttracks_upload_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+)/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'^multi-compare$',views.multi_compare_view),
|
||||||
url(r'^me/teams/c/(?P<message>\w+.*)/s/(?P<successmessage>\w+.*)$',views.rower_teams_view),
|
url(r'^me/teams/c/(?P<message>\w+.*)/s/(?P<successmessage>\w+.*)$',views.rower_teams_view),
|
||||||
url(r'^me/teams/s/(?P<successmessage>\w+.*)$',views.rower_teams_view),
|
url(r'^me/teams/s/(?P<successmessage>\w+.*)$',views.rower_teams_view),
|
||||||
|
|||||||
@@ -1430,6 +1430,72 @@ def workout_runkeeper_upload_view(request,id=0):
|
|||||||
|
|
||||||
return HttpResponseRedirect(url)
|
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
|
# Upload workout to SportTracks
|
||||||
@login_required()
|
@login_required()
|
||||||
def workout_sporttracks_upload_view(request,id=0):
|
def workout_sporttracks_upload_view(request,id=0):
|
||||||
|
|||||||
BIN
static/img/uachecked.png
Normal file
BIN
static/img/uachecked.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
BIN
static/img/uagray.png
Normal file
BIN
static/img/uagray.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
BIN
static/img/uasquare.png
Normal file
BIN
static/img/uasquare.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 35 KiB |
Reference in New Issue
Block a user