diff --git a/.gitignore b/.gitignore index b3b8c056..53885254 100644 --- a/.gitignore +++ b/.gitignore @@ -26,7 +26,7 @@ conftest.py # temporary test files /rowers/tests/testdata/temp -/rowers/tests/testdata/testdata.csv.gz +rowers/tests/testdata/testdata.csv.gz /rowers/tests/testdata/testdata.tcx diff --git a/c6c032ca-da24-42cf-b61f-02816b7e2ccd.tcx b/c6c032ca-da24-42cf-b61f-02816b7e2ccd.tcx new file mode 100644 index 00000000..98408a5a --- /dev/null +++ b/c6c032ca-da24-42cf-b61f-02816b7e2ccd.tcx @@ -0,0 +1,2523 @@ + + + + + 2016-05-20T13:41:26.962390+00:00 + + 537 + 2000 + 1 + + 148 + + + 156 + + Active + 21 + Manual + + + + 5.4 + + 127 + + 0 + + + 19 + + + + + + 13.1 + + 127 + + 19 + + + 26 + + + + + + 21.0 + + 128 + + 20 + + + 45 + + + + + + 30.3 + + 129 + + 20 + + + 64 + + + + + + 39.0 + + 130 + + 20 + + + 74 + + + + + + 48.2 + + 131 + + 21 + + + 80 + + + + + + 57.6 + + 131 + + 20 + + + 83 + + + + + + 66.4 + + 132 + + 20 + + + 87 + + + + + + 75.5 + + 132 + + 21 + + + 86 + + + + + + 85.1 + + 132 + + 20 + + + 88 + + + + + + 95.0 + + 132 + + 21 + + + 100 + + + + + + 105.0 + + 133 + + 22 + + + 127 + + + + + + 115.3 + + 134 + + 21 + + + 135 + + + + + + 125.8 + + 135 + + 21 + + + 139 + + + + + + 136.6 + + 136 + + 21 + + + 146 + + + + + + 147.2 + + 137 + + 22 + + + 150 + + + + + + 157.6 + + 139 + + 22 + + + 152 + + + + + + 167.8 + + 140 + + 21 + + + 146 + + + + + + 178.5 + + 140 + + 22 + + + 150 + + + + + + 188.5 + + 141 + + 21 + + + 155 + + + + + + 199.3 + + 141 + + 21 + + + 148 + + + + + + 209.4 + + 142 + + 22 + + + 151 + + + + + + 219.4 + + 142 + + 22 + + + 151 + + + + + + 230.2 + + 143 + + 22 + + + 148 + + + + + + 240.2 + + 144 + + 22 + + + 147 + + + + + + 250.1 + + 145 + + 23 + + + 150 + + + + + + 259.6 + + 145 + + 23 + + + 152 + + + + + + 270.3 + + 145 + + 23 + + + 152 + + + + + + 280.6 + + 145 + + 22 + + + 149 + + + + + + 290.7 + + 144 + + 22 + + + 150 + + + + + + 300.8 + + 145 + + 23 + + + 149 + + + + + + 311.1 + + 145 + + 22 + + + 152 + + + + + + 321.2 + + 145 + + 22 + + + 157 + + + + + + 331.9 + + 145 + + 21 + + + 150 + + + + + + 342.0 + + 146 + + 22 + + + 151 + + + + + + 352.4 + + 146 + + 22 + + + 151 + + + + + + 363.0 + + 146 + + 22 + + + 153 + + + + + + 373.4 + + 147 + + 22 + + + 152 + + + + + + 383.9 + + 147 + + 22 + + + 153 + + + + + + 394.6 + + 147 + + 22 + + + 152 + + + + + + 405.0 + + 147 + + 21 + + + 149 + + + + + + 415.3 + + 148 + + 22 + + + 152 + + + + + + 426.0 + + 148 + + 22 + + + 151 + + + + + + 436.5 + + 148 + + 21 + + + 149 + + + + + + 446.9 + + 148 + + 22 + + + 149 + + + + + + 456.9 + + 149 + + 22 + + + 156 + + + + + + 467.6 + + 149 + + 22 + + + 155 + + + + + + 478.5 + + 150 + + 22 + + + 156 + + + + + + 489.0 + + 150 + + 21 + + + 154 + + + + + + 499.1 + + 150 + + 21 + + + 148 + + + + + + 510.0 + + 150 + + 22 + + + 151 + + + + + + 519.9 + + 149 + + 22 + + + 153 + + + + + + 530.6 + + 149 + + 22 + + + 151 + + + + + + 540.8 + + 149 + + 22 + + + 148 + + + + + + 550.8 + + 148 + + 22 + + + 149 + + + + + + 560.8 + + 148 + + 22 + + + 144 + + + + + + 571.0 + + 147 + + 22 + + + 149 + + + + + + 580.7 + + 147 + + 22 + + + 150 + + + + + + 591.2 + + 147 + + 22 + + + 151 + + + + + + 601.4 + + 147 + + 22 + + + 150 + + + + + + 611.4 + + 147 + + 23 + + + 153 + + + + + + 621.8 + + 147 + + 23 + + + 151 + + + + + + 632.1 + + 147 + + 22 + + + 155 + + + + + + 642.3 + + 147 + + 22 + + + 154 + + + + + + 652.0 + + 148 + + 23 + + + 157 + + + + + + 662.7 + + 148 + + 23 + + + 162 + + + + + + 673.1 + + 148 + + 23 + + + 163 + + + + + + 683.6 + + 149 + + 22 + + + 163 + + + + + + 693.8 + + 149 + + 22 + + + 162 + + + + + + 703.8 + + 149 + + 22 + + + 164 + + + + + + 714.7 + + 150 + + 23 + + + 162 + + + + + + 724.9 + + 150 + + 22 + + + 162 + + + + + + 735.2 + + 151 + + 23 + + + 159 + + + + + + 745.4 + + 151 + + 22 + + + 158 + + + + + + 756.0 + + 151 + + 23 + + + 164 + + + + + + 766.3 + + 150 + + 22 + + + 163 + + + + + + 776.5 + + 150 + + 22 + + + 161 + + + + + + 786.9 + + 150 + + 23 + + + 163 + + + + + + 797.2 + + 150 + + 22 + + + 165 + + + + + + 807.8 + + 150 + + 23 + + + 166 + + + + + + 818.2 + + 150 + + 23 + + + 166 + + + + + + 828.4 + + 150 + + 22 + + + 168 + + + + + + 839.2 + + 150 + + 23 + + + 169 + + + + + + 849.6 + + 151 + + 23 + + + 166 + + + + + + 860.1 + + 151 + + 22 + + + 172 + + + + + + 870.3 + + 152 + + 22 + + + 172 + + + + + + 881.1 + + 152 + + 22 + + + 169 + + + + + + 891.7 + + 152 + + 23 + + + 167 + + + + + + 902.1 + + 152 + + 22 + + + 164 + + + + + + 913.1 + + 152 + + 22 + + + 161 + + + + + + 923.9 + + 153 + + 22 + + + 158 + + + + + + 934.6 + + 154 + + 21 + + + 158 + + + + + + 945.4 + + 154 + + 21 + + + 154 + + + + + + 956.0 + + 155 + + 21 + + + 155 + + + + + + 966.7 + + 155 + + 21 + + + 152 + + + + + + 977.4 + + 156 + + 21 + + + 150 + + + + + + 988.1 + + 156 + + 21 + + + 157 + + + + + + 998.8 + + 156 + + 21 + + + 155 + + + + + + 1009.6 + + 156 + + 21 + + + 151 + + + + + + 1020.6 + + 156 + + 21 + + + 147 + + + + + + 1031.5 + + 156 + + 20 + + + 145 + + + + + + 1042.5 + + 156 + + 21 + + + 144 + + + + + + 1053.3 + + 155 + + 20 + + + 145 + + + + + + 1064.1 + + 155 + + 21 + + + 147 + + + + + + 1075.3 + + 155 + + 20 + + + 142 + + + + + + 1086.1 + + 155 + + 20 + + + 136 + + + + + + 1097.5 + + 155 + + 21 + + + 141 + + + + + + 1108.5 + + 155 + + 20 + + + 146 + + + + + + 1119.2 + + 155 + + 20 + + + 143 + + + + + + 1130.6 + + 155 + + 20 + + + 143 + + + + + + 1141.3 + + 155 + + 20 + + + 143 + + + + + + 1152.4 + + 155 + + 21 + + + 142 + + + + + + 1163.3 + + 155 + + 20 + + + 138 + + + + + + 1173.8 + + 154 + + 20 + + + 141 + + + + + + 1184.8 + + 154 + + 21 + + + 146 + + + + + + 1195.8 + + 153 + + 21 + + + 146 + + + + + + 1206.6 + + 152 + + 21 + + + 141 + + + + + + 1217.3 + + 153 + + 21 + + + 141 + + + + + + 1227.8 + + 152 + + 21 + + + 140 + + + + + + 1238.7 + + 152 + + 21 + + + 143 + + + + + + 1249.5 + + 151 + + 21 + + + 149 + + + + + + 1260.1 + + 151 + + 20 + + + 141 + + + + + + 1270.9 + + 151 + + 21 + + + 141 + + + + + + 1281.8 + + 150 + + 21 + + + 145 + + + + + + 1292.7 + + 151 + + 20 + + + 142 + + + + + + 1303.4 + + 151 + + 20 + + + 141 + + + + + + 1314.3 + + 151 + + 21 + + + 141 + + + + + + 1325.2 + + 151 + + 21 + + + 146 + + + + + + 1336.1 + + 152 + + 20 + + + 143 + + + + + + 1346.9 + + 152 + + 21 + + + 144 + + + + + + 1357.4 + + 152 + + 20 + + + 141 + + + + + + 1368.1 + + 152 + + 21 + + + 138 + + + + + + 1379.0 + + 152 + + 20 + + + 142 + + + + + + 1389.5 + + 153 + + 21 + + + 145 + + + + + + 1399.9 + + 152 + + 21 + + + 138 + + + + + + 1410.7 + + 152 + + 20 + + + 139 + + + + + + 1422.0 + + 152 + + 20 + + + 139 + + + + + + 1432.8 + + 151 + + 20 + + + 141 + + + + + + 1443.6 + + 151 + + 21 + + + 146 + + + + + + 1454.4 + + 152 + + 20 + + + 143 + + + + + + 1465.1 + + 151 + + 21 + + + 143 + + + + + + 1475.9 + + 152 + + 21 + + + 145 + + + + + + 1486.6 + + 152 + + 21 + + + 148 + + + + + + 1497.4 + + 153 + + 21 + + + 143 + + + + + + 1508.2 + + 153 + + 20 + + + 140 + + + + + + 1519.2 + + 154 + + 20 + + + 144 + + + + + + 1530.0 + + 154 + + 21 + + + 143 + + + + + + 1540.9 + + 153 + + 20 + + + 141 + + + + + + 1551.3 + + 153 + + 21 + + + 143 + + + + + + 1562.6 + + 153 + + 21 + + + 146 + + + + + + 1573.3 + + 153 + + 20 + + + 141 + + + + + + 1584.2 + + 152 + + 20 + + + 139 + + + + + + 1594.6 + + 152 + + 21 + + + 145 + + + + + + 1606.0 + + 152 + + 21 + + + 143 + + + + + + 1616.2 + + 152 + + 20 + + + 138 + + + + + + 1627.4 + + 152 + + 21 + + + 140 + + + + + + 1638.0 + + 152 + + 21 + + + 144 + + + + + + 1649.2 + + 151 + + 20 + + + 143 + + + + + + 1660.2 + + 152 + + 20 + + + 143 + + + + + + 1670.8 + + 151 + + 20 + + + 142 + + + + + + 1681.4 + + 151 + + 21 + + + 140 + + + + + + 1692.1 + + 151 + + 21 + + + 140 + + + + + + 1702.5 + + 150 + + 21 + + + 141 + + + + + + 1713.7 + + 150 + + 21 + + + 144 + + + + + + 1724.4 + + 150 + + 21 + + + 146 + + + + + + 1735.1 + + 150 + + 20 + + + 141 + + + + + + 1745.6 + + 150 + + 21 + + + 140 + + + + + + 1756.3 + + 150 + + 21 + + + 141 + + + + + + 1766.2 + + 151 + + 20 + + + 142 + + + + + + 1777.1 + + 150 + + 22 + + + 138 + + + + + + 1787.5 + + 150 + + 21 + + + 138 + + + + + + 1797.7 + + 150 + + 22 + + + 140 + + + + + + 1808.4 + + 150 + + 21 + + + 140 + + + + + + 1818.4 + + 149 + + 21 + + + 138 + + + + + + 1828.9 + + 149 + + 22 + + + 146 + + + + + + 1839.9 + + 149 + + 21 + + + 142 + + + + + + 1850.5 + + 148 + + 21 + + + 142 + + + + + + 1861.2 + + 148 + + 21 + + + 145 + + + + + + 1871.9 + + 147 + + 21 + + + 143 + + + + + + 1882.6 + + 147 + + 20 + + + 139 + + + + + + 1893.3 + + 148 + + 20 + + + 140 + + + + + + 1904.3 + + 149 + + 21 + + + 144 + + + + + + 1915.4 + + 149 + + 20 + + + 148 + + + + + + 1926.2 + + 150 + + 20 + + + 139 + + + + + + 1937.3 + + 151 + + 20 + + + 140 + + + + + + 1947.8 + + 152 + + 20 + + + 144 + + + + + + 1959.1 + + 152 + + 20 + + + 142 + + + + + + 1969.8 + + 153 + + 20 + + + 140 + + + + + + 1980.6 + + 153 + + 21 + + + 143 + + + + + + 1991.4 + + 153 + + 21 + + + 143 + + + + + + 2000.0 + + 154 + + 21 + + + 147 + + + + + + <Element 'Notes' at 0x15038e80> + + + + rowsandall.com/rowingdata + + + rowingdata + + + 0 + 75 + + Release + + EN + 000-00000-00 + + diff --git a/rowers/plannedsessions.py b/rowers/plannedsessions.py index 87e452ea..06e7c5bc 100644 --- a/rowers/plannedsessions.py +++ b/rowers/plannedsessions.py @@ -335,7 +335,7 @@ def is_session_complete_ws(ws,ps): completiondate = w.date try: - ratio = score/float(value) + ratio = score/float(int(value)) except ZeroDivisionError: ratio = 0 @@ -444,10 +444,6 @@ def is_session_complete(r,ps): ws = Workout.objects.filter(user=r,plannedsession=ps) - print len(ws),'aap' - - print Workout.objects.all() - return is_session_complete_ws(ws,ps) diff --git a/rowers/tests/test_plans.py b/rowers/tests/test_plans.py index 532ed359..d75f848c 100644 --- a/rowers/tests/test_plans.py +++ b/rowers/tests/test_plans.py @@ -174,6 +174,7 @@ class SessionLinkTest(TestCase): self.password = faker.word() self.u.set_password(self.password) self.u.save() + self.pss = [] for w in self.user_workouts: startdatetime = w.startdatetime @@ -194,6 +195,9 @@ class SessionLinkTest(TestCase): ps.save() + + self.pss.append(ps) + result = plannedsessions.add_rower_session(self.r,ps) @@ -365,22 +369,67 @@ class SessionCompleteTest(TestCase): enddate = (startdatetime+datetime.timedelta(days=1)).date() preferreddate = startdatetime.date() - self.ps1 = SessionFactory( + self.ps_rscore = SessionFactory( startdate=startdate,enddate=enddate, sessiontype='session', sessionmode = 'rScore', criterium = 'none', - sessionvalue = 60, + sessionvalue = 69, sessionunit='None', preferreddate=preferreddate, manager=self.u, ) - self.ps1.save() - result = plannedsessions.add_rower_session(self.r,self.ps1) + self.ps_rscore.save() + added = plannedsessions.add_rower_session(self.r,self.ps_rscore) + + self.ps_dist = SessionFactory( + startdate=startdate,enddate=enddate, + sessiontype='session', + sessionmode = 'distance', + criterium = 'none', + sessionvalue = result['totaldist'], + sessionunit='m', + preferreddate=preferreddate, + manager=self.u, + ) + self.ps_dist.save() + added = plannedsessions.add_rower_session(self.r,self.ps_dist) + + self.ps_time = SessionFactory( + startdate=startdate,enddate=enddate, + sessiontype='session', + sessionmode = 'time', + criterium = 'none', + sessionvalue = 38, + sessionunit='min', + preferreddate=preferreddate, + manager=self.u, + ) + + + self.ps_time.save() + added = plannedsessions.add_rower_session(self.r,self.ps_time) + + self.ps_trimp = SessionFactory( + startdate=startdate,enddate=enddate, + sessiontype='session', + sessionmode = 'TRIMP', + criterium = 'none', + sessionvalue = 77, + sessionunit='none', + preferreddate=preferreddate, + manager=self.u, + ) + + + self.ps_trimp.save() + added = plannedsessions.add_rower_session(self.r,self.ps_trimp) + + def tearDown(self): try: os.remove(self.w1.csvfilename) @@ -390,11 +439,552 @@ class SessionCompleteTest(TestCase): def test_session1_complete(self): result = plannedsessions.add_workouts_plannedsession( - [self.w1],self.ps1,self.r + [self.w1],self.ps_rscore,self.r ) ratio,verdict,completiondate = plannedsessions.is_session_complete( - self.r,self.ps1 + self.r,self.ps_rscore ) self.assertEqual(verdict,'on target') + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_dist,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_dist + ) + + self.assertEqual(verdict,'on target') + + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_time,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_time + ) + + self.assertEqual(verdict,'on target') + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_trimp,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_trimp + ) + + self.assertEqual(verdict,'on target') + + + + def test_session1_exact_complete(self): + self.ps_rscore.criterium = 'exact' + self.ps_rscore.save() + + self.ps_dist.criterium = 'exact' + self.ps_dist.save() + + self.ps_time.criterium = 'exact' + self.ps_time.save() + + self.ps_trimp.criterium = 'exact' + self.ps_trimp.save() + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_rscore,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_rscore + ) + + self.assertEqual(verdict,'on target') + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_dist,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_dist + ) + + self.assertEqual(verdict,'on target') + + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_time,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_time + ) + + self.assertEqual(verdict,'partial') + + result = plannedsessions.remove_workout_plannedsession(self.w1,self.ps_time) + + self.assertEqual(result,1) + + result = plannedsessions.remove_workout_plannedsession(self.w1,self.ps_time) + + self.assertEqual(result,0) + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_trimp,self.r + ) + + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_trimp + ) + + self.assertEqual(verdict,'on target') + + + login = self.c.login(username=self.u.username, password=self.password) + self.assertTrue(login) + + url = '/rowers/sessions/{id}/'.format(id=self.ps_trimp.id) + + response = self.c.get(url) + self.assertEqual(response.status_code,200) + + url = '/rowers/sessions/' + response = self.c.get(url) + self.assertEqual(response.status_code,200) + + +class ChallengeCompleteTest(TestCase): + def setUp(self): + self.u = UserFactory() + + self.r = Rower.objects.create(user=self.u, + birthdate=faker.profile()['birthdate'], + gdproptin=True, + gdproptindate=timezone.now(), + rowerplan='coach') + + self.c = Client() + + # workout 1 - 2019-01-13, rScore 69 + result = get_random_file(filename='rowers/tests/testdata/2019-01-13_session.csv',name='sprintervals') + + + self.factory = RequestFactory() + self.password = faker.word() + self.u.set_password(self.password) + self.u.save() + + self.w1 = Workout.objects.create( + name='sprintervals', + notes=faker.text(), + startdatetime = result['startdatetime'], + starttime = result['starttime'], + workouttype='rower', + date=result['date'], + duration=result['duration'], + distance=result['totaldist'], + csvfilename=result['filename'], + trimp = 77, + rscore = 69, + hrtss = 43, + normp = 236, + user=self.r, + ) + + # self.w1.save() + + startdatetime = self.w1.startdatetime + + startdate = (startdatetime-datetime.timedelta(days=1)).date() + enddate = (startdatetime+datetime.timedelta(days=1)).date() + preferreddate = startdatetime.date() + + self.ps_rscore = SessionFactory( + startdate=startdate,enddate=enddate, + sessiontype='challenge', + sessionmode = 'rScore', + criterium = 'none', + sessionvalue = 69, + sessionunit='None', + preferreddate=preferreddate, + manager=self.u, + ) + + + self.ps_rscore.save() + added = plannedsessions.add_rower_session(self.r,self.ps_rscore) + + self.ps_dist = SessionFactory( + startdate=startdate,enddate=enddate, + sessiontype='challenge', + sessionmode = 'distance', + criterium = 'none', + sessionvalue = result['totaldist'], + sessionunit='m', + preferreddate=preferreddate, + manager=self.u, + ) + + + self.ps_dist.save() + added = plannedsessions.add_rower_session(self.r,self.ps_dist) + + self.ps_time = SessionFactory( + startdate=startdate,enddate=enddate, + sessiontype='challenge', + sessionmode = 'time', + criterium = 'none', + sessionvalue = 38, + sessionunit='min', + preferreddate=preferreddate, + manager=self.u, + ) + + + self.ps_time.save() + added = plannedsessions.add_rower_session(self.r,self.ps_time) + + self.ps_trimp = SessionFactory( + startdate=startdate,enddate=enddate, + sessiontype='challenge', + sessionmode = 'TRIMP', + criterium = 'none', + sessionvalue = 77, + sessionunit='none', + preferreddate=preferreddate, + manager=self.u, + ) + + + self.ps_trimp.save() + added = plannedsessions.add_rower_session(self.r,self.ps_trimp) + + + def tearDown(self): + try: + os.remove(self.w1.csvfilename) + except (IOError, WindowsError): + pass + + def test_challenge1_complete(self): + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_rscore,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_rscore + ) + + self.assertEqual(verdict,'partial') + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_dist,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_dist + ) + + self.assertEqual(verdict,'partial') + + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_time,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_time + ) + + self.assertEqual(verdict,'partial') + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_trimp,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_trimp + ) + + self.assertEqual(verdict,'partial') + + + + def test_challenge1_exact_complete(self): + self.ps_rscore.criterium = 'exact' + self.ps_rscore.save() + + self.ps_dist.criterium = 'exact' + self.ps_dist.save() + + self.ps_time.criterium = 'exact' + self.ps_time.save() + + self.ps_trimp.criterium = 'exact' + self.ps_trimp.save() + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_rscore,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_rscore + ) + + self.assertEqual(verdict,'on target') + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_dist,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_dist + ) + + self.assertEqual(verdict,'on target') + + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_time,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_time + ) + + self.assertEqual(verdict,'partial') + + result = plannedsessions.remove_workout_plannedsession(self.w1,self.ps_time) + + self.assertEqual(result,1) + + result = plannedsessions.remove_workout_plannedsession(self.w1,self.ps_time) + + self.assertEqual(result,0) + + + login = self.c.login(username=self.u.username, password=self.password) + self.assertTrue(login) + + url = '/rowers/sessions/{id}/'.format(id=self.ps_trimp.id) + + response = self.c.get(url) + self.assertEqual(response.status_code,200) + + url = '/rowers/sessions/' + response = self.c.get(url) + self.assertEqual(response.status_code,200) + +class MandatoryTestCompleteTest(TestCase): + def setUp(self): + self.u = UserFactory() + + self.r = Rower.objects.create(user=self.u, + birthdate=faker.profile()['birthdate'], + gdproptin=True, + gdproptindate=timezone.now(), + rowerplan='coach') + + self.c = Client() + + # workout 1 - 2019-01-13, rScore 69 + result = get_random_file(filename='rowers/tests/testdata/2019-01-13_session.csv',name='sprintervals') + + + self.factory = RequestFactory() + self.password = faker.word() + self.u.set_password(self.password) + self.u.save() + + self.w1 = Workout.objects.create( + name='sprintervals', + notes=faker.text(), + startdatetime = result['startdatetime'], + starttime = result['starttime'], + workouttype='rower', + date=result['date'], + duration=result['duration'], + distance=result['totaldist'], + csvfilename=result['filename'], + trimp = 77, + rscore = 69, + hrtss = 43, + normp = 236, + user=self.r, + ) + + # self.w1.save() + + startdatetime = self.w1.startdatetime + + startdate = (startdatetime-datetime.timedelta(days=1)).date() + enddate = (startdatetime+datetime.timedelta(days=1)).date() + preferreddate = startdatetime.date() + + self.ps_rscore = SessionFactory( + startdate=startdate,enddate=enddate, + sessiontype='test', + sessionmode = 'rScore', + criterium = 'none', + sessionvalue = 69, + sessionunit='None', + preferreddate=preferreddate, + manager=self.u, + ) + + + self.ps_rscore.save() + added = plannedsessions.add_rower_session(self.r,self.ps_rscore) + + self.ps_dist = SessionFactory( + startdate=startdate,enddate=enddate, + sessiontype='test', + sessionmode = 'distance', + criterium = 'none', + sessionvalue = result['totaldist'], + sessionunit='m', + preferreddate=preferreddate, + manager=self.u, + ) + + + self.ps_dist.save() + added = plannedsessions.add_rower_session(self.r,self.ps_dist) + + self.ps_time = SessionFactory( + startdate=startdate,enddate=enddate, + sessiontype='test', + sessionmode = 'time', + criterium = 'none', + sessionvalue = 38, + sessionunit='min', + preferreddate=preferreddate, + manager=self.u, + ) + + + self.ps_time.save() + added = plannedsessions.add_rower_session(self.r,self.ps_time) + + self.ps_trimp = SessionFactory( + startdate=startdate,enddate=enddate, + sessiontype='test', + sessionmode = 'TRIMP', + criterium = 'none', + sessionvalue = 77, + sessionunit='none', + preferreddate=preferreddate, + manager=self.u, + ) + + + self.ps_trimp.save() + added = plannedsessions.add_rower_session(self.r,self.ps_trimp) + + + def tearDown(self): + try: + os.remove(self.w1.csvfilename) + except (IOError, WindowsError): + pass + + def test_mandatorytest1_complete(self): + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_rscore,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_rscore + ) + + self.assertEqual(verdict,'partial') + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_dist,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_dist + ) + + self.assertEqual(verdict,'on target') + + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_time,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_time + ) + + self.assertEqual(verdict,'partial') + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_trimp,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_trimp + ) + + self.assertEqual(verdict,'partial') + + + + def test_mandatorytest1_exact_complete(self): + self.ps_rscore.criterium = 'exact' + self.ps_rscore.save() + + self.ps_dist.criterium = 'exact' + self.ps_dist.save() + + self.ps_time.criterium = 'exact' + self.ps_time.save() + + self.ps_trimp.criterium = 'exact' + self.ps_trimp.save() + + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_dist,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_dist + ) + + self.assertEqual(verdict,'on target') + + + result = plannedsessions.add_workouts_plannedsession( + [self.w1],self.ps_time,self.r + ) + + ratio,verdict,completiondate = plannedsessions.is_session_complete( + self.r,self.ps_time + ) + + self.assertEqual(verdict,'partial') + + + + login = self.c.login(username=self.u.username, password=self.password) + self.assertTrue(login) + + url = '/rowers/sessions/{id}/'.format(id=self.ps_time.id) + + response = self.c.get(url) + self.assertEqual(response.status_code,200) + + url = '/rowers/sessions/' + response = self.c.get(url) + self.assertEqual(response.status_code,200) + diff --git a/rowers/tests/testdata/testdata.csv.gz b/rowers/tests/testdata/testdata.csv.gz index 0514cd6a..7d6be8d7 100644 Binary files a/rowers/tests/testdata/testdata.csv.gz and b/rowers/tests/testdata/testdata.csv.gz differ