Merge branch 'develop' into feature/fastestchallenges
This commit is contained in:
@@ -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]<thevalue*60*1000:
|
||||
# print(i,restime[i],distance[i],60*1000*thevalue)
|
||||
|
||||
d2 = 0
|
||||
|
||||
if mode == 'distance':
|
||||
d2 = griddata(distance,restime,[thevalue],method='linear',rescale=True)
|
||||
return d2[0]/1000.
|
||||
duration = griddata(distance,restime,[thevalue],method='linear',rescale=True)
|
||||
starttime = griddata(distance,starttimes,[thevalue],method='linear',rescale=True)
|
||||
distance = griddata(distance,distance,[thevalue],method='linear',rescale=True)
|
||||
endtime = starttime+duration
|
||||
print(duration,starttime,endtime)
|
||||
return duration[0]/1000.,starttime[0]/1000.,endtime[0]/1000.
|
||||
else:
|
||||
d2 = griddata(restime,distance,[thevalue*60*1000],method='linear',rescale=True)
|
||||
return d2[0]
|
||||
distance = griddata(restime,distance,[thevalue*60*1000],method='linear',rescale=True)
|
||||
starttime = griddata(restime,starttimes,[thevalue*60*1000],method='linear',rescale=True)
|
||||
duration = griddata(restime,restime,[thevalue*60*1000],method='linear',rescale=True)
|
||||
endtime = starttime+duration
|
||||
return distance[0],starttime[0]/1000.,endtime[0]/1000.
|
||||
|
||||
return 0
|
||||
|
||||
@@ -3267,6 +3267,9 @@ class IndoorVirtualRaceResult(models.Model):
|
||||
acceptsocialmedia = models.BooleanField(default=True,
|
||||
verbose_name = 'I agree with sharing my name in challenge related social media posts (unchecking this does not prevent you from participation)')
|
||||
|
||||
startsecond = models.FloatField(default=0)
|
||||
endsecond = models.FloatField(default=0)
|
||||
|
||||
def isduplicate(self,other):
|
||||
if self.userid != other.userid:
|
||||
return False
|
||||
@@ -3335,7 +3338,8 @@ class CourseTestResult(models.Model):
|
||||
duration = models.TimeField(default=datetime.time(1,0))
|
||||
distance = models.IntegerField(default=0)
|
||||
coursecompleted = models.BooleanField(default=False)
|
||||
|
||||
startsecond = models.FloatField(default=0)
|
||||
endsecond = models.FloatField(default=0)
|
||||
|
||||
|
||||
class IndoorVirtualRaceResultForm(ModelForm):
|
||||
|
||||
@@ -403,7 +403,7 @@ def add_workouts_plannedsession(ws,ps,r):
|
||||
record.delete()
|
||||
|
||||
df = dataprep.getsmallrowdata_db(['time','cumdist'],ids=[w.id])
|
||||
fastest_milliseconds = datautils.getfastest(df,ps.sessionvalue,mode='distance')
|
||||
fastest_milliseconds,starttime,endtime = datautils.getfastest(df,ps.sessionvalue,mode='distance')
|
||||
|
||||
if fastest_milliseconds > 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:
|
||||
|
||||
Reference in New Issue
Block a user