From e6826d75c59e2630f934b47c16bcee91e20f62ea Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Tue, 16 Apr 2024 13:17:36 +0200 Subject: [PATCH] fixing some tests, fixes for failing tests --- rowers/dataprep.py | 4 +++- rowers/datautils.py | 2 ++ rowers/interactiveplots.py | 28 +++++++++++++++++--------- rowers/tests/test_unit_tests.py | 2 +- rowers/tests/test_urls.py | 5 ----- rowers/tests/testdata/testdata.tcx.gz | Bin 3998 -> 3999 bytes rowers/tests/viewnames.csv | 2 -- 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/rowers/dataprep.py b/rowers/dataprep.py index c6f8049d..c69aeffa 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -820,7 +820,9 @@ def update_rolling_cp(r, types, mode='water', dosend=False): powerdf.dropna(axis=0, inplace=True) powerdf.sort_values(['Delta', 'CP'], ascending=[1, 0], inplace=True) powerdf.drop_duplicates(subset='Delta', keep='first', inplace=True) - + if powerdf.empty: + return False + res2 = datautils.cpfit(powerdf) p1 = res2[0] # calculate FTP diff --git a/rowers/datautils.py b/rowers/datautils.py index c53d20cf..c156f307 100644 --- a/rowers/datautils.py +++ b/rowers/datautils.py @@ -83,6 +83,7 @@ def cpfit(powerdf, fraclimit=0.0001, nmax=1000): thesecs = powerdf['Delta'].to_numpy() theavpower = powerdf['CP'].to_numpy() + if len(thesecs) >= 4: try: @@ -95,6 +96,7 @@ def cpfit(powerdf, fraclimit=0.0001, nmax=1000): else: factor = fitfunc(p0, thesecs.mean())/theavpower.mean() p1 = [p0[0]/factor, p0[1]/factor, p0[2], p0[3]] + p1 = [abs(p) for p in p1] fitt = pd.Series(10**(4*np.arange(100)/100.)) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index a0a50b36..1fba7f43 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -340,7 +340,9 @@ def interactive_boxchart(datadf, fieldname, extratitle='', if 'date' not in columns: # pragma: no cover return '', 'Not enough data' - datadf = datadf.with_columns((pl.col("date").apply(lambda x:x.strftime("%Y-%m-%d"))).alias("date")) + + + datadf = datadf.with_columns((pl.col("date").dt.strftime("%Y-%m-%d")).alias("date")) datadf = datadf.with_columns((pl.col(fieldname)).alias("value")) data_dict = datadf.to_dicts() @@ -357,7 +359,7 @@ def interactive_boxchart(datadf, fieldname, extratitle='', def interactive_planchart(data, startdate, enddate): # data = data.melt(id_vars=['startdate'], value_vars=['executed', 'planned']) - data = data.with_columns((pl.col("startdate").apply(lambda x: x.strftime("%Y-%m-%d"))).alias("startdate")) + data = data.with_columns((pl.col("startdate").dt.strftime("%Y-%m-%d")).alias("startdate")) data_dict = data.to_dicts() chart_data = { 'data': data_dict, @@ -625,18 +627,18 @@ def goldmedalscorechart(user, startdate=None, enddate=None): 'id': workoutid, }) - df = df.with_columns((pl.col("id").apply(lambda x: settings.SITE_URL + + df = df.with_columns((pl.col("id").map_elements(lambda x: settings.SITE_URL + '/rowers/workout/{id}/'.format(id=encoder.encode_hex(x)))).alias("url")) - df = df.with_columns((pl.col("id").apply(lambda x: workoutname(x))).alias("workout")) + df = df.with_columns((pl.col("id").map_elements(lambda x: workoutname(x))).alias("workout")) df = df.sort('date') # find index values where score is max dfmax = df.group_by("date", maintain_order=True).max() dfmax = dfmax.fill_nan(0) - dfmax = dfmax.with_columns((pl.col("date").apply(lambda x: x.strftime("%Y-%m-%d"))).alias("date")) - dfmax = dfmax.with_columns((pl.col("duration").apply(lambda x: totaltime_sec_to_string(x, shorten=True))).alias("duration")) - dfmax = dfmax.with_columns((pl.col("markerduration").apply(lambda x: totaltime_sec_to_string(x, shorten=True))).alias("markerduration")) + dfmax = dfmax.with_columns((pl.col("date").dt.strftime("%Y-%m-%d")).alias("date")) + dfmax = dfmax.with_columns((pl.col("duration").map_elements(lambda x: totaltime_sec_to_string(x, shorten=True))).alias("duration")) + dfmax = dfmax.with_columns((pl.col("markerduration").map_elements(lambda x: totaltime_sec_to_string(x, shorten=True))).alias("markerduration")) data_dicts = dfmax.to_dicts() chart_data = { @@ -764,7 +766,7 @@ def performance_chart(user, startdate=None, enddate=None, kfitness=42, kfatigue= "fatigue":df['fatigue'], "form":df['form'], "impulse":df['impulse'], - "date": df['date'].apply(lambda x: x.strftime('%Y-%m-%d')), + "date": df['date'].dt.strftime('%Y-%m-%d'), }) @@ -987,7 +989,7 @@ def leaflet_chart_compare(course, workoutids, labeldict={}, startenddict={}): 'trajectories': trajectories, } - script, div = get_chart("/mapcompare", mapdata, debug=True) + script, div = get_chart("/mapcompare", mapdata, debug=False) return script, div @@ -1267,7 +1269,9 @@ def instroke_multi_interactive_chart(selected, *args, **kwargs): # pragma: no co if len(metrics) > 1: cntr = 1 for analysis in selected: - df2[cntr-1]['y'] = df2[cntr-1]['y'] / maximum_values[analysis.metric] + df2[cntr-1] = df2[cntr-1].with_columns( + (pl.col("y")/ maximum_values[analysis.metric]) + ) ytitle = 'Scaled' cntr = cntr+1 @@ -1376,7 +1380,11 @@ def interactive_chart(id=0, promember=0, intervaldata={}): columns = ['time', 'pace', 'hr', 'fpace', 'ftime', 'spm'] datadf = dataprep.getsmallrowdata_pl(columns, ids=[id]) + if datadf.is_empty(): + return "", "No Valid Data Available" + datadf = datadf.fill_nan(None).drop_nulls() + row = Workout.objects.get(id=id) if datadf.is_empty(): diff --git a/rowers/tests/test_unit_tests.py b/rowers/tests/test_unit_tests.py index 6b20a563..a8b97447 100644 --- a/rowers/tests/test_unit_tests.py +++ b/rowers/tests/test_unit_tests.py @@ -674,7 +674,7 @@ class InteractivePlotTests(TestCase): def test_interactive_boxchart(self): df = pl.read_csv('rowers/tests/testdata/boxplotdata.csv') - df = df.with_columns(pl.col("date").apply(lambda x:datetime.datetime.strptime(x, "%Y-%m-%d"))) + df = df.with_columns(pl.col("date").dt.strftime("%Y-%m-%d")) script, div = interactiveplots.interactive_boxchart(df, 'spm') diff --git a/rowers/tests/test_urls.py b/rowers/tests/test_urls.py index b522fd2d..5d19c820 100644 --- a/rowers/tests/test_urls.py +++ b/rowers/tests/test_urls.py @@ -79,11 +79,6 @@ class URLTests(TestCase): '/rowers/502/', '/rowers/about/', '/rowers/workout/addmanual/', - '/rowers/agegroupcp/30/', - '/rowers/agegroupcp/30/1/', - '/rowers/agegrouprecords/male/hwt/', - '/rowers/agegrouprecords/male/hwt/2000m/', - '/rowers/agegrouprecords/male/hwt/30min/', '/rowers/ajax_agegroup/45/hwt/male/1/', '/rowers/analysis/', '/rowers/analysis/user/1/', diff --git a/rowers/tests/testdata/testdata.tcx.gz b/rowers/tests/testdata/testdata.tcx.gz index ac4ffb0c87e4512084761e3ace406f9fea46db4f..62c65b68b6e7bcbae639a5433d0bde8f0bbe803e 100644 GIT binary patch delta 257 zcmV+c0sj7;ADGkU5<>k-)ExnKF&?^t;!NpZ42sxO}uDI@OA07VuEVJ4Ex!e9r zdW)aEKK)~v?hN1_!0!Kp#g#91Pk#HD4)1JHuh!`~JWME;7mw1@_#<8V@Xr4LT7Xbc H#DD<+l<1LA delta 256 zcmV+b0ssD=AD$lvABzYGi0vD(2dNH!4C3sP*ui(l{SOC=-2r!YXZrXX^XJP?tKIhp z4=)nOvx^V=KI_ukb8+@|)2&~2Cnwvdl|HW4$1l6SOXux&Z>9~UjulrYL7gt`B z2j}M}tD~+@KmGE>xIFh)CrjV`^m=vj^77~Ymfpv7=#_`_VawC*Kk1U$S#b4l^Vhqr z)@iesPy1~*Tt3<_&VTSC-SpwF%adidStbto(}zcQ<-QJ{bnD~Cj}Cu+mf39o+-?6Q zy~WR7pZ>8-cLs0|VE6yQ;>s7hC%=76hj+H9SL^f~9wwB_i%02c{E;qwc;|o7@Zavl GfB^ut%#x)5 diff --git a/rowers/tests/viewnames.csv b/rowers/tests/viewnames.csv index 2f341b8d..245dbb17 100644 --- a/rowers/tests/viewnames.csv +++ b/rowers/tests/viewnames.csv @@ -1,9 +1,7 @@ ,id,view,function,anonymous,anonymous_response,own,own_response,own_nonperm,member,member_response,member_nonperm,coachee,coachee_response,coachee_nonperm,is_staff,userid,workoutid,dotest,realtest,kwargs 0,0,workouts_summaries_email_view,sends summary excel with workouts list and links to data to user,TRUE,302,basic,200,302,FALSE,403,403,FALSE,403,403,FALSE,FALSE,FALSE,TRUE,TRUE, 1,1,rower_update_empower_view,updates old Empower Oarlock files (corrects Power bug),TRUE,302,basic,200,302,FALSE,200,302,FALSE,200,302,FALSE,FALSE,FALSE,TRUE,TRUE, -2,2,agegroupcpview,needs age,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE, 3,4,ajax_agegrouprecords,gets age group records from C2 ,TRUE,200,basic,200,302,basic,200,302,coach,200,302,FALSE,FALSE,FALSE,FALSE,FALSE, -5,6,agegrouprecordview,shows ergo age group records,TRUE,200,basic,200,302,FALSE,200,302,FALSE,200,302,FALSE,FALSE,FALSE,TRUE,TRUE, 6,7,workouts_view,workouts list,TRUE,302,basic,200,302,basic,200,403,coach,200,403,FALSE,TRUE,FALSE,TRUE,TRUE, 7,8,virtualevents_view,virtual races list,TRUE,200,basic,200,302,FALSE,200,302,FALSE,200,302,FALSE,FALSE,FALSE,TRUE,TRUE, 8,9,virtualevent_create_view,create virtual event,TRUE,302,basic,200,302,FALSE,200,302,FALSE,200,302,FALSE,FALSE,FALSE,TRUE,TRUE,