Private
Public Access
1
0

NK LiNK to NK Logbook

This commit is contained in:
Sander Roosendaal
2021-04-21 16:47:44 +02:00
parent c278f7b900
commit ef2229c1ee
10 changed files with 246 additions and 129 deletions

View File

@@ -1002,7 +1002,7 @@ class Rower(models.Model):
nkrefreshtoken = models.TextField(default='',max_length=1000,
blank=True,null=True)
nk_owner_id = models.BigIntegerField(default=0)
nk_auto_import = models.BooleanField(default=False,verbose_name='NK LiNK auto import')
nk_auto_import = models.BooleanField(default=False,verbose_name='NK Logbook auto import')
trainingpeaks_auto_export = models.BooleanField(default=False)

View File

@@ -157,7 +157,7 @@ def checkscores(r,macrocycles):
if mm.type == 'userdefined':
for ps in sps:
for ps in sps: # pragma: no cover
ratio, status, cdate = is_session_complete(r,ps)
if ps.sessionmode == 'time':
mm.plantime += ps.sessionvalue
@@ -256,12 +256,12 @@ def get_execution_report(rower,startdate,enddate,plan=None):
for w in unmatchedworkouts:
if w.rscore != 0:
actualscore += w.rscore
elif w.hrtss != 0:
elif w.hrtss != 0: # pragma: no cover
actualscore += w.hrtss
else:
else: # pragma: no cover
minutes = w.duration.hour*60+w.duration.minute
actualscore += minutes
for ps in sps:
for ps in sps: # pragma: no cover
ratio, status, cdate = is_session_complete(rower,ps)
if ps.sessionmode == 'rScore':
plannedscore += ps.sessionvalue
@@ -386,11 +386,11 @@ def add_workouts_plannedsession(ws,ps,r):
# check if all sessions have same date
dates = [w.date for w in ws]
if (not all(d == dates[0] for d in dates)) and ps.sessiontype not in ['challenge','cycletarget']:
if (not all(d == dates[0] for d in dates)) and ps.sessiontype not in ['challenge','cycletarget']: # pragma: no cover
errors.append('For tests and training sessions, selected workouts must all be done on the same date')
return result,comments,errors
if len(ws)>1 and ps.sessiontype == 'test':
if len(ws)>1 and ps.sessiontype == 'test': # pragma: no cover
errors.append('For tests, you can only attach one workout')
return result,comments,errors
@@ -400,7 +400,7 @@ def add_workouts_plannedsession(ws,ps,r):
ids = [w.id for w in wold] + [w.id for w in ws]
ids = list(set(ids))
if len(ids)>1 and ps.sessiontype in ['test','coursetest','race','fastest_time','fastest_distance']:
if len(ids)>1 and ps.sessiontype in ['test','coursetest','race','fastest_time','fastest_distance']: # pragma: no cover
errors.append('For tests, you can only attach one workout')
return result,comments,errors
@@ -411,7 +411,7 @@ def add_workouts_plannedsession(ws,ps,r):
w.save()
result += 1
comments.append('Attached workout %s to session' % encoder.encode_hex(w.id))
if ps.sessiontype == 'coursetest':
if ps.sessiontype == 'coursetest': # pragma: no cover
record = CourseTestResult(
userid=w.user.id,
plannedsession=ps,
@@ -423,7 +423,7 @@ def add_workouts_plannedsession(ws,ps,r):
w.id,ps.course.id,record.id,
w.user.user.email,w.user.user.first_name,
mode='coursetest')
if ps.sessiontype == 'fastest_distance':
if ps.sessiontype == 'fastest_distance': # pragma: no cover
records = CourseTestResult.objects.filter(userid=w.user.id,plannedsession=ps)
for record in records:
#w1 = Workout.objects.get(id=record.workoutid)
@@ -454,7 +454,7 @@ def add_workouts_plannedsession(ws,ps,r):
record.save()
else:
errors.append('Could not find a matching interval')
if ps.sessiontype == 'fastest_time':
if ps.sessiontype == 'fastest_time': # pragma: no cover
records = CourseTestResult.objects.filter(userid=w.user.id,plannedsession=ps)
for record in records:
#w1 = Workout.objects.get(id=record.workoutid)
@@ -483,7 +483,7 @@ def add_workouts_plannedsession(ws,ps,r):
record.save()
else:
errors.append('Could not find a matching interval')
else:
else: # pragma: no cover
errors.append('Workout %i did not match session dates' % w.id)
return result,comments,errors
@@ -497,7 +497,7 @@ def remove_workout_plannedsession(w,ps):
return 0
def clone_planned_session(ps):
def clone_planned_session(ps): # pragma: no cover
ps.save()
ps.pk = None # creates new instance
ps.save()
@@ -511,7 +511,7 @@ def timefield_to_seconds_duration(t):
return duration
def get_virtualrace_times(virtualrace):
def get_virtualrace_times(virtualrace): # pragma: no cover
geocourse = GeoCourse.objects.get(id = virtualrace.course.id)
timezone_str = get_course_timezone(geocourse)
@@ -564,13 +564,13 @@ def get_session_metrics(ps):
tss = dataprep.workout_rscore(w)[0]
if not np.isnan(tss) and tss != 0:
rscorev += tss
elif tss == 0:
elif tss == 0: # pragma: no cover
rscorev += hrtss
ratio,statusv,completiondate = is_session_complete_ws(ws,ps)
try:
completedatev = completiondate.strftime('%Y-%m-%d')
except AttributeError:
except AttributeError: # pragma: no cover
completedatev = ''
durationv /= 60.
@@ -622,7 +622,7 @@ def is_session_complete_ws(ws,ps):
value = ps.sessionvalue
if ps.sessionunit == 'min':
value *= 60.
elif ps.sessionunit == 'km':
elif ps.sessionunit == 'km': # pragma: no cover
value *= 1000.
cratiomin = 1
@@ -663,7 +663,7 @@ def is_session_complete_ws(ws,ps):
rscore = dataprep.workout_rscore(w)[0]
if not np.isnan(rscore) and rscore != 0:
score += rscore
elif rscore == 0:
elif rscore == 0: # pragma: no cover
trimp,hrtss = dataprep.workout_trimp(w)
score += hrtss
@@ -672,7 +672,7 @@ def is_session_complete_ws(ws,ps):
try:
ratio = score/float(int(value))
except ZeroDivisionError:
except ZeroDivisionError: # pragma: no cover
ratio = 0
verdict = 'better than nothing'
@@ -682,10 +682,10 @@ def is_session_complete_ws(ws,ps):
if ratio == 1.0:
return ratio,'on target',completiondate
else:
if not completiondate:
if not completiondate: # pragma: no cover
completiondate = ws.reverse()[0].date
return ratio,'partial',completiondate
elif ps.criterium == 'minimum':
elif ps.criterium == 'minimum': # pragma: no cover
if ratio >= 1.0:
return ratio,'on target',completiondate
else:
@@ -713,7 +713,7 @@ def is_session_complete_ws(ws,ps):
return ratio,'on target',completiondate
else:
return ratio,'partial',completiondate
elif ps.criterium == 'minimum':
elif ps.criterium == 'minimum': # pragma: no cover
if ratio > 1.0:
return ratio,'on target',completiondate
else:
@@ -721,10 +721,10 @@ def is_session_complete_ws(ws,ps):
completiondate = ws.reverse()[0].date
return ratio,'partial',completiondate
else:
if not completiondate:
if not completiondate: # pragma: no cover
completiondate = ws.reverse()[0].date
return ratio,'partial',completiondate
elif ps.sessiontype == 'race':
elif ps.sessiontype == 'race': # pragma: no cover
vs = VirtualRaceResult.objects.filter(race=ps)
wids = [w.id for w in ws]
for record in vs:
@@ -736,7 +736,7 @@ def is_session_complete_ws(ws,ps):
ratio = record.distance/ps.sessionvalue
return ratio,'partial',completiondate
return (0,'partial',None)
elif ps.sessiontype in ['fastest_time','fastest_distance']:
elif ps.sessiontype in ['fastest_time','fastest_distance']: # pragma: no cover
vs = CourseTestResult.objects.filter(plannedsession=ps,userid=ws[0].user.user.id)
completiondate = ws.reverse()[0].date
wids = [w.id for w in ws]
@@ -757,7 +757,7 @@ def is_session_complete_ws(ws,ps):
)
record.save()
return (0,'not done',None)
elif ps.sessiontype == 'coursetest':
elif ps.sessiontype == 'coursetest': # pragma: no cover
vs = CourseTestResult.objects.filter(plannedsession=ps)
wids = [w.id for w in ws]
for record in vs:
@@ -787,7 +787,7 @@ def is_session_complete_ws(ws,ps):
return (0,'not done',None)
else:
else: # pragma: no cover
if not completiondate:
completiondate = ws.reverse()[0].date
return ratio,verdict,completiondate
@@ -797,7 +797,7 @@ def is_session_complete(r,ps):
verdict = 'not done'
if r not in ps.rower.all():
if r not in ps.rower.all(): # pragma: no cover
return 0,'not assigned',None
ws = Workout.objects.filter(user=r,plannedsession=ps)
@@ -805,7 +805,7 @@ def is_session_complete(r,ps):
return is_session_complete_ws(ws,ps)
def rank_results(ps):
def rank_results(ps): # pragma: no cover
return 1
def add_team_session(t,ps):
@@ -828,7 +828,7 @@ def add_rower_session(r,ps):
return 0
def remove_team_session(t,ps):
def remove_team_session(t,ps): # pragma: no cover
ps.team.remove(t)
return 1
@@ -865,7 +865,7 @@ def get_dates_timeperiod(request,startdatestring='',enddatestring='',
try:
startdate = parser.parse(startdatestring,fuzzy=True).date()
enddate = parser.parse(enddatestring, fuzzy=True).date()
except ValueError:
except ValueError: # pragma: no cover
startdate = timezone.now()-timezone.timedelta(days=5)
startdate = startdate.date()
enddate = timezone.now().date()
@@ -879,31 +879,31 @@ def get_dates_timeperiod(request,startdatestring='',enddatestring='',
daterangetester = re.compile('^(\d+-\d+-\d+)\/(\d+-\d+-\d+)')
if timeperiod=='today':
if timeperiod=='today': # pragma: no cover
startdate=date.today()
enddate=date.today()
elif timeperiod=='tomorrow':
elif timeperiod=='tomorrow': # pragma: no cover
startdate=date.today()+timezone.timedelta(days=1)
enddate=date.today()+timezone.timedelta(days=1)
elif timeperiod=='thisweek':
elif timeperiod=='thisweek': # pragma: no cover
today = date.today()
startdate = date.today()-timezone.timedelta(days=today.weekday())
enddate = startdate+timezone.timedelta(days=6)
elif timeperiod=='thismonth':
elif timeperiod=='thismonth': # pragma: no cover
today = date.today()
startdate = today.replace(day=1)
enddate = startdate+timezone.timedelta(days=32)
enddate = enddate.replace(day=1)
enddate = enddate-timezone.timedelta(days=1)
elif timeperiod=='lastweek':
elif timeperiod=='lastweek': # pragma: no cover
today = date.today()
enddate = today-timezone.timedelta(days=today.weekday())-timezone.timedelta(days=1)
startdate = enddate-timezone.timedelta(days=6)
elif timeperiod=='nextweek':
elif timeperiod=='nextweek': # pragma: no cover
today = date.today()
startdate = today-timezone.timedelta(days=today.weekday())+timezone.timedelta(days=7)
enddate = startdate+timezone.timedelta(days=6)
elif timeperiod=='lastmonth':
elif timeperiod=='lastmonth': # pragma: no cover
today = date.today()
startdate = today.replace(day=1)
startdate = startdate-timezone.timedelta(days=3)
@@ -911,7 +911,7 @@ def get_dates_timeperiod(request,startdatestring='',enddatestring='',
enddate = startdate+timezone.timedelta(days=32)
enddate = enddate.replace(day=1)
enddate = enddate-timezone.timedelta(days=1)
elif timeperiod=='nextmonth':
elif timeperiod=='nextmonth': # pragma: no cover
today = date.today()
startdate = today.replace(day=1)
startdate = startdate+timezone.timedelta(days=32)
@@ -919,7 +919,7 @@ def get_dates_timeperiod(request,startdatestring='',enddatestring='',
enddate = startdate+timezone.timedelta(days=32)
enddate = enddate.replace(day=1)
enddate = enddate-timezone.timedelta(days=1)
elif timeperiod=='lastyear':
elif timeperiod=='lastyear': # pragma: no cover
today = date.today()
startdate = today-timezone.timedelta(days=365)
enddate = today+timezone.timedelta(days=1)
@@ -929,11 +929,11 @@ def get_dates_timeperiod(request,startdatestring='',enddatestring='',
try:
startdate = dt.datetime.strptime(tstartdatestring,'%Y-%m-%d').date()
enddate = dt.datetime.strptime(tenddatestring,'%Y-%m-%d').date()
if startdate > enddate:
if startdate > enddate: # pragma: no cover
startdate2 = enddate
enddate = startdate
startdate = startdate2
except ValueError:
except ValueError: # pragma: no cover
startdate = date.today()
enddate = date.today()
else:
@@ -957,7 +957,7 @@ def get_dates_timeperiod(request,startdatestring='',enddatestring='',
def get_sessions_manager(m,teamid=0,startdate=date.today(),
enddate=date.today()+timezone.timedelta(+1000)):
if teamid:
if teamid: # pragma: no cover
t = Team.objects.get(id=teamid)
rs = Rower.objects.filter(team__in=[t]).distinct()
sps = PlannedSession.objects.filter(
@@ -1039,7 +1039,7 @@ def update_plannedsession(ps,cd):
if attr != 'fitfile':
setattr(ps, attr, value)
if cd['fitfile']:
if cd['fitfile']: # pragma: no cover
f = cd['fitfile']
try:
filename, path_and_filename = handle_uploaded_file(f)
@@ -1079,7 +1079,7 @@ def update_indoorvirtualrace(ps,cd):
registration_form = cd['registration_form']
registration_closure = cd['registration_closure']
if registration_form == 'manual':
if registration_form == 'manual': # pragma: no cover
try:
registration_closure = pytz.timezone(
timezone_str
@@ -1088,9 +1088,9 @@ def update_indoorvirtualrace(ps,cd):
)
except AttributeError:
registration_closure = startdatetime
elif registration_form == 'windowstart':
elif registration_form == 'windowstart': # pragma: no cover
registration_closure = startdatetime
elif registration_form == 'windowend':
elif registration_form == 'windowend': # pragma: no cover
registration_closure = enddatetime
else:
registration_closure = ps.evaluation_closure
@@ -1132,7 +1132,7 @@ def update_virtualrace(ps,cd):
registration_form = cd['registration_form']
registration_closure = cd['registration_closure']
if registration_form == 'manual':
if registration_form == 'manual': # pragma: no cover
try:
registration_closure = pytz.timezone(
timezone_str
@@ -1141,9 +1141,9 @@ def update_virtualrace(ps,cd):
)
except AttributeError:
registration_closure = startdatetime
elif registration_form == 'windowstart':
elif registration_form == 'windowstart': # pragma: no cover
registration_closure = startdatetime
elif registration_form == 'windowend':
elif registration_form == 'windowend': # pragma: no cover
registration_closure = enddatetime
else:
registration_closure = ps.evaluation_closure
@@ -1191,11 +1191,11 @@ def race_can_edit(r,race):
)
if timezone.now()<enddatetime:
return True
else:
else: # pragma: no cover
return False
return False
return False # pragma: no cover
def race_can_submit(r,race):
#if r not in race.rower.all():
@@ -1219,7 +1219,7 @@ def race_can_submit(r,race):
else:
return False
return False
return False # pragma: no cover
def race_can_editentry(r,race):
start_time = race.start_time
@@ -1234,12 +1234,12 @@ def race_can_editentry(r,race):
is_complete,has_registered = race_rower_status(r,race)
if is_complete == False:
return True
else:
else: # pragma: no cover
return False
else:
else: # pragma: no cover
return False
return False
return False # pragma: no cover
def race_can_resubmit(r,race):
records = VirtualRaceResult.objects.filter(
@@ -1263,10 +1263,10 @@ def race_can_resubmit(r,race):
if timezone.now() > startdatetime and timezone.now() < evaluation_closure:
is_complete,has_registered = race_rower_status(r,race)
return is_complete
else:
else: # pragma: no cover
return False
return False
return False # pragma: no cover
def race_can_adddiscipline(r,race):
@@ -1276,7 +1276,7 @@ def race_can_adddiscipline(r,race):
if race.sessiontype in ['race']:
resultobj = VirtualRaceResult
else:
else: # pragma: no cover
resultobj = IndoorVirtualRaceResult
records = resultobj.objects.filter(
@@ -1302,12 +1302,12 @@ def race_can_adddiscipline(r,race):
is_complete,has_registered = race_rower_status(r,race)
if has_registered:
return True
else:
else: # pragma: no cover
return False
else:
else: # pragma: no cover
return False
return False
return False # pragma: no cover
def race_can_withdraw(r,race):
@@ -1334,10 +1334,10 @@ def race_can_withdraw(r,race):
)
registration_closure = race.registration_closure
if registration_closure is None or registration_closure == '':
if registration_closure is None or registration_closure == '': # pragma: no cover
registration_closure = startdatetime
if timezone.now() > registration_closure:
if timezone.now() > registration_closure: # pragma: no cover
return False
elif timezone.now() > startdatetime:
return False
@@ -1348,7 +1348,7 @@ def race_can_withdraw(r,race):
def email_submit_race(r,race,workoutid):
try:
w = Workout.objects.get(id=workoutid)
except Workout.DoesNotExist:
except Workout.DoesNotExist: # pragma: no cover
return 0
if race.sessionmode == 'time':
@@ -1360,7 +1360,7 @@ def email_submit_race(r,race,workoutid):
w.save()
elif race.sessionmode == 'distance':
elif race.sessionmode == 'distance': # pragma: no cover
delta = w.distance - race.sessionvalue
if delta > -5 and delta < 5:
@@ -1375,7 +1375,7 @@ def email_submit_race(r,race,workoutid):
if sex == 'not specified':
sex = 'male'
if not r.birthdate:
if not r.birthdate: # pragma: no cover
return 0
age = calculate_age(r.birthdate)
@@ -1429,7 +1429,7 @@ def email_submit_race(r,race,workoutid):
race=race
)
if not records:
if not records: # pragma: no cover
return 0
record = records[0]
@@ -1461,12 +1461,12 @@ def email_submit_race(r,race,workoutid):
return 1
else:
return 0
else:
return 0 # pragma: no cover
else: # pragma: no cover
return 0
return 0
return 0 # pragma: no cover
def race_can_register(r,race):
@@ -1490,10 +1490,10 @@ def race_can_register(r,race):
)
registration_closure = race.registration_closure
if registration_closure is None or registration_closure == '':
if registration_closure is None or registration_closure == '': # pragma: no cover
registration_closure = startdatetime
if timezone.now() > registration_closure:
if timezone.now() > registration_closure: # pragma: no cover
return False
return True
@@ -1507,12 +1507,12 @@ def add_rower_race(r,race):
def remove_rower_race(r,race,recordid=None):
race.rower.remove(r)
if race.sessiontype in ['race']:
if race.sessiontype in ['race']: # pragma: no cover
recordobj = VirtualRaceResult
else:
recordobj = IndoorVirtualRaceResult
if recordid:
if recordid: # pragma: no cover
records = recordobj.objects.filter(userid=r.id,
workoutid__isnull=True,
race=race,
@@ -1529,14 +1529,14 @@ def remove_rower_race(r,race,recordid=None):
def default_class(r,w,race):
if r.birthdate:
age = calculate_age(r.birthdate)
else:
else: # pragma: no cover
age = 25
sex = r.sex
if sex=='not specified':
sex='male'
if w is not None:
if w is not None: # pragma: no cover
boatclass = w.workouttype
boattype = w.boattype
@@ -1545,7 +1545,7 @@ def default_class(r,w,race):
else:
if race.sessiontype in ['race','fastest_time','fastest_distance']:
boatclass = 'water'
else:
else: # pragma: no cover
boatclass = 'rower'
boattype = '1x'
@@ -1565,7 +1565,7 @@ def default_class(r,w,race):
if standards.count()==0:
if standards.count()==0: # pragma: no cover
# omit weight
standards = CourseStandard.objects.filter(
agemin__lt=age,agemax__gt=age,
@@ -1642,14 +1642,14 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False):
ids = [w.id for w in ws]
ids = list(set(ids))
if len(ids)>1 and race.sessiontype in ['test','coursetest','race','indoorrace','fastest_time','fastest_distance']:
if len(ids)>1 and race.sessiontype in ['test','coursetest','race','indoorrace','fastest_time','fastest_distance']: # pragma: no cover
errors.append('For tests, you can only attach one workout')
return result,comments,errors,0
username = r.user.first_name+' '+r.user.last_name
if r.birthdate:
age = calculate_age(r.birthdate)
else:
else: # pragma: no cover
age = None
try:
@@ -1658,7 +1658,7 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False):
race=race,
id=recordid
)
except IndoorVirtualRaceResult.DoesNotExist:
except IndoorVirtualRaceResult.DoesNotExist: # pragma: no cover
if doregister:
hasinitial,boattype,boatclass,adaptiveclass,weightclass,sex,referencespeed,initialcategory = default_class(r,ws[0],race)
if hasinitial:
@@ -1678,7 +1678,7 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False):
else:
errors.append("Unable to find a suitable start category")
return result,comments,errors,0
else:
else: # pragma: no cover
errors.append("Couldn't find this entry")
return result,comments,errors,0
@@ -1688,19 +1688,19 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False):
workoutid = ws[0].id
)
if ws[0].workouttype != record.boatclass:
if ws[0].workouttype != record.boatclass: # pragma: no cover
errors.append('Your workout boat class is different than on your race registration')
return 0,comments,errors,0
if ws[0].workouttype not in mytypes.otwtypes:
if ws[0].workouttype not in mytypes.otwtypes: # pragma: no cover
errors.append('You must submit a on-the-water rowing workout')
return 0,comments, errors, 0
if record.weightcategory == 'lwt' and ws[0].weightcategory != record.weightcategory:
if record.weightcategory == 'lwt' and ws[0].weightcategory != record.weightcategory: # pragma: no cover
errors.append('Your workout weight category did not match the weight category you registered')
return 0,comments, errors,0
if ws[0].adaptiveclass != record.adaptiveclass:
if ws[0].adaptiveclass != record.adaptiveclass: # pragma: no cover
errors.append('Your adaptive classification did not match the registration')
return 0,comments, errors, 0
@@ -1710,12 +1710,12 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False):
ws[0].save()
result += 1
else:
else: # pragma: no cover
errors.append('Workout %i did not match the race window' % ws[0].id)
return result,comments,errors,0
if result>0:
for otherrecord in records:
for otherrecord in records: # pragma: no cover
otherrecord.workoutid = None
otherrecord.coursecompleted = False
otherrecord.save()
@@ -1739,7 +1739,7 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False):
record.startsecond = startsecond
record.endsecond = endsecond
record.save()
if race.sessiontype == 'fastest_time':
if race.sessiontype == 'fastest_time': # pragma: no cover
df = dataprep.getsmallrowdata_db(['time','cumdist'],ids=[ws[0].id])
fastest_meters, startsecond, endsecond = datautils.getfastest(df,race.sessionvalue,mode='time')
velo = fastest_meters/(60.*race.sessionvalue)
@@ -1757,13 +1757,13 @@ def add_workout_fastestrace(ws, race, r, recordid=0, doregister=False):
if ws[0].privacy == 'private':
if ws[0].privacy == 'private': # pragma: no cover
ws[0].privacy = 'visible'
ws[0].save()
comments.append('Workouts submitted to virtual events have to be public. We have changed the workout to a public workout.')
record.save()
else:
else: # pragma: no cover
errors.append('Could not find a valid interval in this workout')
return result, comments, errors, 0
@@ -1791,12 +1791,12 @@ def add_workout_indoorrace(ws,race,r,recordid=0,doregister=False):
# check if all sessions have same date
dates = [w.date for w in ws]
if (not all(d == dates[0] for d in dates)) and race.sessiontype not in ['challenge','cycletarget']:
if (not all(d == dates[0] for d in dates)) and race.sessiontype not in ['challenge','cycletarget']: # pragma: no cover
errors.append('For tests and training sessions, selected workouts must all be done on the same date')
return result,comments,errors,0
if len(ws)>1 and race.sessiontype == 'test':
if len(ws)>1 and race.sessiontype == 'test': # pragma: no cover
errors.append('For tests, you can only attach one workout')
return result,comments,errors,0
@@ -1805,7 +1805,7 @@ def add_workout_indoorrace(ws,race,r,recordid=0,doregister=False):
ids = [w.id for w in ws]
ids = list(set(ids))
if len(ids)>1 and race.sessiontype in ['test','coursetest','race','indoorrace','fastest_time','fastest_distance']:
if len(ids)>1 and race.sessiontype in ['test','coursetest','race','indoorrace','fastest_time','fastest_distance']: # pragma: no cover
errors.append('For tests, you can only attach one workout')
return result,comments,errors,0
@@ -1814,7 +1814,7 @@ def add_workout_indoorrace(ws,race,r,recordid=0,doregister=False):
username = r.user.first_name+' '+r.user.last_name
if r.birthdate:
age = calculate_age(r.birthdate)
else:
else: # pragma: no cover
age = None
try:
@@ -1823,7 +1823,7 @@ def add_workout_indoorrace(ws,race,r,recordid=0,doregister=False):
race=race,
id=recordid
)
except IndoorVirtualRaceResult.DoesNotExist:
except IndoorVirtualRaceResult.DoesNotExist: # pragma: no cover
if doregister:
hasinitial,boattype,boatclass,adaptiveclass,weightclass,sex,referencespeed,initialcategory = default_class(r,ws[0],race)
if hasinitial:
@@ -1843,7 +1843,7 @@ def add_workout_indoorrace(ws,race,r,recordid=0,doregister=False):
else:
errors.append("Unable to find a suitable start category")
return result,comments,errors,0
else:
else: # pragma: no cover
errors.append("Couldn't find this entry")
return result,comments,errors,0
@@ -1864,7 +1864,7 @@ def add_workout_indoorrace(ws,race,r,recordid=0,doregister=False):
else:
t = ws[0].duration
seconds = t.second+t.minute*60.+t.hour*3600.+t.microsecond/1.e6
if seconds != race.sessionvalue*60.:
if seconds != race.sessionvalue*60.: # pragma: no cover
errors.append('Your workout did not have the correct duration')
return 0, comments, errors, 0
else:
@@ -1875,15 +1875,15 @@ def add_workout_indoorrace(ws,race,r,recordid=0,doregister=False):
errors.append('Your workout boat class is different than on your race registration')
return 0,comments,errors,0
if ws[0].workouttype not in mytypes.otetypes:
if ws[0].workouttype not in mytypes.otetypes: # pragma: no cover
errors.append('You must submit a indoor rowing workout')
return 0,comments, errors, 0
if record.weightcategory == 'lwt' and ws[0].weightcategory != record.weightcategory:
if record.weightcategory == 'lwt' and ws[0].weightcategory != record.weightcategory: # pragma: no cover
errors.append('Your workout weight category did not match the weight category you registered')
return 0,comments, errors,0
if ws[0].adaptiveclass != record.adaptiveclass:
if ws[0].adaptiveclass != record.adaptiveclass: # pragma: no cover
errors.append('Your adaptive classification did not match the registration')
return 0,comments, errors, 0
@@ -1893,12 +1893,12 @@ def add_workout_indoorrace(ws,race,r,recordid=0,doregister=False):
ws[0].save()
result += 1
else:
else: # pragma: no cover
errors.append('Workout %i did not match the race window' % ws[0].id)
return result,comments,errors,0
if result>0:
for otherrecord in records:
for otherrecord in records: # pragma: no cover
otherrecord.workoutid = None
otherrecord.coursecompleted = False
otherrecord.save()
@@ -1906,7 +1906,7 @@ def add_workout_indoorrace(ws,race,r,recordid=0,doregister=False):
record.coursecompleted = True
record.workoutid = ws[0].id
if ws[0].privacy == 'private':
if ws[0].privacy == 'private': # pragma: no cover
ws[0].privacy = 'visible'
ws[0].save()
comments.append('Workouts submitted to virtual events have to be public. We have changed the workout to a public workout.')
@@ -1940,11 +1940,11 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0,doregister=False):
# check if all sessions have same date
dates = [w.date for w in ws]
if (not all(d == dates[0] for d in dates)) and race.sessiontype not in ['challenge','cycletarget']:
if (not all(d == dates[0] for d in dates)) and race.sessiontype not in ['challenge','cycletarget']: # pragma: no cover
errors.append('For tests and training sessions, selected workouts must all be done on the same date')
return result,comments,errors,0
if len(ws)>1 and race.sessiontype == 'test':
if len(ws)>1 and race.sessiontype == 'test': # pragma: no cover
errors.append('For tests, you can only attach one workout')
return result,comments,errors,0
@@ -1953,7 +1953,7 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0,doregister=False):
ids = [w.id for w in ws]
ids = list(set(ids))
if len(ids)>1 and race.sessiontype in ['test','coursetest','race','fastest_time','fastest_distance']:
if len(ids)>1 and race.sessiontype in ['test','coursetest','race','fastest_time','fastest_distance']: # pragma: no cover
errors.append('For tests, you can only attach one workout')
return result,comments,errors,0
@@ -1962,7 +1962,7 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0,doregister=False):
username = r.user.first_name+' '+r.user.last_name
if r.birthdate:
age = calculate_age(r.birthdate)
else:
else: # pragma: no cover
age = None
try:
@@ -1971,7 +1971,7 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0,doregister=False):
race=race,
id=recordid
)
except VirtualRaceResult.DoesNotExist:
except VirtualRaceResult.DoesNotExist: # pragma: no cover
if doregister:
hasinitial,boattype,boatclass,adaptiveclass,weightclass,sex,referencespeed,initialcategory = default_class(r,ws[0],race)
if hasinitial:
@@ -1993,7 +1993,7 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0,doregister=False):
else:
errors.append("Unable to find a suitable start category")
return result,comments,errors,0
else:
else: # pragma: no cover
errors.append("Couldn't find this entry")
return result,comments,errors,0
@@ -2003,7 +2003,7 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0,doregister=False):
workoutid = ws[0].id
)
if not record and not doregister:
if not record and not doregister: # pragma: no cover
errors.append("Couldn't find this entry")
return result,comments,errors,0
@@ -2011,21 +2011,21 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0,doregister=False):
# errors.append('You have to submit a rowing on water workout')
# return 0,comments,errors,0
if ws[0].workouttype != record.boatclass:
if ws[0].workouttype != record.boatclass: # pragma: no cover
ws[0].workouttype = record.boatclass
ws[0].save()
#errors.append('Your workout boat class is different than on your race registration')
#return 0,comments,errors,0
if ws[0].boattype != record.boattype:
if ws[0].boattype != record.boattype: # pragma: no cover
errors.append('Your workout boat type did not match the boat type you registered')
return 0,comments,errors,0
if record.weightcategory == 'lwt' and ws[0].weightcategory != record.weightcategory:
if record.weightcategory == 'lwt' and ws[0].weightcategory != record.weightcategory: # pragma: no cover
errors.append('Your workout weight category did not match the weight category you registered')
return 0,comments, errors,0
if ws[0].adaptiveclass != record.adaptiveclass:
if ws[0].adaptiveclass != record.adaptiveclass: # pragma: no cover
errors.append('Your workout adaptive classification did not match the registration')
return 0,comments, errors,0
@@ -2043,17 +2043,17 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0,doregister=False):
ws[0].save()
result += 1
else:
else: # pragma: no cover
errors.append('Workout %i did not match the race window' % ws[0].id)
return result,comments,errors,0
if result>0:
for otherrecord in records:
for otherrecord in records: # pragma: no cover
otherrecord.workoutid = None
otherrecord.coursecompleted = False
otherrecord.save()
if ws[0].privacy == 'private':
if ws[0].privacy == 'private': # pragma: no cover
ws[0].privacy = 'visible'
ws[0].save()
comments.append('Workouts submitted to virtual events have to be public. We have changed the workout to a public workout.')
@@ -2074,7 +2074,7 @@ def add_workout_race(ws,race,r,splitsecond=0,recordid=0,doregister=False):
return result,comments,errors,job.id
def delete_race_result(workout,race):
def delete_race_result(workout,race): # pragma: no cover
results = VirtualRaceResult.objects.filter(workoutid=workout.id,race=race)
for r in results:
r.workoutid = None

