merged develop
This commit is contained in:
@@ -397,6 +397,144 @@ def handle_stravaexport(f2,workoutname,stravatoken,description='',
|
|||||||
|
|
||||||
return (res.id,message)
|
return (res.id,message)
|
||||||
|
|
||||||
|
# Create workout data from Strava or Concept2
|
||||||
|
# data and create the associated Workout object and save it
|
||||||
|
def add_workout_from_data(user,importid,data,strokedata,
|
||||||
|
source='strava',splitdata=None,
|
||||||
|
workoutsource='strava'):
|
||||||
|
try:
|
||||||
|
workouttype = data['type']
|
||||||
|
except KeyError:
|
||||||
|
workouttype = 'rower'
|
||||||
|
|
||||||
|
if workouttype not in [x[0] for x in Workout.workouttypes]:
|
||||||
|
workouttype = 'other'
|
||||||
|
try:
|
||||||
|
comments = data['comments']
|
||||||
|
except:
|
||||||
|
comments = ' '
|
||||||
|
|
||||||
|
try:
|
||||||
|
thetimezone = tz(data['timezone'])
|
||||||
|
except:
|
||||||
|
thetimezone = 'UTC'
|
||||||
|
|
||||||
|
r = Rower.objects.get(user=user)
|
||||||
|
try:
|
||||||
|
rowdatetime = iso8601.parse_date(data['date_utc'])
|
||||||
|
except KeyError:
|
||||||
|
rowdatetime = iso8601.parse_date(data['start_date'])
|
||||||
|
except ParseError:
|
||||||
|
rowdatetime = iso8601.parse_date(data['date'])
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
intervaltype = data['workout_type']
|
||||||
|
|
||||||
|
except KeyError:
|
||||||
|
intervaltype = ''
|
||||||
|
|
||||||
|
try:
|
||||||
|
title = data['name']
|
||||||
|
except KeyError:
|
||||||
|
title = ""
|
||||||
|
try:
|
||||||
|
t = data['comments'].split('\n', 1)[0]
|
||||||
|
title += t[:20]
|
||||||
|
except:
|
||||||
|
title = 'Imported'
|
||||||
|
|
||||||
|
starttimeunix = arrow.get(rowdatetime).timestamp
|
||||||
|
|
||||||
|
res = make_cumvalues(0.1*strokedata['t'])
|
||||||
|
cum_time = res[0]
|
||||||
|
lapidx = res[1]
|
||||||
|
|
||||||
|
unixtime = cum_time+starttimeunix
|
||||||
|
seconds = 0.1*strokedata.ix[:,'t']
|
||||||
|
|
||||||
|
nr_rows = len(unixtime)
|
||||||
|
|
||||||
|
try:
|
||||||
|
latcoord = strokedata.ix[:,'lat']
|
||||||
|
loncoord = strokedata.ix[:,'lon']
|
||||||
|
except:
|
||||||
|
latcoord = np.zeros(nr_rows)
|
||||||
|
loncoord = np.zeros(nr_rows)
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
strokelength = strokedata.ix[:,'strokelength']
|
||||||
|
except:
|
||||||
|
strokelength = np.zeros(nr_rows)
|
||||||
|
|
||||||
|
dist2 = 0.1*strokedata.ix[:,'d']
|
||||||
|
|
||||||
|
try:
|
||||||
|
spm = strokedata.ix[:,'spm']
|
||||||
|
except KeyError:
|
||||||
|
spm = 0*dist2
|
||||||
|
|
||||||
|
try:
|
||||||
|
hr = strokedata.ix[:,'hr']
|
||||||
|
except KeyError:
|
||||||
|
hr = 0*spm
|
||||||
|
pace = strokedata.ix[:,'p']/10.
|
||||||
|
pace = np.clip(pace,0,1e4)
|
||||||
|
pace = pace.replace(0,300)
|
||||||
|
|
||||||
|
velo = 500./pace
|
||||||
|
|
||||||
|
power = 2.8*velo**3
|
||||||
|
|
||||||
|
# save csv
|
||||||
|
# Create data frame with all necessary data to write to csv
|
||||||
|
df = pd.DataFrame({'TimeStamp (sec)':unixtime,
|
||||||
|
' Horizontal (meters)': dist2,
|
||||||
|
' Cadence (stokes/min)':spm,
|
||||||
|
' HRCur (bpm)':hr,
|
||||||
|
' longitude':loncoord,
|
||||||
|
' latitude':latcoord,
|
||||||
|
' Stroke500mPace (sec/500m)':pace,
|
||||||
|
' Power (watts)':power,
|
||||||
|
' DragFactor':np.zeros(nr_rows),
|
||||||
|
' DriveLength (meters)':np.zeros(nr_rows),
|
||||||
|
' StrokeDistance (meters)':strokelength,
|
||||||
|
' DriveTime (ms)':np.zeros(nr_rows),
|
||||||
|
' StrokeRecoveryTime (ms)':np.zeros(nr_rows),
|
||||||
|
' AverageDriveForce (lbs)':np.zeros(nr_rows),
|
||||||
|
' PeakDriveForce (lbs)':np.zeros(nr_rows),
|
||||||
|
' lapIdx':lapidx,
|
||||||
|
' ElapsedTime (sec)':seconds
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
||||||
|
|
||||||
|
timestr = strftime("%Y%m%d-%H%M%S")
|
||||||
|
|
||||||
|
|
||||||
|
# Create CSV file name and save data to CSV file
|
||||||
|
csvfilename ='media/{code}_{importid}.csv'.format(
|
||||||
|
importid=importid,
|
||||||
|
code = uuid4().hex[:16]
|
||||||
|
)
|
||||||
|
|
||||||
|
res = df.to_csv(csvfilename+'.gz',index_label='index',
|
||||||
|
compression='gzip')
|
||||||
|
|
||||||
|
|
||||||
|
id,message = dataprep.save_workout_database(
|
||||||
|
csvfilename,r,
|
||||||
|
workouttype=workouttype,
|
||||||
|
title=title,notes=comments,
|
||||||
|
workoutsource=workoutsource,
|
||||||
|
dosummary=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return id,message
|
||||||
|
|
||||||
def workout_strava_upload(user,w):
|
def workout_strava_upload(user,w):
|
||||||
message = "Uploading to Strava"
|
message = "Uploading to Strava"
|
||||||
|
|||||||
Reference in New Issue
Block a user