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