Private
Public Access
1
0

Export to MapMyFitness now works

This commit is contained in:
Sander Roosendaal
2018-05-18 11:56:40 +02:00
parent 7abdf92809
commit c330a237ef
2 changed files with 39 additions and 15 deletions

View File

@@ -9,6 +9,7 @@ import requests.auth
import json import json
from django.utils import timezone from django.utils import timezone
from datetime import datetime,timedelta from datetime import datetime,timedelta
import arrow
import numpy as np import numpy as np
from dateutil import parser from dateutil import parser
import time import time
@@ -239,7 +240,11 @@ def createunderarmourworkoutdata(w):
except: except:
return 0 return 0
st = w.startdatetime.astimezone(pytz.timezone(w.timezone))
start_time = st.isoformat()
averagehr = int(row.df[' HRCur (bpm)'].mean()) averagehr = int(row.df[' HRCur (bpm)'].mean())
averagespm = int(row.df[' Cadence (stokes/min)'].mean()/2.)
maxhr = int(row.df[' HRCur (bpm)'].max()) maxhr = int(row.df[' HRCur (bpm)'].max())
duration = w.duration.hour*3600 duration = w.duration.hour*3600
duration += w.duration.minute*60 duration += w.duration.minute*60
@@ -253,31 +258,42 @@ def createunderarmourworkoutdata(w):
# 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)']
t = row.df.ix[:,'TimeStamp (sec)'].values-row.df.ix[0,'TimeStamp (sec)'] t = row.df.ix[:,'TimeStamp (sec)'].values #-row.df.ix[0,'TimeStamp (sec)']
t[0] = t[1]
# t += arrow.get(st).timestamp
# t[0] = t[1]
d = row.df.ix[:,'cum_dist'].values d = row.df.ix[:,'cum_dist'].values
d[0] = d[1] d[0] = d[1]
t = t.astype(int) t = t.astype(float)
d = d.astype(int) d = d.astype(int)
spm = row.df[' Cadence (stokes/min)'].astype(int) spm = row.df[' Cadence (stokes/min)'].astype(int)
spm[0] = spm[1] spm[0] = spm[1]
hr = row.df[' HRCur (bpm)'].astype(int) hr = row.df[' HRCur (bpm)'].astype(int)
speed = row.df[' AverageBoatSpeed (m/s)']
speed = speed.replace(np.inf,0)
haslatlon=1 haslatlon=1
try: try:
lat = row.df[' latitude'].values lat = row.df[' latitude']
lon = row.df[' longitude'].values lon = row.df[' longitude']
if not lat.std() and not lon.std(): if not lat.std() and not lon.std():
haslatlon = 0 haslatlon = 0
except KeyError: except KeyError:
haslatlon = 0 haslatlon = 0
# path data # path data
if haslatlon: if haslatlon:
locdata = [] locdata = []
for e in zip(t,lat,lon): for e in zip(t,lat.values,lon.values):
point = { point = {
'lat':e[1], 'lat':e[1],
'lng':e[2], 'lng':e[2],
@@ -303,8 +319,6 @@ def createunderarmourworkoutdata(w):
for e in zip(t,spm): for e in zip(t,spm):
spmdata.append([e[0],e[1]]) spmdata.append([e[0],e[1]])
st = w.startdatetime.astimezone(pytz.timezone(w.timezone))
start_time = st.isoformat()
timeseries = { timeseries = {
"distance": distancedata, "distance": distancedata,
@@ -312,22 +326,32 @@ def createunderarmourworkoutdata(w):
"cadence": spmdata, "cadence": spmdata,
} }
aggregrates = {
aggregates = {
"elapsed_time_total": int(duration), "elapsed_time_total": int(duration),
"active_time_total": int(duration),
"distance_total": int(max(d)), "distance_total": int(max(d)),
"heartrate_avg": averagehr, "heartrate_avg": averagehr,
"heart_rate_min": int(min(hr)), "heart_rate_min": int(min(hr)),
"heart_rate_max": int(max(hr)), "heart_rate_max": int(max(hr)),
"speed_min": speed.min().astype(float),
"speed_max": speed.max().astype(float),
"speed_avg": speed.mean(),
"cadence_min": int(min(spm)/2.),
"cadence_max": int(max(spm)/2.),
"cadence_avg": averagespm,
} }
# if haslatlon: if haslatlon:
# timeseries["position"] = locdata timeseries["position"] = locdata
data = { data = {
"name": name,
"start_datetime": start_time, "start_datetime": start_time,
"name": name,
"has_time_series": True,
"time_series": timeseries, "time_series": timeseries,
"aggregates": aggregates,
"start_locale_timezone": "Etc/UTC", "start_locale_timezone": "Etc/UTC",
"activity_type": "/v7.1/activity_type/128/", "activity_type": "/v7.1/activity_type/128/",
"notes": notes, "notes": notes,

View File

@@ -2242,7 +2242,6 @@ def workout_underarmour_upload_view(request,id=0):
if (checkworkoutuser(request.user,w)): if (checkworkoutuser(request.user,w)):
data = underarmourstuff.createunderarmourworkoutdata(w) data = underarmourstuff.createunderarmourworkoutdata(w)
# return HttpResponse(json.dumps(data))
if not data: if not data:
message = "Data error" message = "Data error"
messages.error(request,message) messages.error(request,message)
@@ -2262,6 +2261,7 @@ def workout_underarmour_upload_view(request,id=0):
url = "https://api.ua.com/v7.1/workout/" url = "https://api.ua.com/v7.1/workout/"
response = requests.post(url,headers=headers,data=json.dumps(data)) response = requests.post(url,headers=headers,data=json.dumps(data))
# check for duplicate error first # check for duplicate error first
if (response.status_code == 409 ): if (response.status_code == 409 ):
message = "Duplicate error" message = "Duplicate error"
@@ -2276,7 +2276,7 @@ def workout_underarmour_upload_view(request,id=0):
return HttpResponseRedirect(url) return HttpResponseRedirect(url)
else: else:
s = response s = response
message = "Something went wrong in workout_underarmour_upload_view: %s - %s" % (s.reason,s.text) message = "Something went wrong in workout_underarmour_upload_view: %s " % s.reason
messages.error(request,message) messages.error(request,message)
else: else:
message = "You are not authorized to upload this workout" message = "You are not authorized to upload this workout"