Private
Public Access
1
0

added data download button on user settings

This commit is contained in:
Sander Roosendaal
2018-03-05 12:51:07 +01:00
parent c1ad98e885
commit ea78242949
7 changed files with 223 additions and 1 deletions

View File

@@ -65,6 +65,8 @@ queue = django_rq.get_queue('default')
queuelow = django_rq.get_queue('low')
queuehigh = django_rq.get_queue('default')
from rowsandall_app.settings import SITE_URL
user = settings.DATABASES['default']['USER']
password = settings.DATABASES['default']['PASSWORD']
@@ -131,6 +133,66 @@ def get_latlon(id):
return [pd.Series([]), pd.Series([])]
def workout_summary_to_df(
rower,
startdate=datetime.datetime(1970,1,1),
enddate=timezone.now()+timezone.timedelta(days=1)):
ws = Workout.objects.filter(user=rower).order_by("startdatetime")
types = []
names = []
startdatetimes = []
timezones = []
distances = []
durations = []
weightcategories = []
weightvalues = []
notes = []
tcx_links = []
csv_links = []
rscores = []
trimps = []
for w in ws:
types.append(w.workouttype)
names.append(w.name)
startdatetimes.append(w.startdatetime)
timezones.append(w.timezone)
distances.append(w.distance)
durations.append(w.duration)
weightcategories.append(w.weightcategory)
weightvalues.append(w.weightvalue)
notes.append(w.notes)
tcx_link = SITE_URL+'/rowers/workout/{id}/emailtcx'.format(
id=w.id
)
tcx_links.append(tcx_link)
csv_link = SITE_URL+'/rowers/workout/{id}/emailcsv'.format(
id=w.id
)
csv_links.append(csv_link)
trimps.append(workout_trimp(w))
rscore = workout_rscore(w)
rscores.append(int(rscore[0]))
df = pd.DataFrame({
'name':names,
'date':startdatetimes,
'timezone':timezones,
'type':types,
'distance (m)':distances,
'duration ':durations,
'weight category':weightcategories,
'weight (kg)':weightvalues,
'notes':notes,
'Stroke Data TCX':tcx_links,
'Stroke Data CSV':csv_links,
'TRIMP Training Load':trimps,
'TSS Training Load':rscores,
})
return df
def get_workouts(ids, userid):
goodids = []

View File

@@ -499,6 +499,37 @@ def handle_zip_file(emailfrom, subject, file,**kwargs):
# Send email with CSV attachment
@app.task
def handle_sendemailsummary(first_name, last_name, email, csvfile, **kwargs):
# send email with attachment
fullemail = first_name + " " + last_name + " " + "<" + email + ">"
subject = "File from Rowsandall.com"
message = "Dear " + first_name + ",\n\n"
message += "Please find attached the requested summary file.\n\n"
message += "Best Regards, the Rowsandall Team"
email = EmailMessage(subject, message,
'Rowsandall <info@rowsandall.com>',
[fullemail])
if os.path.isfile(csvfile):
email.attach_file(csvfile)
else:
csvfile2 = csvfile
with gzip.open(csvfile + '.gz', 'rb') as f_in, open(csvfile2, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
email.attach_file(csvfile2)
os.remove(csvfile2)
res = email.send()
try:
os.remove(csvfile)
except:
pass
return 1
@app.task
def handle_sendemailcsv(first_name, last_name, email, csvfile,**kwargs):

View File

@@ -0,0 +1,33 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block title %}Rowsandall Workouts Summary Export{% endblock %}
{% block content %}
<div class="grid_12">
<form enctype="multipart/form-data" method="post">
<div class="grid_4 alpha">
<table>
{{ form.as_table }}
</table>
{% csrf_token %}
</div>
<div class="grid_2">
<input class="button green" type="submit" value="Submit">
</div>
</form>
<div class="grid_6 omega">
<p>
With this form, you can export a summary table for all workouts within a selected date range.
The table will be sent to you as a CSV file which can be opened in excel. The table contains
links to download stroke data per workout.
</p>
<p>
By setting the start date to your registration date or earlier and the end date to today,
you will receive all workout data we are storing for you.
</p>
</div>
</div>
{% endblock %}

View File

@@ -212,7 +212,15 @@
</div>
<div class="grid_12 alpha">
<div class="grid_6 suffix_6 alpha">
<div class="grid_6 alpha">
<p>
<h2>GDPR - Data Protection</h2>
<div class="grid_2 suffix_4 alpha">
<a class="button gray small" href="/rowers/exportallworkouts">Download your data</a>
</div>
</p>
</div>
<div class="grid_6 omega">
{% if grants %}
<p>
<h2>Applications</h2>

View File

@@ -121,6 +121,7 @@ urlpatterns = [
url(r'^400/$', TemplateView.as_view(template_name='400.html'),name='400'),
url(r'^403/$', TemplateView.as_view(template_name='403.html'),name='403'),
url(r'^imports/$', TemplateView.as_view(template_name='imports.html'), name='imports'),
url(r'^exportallworkouts$',views.workouts_summaries_email_view),
url(r'^agegroupcp/(?P<age>\d+)$',views.agegroupcpview),
url(r'^agegroupcp/(?P<age>\d+)/(?P<normalize>\d+)$',views.agegroupcpview),
url(r'^ajax_agegroup/(?P<age>\d+)/(?P<weightcategory>\w+.*)/(?P<sex>\w+.*)/(?P<userid>\d+)$',

View File

@@ -118,6 +118,7 @@ from rowers.plannedsessions import *
from rowers.tasks import handle_makeplot,handle_otwsetpower,handle_sendemailtcx,handle_sendemailcsv
from rowers.tasks import (
handle_sendemail_unrecognized,handle_sendemailnewcomment,
handle_sendemailsummary,
handle_sendemailnewresponse, handle_updatedps,
handle_updatecp,long_test_task,long_test_task2,
handle_zip_file,handle_getagegrouprecords,
@@ -1704,6 +1705,34 @@ def workout_gpxemail_view(request,id=0):
return response
# Get Workout summary CSV file
@login_required()
def workouts_summaries_email_view(request):
r = getrower(request.user)
if request.method == 'POST':
form = DateRangeForm(request.POST)
if form.is_valid():
startdate = form.cleaned_data['startdate']
enddate = form.cleaned_data['enddate']
filename = 'rowsandall_workouts_{first}_{last}.csv'
df = dataprep.workout_summary_to_df(r,startdate=startdate,enddate=enddate)
df.to_csv(filename,encoding='utf-8')
res = myqueue(queuehigh,handle_sendemailsummary,
r.user.first_name,
r.user.last_name,
r.user.email,
filename)
messages.info(request,'The summary CSV file was sent to you per email')
else:
form = DateRangeForm()
return render(request,"export_workouts.html",
{
'form':form
})
# Get Workout CSV file and send it to user's email address
@login_required()
def workout_csvemail_view(request,id=0):