From ebea0047cccb8e47c46aa79adb8003404b082822 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Fri, 3 May 2024 16:56:01 +0200 Subject: [PATCH] some fixes, after manual testing --- rowers/dataroutines.py | 43 ++++++++++++++++++++++++++-- rowers/interactiveplots.py | 13 ++++++--- rowers/templates/embedded_video.html | 8 +++--- rowers/templates/multicompare.html | 10 ++----- rowers/views/analysisviews.py | 3 ++ rowers/views/workoutviews.py | 2 ++ 6 files changed, 61 insertions(+), 18 deletions(-) diff --git a/rowers/dataroutines.py b/rowers/dataroutines.py index 40333cdf..9e9f1add 100644 --- a/rowers/dataroutines.py +++ b/rowers/dataroutines.py @@ -186,10 +186,12 @@ def remove_nulls_pl(data): data = data.select(pl.all().forward_fill()) data = data.select(pl.all().backward_fill()) data = data.fill_nan(None) + data = data.select(cs.by_dtype(pl.NUMERIC_DTYPES)).collect() data = data[[s.name for s in data if not s.is_infinite().sum()]] data = data[[s.name for s in data if not (s.null_count() == data.height)]] + if not data.is_empty(): try: data = data.drop_nulls() @@ -207,6 +209,8 @@ def get_video_data(w, groups=['basic'], mode='water'): columns = list(set(columns)) df = getsmallrowdata_pd(columns, ids=[w.id], workstrokesonly=False, doclean=False, compute=False) + df.dropna(axis=0, how='all', inplace=True) + df.dropna(axis=1, how='all', inplace=True) df['time'] = (df['time']-df['time'].min())/1000. @@ -245,7 +249,6 @@ def get_video_data(w, groups=['basic'], mode='water'): coordinates['time'] = coordinates['time']-coordinates['time'].min() latitude = coordinates['latitude'] longitude = coordinates['longitude'] - # bundle data data = { 'boatspeed': boatspeed.values.tolist(), @@ -263,7 +266,10 @@ def get_video_data(w, groups=['basic'], mode='water'): else: sigfigs = dict(rowingmetrics)[c]['sigfigs'] if (c != 'pace'): - da = ((10**sigfigs)*df2[c]).astype(int)/(10**sigfigs) + try: + da = ((10**sigfigs)*df2[c]).astype(int)/(10**sigfigs) + except: + da = df2[c] else: da = df2[c] data[c] = da.values.tolist() @@ -281,6 +287,14 @@ def get_video_data(w, groups=['basic'], mode='water'): maxtime = coordinates['time'].max() + data = pd.DataFrame(data) + data.replace([np.inf, -np.inf], np.nan, inplace=True) + data.dropna(inplace=True) + + data = pl.from_pandas(data) + + data = data.to_dict(as_series=False) + return data, metrics, maxtime @@ -1490,7 +1504,8 @@ def getrowdata_pl(id=0, doclean=False, convertnewtons=True, -def read_data(columns, ids=[], doclean=True, workstrokesonly=True, debug=False, for_chart=False, compute=True): +def read_data(columns, ids=[], doclean=True, workstrokesonly=True, debug=False, for_chart=False, compute=True, + startenddict={}): if ids: csvfilenames = [ 'media/strokedata_{id}.parquet.gz'.format(id=id) for id in ids] @@ -1504,6 +1519,17 @@ def read_data(columns, ids=[], doclean=True, workstrokesonly=True, debug=False, for id, f in zip(ids, csvfilenames): if os.path.isfile(f): df = pl.scan_parquet(f) + if startenddict: + try: + startsecond, endsecond = startenddict[id] + df = df.filter(pl.col("time") >= 1.0e3*startsecond, + pl.col("time") <= 1.0e3*endsecond) + df = df.with_columns(time = pl.col("time")-1.0e3*startsecond) + if 'cumdist' in columns: + df = df.collect() + df = df.with_columns(cumdist = pl.col("cumdist")-df[0, "cumdist"]).lazy() + except KeyError: + pass data.append(df) else: rowdata, row = getrowdata(id=id) @@ -1516,6 +1542,17 @@ def read_data(columns, ids=[], doclean=True, workstrokesonly=True, debug=False, bands=True, otwpower=True, barchart=True, polars=True) df = pl.scan_parquet(f) + if startenddict: + try: + startsecond, endsecond = startenddict[id] + df = df.filter(pl.col("time") >= 1.0e3*startsecond, + pl.col("time") <= 1.0e3*endsecond) + df = df.with_columns(time = pl.col("time")-1.0e3*startsecond) + if 'cumdist' in columns: + df = df.collect() + df = df.with_columns(cumdist = pl.col("cumdist")-df[0, "cumdist"]).lazy() + except KeyError: + pass data.append(df) data = pl.collect_all(data) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 597b5158..b7156e66 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -2099,11 +2099,12 @@ def interactive_multiple_compare_chart(ids, xparam, yparam, plottype='line', promember=0, workstrokesonly=True, labeldict=None, startenddict={}): + print(startenddict) columns = [xparam,yparam] columns_basic = [xparam,yparam] add_columns = [ 'ftime', 'distance', 'fpace', - 'spm', + 'spm','cumdist', 'time', 'pace', 'workoutstate', 'workoutid' ] @@ -2117,15 +2118,17 @@ def interactive_multiple_compare_chart(ids, xparam, yparam, plottype='line', doclean = True - datadf = pd.DataFrame() + datadf = pl.DataFrame() if promember: datadf = dataprep.read_data(columns, ids=ids, doclean=doclean, compute=compute, - workstrokesonly=workstrokesonly, for_chart=True) + workstrokesonly=workstrokesonly, for_chart=True, + startenddict=startenddict) else: datadf = dataprep.read_data(columns_basic, ids=ids, doclean=doclean, compute=compute, - workstrokesonly=workstrokesonly, for_chart=True) + workstrokesonly=workstrokesonly, for_chart=True, + startenddict=startenddict) datadf = dataprep.remove_nulls_pl(datadf) @@ -2135,6 +2138,8 @@ def interactive_multiple_compare_chart(ids, xparam, yparam, plottype='line', datadf = datadf.with_columns(pl.col("workoutid").cast(pl.UInt32).keep_name()) + # filter for start end dict + nrworkouts = len(ids) diff --git a/rowers/templates/embedded_video.html b/rowers/templates/embedded_video.html index 0ff08fbe..0fe35134 100644 --- a/rowers/templates/embedded_video.html +++ b/rowers/templates/embedded_video.html @@ -116,7 +116,7 @@ function copyText() { {% if user.is_authenticated and user == workout.user.user and not locked %}
  • -

    Paste link to you tube video below

    +

    Paste link to Youtube video below

    Use the slider to locate start point for video on workout map

    Playing the video will advance the data in synchonization. Use the regular YouTube controls @@ -169,9 +169,8 @@ function copyText() {

  • - - + + -

    Interactive Comparison

    @@ -22,6 +17,7 @@
  • {{ the_div|safe }} + {{ interactiveplot |safe }}
  • diff --git a/rowers/views/analysisviews.py b/rowers/views/analysisviews.py index ec51ac2d..587db08d 100644 --- a/rowers/views/analysisviews.py +++ b/rowers/views/analysisviews.py @@ -387,6 +387,9 @@ def trendflexdata(workouts, options, userid=0): datadf = dataprep.filter_df(datadf, 'driveneergy', workmax, largerthan=False) + if yparam == 'power': + datadf = dataprep.filter_df(datadf, 'power', 1, largerthan=True) + datadf.dropna(axis=0, how='any', inplace=True) datemapping = { diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 6734e606..e4b49aef 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -347,6 +347,7 @@ def workout_video_create_view(request, id=0): # get data data, metrics, maxtime = dataprep.get_video_data( w, groups=metricsgroups, mode=mode) + hascoordinates = pd.Series(data['latitude']).std() > 0 # create map @@ -377,6 +378,7 @@ def workout_video_create_view(request, id=0): template = 'embedded_video.html' + return render(request, template, {