Private
Public Access
1
0

videodata working

This commit is contained in:
Sander Roosendaal
2019-11-13 21:42:29 +01:00
parent 6a597e43b3
commit c8d84c4aab
3 changed files with 50 additions and 31 deletions

View File

@@ -10,6 +10,7 @@ from __future__ import unicode_literals, absolute_import
from rowers.models import Workout, Team
import pytz
import collections
from rowingdata import rowingdata as rrdata
@@ -122,24 +123,35 @@ 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)
def get_video_data(w,groups=['basic']):
columns = ['time','velo','spm']
columns += [name for name,d in rowingmetrics if d['group'] in groups]
columns = list(set(columns))
df = getsmallrowdata_db(columns,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()
if 'pace' in columns:
df2['pace'] = df2['pace']/1000.
p = df2['pace']
p = p.apply(lambda x:timedeltaconv(x))
p = nicepaceformat(p)
df2['pace'] = p
#mask = df2['time'] < delay
#df2 = df2.mask(mask).dropna()
df2['time'] = (df2['time']-df2['time'].min())
df2 = df2.round(decimals=2)
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)
@@ -155,32 +167,36 @@ def get_video_data(w):
# 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]
'boatspeed':boatspeed.values.tolist(),
'latitude':latitude.values.tolist(),
'longitude':longitude.values.tolist(),
}
# metrics = {
# 'boatspeed': {
# 'unit': 'm/s',
# 'metric': 'boatspeed',
# 'name': 'Boat Speed'
# },
# }
metrics = {}
for c in columns:
if c != 'time':
data[c] = df2[c].values.tolist()
metrics[c] = {
'name': dict(rowingmetrics)[c]['verbose_name'],
'metric': c,
'unit': ''
}
metrics['boatspeed'] = metrics.pop('velo')
# metrics['workperstroke'] = metrics.pop('driveenergy')
metrics = collections.OrderedDict(sorted(metrics.items()))
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

View File

@@ -152,7 +152,7 @@
{% for id, metric in metrics.items %}
document.getElementById("{{ id }}").innerHTML = {{ id }}_now;
{% endfor %}
gauge.set(catch_now);
// gauge.set(catch_now);
var newLatLng = new L.LatLng(lat, lon);
marker.setLatLng(newLatLng);
}
@@ -210,7 +210,7 @@
</span> {{ metric.unit }}
</li>
{% endfor %}
<li class="grid_2">
<!-- <li class="grid_2">
<canvas id="angles"></canvas>
<script type="text/javascript" src="https://bernii.github.io/gauge.js/dist/gauge.js"></script>
<script>
@@ -236,8 +236,9 @@
gauge.animationSpeed = 5;
gauge.set(-75);
</script>
</li>
</li> -->
</ul>
<p>&nbsp;</p>
<form enctype="multipart/form-data" action="" method="post">
<ul class="main-content">
{% if form %}

View File

@@ -95,12 +95,14 @@ def workout_video_view(request,id=''):
}
)
metricsform = VideoAnalysisMetricsForm(initial={'groups':analysis.metricsgroups})
metricsgroups = analysis.metricsgroups
video_id = analysis.video_id
else:
form = None
metricsform = None
metricsgroups = analysis.metricsgroups
data, metrics, maxtime = dataprep.get_video_data(w)
data, metrics, maxtime = dataprep.get_video_data(w,groups=metricsgroups)
# create map
mapscript, mapdiv = leaflet_chart_video(data['latitude'],data['longitude'],
w.name)