View File

@@ -158,7 +158,7 @@
<li id="export-nk">
{% if workout.uploadedtonk %}
<a href="{{ workout|nkviewerlink }}">
NK LiNK <i class="fas fa-check"></i>
NK Logbook <i class="fas fa-check"></i>
</a>
{% endif %}
</li>

View File

@@ -38,7 +38,7 @@
<ul>
<li id="concept2"><a href="/rowers/workout/c2list/">Concept2</a></li>
<li id="nklink"><a href="/rowers/workout/nkimport/">NK LiNK</a></li>
<li id="nklink"><a href="/rowers/workout/nkimport/">NK Logbook</a></li>
<li id="strava"><a href="/rowers/workout/stravaimport/">Strava</a></li>
<li id="runkeeper"><a href="/rowers/workout/runkeeperimport/">RunKeeper</a></li>
<li id="sporttracks"><a href="/rowers/workout/sporttracksimport/">SportTracks</a></li>

View File

@@ -5,7 +5,7 @@
{% block title %}Workouts{% endblock %}
{% block main %}
<h1>Available on NK LiNK Logbook</h1>
<h1>Available on NK Logbook</h1>
{% if workouts %}
<ul class="main-content">
<li>

View File

@@ -12,7 +12,7 @@
Concept2 Logbook,
{% endif %}
{% if rower.nktoken is not None and rower.nktoken != '' %}
NK LiNK,
NK Logbook,
{% endif %}
{% if rower.sporttrackstoken is not None and rower.sporttrackstoken != '' %}
SportTracks,
@@ -74,7 +74,7 @@
choice or to renew the authorization.</p>
<p><a href="/rowers/me/stravaauthorize/"><img src="/static/img/ConnectWithStrava.png" alt="connect with strava" width="120"></a></p>
<p><a href="/rowers/me/c2authorize/"><img src="/static/img/blueC2logo.png" alt="connect with Concept2" width="120"></a></p>
<p><a href="/rowers/me/nkauthorize/"><img src="/static/img/NKLiNK.jpg" alt="connect with NK LiNK" width="120"></a></p>
<p><a href="/rowers/me/nkauthorize/"><img src="/static/img/NKLiNK.jpg" alt="connect with NK Logbook" width="120"></a></p>
<p><a href="/rowers/me/sporttracksauthorize/"><img src="/static/img/sporttracks-button.png" alt="connect with SportTracks" width="120"></a></p>
<p><a href="/rowers/me/runkeeperauthorize/"><img src="/static/img/rk-logo.png" alt="connect with RunKeeper" width="120"></a></p>
<p><a href="/rowers/me/underarmourauthorize/"><img src="/static/img/UAbtn.png" alt="connect with Under Armour" width="120"></a></p>

