From c3b404f8b6e7d56b7c78ac3f38c30406b3f11f04 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Sun, 24 May 2020 17:11:41 +0200 Subject: [PATCH] OTW compare only uses data on course --- rowers/interactiveplots.py | 25 +++++++++++++++++++++++-- rowers/views/workoutviews.py | 13 +++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 8d508a48..cf336baa 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -5045,7 +5045,7 @@ def interactive_bar_chart(id=0,promember=0): def interactive_multiple_compare_chart(ids,xparam,yparam,plottype='line', promember=0, - labeldict=None): + labeldict=None,startenddict={}): message = '' errormessage = '' @@ -5085,9 +5085,13 @@ def interactive_multiple_compare_chart(ids,xparam,yparam,plottype='line', if xparam != 'distance' and xparam != 'time' and xparam != 'cumdist': xaxmax = yaxmaxima[xparam] xaxmin = yaxminima[xparam] - elif xparam == 'time': + elif xparam == 'time' and not startenddict: xaxmax = tseconds.max() xaxmin = tseconds.min() + elif xparam == 'time' and startenddict: + deltas = [pair[1]-pair[0] for key,pair in startenddict.items()] + xaxmin = 0 + xaxmax = pd.Series(deltas).max()*1000. else: xaxmax = datadf['distance'].max() xaxmin = datadf['distance'].min() @@ -5170,10 +5174,27 @@ def interactive_multiple_compare_chart(ids,xparam,yparam,plottype='line', for id,color in items: group = datadf[datadf['workoutid']==int(id)].copy() + try: + startsecond,endsecond = startenddict[id] + except KeyError: + startsecond = 0 + endsecond = 0 group.sort_values(by='time',ascending=True,inplace=True) + group['time'] = group['time'] - 1.e3*startsecond + + mask = group['time'] < 0 + group.mask(mask,inplace=True) + mask = group['time'] > 1.e3*(endsecond-startsecond) + group.mask(mask,inplace=True) + + + + + if xparam == 'cumdist': + group['cumdist'] = group['cumdist'] - group['cumdist'].min() res = make_cumvalues(group[xparam]) group[xparam] = res[0] try: diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 0f2db8d6..bf50dcd2 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -1524,6 +1524,12 @@ def virtualevent_compare_view(request,id=0): workoutids = [result.workoutid for result in results] + startenddict = {} + for result in results: + startenddict[result.workoutid] = (result.startsecond,result.endsecond) + + + if len(workoutids) == 0: url = reverse('virtualevent_view', kwargs={ @@ -1555,10 +1561,13 @@ def virtualevent_compare_view(request,id=0): except Workout.DoesNotExist: pass + labeldict = { int(w.id): w.__str__() for w in workouts } + + chartform = ChartParamChoiceForm( initial = { 'xparam':xparam, @@ -1584,7 +1593,7 @@ def virtualevent_compare_view(request,id=0): for id in workoutids: try: workouts.append(Workout.objects.get( - id=encoder.decode_hex(id))) + id=id)) except Workout.DoesNotExist: pass @@ -1598,7 +1607,7 @@ def virtualevent_compare_view(request,id=0): res = interactive_multiple_compare_chart(workoutids,xparam,yparam, promember=promember, plottype=plottype, - labeldict=labeldict) + labeldict=labeldict,startenddict=startenddict) script = res[0] div = res[1] errormessage = res[3]