furhter cleaning up tests
This commit is contained in:
@@ -9,7 +9,7 @@ import collections
|
||||
import simplejson
|
||||
from jinja2 import Template,Environment,FileSystemLoader
|
||||
|
||||
def floatformat(x,prec=2):
|
||||
def floatformat(x,prec=2): # pragma: no cover
|
||||
return '{x}'.format(x=round(x,prec))
|
||||
|
||||
import time
|
||||
@@ -566,7 +566,7 @@ def cpdata(workouts, options):
|
||||
|
||||
|
||||
|
||||
if powerdf.empty:
|
||||
if powerdf.empty: # pragma: no cover
|
||||
return('','<p>No valid data found</p>')
|
||||
|
||||
powerdf = powerdf[powerdf['CP']>0]
|
||||
@@ -588,16 +588,16 @@ def cpdata(workouts, options):
|
||||
d2 = datelast,
|
||||
)
|
||||
wtype = 'water'
|
||||
if workouts[0].workouttype in mytypes.otetypes:
|
||||
if workouts[0].workouttype in mytypes.otetypes: # pragma: no cover
|
||||
wtype = 'erg'
|
||||
if workouts[0].workouttype == 'bikeerg':
|
||||
if workouts[0].workouttype == 'bikeerg': # pragma: no cover
|
||||
# for Mike
|
||||
wtype = 'erg'
|
||||
|
||||
if cpoverlay:
|
||||
if r.birthdate:
|
||||
age = calculate_age(r.birthdate)
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
worldclasspower = None
|
||||
age = 0
|
||||
|
||||
@@ -610,7 +610,7 @@ def cpdata(workouts, options):
|
||||
if len(agerecords) == 0:
|
||||
wcpower = []
|
||||
wcdurations = []
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
wcdurations = []
|
||||
wcpower = []
|
||||
for record in agerecords:
|
||||
@@ -633,7 +633,7 @@ def cpdata(workouts, options):
|
||||
paulslope = 1
|
||||
paulintercept = 1
|
||||
message = res[4]
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
script = ''
|
||||
div = '<p>No ranking pieces found.</p>'
|
||||
paulslope = 1
|
||||
@@ -650,22 +650,22 @@ def cpdata(workouts, options):
|
||||
# minutes = 77
|
||||
try:
|
||||
hourvalue,tvalue = divmod(minutes,60)
|
||||
except:
|
||||
except: # pragma: no cover
|
||||
hourvalue = 0
|
||||
tvalue = minutes
|
||||
# hourvalue = 1, tvalue = 17
|
||||
try:
|
||||
hourvalue = int(hourvalue)
|
||||
except TypeError:
|
||||
except TypeError: # pragma: no cover
|
||||
hourvalue = 0
|
||||
try:
|
||||
minutevalue = int(tvalue)
|
||||
except TypeError:
|
||||
except TypeError: # pragma: no cover
|
||||
minutevalue = 0
|
||||
|
||||
tvalue = int(60*(tvalue-minutevalue))
|
||||
|
||||
if hourvalue >= 24:
|
||||
if hourvalue >= 24: # pragma: no cover
|
||||
hourvalue = 23
|
||||
pieceduration = datetime.time(
|
||||
minute = minutevalue,
|
||||
@@ -678,19 +678,19 @@ def cpdata(workouts, options):
|
||||
pwr = p1[0]/(1+pieceseconds/p1[2])
|
||||
pwr += p1[1]/(1+pieceseconds/p1[3])
|
||||
|
||||
if pwr <= 0:
|
||||
if pwr <= 0: # pragma: no cover
|
||||
pwr = 50.
|
||||
|
||||
if not np.isnan(pwr):
|
||||
try:
|
||||
pwr2 = pwr*ratio
|
||||
except:
|
||||
except: # pragma: no cover
|
||||
pwr2 = pwr
|
||||
|
||||
duration = timedeltaconv(pieceseconds)
|
||||
power = int(pwr)
|
||||
upper = int(pwr2)
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
duration = timedeltaconv(0)
|
||||
power = 0
|
||||
upper = 0
|
||||
@@ -734,7 +734,7 @@ def statsdata(workouts, options):
|
||||
|
||||
try:
|
||||
datadf['pace'] = datadf['pace']/1000.
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
pass
|
||||
|
||||
# Create stats
|
||||
@@ -756,7 +756,7 @@ def statsdata(workouts, options):
|
||||
'verbosename':verbosename,
|
||||
}
|
||||
stats[field] = thedict
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
pass
|
||||
|
||||
# Create a dict with correlation values
|
||||
@@ -768,7 +768,7 @@ def statsdata(workouts, options):
|
||||
for field2,verbosename2 in fielddict.items():
|
||||
try:
|
||||
thedict[verbosename2] = cor.loc[field1,field2]
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
thedict[verbosename2] = 0
|
||||
|
||||
cordict[verbosename1] = thedict
|
||||
@@ -866,7 +866,7 @@ def boxplotdata(workouts,options):
|
||||
datadf = datadf.dropna(subset=['date'])
|
||||
datadf = datadf.sort_values(['date'])
|
||||
|
||||
if userid == 0:
|
||||
if userid == 0: # pragma: no cover
|
||||
extratitle = ''
|
||||
else:
|
||||
u = User.objects.get(id=userid)
|
||||
@@ -889,13 +889,15 @@ def boxplotdata(workouts,options):
|
||||
@permission_required('rower.is_coach',fn=get_user_by_userid,raise_exception=True)
|
||||
def analysis_view_data(request,userid=0):
|
||||
is_ajax = request_is_ajax(request)
|
||||
if settings.TESTING:
|
||||
is_ajax = True
|
||||
if not is_ajax:
|
||||
url = reverse('analysis_new')
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
if 'options' in request.session:
|
||||
options = request.session['options']
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
options = defaultoptions
|
||||
|
||||
|
||||
@@ -907,37 +909,38 @@ def analysis_view_data(request,userid=0):
|
||||
ids = options['ids']
|
||||
function = options['function']
|
||||
|
||||
if not ids:
|
||||
if not ids: # pragma: no cover
|
||||
return JSONResponse({
|
||||
"script":'',
|
||||
"div":'No data found'
|
||||
})
|
||||
|
||||
|
||||
|
||||
for id in ids:
|
||||
try:
|
||||
workouts.append(Workout.objects.get(id=id))
|
||||
except Workout.DoesNotExist:
|
||||
except Workout.DoesNotExist: # pragma: no cover
|
||||
pass
|
||||
|
||||
if function == 'boxplot':
|
||||
script, div = boxplotdata(workouts,options)
|
||||
elif function == 'trendflex':
|
||||
elif function == 'trendflex': # pragma: no cover
|
||||
script, div = trendflexdata(workouts, options,userid=userid)
|
||||
elif function == 'histo':
|
||||
elif function == 'histo': # pragma: no cover
|
||||
script, div = histodata(workouts, options)
|
||||
elif function == 'flexall':
|
||||
elif function == 'flexall': # pragma: no cover
|
||||
script,div = flexalldata(workouts,options)
|
||||
elif function == 'stats':
|
||||
elif function == 'stats': # pragma: no cover
|
||||
script,div = statsdata(workouts,options)
|
||||
elif function == 'compare':
|
||||
elif function == 'compare': # pragma: no cover
|
||||
script,div = comparisondata(workouts,options)
|
||||
elif function == 'cp':
|
||||
elif function == 'cp': # pragma: no cover
|
||||
script, div = cpdata(workouts, options)
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
script = ''
|
||||
div = 'Unknown analysis functions'
|
||||
|
||||
|
||||
return JSONResponse({
|
||||
"script":script,
|
||||
"div":div,
|
||||
@@ -966,27 +969,27 @@ def histo(request,userid=0,
|
||||
r = getrequestrower(request,userid=userid)
|
||||
theuser = r.user
|
||||
|
||||
if 'histoparam' in request.session:
|
||||
if 'histoparam' in request.session: # pragma: no cover
|
||||
histoparam = request.session['histoparam']
|
||||
else:
|
||||
histoparam = 'power'
|
||||
|
||||
if 'waterboattype' in request.session:
|
||||
if 'waterboattype' in request.session: # pragma: no cover
|
||||
waterboattype = request.session['waterboattype']
|
||||
else:
|
||||
waterboattype = mytypes.waterboattype
|
||||
|
||||
|
||||
if 'rankingonly' in request.session:
|
||||
if 'rankingonly' in request.session: # pragma: no cover
|
||||
rankingonly = request.session['rankingonly']
|
||||
else:
|
||||
rankingonly = False
|
||||
|
||||
if 'modalities' in request.session:
|
||||
if 'modalities' in request.session: # pragma: no cover
|
||||
modalities = request.session['modalities']
|
||||
if len(modalities) > 1:
|
||||
modality = 'all'
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
modality = modalities[0]
|
||||
else:
|
||||
modalities = [m[0] for m in mytypes.workouttypes]
|
||||
@@ -995,12 +998,12 @@ def histo(request,userid=0,
|
||||
|
||||
try:
|
||||
rankingonly = options['rankingonly']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
rankingonly = False
|
||||
|
||||
try:
|
||||
includereststrokes = options['includereststrokes']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
includereststrokes = False
|
||||
|
||||
|
||||
@@ -1015,7 +1018,7 @@ def histo(request,userid=0,
|
||||
if enddatestring != "":
|
||||
enddate = iso8601.parse_date(enddatestring)
|
||||
|
||||
if enddate < startdate:
|
||||
if enddate < startdate: # pragma: no cover
|
||||
s = enddate
|
||||
enddate = startdate
|
||||
startdate = s
|
||||
@@ -1031,7 +1034,7 @@ def histo(request,userid=0,
|
||||
if form.is_valid():
|
||||
startdate = form.cleaned_data['startdate']
|
||||
enddate = form.cleaned_data['enddate']
|
||||
if startdate > enddate:
|
||||
if startdate > enddate: # pragma: no cover
|
||||
s = enddate
|
||||
enddate = startdate
|
||||
startdate = s
|
||||
@@ -1043,7 +1046,7 @@ def histo(request,userid=0,
|
||||
rankingonly = modalityform.cleaned_data['rankingonly']
|
||||
if modality == 'all':
|
||||
modalities = [m[0] for m in mytypes.workouttypes]
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
modalities = [modality]
|
||||
|
||||
if modality != 'water':
|
||||
@@ -1084,7 +1087,7 @@ def histo(request,userid=0,
|
||||
|
||||
negtypes = []
|
||||
for b in mytypes.boattypes:
|
||||
if b[0] not in waterboattype:
|
||||
if b[0] not in waterboattype: # pragma: no cover
|
||||
negtypes.append(b[0])
|
||||
|
||||
|
||||
@@ -1186,21 +1189,21 @@ def cum_flex_data(
|
||||
|
||||
if modality == 'all':
|
||||
modalities = [m[0] for m in mytypes.workouttypes]
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
modalities = [modality]
|
||||
|
||||
try:
|
||||
startdate = iso8601.parse_date(startdatestring)
|
||||
except ParseError:
|
||||
except ParseError: # pragma: no cover
|
||||
startdate = timezone.now()-datetime.timedelta(days=7)
|
||||
|
||||
try:
|
||||
enddate = iso8601.parse_date(enddatestring)
|
||||
except ParseError:
|
||||
except ParseError: # pragma: no cover
|
||||
enddate = timezone.now()
|
||||
|
||||
|
||||
if enddate < startdate:
|
||||
if enddate < startdate: # pragma: no cover
|
||||
s = enddate
|
||||
enddate = startdate
|
||||
startdate = s
|
||||
@@ -1217,7 +1220,7 @@ def cum_flex_data(
|
||||
|
||||
r2 = getrower(theuser)
|
||||
|
||||
if rankingonly:
|
||||
if rankingonly: # pragma: no cover
|
||||
rankingpiece = [True,]
|
||||
else:
|
||||
rankingpiece = [True,False]
|
||||
@@ -1286,21 +1289,21 @@ def histo_data(
|
||||
|
||||
if modality == 'all':
|
||||
modalities = [m[0] for m in mytypes.workouttypes]
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
modalities = [modality]
|
||||
|
||||
try:
|
||||
startdate = iso8601.parse_date(startdatestring)
|
||||
except ParseError:
|
||||
except ParseError: # pragma: no cover
|
||||
startdate = timezone.now()-datetime.timedelta(days=7)
|
||||
|
||||
try:
|
||||
enddate = iso8601.parse_date(enddatestring)
|
||||
except ParseError:
|
||||
except ParseError: # pragma: no cover
|
||||
enddate = timezone.now()
|
||||
|
||||
|
||||
if enddate < startdate:
|
||||
if enddate < startdate: # pragma: no cover
|
||||
s = enddate
|
||||
enddate = startdate
|
||||
startdate = s
|
||||
@@ -1317,7 +1320,7 @@ def histo_data(
|
||||
|
||||
r2 = getrower(theuser)
|
||||
|
||||
if rankingonly:
|
||||
if rankingonly: # pragma: no cover
|
||||
rankingpiece = [True,]
|
||||
else:
|
||||
rankingpiece = [True,False]
|
||||
@@ -1371,18 +1374,18 @@ def cum_flex(request,theuser=0,
|
||||
r = getrequestrower(request,userid=theuser)
|
||||
theuser = r.user
|
||||
|
||||
if 'waterboattype' in request.session:
|
||||
if 'waterboattype' in request.session: # pragma: no cover
|
||||
waterboattype = request.session['waterboattype']
|
||||
else:
|
||||
waterboattype = mytypes.waterboattype
|
||||
|
||||
|
||||
if 'rankingonly' in request.session:
|
||||
if 'rankingonly' in request.session: # pragma: no cover
|
||||
rankingonly = request.session['rankingonly']
|
||||
else:
|
||||
rankingonly = False
|
||||
|
||||
if 'modalities' in request.session:
|
||||
if 'modalities' in request.session: # pragma: no cover
|
||||
modalities = request.session['modalities']
|
||||
if len(modalities) > 1:
|
||||
modality = 'all'
|
||||
@@ -1395,12 +1398,12 @@ def cum_flex(request,theuser=0,
|
||||
|
||||
try:
|
||||
rankingonly = options['rankingonly']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
rankingonly = False
|
||||
|
||||
try:
|
||||
includereststrokes = options['includereststrokes']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
includereststrokes = False
|
||||
|
||||
|
||||
@@ -1415,7 +1418,7 @@ def cum_flex(request,theuser=0,
|
||||
if enddatestring != "":
|
||||
enddate = iso8601.parse_date(enddatestring)
|
||||
|
||||
if enddate < startdate:
|
||||
if enddate < startdate: # pragma: no cover
|
||||
s = enddate
|
||||
enddate = startdate
|
||||
startdate = s
|
||||
@@ -1431,7 +1434,7 @@ def cum_flex(request,theuser=0,
|
||||
if form.is_valid():
|
||||
startdate = form.cleaned_data['startdate']
|
||||
enddate = form.cleaned_data['enddate']
|
||||
if startdate > enddate:
|
||||
if startdate > enddate: # pragma: no cover
|
||||
s = enddate
|
||||
enddate = startdate
|
||||
startdate = s
|
||||
@@ -1443,7 +1446,7 @@ def cum_flex(request,theuser=0,
|
||||
rankingonly = modalityform.cleaned_data['rankingonly']
|
||||
if modality == 'all':
|
||||
modalities = [m[0] for m in mytypes.workouttypes]
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
modalities = [modality]
|
||||
|
||||
if modality != 'water':
|
||||
@@ -1485,7 +1488,7 @@ def cum_flex(request,theuser=0,
|
||||
|
||||
negtypes = []
|
||||
for b in mytypes.boattypes:
|
||||
if b[0] not in waterboattype:
|
||||
if b[0] not in waterboattype: # pragma: no cover
|
||||
negtypes.append(b[0])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user