diff --git a/rowers/datautils.py b/rowers/datautils.py index 603a3b2f..426005da 100644 --- a/rowers/datautils.py +++ b/rowers/datautils.py @@ -398,10 +398,12 @@ def getfastest(df,thevalue,mode='distance'): dd = pd.Series(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) Gver = np.outer(G,ones) Gdif = Ghor-Gver Gdif = np.tril(Gdif.T).T @@ -413,27 +415,42 @@ def getfastest(df,thevalue,mode='distance'): restime = [] distance = [] + starttimes = [] + endtime = [] for i in np.arange(0,len(tt)+1,1): restime.append(deltat*i) cp = np.diag(F,i).max() + loc = np.argmax(np.diag(F,i)) + thestarttime = np.diag(Thor,i)[loc] + starttimes.append(thestarttime) distance.append(cp) + distance[0] = distance[1] restime = np.array(restime) distance = np.array(distance) + starttimes = np.array(starttimes) #for i in range(len(restime)): # if restime[i] 0: w.plannedsession = ps @@ -418,6 +418,8 @@ def add_workouts_plannedsession(ws,ps,r): coursecompleted = True, workoutid=w.id, distance = ps.sessionvalue, + startsecond=starttime, + endsecond=endtime, ) record.save() @@ -440,7 +442,7 @@ def add_workouts_plannedsession(ws,ps,r): record.delete() df = dataprep.getsmallrowdata_db(['time','cumdist'],ids=[w.id]) - fastest_meters = datautils.getfastest(df,ps.sessionvalue,mode='time') + fastest_meters,starttime,endtime = datautils.getfastest(df,ps.sessionvalue,mode='time') if fastest_meters > 0: w.plannedsession = ps @@ -454,6 +456,8 @@ def add_workouts_plannedsession(ws,ps,r): duration = duration, coursecompleted = True, distance = fastest_meters, + startsecond=starttime, + endsecond=endtime, ) record.save() else: