diff --git a/rowers/dataprep.py b/rowers/dataprep.py index f1928802..c9a8fd80 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -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 diff --git a/rowers/templates/embedded_video.html b/rowers/templates/embedded_video.html index 4cbfce56..19164b1b 100644 --- a/rowers/templates/embedded_video.html +++ b/rowers/templates/embedded_video.html @@ -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 @@ {{ metric.unit }} {% endfor %} -