initial version of form working
This commit is contained in:
@@ -51,6 +51,11 @@ class FlexibleDecimalField(forms.DecimalField):
|
||||
value = value.replace('.', '').replace(',', '.')
|
||||
return super(FlexibleDecimalField, self).to_python(value)
|
||||
|
||||
# Video Analysis creation form
|
||||
class VideoAnalysisCreateForm(forms.Form):
|
||||
url = forms.CharField(max_length=255,required=True,label='YouTube Video URL')
|
||||
delay = forms.IntegerField(initial=0,label='Delay (seconds)')
|
||||
|
||||
# BillingForm form
|
||||
class BillingForm(forms.Form):
|
||||
amount = FlexibleDecimalField(required=True,decimal_places=2,
|
||||
@@ -1380,7 +1385,3 @@ class FlexAxesForm(forms.Form):
|
||||
self.fields['xaxis'].choices = axchoicesbasicx
|
||||
self.fields['yaxis1'].choices = axchoicesbasicy
|
||||
self.fields['yaxis2'].choices = axchoicesbasicy
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -45,6 +45,11 @@
|
||||
<span id="time">
|
||||
</span> seconds
|
||||
</li>
|
||||
<li>
|
||||
SPM
|
||||
<span id="spm">
|
||||
</span>
|
||||
</li>
|
||||
<li>
|
||||
Boat Speed
|
||||
<span id="speed">
|
||||
@@ -70,12 +75,13 @@
|
||||
var boatspeed = data["boatspeed"];
|
||||
var latitude = data["latitude"];
|
||||
var longitude = data["longitude"];
|
||||
var spm = data["spm"]
|
||||
|
||||
function onYouTubeIframeAPIReady() {
|
||||
player = new YT.Player('player', {
|
||||
height: '390',
|
||||
width: '640',
|
||||
videoId: '9dLFC2q9RWc',
|
||||
videoId: '{{ video_id }}',
|
||||
events: {
|
||||
'onReady': onPlayerReady
|
||||
}
|
||||
@@ -92,8 +98,10 @@
|
||||
velo = boatspeed[Math.round(videotime)];
|
||||
lat = latitude[Math.round(videotime)];
|
||||
lon = longitude[Math.round(videotime)];
|
||||
strokerate = spm[Math.round(videotime)];
|
||||
document.getElementById("time").innerHTML = Math.round(videotime);
|
||||
document.getElementById("speed").innerHTML = velo;
|
||||
document.getElementById("spm").innerHTML = strokerate;
|
||||
var newLatLng = new L.LatLng(lat, lon);
|
||||
marker.setLatLng(newLatLng);
|
||||
}
|
||||
@@ -117,6 +125,23 @@
|
||||
|
||||
</script>
|
||||
</li>
|
||||
<li class="grid_4">
|
||||
{% if not video_id %}
|
||||
<p>
|
||||
To load your video, paste the URL of your YouTube video in the form below,
|
||||
and submit the form.
|
||||
</p>
|
||||
{% endif %}
|
||||
<p>
|
||||
<form enctype="multipart/form-data" action="" method="post">
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
{% csrf_token %}
|
||||
<input type="submit" value="submit">
|
||||
</form>
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
{% endlanguage %}
|
||||
|
||||
|
||||
@@ -58,7 +58,8 @@ from rowers.forms import (
|
||||
RaceResultFilterForm,PowerIntervalUpdateForm,FlexAxesForm,
|
||||
FlexOptionsForm,DataFrameColumnsForm,OteWorkoutTypeForm,
|
||||
MetricsForm,DisqualificationForm,disqualificationreasons,
|
||||
disqualifiers,SearchForm,BillingForm,PlanSelectForm
|
||||
disqualifiers,SearchForm,BillingForm,PlanSelectForm,
|
||||
VideoAnalysisCreateForm
|
||||
)
|
||||
|
||||
from django.urls import reverse, reverse_lazy
|
||||
@@ -1288,5 +1289,3 @@ def trydf(df,aantal,column):
|
||||
|
||||
import rowers.teams as teams
|
||||
from rowers.models import C2WorldClassAgePerformance
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ from urllib.parse import urlparse, parse_qs
|
||||
|
||||
def default(o):
|
||||
if isinstance(o, numpy.int64): return int(o)
|
||||
if isinstance(o, numpy.int32): return int(o)
|
||||
raise TypeError
|
||||
|
||||
def get_video_id(url):
|
||||
@@ -53,32 +54,59 @@ def workout_video_view(request,id=0):
|
||||
# get workout
|
||||
w = get_workout_permitted(request.user,id)
|
||||
|
||||
# get video ID and offset
|
||||
if request.method == 'POST':
|
||||
form = VideoAnalysisCreateForm(request.POST)
|
||||
if form.is_valid():
|
||||
url = form.cleaned_data['url']
|
||||
delay = form.cleaned_data['delay']
|
||||
video_id = get_video_id(url)
|
||||
else:
|
||||
video_id = None
|
||||
delay = 0
|
||||
else:
|
||||
form = VideoAnalysisCreateForm()
|
||||
video_id = None
|
||||
delay = 0
|
||||
|
||||
# get data
|
||||
df = getsmallrowdata_db(['time','velo'],ids=[w.id])
|
||||
df = getsmallrowdata_db(['time','velo','spm'],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.
|
||||
|
||||
coordinates = dataprep.get_latlon_time(w.id)
|
||||
mask = coordinates['time'] < delay
|
||||
coordinates = coordinates.mask(mask).dropna()
|
||||
coordinates['time'] = coordinates['time']-coordinates['time'].min()
|
||||
coordinates.set_index(pd.to_timedelta(coordinates['time'],unit='s'),inplace=True)
|
||||
coordinates = coordinates.resample('1s').mean().interpolate()
|
||||
latitude = coordinates['latitude']
|
||||
longitude = coordinates['longitude']
|
||||
|
||||
# get video
|
||||
url = "https://www.youtube.com/watch?time_continue=496&v=9dLFC2q9RWc"
|
||||
video_id = get_video_id(url)
|
||||
|
||||
# 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]}
|
||||
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 ]
|
||||
}
|
||||
|
||||
return render(request,
|
||||
'embedded_video.html',
|
||||
@@ -89,6 +117,7 @@ def workout_video_view(request,id=0):
|
||||
'mapscript': mapscript,
|
||||
'mapdiv': mapdiv,
|
||||
'video_id': video_id,
|
||||
'form':form,
|
||||
})
|
||||
|
||||
# Show the EMpower Oarlock generated Stroke Profile
|
||||
|
||||
Reference in New Issue
Block a user