half way through cleaning up and commenting the code
This commit is contained in:
@@ -27,7 +27,7 @@ from rowsandall_app.settings import C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SEC
|
||||
from rowsandall_app.settings import SPORTTRACKS_CLIENT_ID, SPORTTRACKS_REDIRECT_URI, SPORTTRACKS_CLIENT_SECRET
|
||||
import requests
|
||||
import json
|
||||
from rowsandall_app.rows import handle_uploaded_file
|
||||
from rowers.rows import handle_uploaded_file
|
||||
from rowers.tasks import handle_makeplot,handle_otwsetpower,handle_sendemailtcx
|
||||
from scipy.signal import savgol_filter
|
||||
|
||||
@@ -60,6 +60,7 @@ import plots
|
||||
from io import BytesIO
|
||||
from scipy.special import lambertw
|
||||
|
||||
# used in shell to send a newsletter to all Rowers
|
||||
def emailall(emailfile,subject):
|
||||
rowers = Rower.objects.all()
|
||||
for rower in rowers:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from django import forms
|
||||
from rowers.models import Workout
|
||||
from rowsandall_app.rows import validate_file_extension,must_be_csv
|
||||
from rowers.rows import validate_file_extension,must_be_csv
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.admin.widgets import AdminDateWidget
|
||||
@@ -9,10 +9,12 @@ from django.utils import timezone,translation
|
||||
|
||||
import datetime
|
||||
|
||||
# login form
|
||||
class LoginForm(forms.Form):
|
||||
username = forms.CharField()
|
||||
password = forms.CharField(widget=forms.PasswordInput())
|
||||
|
||||
|
||||
# simple form for Contact page. Sends email to info@rowsandall.com
|
||||
class EmailForm(forms.Form):
|
||||
firstname = forms.CharField(max_length=255)
|
||||
lastname = forms.CharField(max_length=255)
|
||||
@@ -21,16 +23,21 @@ class EmailForm(forms.Form):
|
||||
botcheck = forms.CharField(max_length=5)
|
||||
message = forms.CharField()
|
||||
|
||||
|
||||
# Upload the CrewNerd Summary CSV
|
||||
class CNsummaryForm(forms.Form):
|
||||
file = forms.FileField(required=True,validators=[must_be_csv])
|
||||
|
||||
# The little window to type '4x2000m/500m' to update the workout summary
|
||||
class SummaryStringForm(forms.Form):
|
||||
intervalstring = forms.CharField(max_length=255,label='Workout Description')
|
||||
|
||||
# Used for testing the POST API for StrokeData
|
||||
class StrokeDataForm(forms.Form):
|
||||
strokedata = forms.CharField(label='payload',
|
||||
widget=forms.Textarea)
|
||||
|
||||
|
||||
# The form used for uploading files
|
||||
class DocumentsForm(forms.Form):
|
||||
filetypechoices = (
|
||||
('csv' , 'Painsled iOS CSV'),
|
||||
@@ -50,9 +57,6 @@ class DocumentsForm(forms.Form):
|
||||
workouttype = forms.ChoiceField(required=True,
|
||||
choices=Workout.workouttypes,
|
||||
initial='rower')
|
||||
# fileformat = forms.ChoiceField(required=True,
|
||||
# choices=filetypechoices,
|
||||
# initial='csv')
|
||||
notes = forms.CharField(required=False,
|
||||
widget=forms.Textarea)
|
||||
|
||||
@@ -60,7 +64,8 @@ class DocumentsForm(forms.Form):
|
||||
fields = ['title','file','workouttype','fileformat']
|
||||
|
||||
|
||||
|
||||
# The form to indicate additional actions to be performed immediately
|
||||
# after a successful upload
|
||||
class UploadOptionsForm(forms.Form):
|
||||
plotchoices = (
|
||||
('timeplot','Time Plot'),
|
||||
@@ -76,6 +81,8 @@ class UploadOptionsForm(forms.Form):
|
||||
class Meta:
|
||||
fields = ['make_plot','plottype','upload_toc2']
|
||||
|
||||
# This form is used on the Analysis page to add a custom distance/time
|
||||
# trial and predict the pace
|
||||
class PredictedPieceForm(forms.Form):
|
||||
unitchoices = (
|
||||
('t','minutes'),
|
||||
@@ -88,6 +95,7 @@ class PredictedPieceForm(forms.Form):
|
||||
class Meta:
|
||||
fields = ['value','pieceunit']
|
||||
|
||||
# On the Geeky side, to update stream information for river dwellers
|
||||
class UpdateStreamForm(forms.Form):
|
||||
unitchoices = (
|
||||
('m','m/s'),
|
||||
@@ -107,6 +115,7 @@ class UpdateStreamForm(forms.Form):
|
||||
class Meta:
|
||||
fields = ['dist1','dist2','stream1', 'stream2','streamunit']
|
||||
|
||||
# add wind information to your workout
|
||||
class UpdateWindForm(forms.Form):
|
||||
unitchoices = (
|
||||
('m','m/s'),
|
||||
@@ -134,8 +143,7 @@ class UpdateWindForm(forms.Form):
|
||||
'windunit',
|
||||
'winddirection1','winddirection2']
|
||||
|
||||
|
||||
|
||||
# Form to select a data range to show workouts from a certain time period
|
||||
class DateRangeForm(forms.Form):
|
||||
startdate = forms.DateField(initial=timezone.now()-datetime.timedelta(days=365),
|
||||
widget=SelectDateWidget(years=range(1990,2050)),
|
||||
@@ -147,6 +155,7 @@ class DateRangeForm(forms.Form):
|
||||
class Meta:
|
||||
fields = ['startdate','enddate']
|
||||
|
||||
# Form used to select workouts for the past N days
|
||||
class DeltaDaysForm(forms.Form):
|
||||
deltadays = forms.IntegerField(initial=0,required=False,label='')
|
||||
|
||||
@@ -191,13 +200,14 @@ class RegistrationFormUniqueEmail(RegistrationFormTermsOfService):
|
||||
raise forms.ValidationError("This email address is already in use. Please supply a different email address.")
|
||||
return self.cleaned_data['email']
|
||||
|
||||
|
||||
# Time field supporting microseconds. Not used, I believe.
|
||||
class MyTimeField(forms.TimeField):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(MyTimeField, self).__init__(*args, **kwargs)
|
||||
supports_microseconds = True
|
||||
|
||||
# Form used to update interval stats
|
||||
class IntervalUpdateForm(forms.Form):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
@@ -18,6 +18,8 @@ from sqlite3 import OperationalError
|
||||
from django.utils import timezone
|
||||
import datetime
|
||||
|
||||
from rowers.rows import validate_file_extension
|
||||
|
||||
from rowsandall_app.settings import (
|
||||
TWEET_ACCESS_TOKEN_KEY,
|
||||
TWEET_ACCESS_TOKEN_SECRET,
|
||||
@@ -47,12 +49,12 @@ database_url = 'mysql://{user}:{password}@{host}:{port}/{database_name}'.format(
|
||||
if settings.DEBUG or user=='':
|
||||
database_url = 'sqlite:///db.sqlite3'
|
||||
|
||||
|
||||
# Create your models here.
|
||||
# For future Team functionality
|
||||
class Team(models.Model):
|
||||
name = models.CharField(max_length=150)
|
||||
notes = models.CharField(blank=True,max_length=200)
|
||||
|
||||
# Extension of User with rowing specific data
|
||||
class Rower(models.Model):
|
||||
weightcategories = (
|
||||
('hwt','heavy-weight'),
|
||||
@@ -95,6 +97,7 @@ class Rower(models.Model):
|
||||
def __str__(self):
|
||||
return self.user.username
|
||||
|
||||
# Saving a chart as a favorite chart
|
||||
class FavoriteChart(models.Model):
|
||||
y1params = (
|
||||
('hr','Heart Rate'),
|
||||
@@ -181,6 +184,7 @@ class FavoriteForm(ModelForm):
|
||||
fields = ['xparam','yparam1','yparam2',
|
||||
'plottype','workouttype','reststrokes']
|
||||
|
||||
# To generate favorite chart forms on the fly
|
||||
class BaseFavoriteFormSet(BaseFormSet):
|
||||
def clean(self):
|
||||
if any(self.errors):
|
||||
@@ -208,7 +212,8 @@ class BaseFavoriteFormSet(BaseFormSet):
|
||||
|
||||
if not yparam2:
|
||||
yparam2 = 'None'
|
||||
|
||||
|
||||
# Workout
|
||||
class Workout(models.Model):
|
||||
workouttypes = (
|
||||
('water','On-water'),
|
||||
@@ -273,7 +278,7 @@ def auto_delete_file_on_delete(sender, instance, **kwargs):
|
||||
if os.path.isfile(instance.csvfilename+'.gz'):
|
||||
os.remove(instance.csvfilename+'.gz')
|
||||
|
||||
|
||||
# Delete stroke data from the database when a workout is deleted
|
||||
@receiver(models.signals.post_delete,sender=Workout)
|
||||
def auto_delete_strokedata_on_delete(sender, instance, **kwargs):
|
||||
if instance.id:
|
||||
@@ -288,7 +293,12 @@ def auto_delete_strokedata_on_delete(sender, instance, **kwargs):
|
||||
print "Database Locked"
|
||||
conn.close()
|
||||
engine.dispose()
|
||||
|
||||
|
||||
# Model of StrokeData table
|
||||
# the definition here is used only to enable easy Django migration
|
||||
# when the StrokeData are expanded.
|
||||
# No Django Instances of this model are managed. Strokedata table is
|
||||
# accesssed directly with SQL commands
|
||||
class StrokeData(models.Model):
|
||||
class Meta:
|
||||
db_table = 'strokedata'
|
||||
@@ -329,7 +339,8 @@ class StrokeData(models.Model):
|
||||
finish = models.FloatField(default=0,null=True)
|
||||
wash = models.FloatField(default=0,null=True)
|
||||
peakforceangle = models.FloatField(default=0,null=True)
|
||||
|
||||
|
||||
# A wrapper around the png files
|
||||
class GraphImage(models.Model):
|
||||
filename = models.CharField(default='',max_length=150,blank=True,null=True)
|
||||
creationdatetime = models.DateTimeField()
|
||||
@@ -338,7 +349,7 @@ class GraphImage(models.Model):
|
||||
def __str__(self):
|
||||
return self.filename
|
||||
|
||||
# delete related file object
|
||||
# delete related file object when image is deleted
|
||||
@receiver(models.signals.post_delete,sender=GraphImage)
|
||||
def auto_delete_image_on_delete(sender,instance, **kwargs):
|
||||
if instance.filename:
|
||||
@@ -347,11 +358,11 @@ def auto_delete_image_on_delete(sender,instance, **kwargs):
|
||||
else:
|
||||
print "couldn't find the file "+instance.filename
|
||||
|
||||
|
||||
# Date input utility
|
||||
class DateInput(forms.DateInput):
|
||||
input_type = 'date'
|
||||
|
||||
|
||||
# Form to update Workout data
|
||||
class WorkoutForm(ModelForm):
|
||||
duration = forms.TimeInput(format='%H:%M:%S.%f')
|
||||
class Meta:
|
||||
@@ -368,16 +379,20 @@ class WorkoutForm(ModelForm):
|
||||
if self.instance.workouttype != 'water':
|
||||
del self.fields['boattype']
|
||||
|
||||
# Used for the rowing physics calculations
|
||||
class AdvancedWorkoutForm(ModelForm):
|
||||
class Meta:
|
||||
model = Workout
|
||||
fields = ['boattype','weightvalue']
|
||||
|
||||
# Simple form to set rower's Functional Threshold Power
|
||||
class RowerPowerForm(ModelForm):
|
||||
class Meta:
|
||||
model = Rower
|
||||
fields = ['ftp']
|
||||
|
||||
# Form to set rower's Heart Rate zones, including test routines
|
||||
# to enable consistency
|
||||
class RowerForm(ModelForm):
|
||||
class Meta:
|
||||
model = Rower
|
||||
@@ -519,6 +534,8 @@ class RowerForm(ModelForm):
|
||||
if an>=max:
|
||||
raise forms.ValidationError("AN should be lower than Max")
|
||||
|
||||
# An announcement that goes to the right of the workouts list
|
||||
# optionally sends a tweet to our twitter account
|
||||
class SiteAnnouncement(models.Model):
|
||||
created = models.DateField(default=timezone.now)
|
||||
announcement = models.TextField(max_length=140)
|
||||
|
||||
73
rowers/rows.py
Normal file
73
rowers/rows.py
Normal file
@@ -0,0 +1,73 @@
|
||||
import time
|
||||
import gzip
|
||||
import shutil
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
def format_pace_tick(x,pos=None):
|
||||
min=int(x/60)
|
||||
sec=int(x-min*60.)
|
||||
sec_str=str(sec).zfill(2)
|
||||
template='%d:%s'
|
||||
return template % (min,sec_str)
|
||||
|
||||
def format_time_tick(x,pos=None):
|
||||
hour=int(x/3600)
|
||||
min=int((x-hour*3600.)/60)
|
||||
min_str=str(min).zfill(2)
|
||||
template='%d:%s'
|
||||
return template % (hour,min_str)
|
||||
|
||||
def format_pace(x,pos=None):
|
||||
if isinf(x) or isnan(x):
|
||||
x=0
|
||||
|
||||
min=int(x/60)
|
||||
sec=(x-min*60.)
|
||||
|
||||
str1 = "{min:0>2}:{sec:0>4.1f}".format(
|
||||
min = min,
|
||||
sec = sec
|
||||
)
|
||||
|
||||
return str1
|
||||
|
||||
def format_time(x,pos=None):
|
||||
|
||||
|
||||
min = int(x/60.)
|
||||
sec = int(x-min*60)
|
||||
|
||||
str1 = "{min:0>2}:{sec:0>4.1f}".format(
|
||||
min=min,
|
||||
sec=sec,
|
||||
)
|
||||
|
||||
return str1
|
||||
|
||||
def validate_file_extension(value):
|
||||
import os
|
||||
ext = os.path.splitext(value.name)[1]
|
||||
valid_extensions = ['.tcx','.csv','.TCX','.CSV','.fit','.FIT','.zip','.ZIP']
|
||||
if not ext in valid_extensions:
|
||||
raise ValidationError(u'File not supported!')
|
||||
|
||||
def must_be_csv(value):
|
||||
import os
|
||||
ext = os.path.splitext(value.name)[1]
|
||||
valid_extensions = ['.csv','.CSV']
|
||||
if not ext in valid_extensions:
|
||||
raise ValidationError(u'File not supported!')
|
||||
|
||||
|
||||
def handle_uploaded_file(f):
|
||||
fname = f.name
|
||||
timestr = time.strftime("%Y%m%d-%H%M%S")
|
||||
fname = timestr+'-'+fname
|
||||
fname2 = 'media/'+fname
|
||||
with open(fname2,'wb+') as destination:
|
||||
for chunk in f.chunks():
|
||||
destination.write(chunk)
|
||||
|
||||
return fname,fname2
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
# This is just a scratch pad to temporarily park code, just in case I need
|
||||
# it later. Hardly used since i have proper versioning
|
||||
|
||||
|
||||
@login_required()
|
||||
def workout_edit_view(request,id=0):
|
||||
if request.method == 'POST':
|
||||
|
||||
@@ -8,7 +8,7 @@ import rowers.interactiveplots as iplots
|
||||
import datetime
|
||||
from rowingdata import rowingdata as rdata
|
||||
from rowingdata import rower as rrower
|
||||
from rowsandall_app.rows import handle_uploaded_file
|
||||
from rowers.rows import handle_uploaded_file
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from time import strftime,strptime,mktime,time,daylight
|
||||
import os
|
||||
|
||||
@@ -100,7 +100,6 @@ urlpatterns = [
|
||||
url(r'^api-docs$', views.schema_view),
|
||||
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||
url(r'^api/workouts/(?P<id>\d+)/strokedata$',views.strokedatajson),
|
||||
url(r'^testbokeh$',views.testbokeh),
|
||||
url(r'^500/$', TemplateView.as_view(template_name='500.html'),name='500'),
|
||||
url(r'^404/$', TemplateView.as_view(template_name='404.html'),name='404'),
|
||||
url(r'^400/$', TemplateView.as_view(template_name='400.html'),name='400'),
|
||||
@@ -113,10 +112,6 @@ urlpatterns = [
|
||||
url(r'^list-workouts/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.workouts_view),
|
||||
url(r'^list-workouts/$',views.workouts_view),
|
||||
url(r'^list-graphs/$',views.graphs_view),
|
||||
url(r'^dashboard/c/(?P<message>\w+.*)/$',views.dashboard_view),
|
||||
url(r'^dashboard/s/(?P<successmessage>\w+.*)/$',views.dashboard_view),
|
||||
url(r'^dashboard/c/(?P<message>\w+.*)/s/(?P<successmessage>\w+.*)$',views.dashboard_view),
|
||||
url(r'^dashboard/$',views.dashboard_view),
|
||||
url(r'^(?P<theuser>\d+)/ote-bests/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.rankings_view),
|
||||
url(r'^(?P<theuser>\d+)/ote-bests/(?P<deltadays>\d+)$',views.rankings_view),
|
||||
url(r'^ote-bests/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.rankings_view),
|
||||
@@ -194,7 +189,6 @@ urlpatterns = [
|
||||
url(r'^workout/sporttracksimport/$',views.workout_sporttracksimport_view),
|
||||
url(r'^workout/sporttracksimport/(\d+)/$',views.workout_getsporttracksworkout_view),
|
||||
url(r'^workout/(\d+)/deleteconfirm$',views.workout_delete_confirm_view),
|
||||
url(r'^workout/(\d+)/c2upload/$',views.list_c2_upload_view),
|
||||
url(r'^workout/(\d+)/c2uploadw/$',views.workout_c2_upload_view),
|
||||
url(r'^workout/(\d+)/stravauploadw/$',views.workout_strava_upload_view),
|
||||
url(r'^workout/(\d+)/recalcsummary/$',views.workout_recalcsummary_view),
|
||||
|
||||
290
rowers/views.py
290
rowers/views.py
@@ -1,6 +1,7 @@
|
||||
import time
|
||||
import zipfile
|
||||
import operator
|
||||
import warnings
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.db.models import Q
|
||||
from django.db import IntegrityError, transaction
|
||||
@@ -46,7 +47,7 @@ import requests
|
||||
import json
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
from rest_framework.parsers import JSONParser
|
||||
from rowsandall_app.rows import handle_uploaded_file
|
||||
from rowers.rows import handle_uploaded_file
|
||||
from rowers.tasks import handle_makeplot,handle_otwsetpower,handle_sendemailtcx,handle_sendemailcsv
|
||||
from rowers.tasks import handle_sendemail_unrecognized
|
||||
from scipy.signal import savgol_filter
|
||||
@@ -105,8 +106,10 @@ USER_LANGUAGE = 'en-US'
|
||||
|
||||
from interactiveplots import *
|
||||
|
||||
# Define the API documentation
|
||||
schema_view = get_swagger_view(title='Rowsandall API (Unstable)')
|
||||
|
||||
# Custom error pages with Rowsandall headers
|
||||
def error500_view(request):
|
||||
response = render_to_response('500.html', {},
|
||||
context_instance = RequestContext(request))
|
||||
@@ -135,6 +138,8 @@ def error403_view(request):
|
||||
response.status_code = 403
|
||||
return response
|
||||
|
||||
# Wrapper around the rowingdata call to catch some exceptions
|
||||
# Checks for CSV file, then for gzipped CSV file, and if all fails, returns 0
|
||||
def rdata(file,rower=rrower()):
|
||||
try:
|
||||
res = rrdata(file,rower=rower)
|
||||
@@ -146,6 +151,7 @@ def rdata(file,rower=rrower()):
|
||||
|
||||
return res
|
||||
|
||||
# Used for the interval editor - translates seconds to a time object
|
||||
def get_time(second):
|
||||
if (second<=0) or (second>1e9):
|
||||
hours = 0
|
||||
@@ -166,10 +172,13 @@ def get_time(second):
|
||||
return datetime.time(hours,minutes,sec,microsecond)
|
||||
|
||||
|
||||
|
||||
# get the workout ID from the SportTracks URI
|
||||
def getidfromsturi(uri):
|
||||
return uri[len(uri)-8:]
|
||||
|
||||
# Splits SportTracks data which is one long sequence of
|
||||
# [t,[lat,lon],t2,[lat2,lon2] ...]
|
||||
# to [t,t2,t3, ...], [[lat,long],[lat2,long2],...
|
||||
def splitstdata(lijst):
|
||||
t = []
|
||||
latlong = []
|
||||
@@ -188,10 +197,13 @@ def geo_distance(lat1,lon1,lat2,lon2):
|
||||
We're never moving more than 10 meters between trackpoints
|
||||
|
||||
Bearing calculation fails if one of the points is a pole.
|
||||
(Hey, from the North pole you can walk South, East, North and end up
|
||||
on the same spot!)
|
||||
|
||||
"""
|
||||
|
||||
# radius of earth in km
|
||||
# radius of our earth in km --> should be moved to settings if
|
||||
# rowing takes off on other planets
|
||||
R = 6373.0
|
||||
|
||||
# pi
|
||||
@@ -219,11 +231,13 @@ def geo_distance(lat1,lon1,lat2,lon2):
|
||||
|
||||
return [distance,bearing]
|
||||
|
||||
# Check if a user is a Pro member
|
||||
def promember(user):
|
||||
r = Rower.objects.get(user=user)
|
||||
result = user.is_authenticated() and (r.rowerplan=='pro' or r.rowerplan=='coach')
|
||||
return result
|
||||
|
||||
# User registration
|
||||
def rower_register_view(request):
|
||||
if request.method == 'POST':
|
||||
form = RegistrationFormUniqueEmail(request.POST)
|
||||
@@ -289,7 +303,8 @@ def rower_register_view(request):
|
||||
return render(request,
|
||||
"registration_form.html",
|
||||
{'form':form,})
|
||||
|
||||
|
||||
# Shows email form and sends it if submitted
|
||||
def sendmail(request):
|
||||
if request.method == 'POST':
|
||||
form = EmailForm(request.POST)
|
||||
@@ -312,6 +327,7 @@ def sendmail(request):
|
||||
else:
|
||||
return HttpResponseRedirect('/rowers/email/')
|
||||
|
||||
# Check if workout belongs to this user
|
||||
def checkworkoutuser(user,workout):
|
||||
try:
|
||||
r = Rower.objects.get(user=user)
|
||||
@@ -319,6 +335,8 @@ def checkworkoutuser(user,workout):
|
||||
except Rower.DoesNotExist:
|
||||
return(False)
|
||||
|
||||
# Create workout data from Strava or Concept2
|
||||
# data and create the associated Workout object and save it
|
||||
def add_workout_from_strokedata(user,importid,data,strokedata,
|
||||
source='c2',splitdata=None):
|
||||
workouttype = data['type']
|
||||
@@ -393,10 +411,8 @@ def add_workout_from_strokedata(user,importid,data,strokedata,
|
||||
pace = strokedata.ix[:,'p']/10.
|
||||
|
||||
velo = 500./pace
|
||||
# if (source=='c2' or source=='strava'):
|
||||
|
||||
power = 2.8*velo**3
|
||||
# else:
|
||||
# power = 0.0*velo
|
||||
|
||||
# save csv
|
||||
# Create data frame with all necessary data to write to csv
|
||||
@@ -419,7 +435,7 @@ def add_workout_from_strokedata(user,importid,data,strokedata,
|
||||
' ElapsedTime (sec)':seconds
|
||||
})
|
||||
|
||||
# data.sort(['TimeStamp (sec)'],ascending=True)
|
||||
|
||||
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
||||
|
||||
timestr = strftime("%Y%m%d-%H%M%S")
|
||||
@@ -451,19 +467,21 @@ def add_workout_from_strokedata(user,importid,data,strokedata,
|
||||
|
||||
# end autosmoothing
|
||||
|
||||
# Create CSV file name and save data to CSV file
|
||||
csvfilename ='media/Import_'+str(importid)+'.csv'
|
||||
|
||||
res = df.to_csv(csvfilename+'.gz',index_label='index',
|
||||
compression='gzip')
|
||||
|
||||
averagehr = df[' HRCur (bpm)'].mean()
|
||||
maxhr = df[' HRCur (bpm)'].max()
|
||||
|
||||
# make workout
|
||||
rr = rrower(hrmax=r.max,hrut2=r.ut2,
|
||||
hrut1=r.ut1,hrat=r.at,
|
||||
hrtr=r.tr,hran=r.an,ftp=r.ftp)
|
||||
row = rdata(csvfilename,rower=rr)
|
||||
|
||||
averagehr = row.df[' HRCur (bpm)'].mean()
|
||||
maxhr = row.df[' HRCur (bpm)'].max()
|
||||
totaldist = row.df['cum_dist'].max()
|
||||
totaltime = row.df['TimeStamp (sec)'].max()-row.df['TimeStamp (sec)'].min()
|
||||
totaltime = totaltime+row.df.ix[0,' ElapsedTime (sec)']
|
||||
@@ -488,8 +506,9 @@ def add_workout_from_strokedata(user,importid,data,strokedata,
|
||||
ws = Workout.objects.filter(starttime=workoutstarttime,
|
||||
user=r)
|
||||
if (len(ws) != 0):
|
||||
print "Warning: This workout probably already exists in the database"
|
||||
warnings.warn("Probably a duplicate workout",UserWarning)
|
||||
|
||||
# Create the Workout object
|
||||
w = Workout(user=r,name=title,
|
||||
date=workoutdate,workouttype=workouttype,
|
||||
duration=duration,distance=totaldist,
|
||||
@@ -503,6 +522,8 @@ def add_workout_from_strokedata(user,importid,data,strokedata,
|
||||
|
||||
return w.id
|
||||
|
||||
# Create workout from SportTracks Data, which are slightly different
|
||||
# than Strava or Concept2 data
|
||||
def add_workout_from_stdata(user,importid,data):
|
||||
workouttype = data['type']
|
||||
if workouttype not in [x[0] for x in Workout.workouttypes]:
|
||||
@@ -512,7 +533,6 @@ def add_workout_from_stdata(user,importid,data):
|
||||
except:
|
||||
comments = ''
|
||||
|
||||
# comments = "Imported data \n"+str(comments)
|
||||
try:
|
||||
thetimezone = tz(data['timezone'])
|
||||
except:
|
||||
@@ -653,8 +673,6 @@ def add_workout_from_stdata(user,importid,data):
|
||||
|
||||
df = df.fillna(0)
|
||||
|
||||
|
||||
# data.sort(['TimeStamp (sec)'],ascending=True)
|
||||
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
||||
|
||||
timestr = strftime("%Y%m%d-%H%M%S")
|
||||
@@ -689,14 +707,15 @@ def add_workout_from_stdata(user,importid,data):
|
||||
res = df.to_csv(csvfilename+'.gz',index_label='index',
|
||||
compression='gzip')
|
||||
|
||||
averagehr = df[' HRCur (bpm)'].mean()
|
||||
maxhr = df[' HRCur (bpm)'].max()
|
||||
|
||||
# make workout
|
||||
rr = rrower(hrmax=r.max,hrut2=r.ut2,
|
||||
hrut1=r.ut1,hrat=r.at,
|
||||
hrtr=r.tr,hran=r.an,ftp=r.ftp)
|
||||
row = rdata(csvfilename,rower=rr)
|
||||
|
||||
averagehr = row.df[' HRCur (bpm)'].mean()
|
||||
maxhr = row.df[' HRCur (bpm)'].max()
|
||||
|
||||
totaldist = row.df['cum_dist'].max()
|
||||
totaltime = row.df['TimeStamp (sec)'].max()-row.df['TimeStamp (sec)'].min()
|
||||
totaltime = totaltime+row.df.ix[0,' ElapsedTime (sec)']
|
||||
@@ -736,12 +755,13 @@ def add_workout_from_stdata(user,importid,data):
|
||||
|
||||
return w.id
|
||||
|
||||
# Checks if user has Concept2 tokens, resets tokens if they are
|
||||
# expired.
|
||||
def c2_open(user):
|
||||
r = Rower.objects.get(user=user)
|
||||
if (r.c2token == '') or (r.c2token is None):
|
||||
s = "Token doesn't exist. Need to authorize"
|
||||
raise C2NoTokenError("User has no token")
|
||||
# return HttpResponseRedirect("/rowers/me/c2authorize/")
|
||||
else:
|
||||
if (timezone.now()>r.tokenexpirydate):
|
||||
res = c2stuff.rower_c2_token_refresh(user)
|
||||
@@ -754,7 +774,7 @@ def c2_open(user):
|
||||
|
||||
return thetoken
|
||||
|
||||
|
||||
# Checks if user has SportTracks token, renews them if they are expired
|
||||
def sporttracks_open(user):
|
||||
r = Rower.objects.get(user=user)
|
||||
if (r.sporttrackstoken == '') or (r.sporttrackstoken is None):
|
||||
@@ -768,60 +788,7 @@ def sporttracks_open(user):
|
||||
|
||||
return thetoken
|
||||
|
||||
|
||||
# Create your views here.
|
||||
|
||||
@login_required()
|
||||
def list_c2_upload_view(request,id=0):
|
||||
message = ""
|
||||
try:
|
||||
thetoken = c2_open(request.user)
|
||||
except C2NoTokenError:
|
||||
return HttpResponseRedirect("/rowers/me/c2authorize/")
|
||||
|
||||
# ready to upload. Hurray
|
||||
w = Workout.objects.get(id=id)
|
||||
if (checkworkoutuser(request.user,w)):
|
||||
c2userid = c2stuff.get_userid(thetoken)
|
||||
data = c2stuff.createc2workoutdata(w)
|
||||
authorizationstring = str('Bearer ' + thetoken)
|
||||
headers = {'Authorization': authorizationstring,
|
||||
'user-agent': 'sanderroosendaal',
|
||||
'Content-Type': 'application/json'}
|
||||
import urllib
|
||||
url = "https://log.concept2.com/api/users/%s/results" % (c2userid)
|
||||
response = requests.post(url,headers=headers,data=json.dumps(data))
|
||||
|
||||
# check for duplicate error first
|
||||
if (response.status_code == 409 ):
|
||||
message = "Duplicate error"
|
||||
w.uploadedtoc2 = -1
|
||||
w.save()
|
||||
elif (response.status_code == 201 or response.status_code == 200):
|
||||
try:
|
||||
s= json.loads(response.text)
|
||||
c2id = s['data']['id']
|
||||
w.uploadedtoc2 = c2id
|
||||
w.save()
|
||||
url = reverse(workouts_view)
|
||||
return HttpResponseRedirect(url)
|
||||
except:
|
||||
message = "Something went wrong in list_c2_upload_view. Response 200/201 but Upload to C2 failed: "+response.text
|
||||
else:
|
||||
s = response
|
||||
message = "Something went wrong in list_c2_upload_view. Upload to C2 failed."
|
||||
|
||||
else:
|
||||
message = "You are not authorized to upload this workout"
|
||||
|
||||
url = reverse(workouts_view,
|
||||
kwargs = {
|
||||
'message':str(message),
|
||||
})
|
||||
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
# Export workout to TCX and send to user's email address
|
||||
@login_required()
|
||||
def workout_tcxemail_view(request,id=0):
|
||||
message = ""
|
||||
@@ -874,6 +841,7 @@ def workout_tcxemail_view(request,id=0):
|
||||
|
||||
return response
|
||||
|
||||
# Get Workout CSV file and send it to user's email address
|
||||
@login_required()
|
||||
def workout_csvemail_view(request,id=0):
|
||||
message = ""
|
||||
@@ -910,6 +878,8 @@ def workout_csvemail_view(request,id=0):
|
||||
|
||||
return response
|
||||
|
||||
# Send workout to Strava
|
||||
# abundance of error logging here because there were/are some bugs
|
||||
@login_required()
|
||||
def workout_strava_upload_view(request,id=0):
|
||||
message = ""
|
||||
@@ -991,6 +961,7 @@ def workout_strava_upload_view(request,id=0):
|
||||
|
||||
return response
|
||||
|
||||
# Upload workout to Concept2 logbook
|
||||
@login_required()
|
||||
def workout_c2_upload_view(request,id=0):
|
||||
message = ""
|
||||
@@ -1059,6 +1030,7 @@ def workout_c2_upload_view(request,id=0):
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
# Upload workout to SportTracks
|
||||
@login_required()
|
||||
def workout_sporttracks_upload_view(request,id=0):
|
||||
message = ""
|
||||
@@ -1116,7 +1088,7 @@ def workout_sporttracks_upload_view(request,id=0):
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
# Concept2 authorization
|
||||
@login_required()
|
||||
def rower_c2_authorize(request):
|
||||
# Generate a random string for the state parameter
|
||||
@@ -1132,6 +1104,7 @@ def rower_c2_authorize(request):
|
||||
url += "&scope="+scope
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
# Strava Authorization
|
||||
@login_required()
|
||||
def rower_strava_authorize(request):
|
||||
# Generate a random string for the state parameter
|
||||
@@ -1149,6 +1122,7 @@ def rower_strava_authorize(request):
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
# SportTracks Authorization
|
||||
@login_required()
|
||||
def rower_sporttracks_authorize(request):
|
||||
# Generate a random string for the state parameter
|
||||
@@ -1167,6 +1141,7 @@ def rower_sporttracks_authorize(request):
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
# Concept2 token refresh. URL for manual refresh. Not visible to users
|
||||
@login_required()
|
||||
def rower_c2_token_refresh(request):
|
||||
r = Rower.objects.get(user=request.user)
|
||||
@@ -1191,6 +1166,7 @@ def rower_c2_token_refresh(request):
|
||||
|
||||
return imports_view(request,successmessage=successmessage,message=message)
|
||||
|
||||
# SportTracks token refresh. URL for manual refresh. Not visible to users
|
||||
@login_required()
|
||||
def rower_sporttracks_token_refresh(request):
|
||||
r = Rower.objects.get(user=request.user)
|
||||
@@ -1211,6 +1187,7 @@ def rower_sporttracks_token_refresh(request):
|
||||
return imports_view(request,successmessage=successmessage)
|
||||
|
||||
|
||||
# Concept2 Callback
|
||||
@login_required()
|
||||
def rower_process_callback(request):
|
||||
try:
|
||||
@@ -1235,6 +1212,7 @@ def rower_process_callback(request):
|
||||
successmessage = "Tokens stored. Good to go"
|
||||
return imports_view(request,successmessage=successmessage)
|
||||
|
||||
# The imports page
|
||||
@login_required()
|
||||
def imports_view(request,successmessage="",message=""):
|
||||
return render(request,"imports.html",
|
||||
@@ -1242,16 +1220,19 @@ def imports_view(request,successmessage="",message=""):
|
||||
'message': message,
|
||||
})
|
||||
|
||||
# Just for testing purposes
|
||||
@login_required()
|
||||
def test_reverse_view(request):
|
||||
successmessage = "Tokens stored. Good to go"
|
||||
|
||||
return imports_view(request,successmessage=successmessage)
|
||||
|
||||
# dummy
|
||||
@login_required()
|
||||
def rower_process_twittercallback(request):
|
||||
return "dummy"
|
||||
|
||||
# Process Strava Callback
|
||||
@login_required()
|
||||
def rower_process_stravacallback(request):
|
||||
code = request.GET['code']
|
||||
@@ -1268,7 +1249,7 @@ def rower_process_stravacallback(request):
|
||||
return imports_view(request,successmessage=successmessage)
|
||||
|
||||
|
||||
|
||||
# Process SportTracks callback
|
||||
@login_required()
|
||||
def rower_process_sporttrackscallback(request):
|
||||
code = request.GET['code']
|
||||
@@ -1290,6 +1271,7 @@ def rower_process_sporttrackscallback(request):
|
||||
successmessage = "Tokens stored. Good to go"
|
||||
return imports_view(request,successmessage=successmessage)
|
||||
|
||||
# Process Own API callback - for API testing purposes
|
||||
@login_required()
|
||||
def rower_process_testcallback(request):
|
||||
code = request.GET['code']
|
||||
@@ -1309,7 +1291,7 @@ def rower_process_testcallback(request):
|
||||
|
||||
return HttpResponse(text)
|
||||
|
||||
|
||||
# View around the Histogram of all strokes. Not implemented in UI
|
||||
@login_required()
|
||||
def histo_all(request,theuser=0):
|
||||
promember=0
|
||||
@@ -1356,6 +1338,7 @@ def histo_all(request,theuser=0):
|
||||
'theuser':u,
|
||||
})
|
||||
|
||||
# The Flex plot for a large selection of workouts
|
||||
@login_required()
|
||||
def cum_flex(request,theuser=0,
|
||||
xparam='spm',
|
||||
@@ -1478,6 +1461,7 @@ def cum_flex(request,theuser=0,
|
||||
'promember':promember,
|
||||
})
|
||||
|
||||
# Show the EMpower Oarlock generated Stroke Profile
|
||||
@user_passes_test(promember,login_url="/",redirect_field_name=None)
|
||||
def workout_forcecurve_view(request,id=0,workstrokesonly=False):
|
||||
row = Workout.objects.get(id=id)
|
||||
@@ -1516,6 +1500,7 @@ def workout_forcecurve_view(request,id=0,workstrokesonly=False):
|
||||
'workstrokesonly': not workstrokesonly,
|
||||
})
|
||||
|
||||
# Show Stroke power histogram for a workout
|
||||
@login_required()
|
||||
def workout_histo_view(request,id=0):
|
||||
row = Workout.objects.get(id=id)
|
||||
@@ -1544,6 +1529,7 @@ def workout_histo_view(request,id=0):
|
||||
'mayedit':mayedit,
|
||||
})
|
||||
|
||||
# Histogram for a date/time range
|
||||
@login_required()
|
||||
def histo(request,theuser=0,
|
||||
startdate=timezone.now()-datetime.timedelta(days=365),
|
||||
@@ -1651,6 +1637,7 @@ def histo(request,theuser=0,
|
||||
'deltaform':deltaform,
|
||||
})
|
||||
|
||||
# Show ranking distances including predicted paces
|
||||
@login_required()
|
||||
def rankings_view(request,theuser=0,
|
||||
startdate=timezone.now()-datetime.timedelta(days=365),
|
||||
@@ -1683,7 +1670,7 @@ def rankings_view(request,theuser=0,
|
||||
if result:
|
||||
promember=1
|
||||
|
||||
# get all indoor rows of in date range
|
||||
# get all indoor rows in date range
|
||||
|
||||
# process form
|
||||
if request.method == 'POST' and "daterange" in request.POST:
|
||||
@@ -1945,6 +1932,7 @@ def rankings_view(request,theuser=0,
|
||||
'enddate':enddate,
|
||||
})
|
||||
|
||||
# Reload the workout and calculate the summary from the stroke data (lapIDx)
|
||||
@login_required()
|
||||
def workout_recalcsummary_view(request,id=0):
|
||||
row = Workout.objects.get(id=id)
|
||||
@@ -1967,7 +1955,7 @@ def workout_recalcsummary_view(request,id=0):
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
# List Workouts
|
||||
@login_required()
|
||||
def workouts_view(request,message='',successmessage='',
|
||||
startdatestring="",enddatestring="",
|
||||
@@ -1975,9 +1963,6 @@ def workouts_view(request,message='',successmessage='',
|
||||
enddate=timezone.now()+datetime.timedelta(days=1)):
|
||||
try:
|
||||
r = Rower.objects.get(user=request.user)
|
||||
# res = mailprocessing.safeprocessattachments()
|
||||
#if len(res)>0 and np.cumsum(np.array(res)).max()>0:
|
||||
# successmessage = 'New Workouts have been created from email'
|
||||
|
||||
if request.method == 'POST':
|
||||
dateform = DateRangeForm(request.POST)
|
||||
@@ -2049,6 +2034,7 @@ def workouts_view(request,message='',successmessage='',
|
||||
except Rower.DoesNotExist:
|
||||
return HttpResponse("User has no rower instance")
|
||||
|
||||
# List of workouts to compare a selected workout to
|
||||
@user_passes_test(promember,login_url="/",redirect_field_name=None)
|
||||
def workout_comparison_list(request,id=0,message='',successmessage='',
|
||||
startdatestring="",enddatestring="",
|
||||
@@ -2124,6 +2110,7 @@ def workout_comparison_list(request,id=0,message='',successmessage='',
|
||||
except Rower.DoesNotExist:
|
||||
return HttpResponse("User has no rower instance")
|
||||
|
||||
# Basic 'EDIT' view of workout
|
||||
def workout_view(request,id=0):
|
||||
try:
|
||||
# check if valid ID exists (workout exists)
|
||||
@@ -2162,7 +2149,7 @@ def workout_view(request,id=0):
|
||||
except Workout.DoesNotExist:
|
||||
return HttpResponseNotFound("Workout doesn't exist")
|
||||
|
||||
|
||||
# Resets stroke data to raw data (pace)
|
||||
@user_passes_test(promember,login_url="/",redirect_field_name=None)
|
||||
def workout_undo_smoothenpace_view(request,id=0,message="",successmessage=""):
|
||||
row = Workout.objects.get(id=id)
|
||||
@@ -2189,7 +2176,7 @@ def workout_undo_smoothenpace_view(request,id=0,message="",successmessage=""):
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
|
||||
# Data smoothing of pace data
|
||||
@user_passes_test(promember,login_url="/",redirect_field_name=None)
|
||||
def workout_smoothenpace_view(request,id=0,message="",successmessage=""):
|
||||
row = Workout.objects.get(id=id)
|
||||
@@ -2225,6 +2212,7 @@ def workout_smoothenpace_view(request,id=0,message="",successmessage=""):
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
# Process CrewNerd Summary CSV and update summary
|
||||
@user_passes_test(promember,login_url="/",redirect_field_name=None)
|
||||
def workout_crewnerd_summary_view(request,id=0,message="",successmessage=""):
|
||||
row = Workout.objects.get(id=id)
|
||||
@@ -2268,7 +2256,8 @@ def workout_crewnerd_summary_view(request,id=0,message="",successmessage=""):
|
||||
"cn_form.html",
|
||||
{'form':form,
|
||||
'id':row.id})
|
||||
|
||||
|
||||
# Get weather for given location and date/time
|
||||
@user_passes_test(promember,login_url="/",redirect_field_name=None)
|
||||
def workout_downloadwind_view(request,id=0,message="",successmessage=""):
|
||||
row = Workout.objects.get(id=id)
|
||||
@@ -2325,7 +2314,7 @@ def workout_downloadwind_view(request,id=0,message="",successmessage=""):
|
||||
|
||||
return response
|
||||
|
||||
|
||||
# Show form to update wind data
|
||||
@user_passes_test(promember,login_url="/",redirect_field_name=None)
|
||||
def workout_wind_view(request,id=0,message="",successmessage=""):
|
||||
row = Workout.objects.get(id=id)
|
||||
@@ -2425,6 +2414,7 @@ def workout_wind_view(request,id=0,message="",successmessage=""):
|
||||
'gmapdiv':gmdiv})
|
||||
|
||||
|
||||
# Show form to update River stream data (for river dwellers)
|
||||
@user_passes_test(promember,login_url="/",redirect_field_name=None)
|
||||
def workout_stream_view(request,id=0,message="",successmessage=""):
|
||||
row = Workout.objects.get(id=id)
|
||||
@@ -2486,7 +2476,7 @@ def workout_stream_view(request,id=0,message="",successmessage=""):
|
||||
'form':form,
|
||||
'the_div':div})
|
||||
|
||||
|
||||
# Form to set average crew weight and boat type, then run power calcs
|
||||
@user_passes_test(promember, login_url="/",redirect_field_name=None)
|
||||
def workout_otwsetpower_view(request,id=0,message="",successmessage=""):
|
||||
row = Workout.objects.get(id=id)
|
||||
@@ -2572,7 +2562,7 @@ def workout_otwsetpower_view(request,id=0,message="",successmessage=""):
|
||||
'form':form,
|
||||
})
|
||||
|
||||
|
||||
# A special Edit page with all the Geeky functionality for the workout
|
||||
@login_required()
|
||||
def workout_geeky_view(request,id=0,message="",successmessage=""):
|
||||
row = Workout.objects.get(id=id)
|
||||
@@ -2617,7 +2607,7 @@ def workout_geeky_view(request,id=0,message="",successmessage=""):
|
||||
'interactiveplot':script,
|
||||
'the_div':div})
|
||||
|
||||
#@user_passes_test(promember,login_url="/",redirect_field_name=None)
|
||||
# The Advanced edit page
|
||||
@login_required()
|
||||
def workout_advanced_view(request,id=0,message="",successmessage=""):
|
||||
row = Workout.objects.get(id=id)
|
||||
@@ -2662,6 +2652,7 @@ def workout_advanced_view(request,id=0,message="",successmessage=""):
|
||||
'interactiveplot':script,
|
||||
'the_div':div})
|
||||
|
||||
# The interactive plot comparing two workouts (obsolete version)
|
||||
def workout_comparison_view(request,id1=0,id2=0,xparam='distance',yparam='spm'):
|
||||
promember=0
|
||||
if not request.user.is_anonymous():
|
||||
@@ -2686,7 +2677,8 @@ def workout_comparison_view(request,id1=0,id2=0,xparam='distance',yparam='spm'):
|
||||
'xparam':xparam,
|
||||
'yparam':yparam,
|
||||
})
|
||||
|
||||
|
||||
# Updated version of comparison pliot
|
||||
def workout_comparison_view2(request,id1=0,id2=0,xparam='distance',
|
||||
yparam='spm',plottype='line'):
|
||||
promember=0
|
||||
@@ -2715,7 +2707,7 @@ def workout_comparison_view2(request,id1=0,id2=0,xparam='distance',
|
||||
})
|
||||
|
||||
|
||||
|
||||
# The famous flex chart
|
||||
def workout_flexchart3_view(request,*args,**kwargs):
|
||||
|
||||
try:
|
||||
@@ -2879,98 +2871,8 @@ def workout_flexchart3_view(request,*args,**kwargs):
|
||||
'maxfav':maxfav,
|
||||
})
|
||||
|
||||
def testbokeh(request):
|
||||
|
||||
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,resize,crosshair'
|
||||
|
||||
x = np.array(range(51))/10.
|
||||
y = x**2.
|
||||
z = (2*(x-2.5))**2
|
||||
data = dict(
|
||||
x = x,
|
||||
y = y,
|
||||
z = z,
|
||||
)
|
||||
|
||||
df = pd.DataFrame(data)
|
||||
filtered_df = df
|
||||
|
||||
source = ColumnDataSource(
|
||||
df
|
||||
)
|
||||
|
||||
source2 = ColumnDataSource(
|
||||
filtered_df
|
||||
)
|
||||
|
||||
plot = Figure(tools=TOOLS)
|
||||
plot.circle('x','y',source=source2)
|
||||
plot.xaxis.axis_label = "X"
|
||||
plot.yaxis.axis_label = "Y"
|
||||
plot.x_range = Range1d(-1,6)
|
||||
plot.y_range = Range1d(-5,30)
|
||||
|
||||
callback = CustomJS(args = dict(source=source,source2=source2), code="""
|
||||
var data = source.data
|
||||
var data2 = source2.data
|
||||
var x1 = data['x']
|
||||
var y1 = data['y']
|
||||
var z1 = data['z']
|
||||
var mina = mina.value
|
||||
var maxa = maxa.value
|
||||
var minz = minz.value
|
||||
var maxz = maxz.value
|
||||
data2['x'] = []
|
||||
data2['y'] = []
|
||||
data2['z'] = []
|
||||
|
||||
for (i=0; i<x1.length; i++) {
|
||||
if (x1[i]>=mina && x1[i]<=maxa && z1[i]<=maxz && z1[i]>=minz) {
|
||||
data2['x'].push(x1[i])
|
||||
data2['y'].push(y1[i])
|
||||
data2['z'].push(z1[i])
|
||||
}
|
||||
}
|
||||
|
||||
source2.trigger('change');
|
||||
""")
|
||||
|
||||
s1 = Slider(start=0.0, end=5,value=0.0, step=.1,title="Min X Value",callback=callback)
|
||||
callback.args["mina"] = s1
|
||||
|
||||
s2 = Slider(start=0.0, end=5,value=5.0, step=.1,title="Max X Value",callback=callback)
|
||||
callback.args["maxa"] = s2
|
||||
|
||||
s3 = Slider(start=0.0, end=25,value=0.0, step=.1,title="Min Z Value",callback=callback)
|
||||
callback.args["minz"] = s3
|
||||
|
||||
s4 = Slider(start=0.0, end=25,value=25.0, step=.1,title="Max Z Value",callback=callback)
|
||||
callback.args["maxz"] = s4
|
||||
|
||||
hover = plot.select(dict(type=HoverTool))
|
||||
|
||||
hover.tooltips = OrderedDict([
|
||||
('X value','@x'),
|
||||
('Y value','@y'),
|
||||
('Z value','@z'),
|
||||
])
|
||||
|
||||
hover.mode = 'mouse'
|
||||
|
||||
layout = layoutrow([layoutcolumn([s1,s2,s3,s4]),plot])
|
||||
# widgetbox(s)
|
||||
script, div = components(layout)
|
||||
js_resources = INLINE.render_js()
|
||||
css_resources = INLINE.render_css()
|
||||
return render(request,
|
||||
'test.html',
|
||||
{'the_script': script,
|
||||
'the_div': div,
|
||||
'js_res': js_resources,
|
||||
'css_res':css_resources,
|
||||
})
|
||||
|
||||
#@user_passes_test(promember,login_url="/",redirect_field_name=None)
|
||||
# The interactive plot with the colored Heart rate zones
|
||||
def workout_biginteractive_view(request,id=0,message="",successmessage=""):
|
||||
row = Workout.objects.get(id=id)
|
||||
# check if user is owner of this workout
|
||||
@@ -3007,6 +2909,7 @@ def workout_biginteractive_view(request,id=0,message="",successmessage=""):
|
||||
'promember':promember,
|
||||
'mayedit':mayedit})
|
||||
|
||||
# The interactive plot with wind corrected pace for OTW outings
|
||||
def workout_otwpowerplot_view(request,id=0,message="",successmessage=""):
|
||||
row = Workout.objects.get(id=id)
|
||||
# check if user is owner of this workout
|
||||
@@ -4414,31 +4317,6 @@ def graph_delete_view(request,id=0):
|
||||
return HttpResponse("Graph Image doesn't exist")
|
||||
|
||||
|
||||
@login_required()
|
||||
def dashboard_view(request,message="",successmessage=""):
|
||||
try:
|
||||
request.session[translation.LANGUAGE_SESSION_KEY] = USER_LANGUAGE
|
||||
|
||||
r = Rower.objects.get(user=request.user)
|
||||
workouts = Workout.objects.filter(user=r).order_by("-date", "-starttime")
|
||||
g = GraphImage.objects.filter(workout__in=workouts).order_by("-creationdatetime")
|
||||
if (len(g)<=3):
|
||||
return render(request,'dashboard.html',
|
||||
{'workouts':workouts,
|
||||
'graphs1':g[0:3],
|
||||
'message':message,
|
||||
'successmessage':successmessage})
|
||||
else:
|
||||
return render(request,'dashboard.html',
|
||||
{'workouts':workouts,
|
||||
'graphs1':g[0:3],
|
||||
'graphs2':g[3:6],
|
||||
'message':message,
|
||||
'successmessage':successmessage})
|
||||
|
||||
except Rower.DoesNotExist:
|
||||
return HttpResponse("User has no rower instance")
|
||||
|
||||
|
||||
@login_required()
|
||||
def graphs_view(request):
|
||||
|
||||
Reference in New Issue
Block a user