From ee02c6f57f383ee897bad63b1f6d8d09a212ea42 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 6 Jan 2021 21:12:08 +0100 Subject: [PATCH 1/3] setting marker on workout first save --- rowers/dataprep.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 21739f73..e495403c 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -1102,6 +1102,56 @@ def workout_goldmedalstandard(workout): else: return 0,0 +def check_marker(workout): + r = workout.user + ws = Workout.objects.filter(date__gte=workout.date-datetime.timedelta(days=r.kfit), + date__lte=workout.date, + user=r,duplicate=False, + ).order_by("date") + ids = [] + gms = [] + for w in ws: + gmstandard,gmseconds = workout_goldmedalstandard(w) + if gmseconds>60: + ids.append(w.id) + gms.append(gmstandard) + + df = pd.DataFrame({ + 'id':ids, + 'gms':gms, + }) + + if df.empty: + workout.ranking = True + workout.save() + return workout + + indexmax = df['gms'].idxmax() + theid = df.loc[indexmax,'id'] + + wmax = Workout.objects.get(id=theid) + gms_max = wmax.goldmedalstandard + + # check if equal, bigger, or smaller than previous + if not wmax.rankingpiece: + rankingworkouts = ws.filter(rankingpiece=True) + if len(rankingworkouts) == 0: + wmax.rankingpiece = True + wmax.save() + return wmax + + lastranking = rankingworkouts[len(rankingworkouts)-1] + if lastranking.goldmedalstandard+0.2 < wmax.goldmedalstandard: + wmax.rankingpiece = True + wmax.save() + return wmax + else: + return wmax + + return None + + + def calculate_goldmedalstandard(rower,workout,recurrance=True): cpfile = 'media/cpdata_{id}.parquet.gz'.format(id=workout.id) try: @@ -1470,6 +1520,8 @@ def checkbreakthrough(w, r): # submit email task to send email about breakthrough workout if isbreakthrough: + w.rankingpiece = True + w.save() if r.getemailnotifications and not r.emailbounced: job = myqueue(queuehigh,handle_sendemail_breakthrough, w.id, @@ -1480,6 +1532,8 @@ def checkbreakthrough(w, r): # submit email task to send email about breakthrough workout if ishard: + w.rankingpiece = True + w.save() if r.getemailnotifications and not r.emailbounced: job = myqueue(queuehigh,handle_sendemail_hard, w.id, @@ -1724,6 +1778,8 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower', # check for duplicate start times and duration duplicate = checkduplicates(r,workoutdate,workoutstartdatetime,workoutenddatetime) + if duplicate: + rankingpiece = False # test title length if title is not None and len(title)>140: @@ -1771,6 +1827,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower', job = myqueue(queuehigh,handle_calctrimp,w.id,f2,r.ftp,r.sex,r.hrftp,r.max,r.rest) isbreakthrough, ishard = checkbreakthrough(w, r) + marker = check_marker(w) return (w.id, message) From 67fc069cf6fb95d28248cd5acb76fd5ab813bbac Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 6 Jan 2021 21:17:57 +0100 Subject: [PATCH 2/3] fix duplicate case --- rowers/dataprep.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/rowers/dataprep.py b/rowers/dataprep.py index e495403c..e6d50ad3 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -1104,7 +1104,8 @@ def workout_goldmedalstandard(workout): def check_marker(workout): r = workout.user - ws = Workout.objects.filter(date__gte=workout.date-datetime.timedelta(days=r.kfit), + dd = arrow.get(workout.date).datetime-datetime.timedelta(days=r.kfit) + ws = Workout.objects.filter(date__gte=dd, date__lte=workout.date, user=r,duplicate=False, ).order_by("date") @@ -1520,8 +1521,9 @@ def checkbreakthrough(w, r): # submit email task to send email about breakthrough workout if isbreakthrough: - w.rankingpiece = True - w.save() + if not w.duplicate: + w.rankingpiece = True + w.save() if r.getemailnotifications and not r.emailbounced: job = myqueue(queuehigh,handle_sendemail_breakthrough, w.id, @@ -1532,8 +1534,9 @@ def checkbreakthrough(w, r): # submit email task to send email about breakthrough workout if ishard: - w.rankingpiece = True - w.save() + if not w.duplicate: + w.rankingpiece = True + w.save() if r.getemailnotifications and not r.emailbounced: job = myqueue(queuehigh,handle_sendemail_hard, w.id, From 44669eaa5d1dc851b36b4bd15f2e18047ebbd076 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 6 Jan 2021 21:58:28 +0100 Subject: [PATCH 3/3] perf chart and gms chart now use rankingpiece --- rowers/dataprep.py | 5 +++ rowers/interactiveplots.py | 62 ++++++++++++++------------------------ 2 files changed, 27 insertions(+), 40 deletions(-) diff --git a/rowers/dataprep.py b/rowers/dataprep.py index e6d50ad3..bdef3641 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -1104,10 +1104,15 @@ def workout_goldmedalstandard(workout): def check_marker(workout): r = workout.user + gmstandard,gmseconds = workout_goldmedalstandard(workout) + if gmseconds<60: + return None + dd = arrow.get(workout.date).datetime-datetime.timedelta(days=r.kfit) ws = Workout.objects.filter(date__gte=dd, date__lte=workout.date, user=r,duplicate=False, + workouttype__in=mytypes.rowtypes, ).order_by("date") ids = [] gms = [] diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index dacd6799..b8418865 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -1801,9 +1801,17 @@ def goldmedalscorechart(user,startdate=None,enddate=None): duplicate=False) # marker workouts - dates,testpower,testduration,fatigues,fitnesses,impulses, outids = build_goldmedalstandards( - workouts,42 - ) + workouts = Workout.objects.filter(user=user.rower,date__gte=startdate, + date__lte=enddate, + workouttype__in=mytypes.rowtypes, + duplicate=False).order_by('date') + + markerworkouts = workouts.filter(rankingpiece=True) + outids = [w.id for w in markerworkouts] + dates = [arrow.get(w.date).datetime for w in markerworkouts] + testpower = [w.goldmedalstandard if w.rankingpiece else np.nan for w in markerworkouts] + + testduration = [w.goldmedalseconds if w.rankingpiece else 0 for w in markerworkouts] df = pd.DataFrame({ 'id':outids, @@ -1813,8 +1821,8 @@ def goldmedalscorechart(user,startdate=None,enddate=None): }) df.sort_values(['date'],inplace=True) - df['testdup'] = df['testpower'].shift(1) - df['testpower'] = df.apply(lambda x: newtestpower(x),axis=1) + #df['testdup'] = df['testpower'].shift(1) + #df['testpower'] = df.apply(lambda x: newtestpower(x),axis=1) #df['date'] = df.apply(lambda x: newtestpowerdate(x), axis=1) @@ -1985,41 +1993,16 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, workouts = Workout.objects.filter(user=user.rower,date__gte=startdate, date__lte=enddate, workouttype__in=mytypes.rowtypes, - duplicate=False) - dates,testpower,testduration,fatigues,fitnesses,impulses, outids = build_goldmedalstandards( - workouts,kfitness - ) + duplicate=False).order_by('date') - - df = pd.DataFrame({ - 'id': outids, - 'date':dates, - 'testpower':testpower, - 'testduration':testduration, - 'fatigue':fatigues, - 'fitness':fitnesses, - 'impulse':impulses, - }) - df.sort_values(['date'],inplace=True) - if showtests: - df['testdup'] = df['testpower'].shift(1) - df['testpower'] = df.apply(lambda x: newtestpower(x),axis=1) - df['id'] = df.apply(lambda x: newtestpowerid(x),axis=1) - - #try: - # df['testpower'].iloc[-1] = df['testdup'].iloc[-1] - #except IndexError: - # pass - - - dates = [d for d in df['date']] - testpower = df['testpower'].values.tolist() - fatigues = df['fatigue'].values.tolist() - fitnesses = df['fitness'].values.tolist() - testduration = df['testduration'].values.tolist() - impulses = df['impulse'].tolist() - - outids = df['id'].unique() + markerworkouts = workouts.filter(rankingpiece=True) + outids = [w.id for w in markerworkouts] + dates = [arrow.get(w.date).datetime for w in workouts] + testpower = [w.goldmedalstandard if w.rankingpiece else np.nan for w in workouts] + impulses = [np.nan for w in workouts] + testduration = [w.goldmedalseconds if w.rankingpiece else 0 for w in workouts] + fitnesses = [np.nan for w in workouts] + fatigues = [np.nan for w in workouts] fatigues,fitnesses,dates,testpower,testduration,impulses = getfatigues(fatigues, fitnesses, @@ -2031,7 +2014,6 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, kfatigue,kfitness) - df = pd.DataFrame({ 'date':dates, 'testpower':testpower,