diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 8d508a48..07a84620 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,15 @@ 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. + if xaxmax == 0: + xaxmax = tseconds.max() else: xaxmax = datadf['distance'].max() xaxmin = datadf['distance'].min() @@ -5170,12 +5176,29 @@ 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) + if endsecond > 0: + 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] + elif xparam == 'distance': + group['distance'] = group['distance'] - group['distance'].min() + + try: group['x'] = group[xparam] except KeyError: diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 0f2db8d6..40be42c1 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -1524,6 +1524,13 @@ def virtualevent_compare_view(request,id=0): workoutids = [result.workoutid for result in results] + startenddict = {} + if race.sessiontype == 'race': + for result in results: + startenddict[result.workoutid] = (result.startsecond,result.endsecond) + + + if len(workoutids) == 0: url = reverse('virtualevent_view', kwargs={ @@ -1536,7 +1543,11 @@ def virtualevent_compare_view(request,id=0): if request.method == 'GET': - xparam = race.sessionmode if race.sessionmode in ['distance','time'] else 'time' + xparam = 'time' + if race.sessionmode == 'distance': + xparam = 'cumdist' + + yparam = 'pace' plottype = 'line' @@ -1555,10 +1566,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 +1598,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 +1612,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]