View File

@@ -111,6 +111,17 @@ class ChallengesTest(TestCase):
workouttype = 'water',
)
result = get_random_file(filename='rowers/tests/testdata/thyro.csv')
self.wthyro3 = WorkoutFactory(user=self.r2,
csvfilename=result['filename'],
starttime=result['starttime'],
startdatetime=result['startdatetime'],
duration=result['duration'],
distance=result['totaldist'],
workouttype = 'water',
)
self.wthyro2.startdatetime = arrow.get(nu).datetime
self.wthyro2.date = nu.date()
self.wthyro2.save()
@@ -164,6 +175,40 @@ class ChallengesTest(TestCase):
)
self.result.save()
self.FastestRace = VirtualRace(
name='Thyro 5K',
startdate=startdate,
preferreddate = startdate,
start_time = start_time,
enddate=enddate,
end_time=end_time,
sessionvalue=200,
comment='',
sessiontype = 'fastest_distance',
timezone=timezone_str,
evaluation_closure=evaluation_closure,
registration_closure=registration_closure,
contact_phone=contact_phone,
contact_email=contact_email,
manager=self.u,
)
self.FastestRace.save()
self.result = VirtualRaceResult(
userid = self.u2.id,
username = self.u2.username,
race = self.FastestRace,
distance = 300,
duration = datetime.time(0,1,20),
points = 75,
coursecompleted = True,
age = 28,
startsecond = 0,
endsecond = 120,
workoutid = self.wthyro3.id
)
self.result.save()
def tearDown(self):
for workout in self.user_workouts:
@@ -182,12 +227,12 @@ class ChallengesTest(TestCase):
lat_lon = (52.214229145558484, 6.890036546847821)
races = VirtualRace.objects.all()
traces = getnearestraces(lat_lon,races)
self.assertEqual(len(traces),1)
self.assertEqual(len(traces),2)
lat_lon = (0, 0)
races = VirtualRace.objects.all()
traces = getnearestraces(lat_lon,races)
self.assertEqual(len(traces),1)
self.assertEqual(len(traces),2)
def test_getnearestcourses(self):
lat_lon = (52.214229145558484, 6.890036546847821)
@@ -388,6 +433,72 @@ class ChallengesTest(TestCase):
self.assertEqual(response.status_code, 200)
def test_fastestrace_view(self):
login = self.c.login(username=self.u.username, password=self.password)
self.assertTrue(login)
race = self.FastestRace
if self.r.birthdate:
age = calculate_age(self.r.birthdate)
else:
age = 25
# look at event
url = reverse('virtualevent_view',kwargs={'id':race.id})
response = self.c.get(url)
self.assertEqual(response.status_code,200)
# register
url = reverse('virtualevent_register_view',kwargs={'id':race.id})
response = self.c.get(url)
self.assertEqual(response.status_code,200)
form_data = {
'teamname': 'ApeTeam',
'boatclass': 'water',
'boattype': '1x',
'weightcategory': 'hwt',
'adaptiveclass': 'None',
'age': age,
'mix': False,
'acceptsocialmedia': True,
}
form = VirtualRaceResultForm(form_data)
self.assertTrue(form.is_valid())
response = self.c.post(url,form_data,follow=True)
expected_url = reverse('virtualevent_view',kwargs={'id':race.id})
self.assertRedirects(response, expected_url=expected_url,
status_code=302,target_status_code=200)
self.assertEqual(response.status_code, 200)
# submit workout
url = reverse('virtualevent_submit_result_view',kwargs={'id':race.id,'workoutid':self.wthyro.id})
response = self.c.get(url)
self.assertEqual(response.status_code, 200)
records = IndoorVirtualRaceResult.objects.filter(userid=self.u.id)
self.assertEqual(len(records),1)
record = records[0]
form_data = {
'workouts':[self.wthyro.id],
'record':record.id,
}
response = self.c.post(url,form_data,follow=True)
self.assertRedirects(response, expected_url=expected_url,
status_code=302,target_status_code=200)
self.assertEqual(response.status_code, 200)
def test_virtualevents_view(self):
login = self.c.login(username=self.u.username, password=self.password)
self.assertTrue(login)
@@ -995,6 +1106,8 @@ class IndoorChallengesTest(TestCase):
self.assertEqual(response.url,expected)
@patch('rowers.views.racesviews.myqueue')
def test_virtualevent_view(self,mocked_myqueue):
login = self.c.login(username=self.u.username, password=self.password)

View File

@@ -296,6 +296,11 @@ class PlannedSessionTests(TestCase):
micro2 = plannedsessions.get_todays_micro(self.plan,thedate=datetime.date.today())
self.assertEqual(micro1.id,micro2.id)
def test_get_session_ids(self):
ids = plannedsessions.get_my_session_ids(self.r)
pss = PlannedSession.objects.filter(rower__in=[self.r])
self.assertEqual(len(ids),len(pss))
class DataPrepTests(TestCase):
def setUp(self):
self.u = UserFactory()

View File

@@ -393,7 +393,7 @@ def workout_sporttracks_upload_view(request,id=0):
return HttpResponseRedirect(url) # pragma: no cover
# NK LiNK authorization
# NK Logbook authorization
@login_required()
def rower_nk_authorize(request): # pragma: no cover
state = str(uuid4())

View File

@@ -3281,7 +3281,6 @@ def virtualevent_submit_result_view(request,id=0,workoutid=0):
if request.method == 'POST':
w_form = WorkoutRaceSelectForm(workoutdata,entries,request.POST)
if w_form.is_valid():
selectedworkout = w_form.cleaned_data['workouts']
splitsecond = 0