Private
Public Access
1
0

cp data sending to admin

This commit is contained in:
Sander Roosendaal
2018-08-28 11:59:18 +02:00
parent 18b8f96418
commit 4f5695723b
4 changed files with 121 additions and 0 deletions

View File

@@ -132,6 +132,7 @@ from rowers.tasks import handle_makeplot,handle_otwsetpower,handle_sendemailtcx,
from rowers.tasks import (
handle_sendemail_unrecognized,handle_sendemailnewcomment,
handle_sendemailsummary,
handle_sendemailfile,
handle_sendemailkml,
handle_sendemailnewresponse, handle_updatedps,
handle_updatecp,long_test_task,long_test_task2,
@@ -4276,6 +4277,79 @@ def otwrankings_view(request,theuser=0,
'workouttype':'water',
})
@login_required()
def otecp_toadmin_view(request,theuser=0,
startdate=timezone.now()-datetime.timedelta(days=365),
enddate=timezone.now(),
startdatestring="",
enddatestring="",
):
if startdatestring != "":
try:
startdate = iso8601.parse_date(startdatestring)
except ParseError:
pass
if enddatestring != "":
try:
enddate = iso8601.parse_date(enddatestring)
except ParseError:
pass
if theuser == 0:
theuser = request.user.id
r = Rower.objects.get(user=request.user)
startdate = datetime.datetime.combine(startdate,datetime.time())
enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59))
theworkouts = Workout.objects.filter(
user=r,rankingpiece=True,
workouttype__in=[
'rower',
'dynamic',
'slides'
],
startdatetime__gte=startdate,
startdatetime__lte=enddate
).order_by("-startdatetime")
delta,cpvalue,avgpower = dataprep.fetchcp(
r,theworkouts,table='cpergdata'
)
powerdf = pd.DataFrame({
'Delta':delta,
'CP':cpvalue,
})
csvfilename = 'CP_data_user_{id}.csv'.format(
id = theuser
)
powerdf = powerdf[powerdf['CP']>0]
powerdf.dropna(axis=0,inplace=True)
powerdf.sort_values(['Delta','CP'],ascending=[1,0],inplace=True)
powerdf.drop_duplicates(subset='Delta',keep='first',inplace=True)
powerdf.to_csv(csvfilename)
res = myqueue(queuehigh,
handle_sendemailfile,
'Sander',
'Roosendaal',
'roosendaalsander@gmail.com',
csvfilename,
delete=True)
successmessage = "The CSV file was sent to the site admin per email"
messages.info(request,successmessage)
response = HttpResponseRedirect('/rowers/list-workouts/')
return response
# Show ranking distances including predicted paces
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
def oterankings_view(request,theuser=0,