Private
Public Access
1
0

plans dedicated to rowers if possible

This commit is contained in:
Sander Roosendaal
2021-05-03 15:32:50 +02:00
parent f7a585adb9
commit 04cfc2d915
3 changed files with 51 additions and 20 deletions

View File

@@ -1931,6 +1931,25 @@ description: ""
self.assertEqual(self.ps_trimp.approximate_rscore,72)
@patch('rowers.garmin_stuff.requests.post', side_effect=mocked_requests)
@patch('rowers.utils.requests.post', side_effect=mocked_requests)
@patch('rowers.garmin_stuff.OAuth1Session', side_effect=MockOAuth1Session)
def test_plannedsession_steps_distance(self,mockpost,mock_post,MockOAuth1Session):
self.ps_trimp.interval_string = '10km'
self.ps_trimp.save()
self.assertEqual(self.ps_trimp.approximate_rscore,52)
@patch('rowers.garmin_stuff.requests.post', side_effect=mocked_requests)
@patch('rowers.utils.requests.post', side_effect=mocked_requests)
@patch('rowers.garmin_stuff.OAuth1Session', side_effect=MockOAuth1Session)
def test_plannedsession_steps_time(self,mockpost,mock_post,MockOAuth1Session):
self.ps_trimp.interval_string = '60min'
self.ps_trimp.save()
self.assertEqual(self.ps_trimp.approximate_rscore,60)
def test_plannedsessions_dateform_view(self):
login = self.c.login(username=self.u.username, password=self.password)
self.assertTrue(login)

View File

@@ -599,13 +599,11 @@ def step_to_time_dist(step,avgspeed = 3.2,ftp=200,ftspm=25,ftv=3.7):
except KeyError: # pragma: no cover
targettype = 0
if durationtype == 'Time':
value = step['durationValue']
seconds = value/1000.
distance = avgspeed*seconds
rscore = 60.*seconds/3600.
if targettype == 'Speed':
value = step.get('targetValue',0)
@@ -663,6 +661,7 @@ def step_to_time_dist(step,avgspeed = 3.2,ftp=200,ftspm=25,ftv=3.7):
value = step['durationValue']
distance = value/100.
seconds = distance/avgspeed
rscore = 60*seconds/3600.
if targettype == 'Speed':
value = step.get('targetValue',0)
@@ -779,13 +778,19 @@ def ps_dict_order_dict(d,short=False):
return sdict2
def ps_dict_order(d,short=False):
def ps_dict_order(d,short=False,rower=None):
sdict = collections.OrderedDict({})
steps = d['steps']
ftp = 200
if rower is not None:
ftp = rower.ftp
# ftv = rower.ftv
# ftspm = rower.ftspm
for step in steps:
sstring, type, stepID, repeatID, repeatValue = step_to_string(step,short=short)
seconds, meters,rscore = step_to_time_dist(step)
seconds, meters,rscore = step_to_time_dist(step,ftp=ftp)
sdict[stepID] = {
'string':sstring,

View File

@@ -1477,22 +1477,29 @@ def plannedsessions_view(request,
sessioncolor[ps.id] = cratiocolors[status]
ws = Workout.objects.filter(user=r,plannedsession=ps)
completiondate[ps.id] = cdate
if ps.sessionmode == 'distance':
totals['planneddistance'] += ps.sessionvalue
if ps.steps:
sdict, totalmeters, totalseconds, totalrscore = ps_dict_order(ps.steps,rower=r)
totals['planneddistance'] += int(totalmeters)
totals['plannedtime'] += int(totalseconds)/60.
totals['plannedrscore'] += int(totalrscore)
totals['plannedtrimp'] += int(totalrscore)*2
else:
totals['planneddistance'] += ps.approximate_distance
if ps.sessionmode == 'time':
totals['plannedtime'] += ps.sessionvalue
else:
totals['plannedtime'] += ps.approximate_duration
if ps.sessionmode == 'rScore': # pragma: no cover
totals['plannedrscore'] += ps.sessionvalue
else:
totals['plannedrscore'] += ps.approximate_rscore
if ps.sessionmode == 'TRIMP': # pragma: no cover
totals['plannedtrimp'] += ps.sessionvalue
else:
totals['plannedtrimp'] += ps.approximate_rscore*2
if ps.sessionmode == 'distance':
totals['planneddistance'] += ps.sessionvalue
else:
totals['planneddistance'] += ps.approximate_distance
if ps.sessionmode == 'time':
totals['plannedtime'] += ps.sessionvalue
else:
totals['plannedtime'] += ps.approximate_duration
if ps.sessionmode == 'rScore': # pragma: no cover
totals['plannedrscore'] += ps.sessionvalue
else:
totals['plannedrscore'] += ps.approximate_rscore
if ps.sessionmode == 'TRIMP': # pragma: no cover
totals['plannedtrimp'] += ps.sessionvalue
else:
totals['plannedtrimp'] += ps.approximate_rscore*2
totals['time'] = int(totals['time']/60.)
totals['actualtime'] = int(totals['actualtime']/60.)