From cd4faf861a7434de9a8b9922a148cc0774a0bfb6 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 4 Jan 2018 08:54:16 +0100 Subject: [PATCH 1/3] error checking around rdata in updateergcp --- rowers/tasks.py | 12 +++++++++++- rowers/templates/.#oterankings.html | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) delete mode 100644 rowers/templates/.#oterankings.html diff --git a/rowers/tasks.py b/rowers/tasks.py index e40aa000..f17fb216 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -493,7 +493,17 @@ def handle_otwsetpower(self,f1, boattype, weightvalue, def handle_updateergcp(rower_id,workoutfilenames,debug=False,**kwargs): therows = [] for f1 in workoutfilenames: - rowdata = rdata(f1) + try: + rowdata = rdata(f1) + except IOError: + try: + rowdata = rdata(f1 + '.csv') + except IOError: + try: + rowdata = rdata(f1 + '.gz') + except IOError: + rowdata = 0 + if rowdata != 0: therows.append(rowdata) diff --git a/rowers/templates/.#oterankings.html b/rowers/templates/.#oterankings.html deleted file mode 100644 index 0075ef80..00000000 --- a/rowers/templates/.#oterankings.html +++ /dev/null @@ -1 +0,0 @@ -E408191@CZ27LT9RCGN72.63064:1514927368 \ No newline at end of file From efeb5bc2f718dbaef37cce4ce61d54154785c5d3 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 4 Jan 2018 21:13:33 +0100 Subject: [PATCH 2/3] made ranking pieces explicit --- rowers/templates/list_workouts.html | 309 ++++++++++++++++------------ rowers/urls.py | 1 + rowers/utils.py | 17 ++ rowers/views.py | 41 +++- static/css/rowsandall.css | 13 ++ 5 files changed, 240 insertions(+), 141 deletions(-) diff --git a/rowers/templates/list_workouts.html b/rowers/templates/list_workouts.html index e051f0b6..d82399c7 100644 --- a/rowers/templates/list_workouts.html +++ b/rowers/templates/list_workouts.html @@ -4,12 +4,49 @@ {% block title %}Rowsandall Workouts List{% endblock %} -{% block content %} - +{% block scripts %} + + +{% endblock %} + +{% block content %} +
@@ -51,6 +88,7 @@ + @@ -76,155 +114,166 @@ {% else %} {% endif %} + - - {% else %} - No Name -{% endif %} -{% else %} -{% if workout.name != '' %} -{{ workout.name }} -{% else %} -No Name -{% endif %} -{% endif %} - - - - - - {% if not team %} - + + {% else %} + + {% endif %} + {% else %} + {% if workout.name != '' %} + + {% else %} + + {% endif %} + {% endif %} + + + + + + {% if not team %} + + {% else %} + + {% endif %} + + + + + + {% endfor %} + +
R Date Time Name
+ {% if workout.rankingpiece %} + + {% else %} + + {% endif %} + {{ workout.date|date:"Y-m-d" }} {{ workout.starttime|date:"H:i" }} {% if workout.user.user == user or user == team.manager %} - {% if workout.rankingpiece %} - [RANKING PIECE] - {% endif %} {% if workout.name != '' %} - {{ workout.name }} {{ workout.workouttype }} {{ workout.distance }}m {{ workout.duration |durationprint:"%H:%M:%S.%f" }} {{ workout.averagehr }} {{ workout.maxhr }} - Export - + + {{ workout.name }} + + + No Name + {{ workout.name }}No Name {{ workout.workouttype }} {{ workout.distance }}m {{ workout.duration |durationprint:"%H:%M:%S.%f" }} {{ workout.averagehr }} {{ workout.maxhr }} + Export + + {{ workout.user.user.first_name }} {{ workout.user.user.last_name }} + Flex + Delete +
{% else %} - - {{ workout.user.user.first_name }} {{ workout.user.user.last_name }} - +

No workouts found

