From ea87daf72657d5eefee231ab2f9d411bab9d2433 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Tue, 11 Oct 2022 06:44:00 +0200 Subject: [PATCH 1/2] works --- rowers/models.py | 2 ++ rowers/templates/instroke_interactive.html | 12 +++++++-- rowers/views/workoutviews.py | 30 ++++++++++++++++++++++ static/css/rowsandall2.css | 5 ++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/rowers/models.py b/rowers/models.py index 56af4950..a9475f73 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -4978,6 +4978,8 @@ class InStrokeAnalysis(models.Model): end_second = models.IntegerField(default=3600) spm_min = models.IntegerField(default=10) spm_max = models.IntegerField(default=45) + average_spm = models.FloatField(default=23) + average_boatspeed = models.FloatField(default=4.0) def __str__(self): s = 'In-Stroke Analysis {name} ({date})'.format(name = self.name, diff --git a/rowers/templates/instroke_interactive.html b/rowers/templates/instroke_interactive.html index 7eec7665..44e599a0 100644 --- a/rowers/templates/instroke_interactive.html +++ b/rowers/templates/instroke_interactive.html @@ -143,8 +143,16 @@ $( function() {

-

-

+
+ + + +

+ With the Save buttons, you can save your analysis for future use and to compare + multiple analyses to each other. You can find the saved analyses under the Analysis + tab (in-stroke analysis). +

+
  • diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 469a6d4f..8910930d 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -3082,6 +3082,24 @@ def instroke_chart_interactive(request, id=0, analysis=0, userid=0): messages.info(request,'In-Stroke Analysis saved') + if "_save_as_new" in request.POST: + instroke_analysis = InStrokeAnalysis( + workout = w, + metric = metric, + name = name, + date = timezone.now().date(), + notes = notes, + start_second = 60*activeminutesmin, + end_second = 60*activeminutesmax, + spm_min = spm_min, + spm_max = spm_max, + rower=w.user, + ) + + instroke_analysis.save() + messages.info(request,'In-Stroke Analysis saved') + + activesecondsmin = 60.*activeminutesmin activesecondsmax = 60.*activeminutesmax @@ -3112,6 +3130,18 @@ def instroke_chart_interactive(request, id=0, analysis=0, userid=0): intervalstats = rowdata.allstats() itime, idist, itype = rowdata.intervalstats_values() + + totaldist = 0 + totaltime = 0 + avg_speed = 0 + for i in range(len(idist)): + if itype[i] == 4: + totaldist += idist[i] + totaltime += itime[i] + + if totaltime > 0: + avg_speed = totaldist/totaltime + intervaldata = { 'itime': itime, 'idist': idist, diff --git a/static/css/rowsandall2.css b/static/css/rowsandall2.css index b58cf043..708a467f 100644 --- a/static/css/rowsandall2.css +++ b/static/css/rowsandall2.css @@ -377,6 +377,11 @@ th.rotate > div > span { margin-top: 50%; } +.buttoncontainer input { + float: left; + margin: 5px; +} + .divlines { display: block; overflow-x: hidden; From 7fc01984ed21c100840831415b928a2ae0fd1dbd Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Tue, 11 Oct 2022 06:57:41 +0200 Subject: [PATCH 2/2] cosmetical fixes --- rowers/templates/instroke_analysis.html | 8 +++++++- rowers/templatetags/rowerfilters.py | 10 +++++++++- rowers/views/workoutviews.py | 7 ++++++- static/css/rowsandall2.css | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/rowers/templates/instroke_analysis.html b/rowers/templates/instroke_analysis.html index c63273d3..d16e352c 100644 --- a/rowers/templates/instroke_analysis.html +++ b/rowers/templates/instroke_analysis.html @@ -51,7 +51,8 @@
    Workout
    - {{ analysis.workout }} + {{ analysis.workout.name }}
    + {{ analysis.workout.date }}, {{ analysis.workout.distance }}m
    Metric
    @@ -69,6 +70,11 @@ Time
    {{ analysis.start_second|secondstotimestring }} - {{ analysis.end_second|secondstotimestring }}
    +
    + Avg Pace
    + {{ analysis.average_boatspeed|velotopace }} +
    +
  • {% endfor %} diff --git a/rowers/templatetags/rowerfilters.py b/rowers/templatetags/rowerfilters.py index 5faae199..ba04a374 100644 --- a/rowers/templatetags/rowerfilters.py +++ b/rowers/templatetags/rowerfilters.py @@ -10,7 +10,7 @@ import math import datetime import re -from rowers.utils import calculate_age +from rowers.utils import calculate_age, to_pace from rowers.models import ( course_length, WorkoutComment, TrainingMacroCycle, TrainingMesoCycle, TrainingMicroCycle, @@ -491,6 +491,14 @@ def previousperiodstart(timeperiod): return newstartdate.strftime("%Y-%m-%d") +@register.filter +def velotopace(v): + if v > 0: + time500 = 500./v + return to_pace(time500) + + return "" + @register.filter def paceprint(d): diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 8910930d..9b4658de 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -3039,7 +3039,7 @@ def instroke_chart_interactive(request, id=0, analysis=0, userid=0): div = get_call() - + dosave = False if request.method == 'POST': form = InstrokeForm(request.POST,choices=instrokemetrics) if form.is_valid(): @@ -3079,6 +3079,7 @@ def instroke_chart_interactive(request, id=0, analysis=0, userid=0): instroke_analysis.rower=w.user instroke_analysis.save() + dosave = True messages.info(request,'In-Stroke Analysis saved') @@ -3097,6 +3098,7 @@ def instroke_chart_interactive(request, id=0, analysis=0, userid=0): ) instroke_analysis.save() + dosave = True messages.info(request,'In-Stroke Analysis saved') @@ -3141,6 +3143,9 @@ def instroke_chart_interactive(request, id=0, analysis=0, userid=0): if totaltime > 0: avg_speed = totaldist/totaltime + if dosave: + instroke_analysis.average_boatspeed = avg_speed + instroke_analysis.save() intervaldata = { 'itime': itime, diff --git a/static/css/rowsandall2.css b/static/css/rowsandall2.css index 708a467f..11026c9f 100644 --- a/static/css/rowsandall2.css +++ b/static/css/rowsandall2.css @@ -402,7 +402,7 @@ th.rotate > div > span { .analysiscontainer { display: grid; - grid-template-columns: 50px repeat(auto-fit, minmax(calc((100% - 100px)/7), 1fr)); + grid-template-columns: 50px repeat(auto-fit, minmax(calc((100% - 100px)/8), 1fr)); /* grid-template-columns: 50px repeat(auto-fit, minmax(100px, 1fr)) 50px; ????*/ padding: 5px; margin: 0px;