Private
Public Access
1
0

removing obsolete rowingdata(csvfile)

This commit is contained in:
Sander Roosendaal
2019-11-11 17:31:56 +01:00
parent 23909feabf
commit 2294603129
6 changed files with 152 additions and 156 deletions

View File

@@ -89,7 +89,7 @@ def get_workout(user,underarmourid):
strokedata = pd.DataFrame.from_dict({
key: pd.Series(value) for key, value in data.items()
})
return data,strokedata
@@ -97,10 +97,10 @@ def get_workout(user,underarmourid):
def createunderarmourworkoutdata(w):
filename = w.csvfilename
try:
row = rowingdata(filename)
row = rowingdata(csvfile=filename)
except:
return 0
st = w.startdatetime.astimezone(pytz.timezone(w.timezone))
start_time = st.isoformat()
@@ -126,16 +126,16 @@ def createunderarmourworkoutdata(w):
t = row.df.loc[:,'TimeStamp (sec)'].values #-row.df.ix[0,'TimeStamp (sec)']
# t += arrow.get(st).timestamp
# t[0] = t[1]
d = row.df.loc[:,'cum_dist'].values
d[0] = d[1]
t = t.astype(float).tolist()
d = d.astype(int).tolist()
spm = row.df[' Cadence (stokes/min)'].astype(int).tolist()
spm[0] = spm[1]
@@ -146,10 +146,10 @@ def createunderarmourworkoutdata(w):
speedmean = float(row.df[' AverageBoatSpeed (m/s)'].mean())
speed = speed.replace(np.inf,0).tolist()
haslatlon=1
try:
lat = row.df[' latitude'].tolist()
lon = row.df[' longitude'].tolist()
@@ -158,10 +158,10 @@ def createunderarmourworkoutdata(w):
except KeyError:
haslatlon = 0
# path data
if haslatlon:
locdata = []
locdata = []
for e in zip(t,lat.values,lon.values):
point = {
'lat':e[1],
@@ -187,7 +187,7 @@ def createunderarmourworkoutdata(w):
spmdata = []
for e in zip(t,spm):
spmdata.append([e[0],e[1]])
timeseries = {
"distance": distancedata,
@@ -215,7 +215,7 @@ def createunderarmourworkoutdata(w):
if haslatlon:
timeseries["position"] = locdata
data = {
"start_datetime": start_time,
"name": name,
@@ -235,7 +235,7 @@ def get_idfromuri(user,links):
typeid = links['activity_type'][0]['id']
typename = get_typefromid(typeid,user)
return id,typename
def getidfromresponse(response):
@@ -256,7 +256,7 @@ def refresh_ua_actlist(user):
'Content-Type': 'application/json'}
url = "https://api.ua.com/v7.1/activity_type/"
response = requests.get(url,headers=headers)
me_json = response.json()
types = me_json["_embedded"]["activity_types"]
w = {int(t["_links"]["self"][0]["id"]):t["name"] for t in types}
@@ -290,11 +290,11 @@ def get_typefromid(typeid,user):
res = me_json['name']
except KeyError:
res = 0
return res
return res
# Get user id, having access token
# Handy for checking if the API access is working
def get_userid(access_token):
@@ -313,11 +313,11 @@ def get_userid(access_token):
res = me_json['id']
except KeyError:
res = 0
return res
def default(o):
if isinstance(o, numpy.int64): return int(o)
if isinstance(o, numpy.int64): return int(o)
raise TypeError
@@ -338,7 +338,7 @@ def workout_ua_upload(user,w):
message = "Data error"
uaid = 0
return message, uaid
authorizationstring = str('Bearer ' + thetoken)
headers = {'Authorization': authorizationstring,
'Api-Key': UNDERARMOUR_CLIENT_KEY,
@@ -357,7 +357,7 @@ def workout_ua_upload(user,w):
w.save()
elif (response.status_code == 201 or response.status_code==200):
uaid = getidfromresponse(response)
w.uploadedtounderarmour = uaid
w.uploadedtounderarmour = uaid
w.save()
return 'Successfully synchronized with MapMyFitness',uaid
else:
@@ -365,7 +365,7 @@ def workout_ua_upload(user,w):
message = "Something went wrong in workout_underarmour_upload_view: %s - %s" % (s.reason,s.text)
uaid = 0
return message, uaid
else:
message = "You are not authorized to upload this workout"
uaid = 0
@@ -384,7 +384,7 @@ def add_workout_from_data(user,importid,data,strokedata,
comments = data['notes']
except:
comments = ''
try:
thetimezone = tz(data['start_locale_timezone'])
except:
@@ -405,8 +405,8 @@ def add_workout_from_data(user,importid,data,strokedata,
rowdatetime = datetime.strptime(data['date'],"%Y-%m-%d %H:%M:%S")
rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
starttimeunix = arrow.get(rowdatetime).timestamp
try:
title = data['name']
except:
@@ -414,7 +414,7 @@ def add_workout_from_data(user,importid,data,strokedata,
timeseries = data['time_series']
# position, distance, speed, cadence, power,
# position, distance, speed, cadence, power,
try:
res = splituadata(timeseries['distance'])
@@ -427,7 +427,7 @@ def add_workout_from_data(user,importid,data,strokedata,
try:
l = timeseries['position']
res = splituadata(l)
times_location = res[0]
latlong = res[1]
@@ -445,7 +445,7 @@ def add_workout_from_data(user,importid,data,strokedata,
loncoord = np.zeros(len(times_distance))
if workouttype in otwtypes:
workouttype = 'rower'
try:
res = splituadata(timeseries['cadence'])
times_spm = res[0]
@@ -453,7 +453,7 @@ def add_workout_from_data(user,importid,data,strokedata,
except KeyError:
times_spm = times_distance
spm = 0*times_distance
try:
res = splituadata(timeseries['heartrate'])
hr = res[1]
@@ -485,7 +485,7 @@ def add_workout_from_data(user,importid,data,strokedata,
' HRCur (bpm)' : hrseries,
}
df = pd.DataFrame(d)
@@ -495,7 +495,7 @@ def add_workout_from_data(user,importid,data,strokedata,
df[' ElapsedTime (sec)'] = cum_time
velo = df[' Horizontal (meters)'].diff()/df[' ElapsedTime (sec)'].diff()
df[' Power (watts)'] = 0.0*velo
nr_rows = len(velo.values)
@@ -512,17 +512,17 @@ def add_workout_from_data(user,importid,data,strokedata,
unixtime = cum_time+starttimeunix
unixtime[0] = starttimeunix
df['TimeStamp (sec)'] = unixtime
dt = np.diff(cum_time).mean()
wsize = round(5./dt)
df = df.fillna(0)
df.sort_values(by='TimeStamp (sec)',ascending=True)
timestr = strftime("%Y%m%d-%H%M%S")
csvfilename ='media/{code}_{importid}.csv'.format(
@@ -540,4 +540,3 @@ def add_workout_from_data(user,importid,data,strokedata,
notes=comments)
return (id,message)