better metrics selection
This commit is contained in:
@@ -123,9 +123,11 @@ from scipy.signal import savgol_filter
|
||||
|
||||
import datetime
|
||||
|
||||
def get_video_data(w,groups=['basic']):
|
||||
|
||||
def get_video_data(w,groups=['basic'],mode='water'):
|
||||
modes = [mode,'both','basic']
|
||||
columns = ['time','velo','spm']
|
||||
columns += [name for name,d in rowingmetrics if d['group'] in groups]
|
||||
columns += [name for name,d in rowingmetrics if d['group'] in groups and d['mode'] in modes]
|
||||
columns = list(set(columns))
|
||||
df = getsmallrowdata_db(columns,ids=[w.id],
|
||||
workstrokesonly=False,doclean=False,compute=False)
|
||||
|
||||
@@ -53,25 +53,38 @@ class FlexibleDecimalField(forms.DecimalField):
|
||||
|
||||
# Video Analysis creation form
|
||||
class VideoAnalysisCreateForm(forms.Form):
|
||||
name = forms.CharField(max_length=255,label='Analysis Name')
|
||||
name = forms.CharField(max_length=255,label='Analysis Name',required=False)
|
||||
url = forms.CharField(max_length=255,required=True,label='YouTube Video URL')
|
||||
delay = forms.IntegerField(initial=0,label='Delay (seconds)')
|
||||
|
||||
metricsdescriptions = {}
|
||||
for m in metricsgroups:
|
||||
metricsdescriptions[m] = m+' ('
|
||||
for name,d in rowingmetrics:
|
||||
if d['group']==m:
|
||||
metricsdescriptions[m]+=d['verbose_name']+', '
|
||||
metricsdescriptions[m]=metricsdescriptions[m][0:-2]+')'
|
||||
def get_metricschoices(mode='water'):
|
||||
modes = [mode,'both','basic']
|
||||
metricsdescriptions = {}
|
||||
for m in metricsgroups:
|
||||
metricsdescriptions[m] = m+' ('
|
||||
for name,d in rowingmetrics:
|
||||
if d['group']==m and d['mode'] in modes:
|
||||
metricsdescriptions[m]+=d['verbose_name']+', '
|
||||
metricsdescriptions[m]=metricsdescriptions[m][0:-2]+')'
|
||||
|
||||
metricsgroupschoices = ((m,metricsdescriptions[m]) for m in metricsgroups)
|
||||
metricsgroupschoices = ((m,metricsdescriptions[m]) for m in metricsgroups)
|
||||
|
||||
return metricsgroupschoices
|
||||
|
||||
class VideoAnalysisMetricsForm(forms.Form):
|
||||
groups = forms.MultipleChoiceField(label='Metrics Groups',
|
||||
choices=metricsgroupschoices,
|
||||
choices=get_metricschoices(mode='water'),
|
||||
widget=forms.CheckboxSelectMultiple,)
|
||||
|
||||
class Meta:
|
||||
mode = 'water'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
mode = kwargs.pop('mode','water')
|
||||
super(VideoAnalysisMetricsForm, self).__init__(*args, **kwargs)
|
||||
self.fields['groups'].choices = get_metricschoices(mode=mode)
|
||||
|
||||
|
||||
# BillingForm form
|
||||
class BillingForm(forms.Form):
|
||||
amount = FlexibleDecimalField(required=True,decimal_places=2,
|
||||
|
||||
@@ -172,7 +172,7 @@ rowingmetrics = (
|
||||
('distance',{
|
||||
'numtype':'float',
|
||||
'null':True,
|
||||
'verbose_name': 'Distance (m)',
|
||||
'verbose_name': 'Interval Distance (m)',
|
||||
'ax_min': 0,
|
||||
'ax_max': 1e5,
|
||||
'mode':'both',
|
||||
|
||||
@@ -13,6 +13,15 @@
|
||||
{% leaflet_css %}
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.js"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('form').submit(function(e) {
|
||||
$(':disabled').each(function(e) {
|
||||
$(this).removeAttr('disabled');
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
@@ -158,7 +167,7 @@
|
||||
{% endfor %}
|
||||
// gauge.set(catch_now);
|
||||
var newLatLng = new L.LatLng(lat, lon);
|
||||
console.log(newLatLng);
|
||||
// console.log(newLatLng);
|
||||
marker.setLatLng(newLatLng);
|
||||
}
|
||||
if(videotime !== oldTime) {
|
||||
@@ -275,8 +284,10 @@
|
||||
<script>
|
||||
// lock
|
||||
var lock = document.getElementById("lock");
|
||||
var output = document.getElementById("id_delay");
|
||||
{% if locked %}
|
||||
lock.checked = true;
|
||||
output.disabled = true;
|
||||
{% endif %}
|
||||
|
||||
|
||||
@@ -310,7 +321,7 @@
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log('changing');
|
||||
// console.log('changing');
|
||||
output.value = this.value-Math.round(player.getCurrentTime());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from rowers.views.statements import *
|
||||
import rowers.teams as teams
|
||||
|
||||
import rowers.mytypes as mytypes
|
||||
import numpy
|
||||
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
@@ -58,6 +58,11 @@ def workout_video_view(request,id=''):
|
||||
w = analysis.workout
|
||||
delay = analysis.delay
|
||||
|
||||
if w.workouttype in mytypes.otwtypes:
|
||||
mode = 'water'
|
||||
else:
|
||||
mode = 'erg'
|
||||
|
||||
if request.user.is_authenticated:
|
||||
mayedit = checkworkoutuser(request.user,w) and isprorower(request.user.rower)
|
||||
rower = request.user.rower
|
||||
@@ -68,7 +73,7 @@ def workout_video_view(request,id=''):
|
||||
# get video ID and offset
|
||||
if mayedit and request.method == 'POST':
|
||||
form = VideoAnalysisCreateForm(request.POST)
|
||||
metricsform = VideoAnalysisMetricsForm(request.POST)
|
||||
metricsform = VideoAnalysisMetricsForm(request.POST,mode=mode)
|
||||
if form.is_valid() and metricsform.is_valid():
|
||||
video_id = form.cleaned_data['url']
|
||||
try:
|
||||
@@ -94,7 +99,8 @@ def workout_video_view(request,id=''):
|
||||
'url': analysis.video_id,
|
||||
}
|
||||
)
|
||||
metricsform = VideoAnalysisMetricsForm(initial={'groups':analysis.metricsgroups})
|
||||
metricsform = VideoAnalysisMetricsForm(initial={'groups':analysis.metricsgroups},
|
||||
mode=mode)
|
||||
metricsgroups = analysis.metricsgroups
|
||||
video_id = analysis.video_id
|
||||
else:
|
||||
@@ -102,10 +108,16 @@ def workout_video_view(request,id=''):
|
||||
metricsform = None
|
||||
metricsgroups = analysis.metricsgroups
|
||||
|
||||
data, metrics, maxtime = dataprep.get_video_data(w,groups=metricsgroups)
|
||||
data, metrics, maxtime = dataprep.get_video_data(w,groups=metricsgroups,mode=mode)
|
||||
hascoordinates = pd.Series(data['latitude']).std() > 0
|
||||
# create map
|
||||
mapscript, mapdiv = leaflet_chart_video(data['latitude'],data['longitude'],
|
||||
if hascoordinates:
|
||||
mapscript, mapdiv = leaflet_chart_video(data['latitude'],data['longitude'],
|
||||
w.name)
|
||||
else:
|
||||
mapscript, mapdiv = interactive_chart_video(data)
|
||||
data['longitude'] = data['spm']
|
||||
data['latitude'] = list(range(len(data['spm'])))
|
||||
|
||||
|
||||
breadcrumbs = [
|
||||
@@ -150,11 +162,16 @@ def workout_video_view(request,id=''):
|
||||
def workout_video_create_view(request,id=0):
|
||||
# get workout
|
||||
w = get_workout_permitted(request.user,id)
|
||||
if w.workouttype in mytypes.otwtypes:
|
||||
mode = 'water'
|
||||
else:
|
||||
mode = 'erg'
|
||||
|
||||
# get video ID and offset
|
||||
if request.method == 'POST':
|
||||
form = VideoAnalysisCreateForm(request.POST)
|
||||
metricsform = VideoAnalysisMetricsForm(request.POST)
|
||||
metricsform = VideoAnalysisMetricsForm(request.POST,mode=mode)
|
||||
print(request.POST)
|
||||
if form.is_valid() and metricsform.is_valid():
|
||||
url = form.cleaned_data['url']
|
||||
delay = form.cleaned_data['delay']
|
||||
@@ -189,13 +206,13 @@ def workout_video_create_view(request,id=0):
|
||||
metricsgroups = ['basic']
|
||||
else:
|
||||
form = VideoAnalysisCreateForm()
|
||||
metricsform = VideoAnalysisMetricsForm(initial={'groups':['basic']})
|
||||
metricsform = VideoAnalysisMetricsForm(initial={'groups':['basic']},mode=mode)
|
||||
video_id = None
|
||||
delay = 0
|
||||
metricsgroups = ['basic']
|
||||
|
||||
# get data
|
||||
data, metrics, maxtime = dataprep.get_video_data(w,groups=metricsgroups)
|
||||
data, metrics, maxtime = dataprep.get_video_data(w,groups=metricsgroups,mode=mode)
|
||||
hascoordinates = pd.Series(data['latitude']).std() > 0
|
||||
|
||||
# create map
|
||||
@@ -227,7 +244,6 @@ def workout_video_create_view(request,id=0):
|
||||
|
||||
template = 'embedded_video.html'
|
||||
|
||||
print(data['latitude'],'aap')
|
||||
|
||||
return render(request,
|
||||
template,
|
||||
|
||||
Reference in New Issue
Block a user