From e08ebd1d645b4ec1a9ab54a008fde45f8fe8029c Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 9 Nov 2020 19:16:21 +0100 Subject: [PATCH] getfastest (distance) --- rowers/datautils.py | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/rowers/datautils.py b/rowers/datautils.py index a9610e99..dda402c0 100644 --- a/rowers/datautils.py +++ b/rowers/datautils.py @@ -364,3 +364,54 @@ def getmaxwattinterval(tt,ww,i): deltat = 0 return deltat,wmax + +def getfastest(df,thedistance): + tt = df['time'].copy() + dd = df['cumdist'].copy() + + tmax = tt.max() + + if tmax > 500000: + newlen=int(tmax/2000.) + newt = np.arange(newlen)*tmax/float(newlen) + deltat = newt[1]-newt[0] + else: + newt = np.arange(0,tmax,10.) + deltat = 10. + + dd = griddata(tt.values, + dd.values,newt,method='linear',rescale=True) + + tt = pd.Series(newt) + dd = pd.Series(dd) + + G = pd.concat([pd.Series([0]),dd]) + h = np.mgrid[0:len(tt)+1:1,0:len(tt)+1:1] + distances = pd.DataFrame(h[1]-h[0]) + ones = 1+np.zeros(len(G)) + Ghor = np.outer(ones,G) + Gver = np.outer(G,ones) + Gdif = Ghor-Gver + Gdif = np.tril(Gdif.T).T + Gdif = pd.DataFrame(Gdif) + F = Gdif + + F.fillna(inplace=True,method='ffill',axis=1) + F.fillna(inplace=True,value=0) + + restime = [] + distance = [] + + for i in np.arange(0,len(tt)+1,1): + restime.append(deltat*i) + cp = np.diag(F,i).max() + distance.append(cp) + + distance[0] = distance[1] + + restime = np.array(restime) + distance = np.array(distance) + + d2 = griddata(distance,restime,[thedistance],method='linear',rescale=True) + + return d2[0]/1000.