adding data download
This commit is contained in:
@@ -3134,6 +3134,57 @@ def instroke_chart(request, id=0, metric=''): # pragma: no cover
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
@user_passes_test(ispromember, login_url="/rowers/paidplans",
|
||||
message="This functionality requires a Pro plan or higher."
|
||||
" If you are already a Pro user, please log in to access this functionality",
|
||||
redirect_field_name=None)
|
||||
@permission_required('workout.change_workout', fn=get_workout_by_opaqueid, raise_exception=True)
|
||||
def instroke_data(request, metric='', spm_min=15, spm_max=45, activeminutesmin=0, activeminutesmax=0, id=0, ):
|
||||
r = getrequestrower(request, userid=0)
|
||||
w = get_workoutuser(id, request)
|
||||
rowdata = rrdata(csvfile=w.csvfilename)
|
||||
instrokemetrics = rowdata.get_instroke_columns()
|
||||
if not metric:
|
||||
metric = instrokemetrics[0]
|
||||
if activeminutesmax == 0:
|
||||
activeminutesmax = rowdata.duration/60.
|
||||
|
||||
try:
|
||||
spm_min = float(spm_min)
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
spm_max = float(spm_max)
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
activeminutesmin = float(activeminutesmin)
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
activeminutesmax = float(activeminutesmax)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
data = rowdata.get_instroke_data(metric, spm_min=spm_min,
|
||||
spm_max=spm_max,
|
||||
activeminutesmin=activeminutesmin,
|
||||
activeminutesmax=activeminutesmax,
|
||||
)
|
||||
|
||||
filename = str(uuid4())+'.csv'
|
||||
|
||||
data.to_csv(filename)
|
||||
with open(filename, 'r') as f:
|
||||
response = HttpResponse(f)
|
||||
response['Content-Disposition'] = 'attachment; filename="%s"' % filename
|
||||
response['Content-Type'] = 'application/octet-stream'
|
||||
|
||||
os.remove(filename)
|
||||
return response
|
||||
|
||||
|
||||
@user_passes_test(ispromember, login_url="/rowers/paidplans",
|
||||
message="This functionality requires a Pro plan or higher."
|
||||
" If you are already a Pro user, please log in to access this functionality",
|
||||
@@ -3398,6 +3449,7 @@ def instroke_chart_interactive(request, id=0, analysis=0, userid=0):
|
||||
'teams': get_my_teams(request.user),
|
||||
'instrokemetrics': instrokemetrics,
|
||||
'form':form,
|
||||
'metric': metric,
|
||||
'the_script': script,
|
||||
'the_div': div,
|
||||
'spm_min': spm_min,
|
||||
|
||||
Reference in New Issue
Block a user