Offline CP calculations for OTW
A new table in the database with precalculated CP values. The data are updated through RQ/Celery asynchronous functions
This commit is contained in:
@@ -98,7 +98,8 @@ from rowers.rows import handle_uploaded_file
|
||||
from rowers.tasks import handle_makeplot,handle_otwsetpower,handle_sendemailtcx,handle_sendemailcsv
|
||||
from rowers.tasks import (
|
||||
handle_sendemail_unrecognized,handle_sendemailnewcomment,
|
||||
handle_sendemailnewresponse, handle_updatedps
|
||||
handle_sendemailnewresponse, handle_updatedps,
|
||||
handle_updatecp
|
||||
)
|
||||
|
||||
from scipy.signal import savgol_filter
|
||||
@@ -2977,6 +2978,10 @@ def workout_update_cp_view(request,id=0):
|
||||
row.rankingpiece = True
|
||||
row.save()
|
||||
|
||||
r = getrower(request.user)
|
||||
|
||||
dataprep.runcpupdate(r)
|
||||
|
||||
url = reverse(otwrankings_view)
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
@@ -3089,39 +3094,12 @@ def otwrankings_view(request,theuser=0,
|
||||
startdatetime__lte=enddate)
|
||||
|
||||
|
||||
# get all power data from database (plus workoutid)
|
||||
theids = [int(w.id) for w in theworkouts]
|
||||
columns = ['power','workoutid','time']
|
||||
df = dataprep.getsmallrowdata_db(columns,ids=theids)
|
||||
|
||||
thesecs = []
|
||||
|
||||
for w in theworkouts:
|
||||
timesecs = 3600*w.duration.hour
|
||||
timesecs += 60*w.duration.minute
|
||||
timesecs += w.duration.second
|
||||
timesecs += 1.e-5*w.duration.microsecond
|
||||
|
||||
thesecs.append(timesecs)
|
||||
|
||||
|
||||
if len(thesecs) != 0:
|
||||
maxt = 1.05*pd.Series(thesecs).max()
|
||||
else:
|
||||
maxt = 1000.
|
||||
|
||||
|
||||
logarr = datautils.getlogarr(maxt)
|
||||
|
||||
dfgrouped = df.groupby(['workoutid'])
|
||||
delta,cpvalue,avgpower = datautils.getcp(dfgrouped,logarr)
|
||||
delta,cpvalue,avgpower = dataprep.fetchcp(r,theworkouts)
|
||||
|
||||
powerdf = pd.DataFrame({
|
||||
'Delta':delta,
|
||||
'CP':cpvalue,
|
||||
})
|
||||
|
||||
|
||||
|
||||
powerdf = powerdf[powerdf['CP']>0]
|
||||
powerdf.dropna(axis=0,inplace=True)
|
||||
@@ -3203,7 +3181,7 @@ def otwrankings_view(request,theuser=0,
|
||||
|
||||
|
||||
del form.fields["pieceunit"]
|
||||
|
||||
|
||||
messages.error(request,message)
|
||||
return render(request, 'otwrankings.html',
|
||||
{'rankingworkouts':theworkouts,
|
||||
@@ -6655,6 +6633,10 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
||||
r.write_csv(row.csvfilename,gzip=True)
|
||||
dataprep.update_strokedata(id,r.df)
|
||||
successmessage = "Changes saved"
|
||||
|
||||
if rankingpiece:
|
||||
dataprep.runcpupdate(row.user)
|
||||
|
||||
messages.info(request,successmessage)
|
||||
url = reverse(workout_edit_view,
|
||||
kwargs = {
|
||||
|
||||
Reference in New Issue
Block a user