minimal refactoring and unique together constraint
This commit is contained in:
@@ -3728,5 +3728,8 @@ class VideoAnalysis(models.Model):
|
||||
delay = models.IntegerField(default=0)
|
||||
workout = models.ForeignKey(Workout, on_delete=models.CASCADE)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('video_id','workout')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
@@ -46,6 +46,50 @@ def get_video_id(url):
|
||||
else:
|
||||
raise ValueError
|
||||
|
||||
def get_video_data(w):
|
||||
df = getsmallrowdata_db(['time','velo','spm'],ids=[w.id],
|
||||
workstrokesonly=False,doclean=False,compute=False)
|
||||
df['time'] = (df['time']-df['time'].min())/1000.
|
||||
df.sort_values(by='time',inplace=True)
|
||||
|
||||
|
||||
df.set_index(pd.to_timedelta(df['time'],unit='s'),inplace=True)
|
||||
df2 = df.resample('1s').mean().interpolate()
|
||||
|
||||
|
||||
#mask = df2['time'] < delay
|
||||
#df2 = df2.mask(mask).dropna()
|
||||
df2['time'] = (df2['time']-df2['time'].min())
|
||||
|
||||
boatspeed = (100*df2['velo']).astype(int)/100.
|
||||
spm = (10*df2['spm']).astype(int)/10.
|
||||
|
||||
coordinates = dataprep.get_latlon_time(w.id)
|
||||
|
||||
coordinates.set_index(pd.to_timedelta(coordinates['time'],unit='s'),inplace=True)
|
||||
coordinates = coordinates.resample('1s').mean().interpolate()
|
||||
#mask = coordinates['time'] < delay
|
||||
#coordinates = coordinates.mask(mask).dropna()
|
||||
coordinates['time'] = coordinates['time']-coordinates['time'].min()
|
||||
latitude = coordinates['latitude']
|
||||
longitude = coordinates['longitude']
|
||||
|
||||
# create map
|
||||
mapscript, mapdiv = leaflet_chart_video(latitude,longitude,
|
||||
w.name)
|
||||
|
||||
# bundle data
|
||||
data = {
|
||||
'boatspeed':[ v for v in boatspeed.values],
|
||||
'latitude':[ l for l in latitude.values],
|
||||
'longitude':[ l for l in longitude.values],
|
||||
'spm':[ s for s in spm.values ]
|
||||
}
|
||||
|
||||
maxtime = coordinates['time'].max()
|
||||
|
||||
return data, mapscript, mapdiv, maxtime
|
||||
|
||||
# Show a video compared with data
|
||||
def workout_video_view(request,id=''):
|
||||
try:
|
||||
@@ -95,44 +139,7 @@ def workout_video_view(request,id=''):
|
||||
form = None
|
||||
|
||||
# get data
|
||||
df = getsmallrowdata_db(['time','velo','spm'],ids=[w.id],
|
||||
workstrokesonly=False,doclean=False,compute=False)
|
||||
df['time'] = (df['time']-df['time'].min())/1000.
|
||||
df.sort_values(by='time',inplace=True)
|
||||
|
||||
|
||||
df.set_index(pd.to_timedelta(df['time'],unit='s'),inplace=True)
|
||||
df2 = df.resample('1s').mean().interpolate()
|
||||
|
||||
|
||||
#mask = df2['time'] < delay
|
||||
#df2 = df2.mask(mask).dropna()
|
||||
df2['time'] = (df2['time']-df2['time'].min())
|
||||
|
||||
boatspeed = (100*df2['velo']).astype(int)/100.
|
||||
spm = (10*df2['spm']).astype(int)/10.
|
||||
|
||||
coordinates = dataprep.get_latlon_time(w.id)
|
||||
|
||||
coordinates.set_index(pd.to_timedelta(coordinates['time'],unit='s'),inplace=True)
|
||||
coordinates = coordinates.resample('1s').mean().interpolate()
|
||||
#mask = coordinates['time'] < delay
|
||||
#coordinates = coordinates.mask(mask).dropna()
|
||||
coordinates['time'] = coordinates['time']-coordinates['time'].min()
|
||||
latitude = coordinates['latitude']
|
||||
longitude = coordinates['longitude']
|
||||
|
||||
# create map
|
||||
mapscript, mapdiv = leaflet_chart_video(latitude,longitude,
|
||||
w.name)
|
||||
|
||||
# bundle data
|
||||
data = {
|
||||
'boatspeed':[ v for v in boatspeed.values],
|
||||
'latitude':[ l for l in latitude.values],
|
||||
'longitude':[ l for l in longitude.values],
|
||||
'spm':[ s for s in spm.values ]
|
||||
}
|
||||
data, mapscript, mapdiv, maxtime = get_video_data(w)
|
||||
|
||||
breadcrumbs = [
|
||||
{
|
||||
@@ -162,7 +169,7 @@ def workout_video_view(request,id=''):
|
||||
'form':form,
|
||||
'breadcrumbs':breadcrumbs,
|
||||
'analysis':analysis,
|
||||
'maxtime':coordinates['time'].max(),
|
||||
'maxtime':maxtime,
|
||||
})
|
||||
|
||||
|
||||
@@ -201,44 +208,7 @@ def workout_video_create_view(request,id=0):
|
||||
delay = 0
|
||||
|
||||
# get data
|
||||
df = getsmallrowdata_db(['time','velo','spm'],ids=[w.id],
|
||||
workstrokesonly=False,doclean=False,compute=False)
|
||||
df['time'] = (df['time']-df['time'].min())/1000.
|
||||
df.sort_values(by='time',inplace=True)
|
||||
|
||||
|
||||
df.set_index(pd.to_timedelta(df['time'],unit='s'),inplace=True)
|
||||
df2 = df.resample('1s').mean().interpolate()
|
||||
|
||||
|
||||
#mask = df2['time'] < delay
|
||||
#df2 = df2.mask(mask).dropna()
|
||||
df2['time'] = (df2['time']-df2['time'].min())
|
||||
|
||||
boatspeed = (100*df2['velo']).astype(int)/100.
|
||||
spm = (10*df2['spm']).astype(int)/10.
|
||||
|
||||
coordinates = dataprep.get_latlon_time(w.id)
|
||||
|
||||
coordinates.set_index(pd.to_timedelta(coordinates['time'],unit='s'),inplace=True)
|
||||
coordinates = coordinates.resample('1s').mean().interpolate()
|
||||
#mask = coordinates['time'] < delay
|
||||
#coordinates = coordinates.mask(mask).dropna()
|
||||
coordinates['time'] = coordinates['time']-coordinates['time'].min()
|
||||
latitude = coordinates['latitude']
|
||||
longitude = coordinates['longitude']
|
||||
|
||||
# create map
|
||||
mapscript, mapdiv = leaflet_chart_video(latitude,longitude,
|
||||
w.name)
|
||||
|
||||
# bundle data
|
||||
data = {
|
||||
'boatspeed':[ v for v in boatspeed.values],
|
||||
'latitude':[ l for l in latitude.values],
|
||||
'longitude':[ l for l in longitude.values],
|
||||
'spm':[ s for s in spm.values ]
|
||||
}
|
||||
data, mapscript, mapdiv, maxtime = get_video_data(w)
|
||||
|
||||
breadcrumbs = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user