Private
Public Access
1
0

passing tests ...

This commit is contained in:
2024-04-29 21:41:34 +02:00
parent f6c535d2d6
commit e83d0a26f6
7 changed files with 44 additions and 47 deletions

View File

@@ -1,8 +1,10 @@
import pandas as pd
import polars as pl
import numpy as np
from scipy.interpolate import griddata
from scipy import optimize
from rowers.mytypes import otwtypes, otetypes, rowtypes
from rowers.models import Workout
@@ -358,8 +360,8 @@ def getmaxwattinterval(tt, ww, i):
def getfastest(df, thevalue, mode='distance'):
tt = df['time'].copy()
dd = df['cumdist'].copy()
tt = df['time'].clone()
dd = df['cumdist'].clone()
tmax = tt.max()
if mode == 'distance': # pragma: no cover
@@ -370,40 +372,28 @@ def getfastest(df, thevalue, mode='distance'):
return 0
# 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.
newlen = 1000
newt = np.arange(newlen)*tmax/float(newlen)
deltat = newt[1]-newt[0]
dd = griddata(tt.values,
dd.values, newt, method='linear', rescale=True)
dd = griddata(tt.to_numpy(),
dd.to_numpy(), newt, method='linear', rescale=True)
tt = pd.Series(newt, dtype='float')
dd = pd.Series(dd, dtype='float')
tt = pl.Series(newt, dtype=pl.Float64)
dd = pl.Series(dd, dtype=pl.Float64)
G = pl.concat([pl.Series([0.0]), dd])
G = pd.concat([pd.Series([0]), dd])
# T = 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)
# Thor = np.outer(ones, T)
# Tver = np.outer(T, ones)
Gver = np.outer(G, ones)
Gdif = Ghor-Gver
Gdif = np.tril(Gdif.T).T
Gdif = pd.DataFrame(Gdif)
Gdif = pl.DataFrame(Gdif)
F = Gdif
F.fillna(inplace=True, method='ffill', axis=1)
F.fillna(inplace=True, value=0)
F = F.fill_nan(0)
restime = []
distance = []
@@ -414,7 +404,7 @@ def getfastest(df, thevalue, mode='distance'):
restime.append(deltat*i)
cp = np.diag(F, i).max()
loc = np.argmax(np.diag(F, i))
thestarttime = tt[loc]
thestarttime = tt.to_numpy()[loc]
starttimes.append(thestarttime)
distance.append(cp)
@@ -424,10 +414,6 @@ def getfastest(df, thevalue, mode='distance'):
distance = np.array(distance)
starttimes = np.array(starttimes)
# for i in range(len(restime)):
# if restime[i]<thevalue*60*1000:
# print(i,restime[i],distance[i],60*1000*thevalue)
if mode == 'distance':
duration = griddata(distance, restime, [
thevalue], method='linear', rescale=True)
@@ -436,7 +422,6 @@ def getfastest(df, thevalue, mode='distance'):
distance = griddata(distance, distance, [
thevalue], method='linear', rescale=True)
endtime = starttime+duration
# print(duration,starttime,endtime,'aa')
return duration[0]/1000., starttime[0]/1000., endtime[0]/1000.
else: # pragma: no cover
distance = griddata(restime, distance, [