From ac2ad454bb3f752e1e3a5b9b1f367bb22c067090 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 2 Jan 2023 22:22:51 +0100 Subject: [PATCH] quiske fixes --- rowers/dataprep.py | 32 ++++++++++++++++++++++++++++++++ rowers/plannedsessions.py | 7 +++++++ rowers/views/workoutviews.py | 16 ++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/rowers/dataprep.py b/rowers/dataprep.py index d891396e..a5972d17 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -110,6 +110,12 @@ from django.core.exceptions import ValidationError from time import strftime import arrow +from rq.job import Job +from rq.registry import StartedJobRegistry +from redis import Redis +from rq import Queue + + thetimezone = get_current_timezone() allowedcolumns = [key for key, value in strokedatafields.items()] @@ -1542,7 +1548,24 @@ def new_workout_from_df(r, df, # A wrapper around the rowingdata class, with some error catching +from redis import StrictRedis, Redis +def get_existing_job(w): + # check if this filename is in the queue + r = StrictRedis() + for key in r.keys(): + res = key.decode('utf8').split(':') + if len(res) == 3: + jobid = res[2] + try: + job = Job.fetch(jobid, connection=r) + if isinstance(job.args[1], str): + if job.args[1] == w.csvfilename: + return 1 + except: + pass + + return 0 def workout_trimp(w, reset=False): r = w.user @@ -1550,6 +1573,9 @@ def workout_trimp(w, reset=False): if w.trimp > 0 and not reset: return w.trimp, w.hrtss + if get_existing_job(w): + return 0, 0 + r = w.user ftp = float(r.ftp) if w.workouttype in otwtypes: @@ -1592,6 +1618,9 @@ def workout_rscore(w, reset=False): if w.rscore > 0 and not reset: return w.rscore, w.normp + if get_existing_job(w): + return 0, 0 + r = w.user ftp = float(r.ftp) if w.workouttype in otwtypes: @@ -1620,6 +1649,9 @@ def workout_normv(w, pp=4.0): if w.normv > 0: # pragma: no cover return w.normv, w.normw + if get_existing_job(w): + return 0, 0 + r = w.user ftp = float(r.ftp) if w.workouttype in otwtypes: diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py index 5f1c1a37..1b52f280 100644 --- a/rowers/plannedsessions.py +++ b/rowers/plannedsessions.py @@ -320,6 +320,9 @@ def get_execution_report(rower, startdate, enddate, plan=None): def get_indoorraces(workout): + if workout is None: + return [] + races1 = VirtualRace.objects.filter( sessiontype='indoorrace', startdate__lte=workout.date, @@ -327,6 +330,10 @@ def get_indoorraces(workout): sessionmode='distance', sessionvalue=workout.distance) + + if workout.duration is None: + workout.duration = timedelta(0) + if workout.duration.second == 0 and workout.duration.microsecond == 0: duration = 60*workout.duration.hour+workout.duration.minute diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index c8ec5e45..623c1594 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -3383,6 +3383,22 @@ def instroke_chart_interactive(request, id=0, analysis=0, userid=0): activeminutesmax=activeminutesmax, ) + + if metric == 'boat accelerator curve' and data.median().max() < 0.5: + data = 9.81*data + + if metric == 'instroke boat speed' and data.median().max() < 0.15: + rowdata.add_instroke_speed() + rowdata.write_csv(w.csvfilename, gzip=True) + data = rowdata.get_instroke_data( + metric, + spm_min=spm_min, + spm_max=spm_max, + activeminutesmin=activeminutesmin, + activeminutesmax=activeminutesmax, + ) + + script, div = instroke_interactive_chart( data, metric, w, spm_min,