{% endif %} - Flex - - Delete - - - - -{% endfor %} - - -{% else %} -

No workouts found

-{% endif %} -
- - -
- {% if team %} -
-
-

-   -

-
- {% endif %} -
- - - - {{ interactiveplot |safe }} - - - - {{ the_div |safe }} -
-
- {% if announcements %} -

What's New?

- {% for a in announcements %} -
-
- {{ a.created }}: - {{ a.announcement|urlize }} + + +
+ {% if team %} +
+
+

+   +

- {% endfor %} -

 

{% endif %} -
-
-

About

-

This site is a beta site, pioneering rowing data visualization and analysis. No warranties. The site's author is - Sander Roosendaal. A Masters rower. +

+ + - Read his blog -

-
- - + {{ interactiveplot |safe }} + + + + {{ the_div |safe }} +
+
+ {% if announcements %} +

What's New?

+ {% for a in announcements %} +
+
+ {{ a.created }}: + {{ a.announcement|urlize }} +
+
+ {% endfor %} +

 

+ {% endif %} +
+
+

About

+

This site is a beta site, pioneering rowing data visualization and analysis. No warranties. The site's author is + Sander Roosendaal. A Masters rower. + + Read his blog +

+
+ + +
-
{% if rankingonly and not team %} - - {% elif not team %} - - {% endif %} - -

 

+ + {% elif not team %} + + {% endif %} + +

 

