move get_video_data to dataprep.py
This commit is contained in:
@@ -122,6 +122,69 @@ from scipy.signal import savgol_filter
|
||||
|
||||
import datetime
|
||||
|
||||
def get_video_data(w):
|
||||
df = getsmallrowdata_db(['time','velo','spm','catch'],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.
|
||||
catch = (10*df2['catch']).astype(int)/10.
|
||||
|
||||
coordinates = 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']
|
||||
|
||||
|
||||
|
||||
# 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 ],
|
||||
'catch': [c for c in catch.values]
|
||||
}
|
||||
|
||||
maxtime = coordinates['time'].max()
|
||||
|
||||
metrics = {
|
||||
'spm': {
|
||||
'unit': '',
|
||||
'metric': 'spm',
|
||||
'name': 'SPM',
|
||||
},
|
||||
'boatspeed': {
|
||||
'unit': 'm/s',
|
||||
'metric': 'boatspeed',
|
||||
'name': 'Boat Speed'
|
||||
},
|
||||
'catch': {
|
||||
'unit': 'degrees',
|
||||
'metric': 'catch',
|
||||
'name': 'Catch Angle'
|
||||
}
|
||||
}
|
||||
|
||||
return data, metrics, maxtime
|
||||
|
||||
|
||||
def polarization_index(df,rower):
|
||||
df['dt'] = df['time'].diff()/6.e4
|
||||
# remove rest (spm<15)
|
||||
|
||||
@@ -1810,7 +1810,7 @@ def leaflet_chart2(lat,lon,name=""):
|
||||
return script,div
|
||||
|
||||
def leaflet_chart_video(lat,lon,name=""):
|
||||
if lat.empty or lon.empty:
|
||||
if not len(lat) or not len(lon):
|
||||
return [0,"invalid coordinate data"]
|
||||
|
||||
|
||||
|
||||
@@ -46,69 +46,6 @@ def get_video_id(url):
|
||||
else:
|
||||
raise ValueError
|
||||
|
||||
def get_video_data(w):
|
||||
df = getsmallrowdata_db(['time','velo','spm','catch'],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.
|
||||
catch = (10*df2['catch']).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 ],
|
||||
'catch': [c for c in catch.values]
|
||||
}
|
||||
|
||||
maxtime = coordinates['time'].max()
|
||||
|
||||
metrics = {
|
||||
'spm': {
|
||||
'unit': '',
|
||||
'metric': 'spm',
|
||||
'name': 'SPM',
|
||||
},
|
||||
'boatspeed': {
|
||||
'unit': 'm/s',
|
||||
'metric': 'boatspeed',
|
||||
'name': 'Boat Speed'
|
||||
},
|
||||
'catch': {
|
||||
'unit': 'degrees',
|
||||
'metric': 'catch',
|
||||
'name': 'Catch Angle'
|
||||
}
|
||||
}
|
||||
|
||||
return data, metrics, mapscript, mapdiv, maxtime
|
||||
|
||||
# Show a video compared with data
|
||||
def workout_video_view(request,id=''):
|
||||
@@ -158,8 +95,11 @@ def workout_video_view(request,id=''):
|
||||
else:
|
||||
form = None
|
||||
|
||||
# get data
|
||||
data, metrics, mapscript, mapdiv, maxtime = get_video_data(w)
|
||||
data, metrics, maxtime = dataprep.get_video_data(w)
|
||||
# create map
|
||||
mapscript, mapdiv = leaflet_chart_video(data['latitude'],data['longitude'],
|
||||
w.name)
|
||||
|
||||
|
||||
breadcrumbs = [
|
||||
{
|
||||
@@ -241,7 +181,10 @@ def workout_video_create_view(request,id=0):
|
||||
delay = 0
|
||||
|
||||
# get data
|
||||
data, metrics, mapscript, mapdiv, maxtime = get_video_data(w)
|
||||
data, metrics, maxtime = dataprep.get_video_data(w)
|
||||
# create map
|
||||
mapscript, mapdiv = leaflet_chart_video(data['latitude'],data['longitude'],
|
||||
w.name)
|
||||
|
||||
breadcrumbs = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user