Private
Public Access
1
0

Merge branch 'feature/usegps' into develop

This commit is contained in:
Sander Roosendaal
2020-01-07 22:15:43 +01:00
7 changed files with 93 additions and 26 deletions
+22 -12
View File
@@ -1081,7 +1081,8 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
makeprivate=False,
oarlength=2.89, inboard=0.88,
forceunit='lbs',
consistencychecks=False):
consistencychecks=False,
impeller=False):
message = None
powerperc = 100 * np.array([r.pw_ut2,
@@ -1289,7 +1290,8 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
startdatetime=workoutstartdatetime,
inboard=inboard, oarlength=oarlength,
timezone=timezone_str,
privacy=privacy)
privacy=privacy,
impeller=impeller)
try:
w.save()
except ValidationError:
@@ -1421,24 +1423,30 @@ def handle_nonpainsled(f2, fileformat, summary=''):
oarlength = 2.89
inboard = 0.88
hasrecognized = False
impeller = False
row,hasrecognized,summary,fileformat = parsenonpainsled(fileformat,f2,summary)
# Handle c2log
if (fileformat == 'c2log' or fileformat == 'rowprolog'):
return (0,'',0,0,'')
return (0,'',0,0,'',impeller)
if not hasrecognized:
return (0,'',0,0,'')
return (0,'',0,0,'',impeller)
f_to_be_deleted = f2
# should delete file
f2 = f2[:-4] + 'o.csv'
try:
row2 = rrdata(df = row.df)
row2.write_csv(f2, gzip=True)
except:
return (0,'',0,0,'')
row2 = rrdata(df = row.df)
if 'speedcoach2' in fileformat:
# impeller consistency
impellerdata, consistent, ratio = row.impellerconsistent(threshold=0.3)
if impellerdata and consistent:
impeller = True
if impellerdata and not consistent:
row2.use_gpsdata()
row2.write_csv(f2, gzip=True)
# os.remove(f2)
try:
@@ -1449,7 +1457,7 @@ def handle_nonpainsled(f2, fileformat, summary=''):
except:
pass
return (f2, summary, oarlength, inboard, fileformat)
return (f2, summary, oarlength, inboard, fileformat, impeller)
# Create new workout from file and store it in the database
# This routine should be used everywhere in views.py and mailprocessing.py
@@ -1476,6 +1484,7 @@ def new_workout_from_file(r, f2,
inboard = 0.88
if len(fileformat) == 3 and fileformat[0] == 'zip':
f_to_be_deleted = f2
impeller = False
workoutsbox = Mailbox.objects.filter(name='workouts')[0]
msg = Message(mailbox=workoutsbox,
from_header=r.user.email,
@@ -1543,7 +1552,7 @@ def new_workout_from_file(r, f2,
# handle non-Painsled by converting it to painsled compatible CSV
if (fileformat != 'csv'):
f2, summary, oarlength, inboard, fileformat = handle_nonpainsled(
f2, summary, oarlength, inboard, fileformat, impeller = handle_nonpainsled(
f2,
fileformat,
summary=summary
@@ -1571,7 +1580,8 @@ def new_workout_from_file(r, f2,
summary=summary,
inboard=inboard, oarlength=oarlength,
title=title,
forceunit='N'
forceunit='N',
impeller=impeller,
)
return (id, message, f2)
+1
View File
@@ -2734,6 +2734,7 @@ class Workout(models.Model):
choices=privacychoices)
rankingpiece = models.BooleanField(default=False,verbose_name='Ranking Piece')
duplicate = models.BooleanField(default=False,verbose_name='Duplicate Workout')
impeller = models.BooleanField(default=False,verbose_name='Impeller')
def save(self, *args, **kwargs):
user = self.user
+16 -1
View File
@@ -287,10 +287,25 @@
<i class="fas fa-calculator-alt fa-fw"></i>&nbsp;OTW Power
</a>
</li>
{% if 'speedcoach2' in workout.workoutsource %}
<li id="advanced-usegps">
<a href="/rowers/workout/{{ workout.id|encode }}/otwusegps/">
<i class="fas fa-satellite"></i>
{% if workout.impeller %}&nbsp;{% else %}&bull;&nbsp;{% endif %}Use GPS data
</a>
</li>
<li id="advanced-useimpeller">
<a href="/rowers/workout/{{ workout.id|encode }}/otwuseimpeller/">
<i class="fas fa-wind-turbine fa-rotate-180"></i>
{% if workout.impeller %}&bull;&nbsp;{% else %}&nbsp;{% endif %}Use Impeller data
</a>
</li>
{% endif %}
{% endif %}
<li id="advanced-instroke">
<a href="/rowers/workout/{{ workout.id|encode }}/instroke/">
<i class="fas fa-search-plus fa-fw"></i>&nbsp;In-Stroke Metrics
<i class="fas fa-search-plus fa-fw"></i>
In-Stroke Metrics
</a>
</li>
<li id="advanced-recalcsummary">
+4
View File
@@ -283,6 +283,10 @@ urlpatterns = [
re_path(r'^graph/(?P<pk>\d+)/delete/$',views.GraphDelete.as_view(),name='graph_delete'),
re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/get-thumbnails/$',views.get_thumbnails,
name='get_thumbnails'),
re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/otwuseimpeller/$',views.otw_use_impeller,
name='otw_use_impeller'),
re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/otwusegps/$',views.otw_use_gps,
name='otw_use_gps'),
re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/toggle-ranking/$',views.workout_toggle_ranking,
name='workout_toggle_ranking'),
re_path(r'^workout/(?P<id>\b[0-9A-Fa-f]+\b)/get-testscript/$',views.get_testscript,
+1 -1
View File
@@ -4453,7 +4453,7 @@ def alert_report_view(request,id=0,userid=0,nperiod=0):
raise Http404("This alert doesn't exist")
if alert.manager != request.user:
if not checkalertowner(alert,request.user):
raise PermissionDenied('You are not allowed to edit this Alert')
stats = alert_get_stats(alert,nperiod=nperiod)
+48 -12
View File
@@ -456,18 +456,54 @@ def workout_forcecurve_view(request,id=0,workstrokesonly=False):
'teams':get_my_teams(request.user),
})
# Test asynchronous tasking and messaging
#@login_required()
#def workout_test_task_view(request,id=0):
# row = Workout.objects.get(id=id)
# res = myqueue(queuehigh,addcomment2,request.user.id,row.id)#
#
#
# url = reverse('workout_edit_view',
# kwargs = {
# 'id':int(id),
# })
# return HttpResponseRedirect(url)
# Switch from GPS to Impeller (only for SpeedCoach 2, if impeller data)
@login_required
def otw_use_impeller(request,id=0):
w = get_workout(id)
if (checkworkoutuser(request.user,w)==False):
raise PermissionDenied("Access denied")
row = rdata(w.csvfilename)
success = row.use_impellerdata()
if success:
row.write_csv(w.csvfilename)
dataprep.update_strokedata(w.id,row.df)
w.impeller = True
w.save()
messages.info(request,'The distance and speed data are now based on Impeller data')
else:
messages.error(request,'No impeller data found')
url = reverse('workout_edit_view',kwargs={'id':encoder.encode_hex(w.id)})
return HttpResponseRedirect(url)
# Switch from Impeller to GPS (only for SpeedCoach 2, if impeller data)
@login_required
def otw_use_gps(request,id=0):
w = get_workout(id)
if (checkworkoutuser(request.user,w)==False):
raise PermissionDenied("Access denied")
row = rdata(w.csvfilename)
success = row.use_gpsdata()
if success:
row.write_csv(w.csvfilename)
dataprep.update_strokedata(w.id,row.df)
w.impeller = False
w.save()
messages.info(request,'The distance and speed data are now based on GPS data')
else:
messages.error(request,'No GPS data found')
url = reverse('workout_edit_view',kwargs={'id':encoder.encode_hex(w.id)})
return HttpResponseRedirect(url)
# Show Stroke power histogram for a workout
@login_required()
+1
View File
@@ -43,6 +43,7 @@
<link rel="stylesheet" href="/static/css/resetnew.css" />
<link rel="stylesheet" href="/static/fontawesome/css/fontawesome.min.css">
<link rel="stylesheet" href="/static/fontawesome/css/all.min.css">
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.12.0/css/all.css" integrity="sha384-ekOryaXPbeCpWQNxMwSWVvQ0+1VrStoPJq54shlYhR8HzQgig1v5fas6YgOqLoKz" crossorigin="anonymous">
<link rel="stylesheet" href="/static/css/styles2.min.css">
<link rel="stylesheet" href="/static/css/text2.css" />
<link rel="stylesheet" href="/static/css/rowsandall2.min.css" />