{% if team %}
{% else %} - -{% endif %} -
- -
-
- -
-
+
+ {% endif %} +
+ +
+
+ +
+
@@ -248,5 +297,5 @@ {% endif %} {% endif %} - -{% endblock %} + + {% endblock %} diff --git a/rowers/urls.py b/rowers/urls.py index 59e86aa2..7c5b3679 100644 --- a/rowers/urls.py +++ b/rowers/urls.py @@ -212,6 +212,7 @@ urlpatterns = [ url(r'^graph/(?P\d+)/deleteconfirm$',views.graph_delete_confirm_view), url(r'^graph/(?P\d+)/delete$',views.graph_delete_view), url(r'^workout/(?P\d+)/get-thumbnails$',views.get_thumbnails), + url(r'^workout/(?P\d+)/toggle-ranking$',views.workout_toggle_ranking), url(r'^workout/(?P\d+)/get-testscript$',views.get_testscript), url(r'^workout/upload/team/$',views.team_workout_upload_view), url(r'^workout/upload/$',views.workout_upload_view,name='workout_upload_view'), diff --git a/rowers/utils.py b/rowers/utils.py index 5b87053a..26f74d3d 100644 --- a/rowers/utils.py +++ b/rowers/utils.py @@ -5,6 +5,7 @@ import colorsys from django.conf import settings import uuid +import datetime lbstoN = 4.44822 @@ -127,6 +128,22 @@ palettes = { 'yellow_red':trcolors(255,255,178,189,0,39) } +rankingdistances = [100,500,1000,2000,5000,6000,10000,21097,42195,100000] +rankingdurations = [] +rankingdurations.append(datetime.time(minute=1)) +rankingdurations.append(datetime.time(minute=4)) +rankingdurations.append(datetime.time(minute=30)) +rankingdurations.append(datetime.time(hour=1,minute=15)) +rankingdurations.append(datetime.time(hour=1)) + + +def is_ranking_piece(workout): + if workout.distance in rankingdistances: + return True + elif workout.duration in rankingdurations: + return True + + return False def range_to_color_hex(groupcols,palette='monochrome_blue'): diff --git a/rowers/views.py b/rowers/views.py index a19d7eeb..65b9bdcf 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -711,7 +711,7 @@ def splitstdata(lijst): from utils import ( geo_distance,serialize_list,deserialize_list,uniqify, str2bool,range_to_color_hex,absolute,myqueue,get_call, - calculate_age + calculate_age,rankingdistances,rankingdurations ) import datautils @@ -3297,20 +3297,10 @@ def rankings_view(request,theuser=0, enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59)) enddate = enddate+datetime.timedelta(days=1) - rankingdistances = [100,500,1000,2000,5000,6000,10000,21097,42195,100000] - rankingdurations = [] - rankingdurations.append(datetime.time(minute=1)) - rankingdurations.append(datetime.time(minute=4)) - rankingdurations.append(datetime.time(minute=30)) - rankingdurations.append(datetime.time(hour=1,minute=15)) - rankingdurations.append(datetime.time(hour=1)) - thedistances = [] theworkouts = [] thesecs = [] - - rankingdistances.sort() rankingdurations.sort() @@ -9302,6 +9292,35 @@ def workout_getc2workout_view(request,c2id): url = reverse(workout_c2import_view) return HttpResponseRedirect(url) +@login_required +def workout_toggle_ranking(request,id=0): + is_ajax = False + if request.is_ajax(): + is_ajax = True + + try: + # check if valid ID exists (workout exists) + row = Workout.objects.get(id=id) + except Workout.DoesNotExist: + raise Http404("Workout doesn't exist") + + if not checkworkoutuser(request.user,row): + message = "You are not allowed to change this workout" + messages.error(request,message) + + # we are still here - we own the workout + row.rankingpiece = not row.rankingpiece + row.save() + + if is_ajax: + return JSONResponse({'result':row.rankingpiece}) + else: + url = reverse(workouts_view) + response = HttpResponseRedirect(url) + + return response + + # This is the main view for processing uploaded files @login_required() def workout_upload_view(request, diff --git a/static/css/rowsandall.css b/static/css/rowsandall.css index 0362df15..8b649642 100644 --- a/static/css/rowsandall.css +++ b/static/css/rowsandall.css @@ -56,6 +56,19 @@ body { padding-bottom: 20px; } +.notyellow { + font-size: 1.2em; + height: auto; + padding: 0px; +} + +.yellow { + color: #cccc00; + font-size: 1.2em; + height: auto; + padding: 0px; +} + a { /* color: #fff; */ From 275124976d0e26e52c17c62d5bbf7c5df29e4e0a Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 4 Jan 2018 21:52:24 +0100 Subject: [PATCH 3/3] Basic ranking page now uses only workouts marked as ranking pieces --- rowers/dataprep.py | 5 +++- rowers/views.py | 68 ++++++++++++++++++++-------------------------- 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 6efa68d0..6fa013b4 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -56,7 +56,7 @@ import sys import utils import datautils -from utils import lbstoN,myqueue +from utils import lbstoN,myqueue,is_ranking_piece from timezonefinder import TimezoneFinder @@ -921,6 +921,9 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower', w.startdatetime = timezone.now() w.save() + if is_ranking_piece(w): + w.rankingpiece = True + w.save() if privacy == 'visible': ts = Team.objects.filter(rower=r) diff --git a/rowers/views.py b/rowers/views.py index 65b9bdcf..5d9f9b82 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -711,7 +711,8 @@ def splitstdata(lijst): from utils import ( geo_distance,serialize_list,deserialize_list,uniqify, str2bool,range_to_color_hex,absolute,myqueue,get_call, - calculate_age,rankingdistances,rankingdurations + calculate_age,rankingdistances,rankingdurations, + is_ranking_piece ) import datautils @@ -3175,7 +3176,7 @@ def addmanual_view(request): if id: w = Workout.objects.get(id=id) - w.rankingpiece = rankingpiece + w.rankingpiece = rankingpiece or is_ranking_piece(w) w.notes = notes w.save() messages.info(request,'New workout created') @@ -3306,10 +3307,13 @@ def rankings_view(request,theuser=0, for rankingdistance in rankingdistances: - workouts = Workout.objects.filter(user=r,distance=rankingdistance, - workouttype__in=['rower','dynamic','slides'], - startdatetime__gte=startdate, - startdatetime__lte=enddate).order_by('duration') + workouts = Workout.objects.filter( + user=r,distance=rankingdistance, + workouttype__in=['rower','dynamic','slides'], + rankingpiece=True, + startdatetime__gte=startdate, + startdatetime__lte=enddate + ).order_by('duration') if workouts: thedistances.append(rankingdistance) theworkouts.append(workouts[0]) @@ -3323,10 +3327,13 @@ def rankings_view(request,theuser=0, for rankingduration in rankingdurations: - workouts = Workout.objects.filter(user=r,duration=rankingduration, - workouttype='rower', - startdatetime__gte=startdate, - startdatetime__lte=enddate).order_by('-distance') + workouts = Workout.objects.filter( + user=r,duration=rankingduration, + workouttype='rower', + rankingpiece=True, + startdatetime__gte=startdate, + startdatetime__lte=enddate + ).order_by('-distance') if workouts: thedistances.append(workouts[0].distance) theworkouts.append(workouts[0]) @@ -3631,13 +3638,6 @@ def rankings_view2(request,theuser=0, enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59)) enddate = enddate+datetime.timedelta(days=1) - rankingdistances = [100,500,1000,2000,5000,6000,10000,21097,42195,100000] - rankingdurations = [] - rankingdurations.append(datetime.time(minute=1)) - rankingdurations.append(datetime.time(minute=4)) - rankingdurations.append(datetime.time(minute=30)) - rankingdurations.append(datetime.time(hour=1,minute=15)) - rankingdurations.append(datetime.time(hour=1)) thedistances = [] theworkouts = [] @@ -3650,10 +3650,12 @@ def rankings_view2(request,theuser=0, for rankingdistance in rankingdistances: - workouts = Workout.objects.filter(user=r,distance=rankingdistance, - workouttype__in=['rower','dynamic','slides'], - startdatetime__gte=startdate, - startdatetime__lte=enddate).order_by('duration') + workouts = Workout.objects.filter( + user=r,distance=rankingdistance, + workouttype__in=['rower','dynamic','slides'], + rankingpiece=True, + startdatetime__gte=startdate, + startdatetime__lte=enddate).order_by('duration') if workouts: thedistances.append(rankingdistance) theworkouts.append(workouts[0]) @@ -3667,10 +3669,12 @@ def rankings_view2(request,theuser=0, for rankingduration in rankingdurations: - workouts = Workout.objects.filter(user=r,duration=rankingduration, - workouttype='rower', - startdatetime__gte=startdate, - startdatetime__lte=enddate).order_by('-distance') + workouts = Workout.objects.filter( + user=r,duration=rankingduration, + workouttype='rower', + rankingpiece=True, + startdatetime__gte=startdate, + startdatetime__lte=enddate).order_by('-distance') if workouts: thedistances.append(workouts[0].distance) theworkouts.append(workouts[0]) @@ -3973,12 +3977,6 @@ def otwrankings_view(request,theuser=0, enddate = enddate+datetime.timedelta(days=1) - rankingdurations = [] - rankingdurations.append(datetime.time(minute=1)) - rankingdurations.append(datetime.time(minute=4)) - rankingdurations.append(datetime.time(minute=30)) - rankingdurations.append(datetime.time(hour=1)) - rankingdurations.append(datetime.time(hour=1,minute=15)) thedistances = [] theworkouts = [] @@ -4225,14 +4223,6 @@ def oterankings_view(request,theuser=0, enddate = enddate+datetime.timedelta(days=1) - rankingdurations = [] - rankingdurations.append(datetime.time(minute=1)) - rankingdurations.append(datetime.time(minute=4)) - rankingdurations.append(datetime.time(minute=30)) - rankingdurations.append(datetime.time(hour=1)) - rankingdurations.append(datetime.time(hour=1,minute=15)) - - rankingdistances = [100,500,1000,2000,5000,6000,10000,21097,42195,100000] thedistances = [] theworkouts = []