f
This commit is contained in:
@@ -1900,9 +1900,6 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7,
|
||||
df['date'] = df.index.values
|
||||
|
||||
|
||||
#for row in df.iterrows():
|
||||
# print(row)
|
||||
|
||||
source = ColumnDataSource(
|
||||
data = dict(
|
||||
testpower = df['testpower'],
|
||||
@@ -3141,7 +3138,8 @@ def interactive_agegroupcpchart(age,normalized=False):
|
||||
mlduration.append(duration)
|
||||
mlpower.append(worldclasspower)
|
||||
except ZeroDivisionError:
|
||||
pass
|
||||
mlduration.append(duration)
|
||||
mlpower.append(np.nan)
|
||||
for duration in durations:
|
||||
worldclasspower = c2stuff.getagegrouprecord(
|
||||
age,
|
||||
@@ -3155,7 +3153,8 @@ def interactive_agegroupcpchart(age,normalized=False):
|
||||
mlduration.append(60.*duration)
|
||||
mlpower.append(worldclasspower)
|
||||
except ValueError: # pragma: no cover
|
||||
pass
|
||||
mlduration.append(60.*duration)
|
||||
mlpower.append(np.nan)
|
||||
|
||||
|
||||
mhduration = []
|
||||
@@ -3174,7 +3173,8 @@ def interactive_agegroupcpchart(age,normalized=False):
|
||||
mhduration.append(duration)
|
||||
mhpower.append(worldclasspower)
|
||||
except ZeroDivisionError:
|
||||
pass
|
||||
mhduration.append(duration)
|
||||
mhpower.append(np.nan)
|
||||
for duration in durations:
|
||||
worldclasspower = c2stuff.getagegrouprecord(
|
||||
age,
|
||||
@@ -3188,7 +3188,8 @@ def interactive_agegroupcpchart(age,normalized=False):
|
||||
mhduration.append(60.*duration)
|
||||
mhpower.append(worldclasspower)
|
||||
except ValueError: # pragma: no cover
|
||||
pass
|
||||
mhduration.append(60.*duration)
|
||||
mhpower.append(np.nan)
|
||||
|
||||
|
||||
|
||||
@@ -3247,23 +3248,43 @@ def interactive_agegroupcpchart(age,normalized=False):
|
||||
|
||||
|
||||
|
||||
source = ColumnDataSource(
|
||||
sourcemh = ColumnDataSource(
|
||||
data = dict(
|
||||
mhduration = mhduration,
|
||||
mhpower = mhpower,
|
||||
)
|
||||
)
|
||||
|
||||
sourcefl = ColumnDataSource(
|
||||
data = dict(
|
||||
flduration = flduration,
|
||||
flpower = flpower,
|
||||
)
|
||||
)
|
||||
|
||||
sourcefh = ColumnDataSource(
|
||||
data = dict(
|
||||
fhduration = fhduration,
|
||||
fhpower = fhpower,
|
||||
)
|
||||
)
|
||||
|
||||
sourceml = ColumnDataSource(
|
||||
data = dict(
|
||||
mlduration = mlduration,
|
||||
mlpower = mlpower,
|
||||
)
|
||||
)
|
||||
|
||||
sourcefit = ColumnDataSource(
|
||||
data = dict(
|
||||
duration = fitt,
|
||||
fitpowerfh = fitpowerfh,
|
||||
fitpowerfl = fitpowerfl,
|
||||
fitpowerml = fitpowerml,
|
||||
fitpowermh = fitpowermh,
|
||||
flduration = flduration,
|
||||
flpower = flpower,
|
||||
fhduration = fhduration,
|
||||
fhpower = fhpower,
|
||||
mlduration = mlduration,
|
||||
mlpower = mlpower,
|
||||
mhduration = mhduration,
|
||||
mhpower = mhpower,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
x_axis_type = 'log'
|
||||
y_axis_type = 'linear'
|
||||
@@ -3274,28 +3295,28 @@ def interactive_agegroupcpchart(age,normalized=False):
|
||||
tools=TOOLS)
|
||||
plot.sizing_mode = 'stretch_both'
|
||||
|
||||
plot.line('duration','fitpowerfh',source=source,
|
||||
plot.line('duration','fitpowerfh',source=sourcefit,
|
||||
legend_label='Female HW',color='blue')
|
||||
plot.line('duration','fitpowerfl',source=source,
|
||||
plot.line('duration','fitpowerfl',source=sourcefit,
|
||||
legend_label='Female LW',color='red')
|
||||
|
||||
plot.line('duration','fitpowerml',source=source,
|
||||
plot.line('duration','fitpowerml',source=sourcefit,
|
||||
legend_label='Male LW',color='green')
|
||||
|
||||
plot.line('duration','fitpowermh',source=source,
|
||||
plot.line('duration','fitpowermh',source=sourcefit,
|
||||
legend_label='Male HW',color='orange')
|
||||
|
||||
|
||||
plot.circle('flduration','flpower',source=source,
|
||||
plot.circle('flduration','flpower',source=sourcefl,
|
||||
fill_color='red',size=15)
|
||||
|
||||
plot.circle('fhduration','fhpower',source=source,
|
||||
plot.circle('fhduration','fhpower',source=sourcefh,
|
||||
fill_color='blue',size=15)
|
||||
|
||||
plot.circle('mlduration','mlpower',source=source,
|
||||
plot.circle('mlduration','mlpower',source=sourceml,
|
||||
fill_color='green',size=15)
|
||||
|
||||
plot.circle('mhduration','mhpower',source=source,
|
||||
plot.circle('mhduration','mhpower',source=sourcemh,
|
||||
fill_color='orange',size=15)
|
||||
|
||||
plot.title.text = 'age '+str(age)
|
||||
@@ -3400,16 +3421,23 @@ def interactive_otwcpchart(powerdf,promember=0,rowername="",r=None,cpfit='data',
|
||||
CPmax = ratio*fitpower,
|
||||
duration = fitt/60.,
|
||||
ftime = ftime,
|
||||
workout = workouts,
|
||||
# workout = workouts,
|
||||
fitpowerwc = fitpowerwc,
|
||||
fitpowerexcellent = fitpowerexcellent,
|
||||
fitpowergood = fitpowergood,
|
||||
fitpowerfair = fitpowerfair,
|
||||
fitpoweraverage = fitpoweraverage,
|
||||
url = urls,
|
||||
# url = urls,
|
||||
)
|
||||
)
|
||||
|
||||
sourceannot= ColumnDataSource(
|
||||
data = dict(
|
||||
workout = workouts,
|
||||
url = urls,
|
||||
)
|
||||
)
|
||||
|
||||
# making the plot
|
||||
plot = Figure(tools=TOOLS,x_axis_type=x_axis_type,
|
||||
plot_width=900,
|
||||
@@ -3544,13 +3572,20 @@ def interactive_agegroup_plot(df,distance=2000,duration=None,
|
||||
data = dict(
|
||||
age = age,
|
||||
power = power,
|
||||
age2 = age2,
|
||||
expo_vals = expo_vals,
|
||||
#age2 = age2,
|
||||
#expo_vals = expo_vals,
|
||||
season = season,
|
||||
name=name,
|
||||
)
|
||||
)
|
||||
|
||||
sourcefit = ColumnDataSource(
|
||||
data = dict(
|
||||
age2 = age2,
|
||||
expo_vals = expo_vals,
|
||||
)
|
||||
)
|
||||
|
||||
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair'
|
||||
|
||||
plot = Figure(tools=TOOLS,plot_width=900)
|
||||
@@ -3558,7 +3593,7 @@ def interactive_agegroup_plot(df,distance=2000,duration=None,
|
||||
plot.circle('age','power',source=source,fill_color='red',size=15,
|
||||
legend_label='World Record')
|
||||
|
||||
plot.line(age2,expo_vals)
|
||||
plot.line('age2','expo_vals',source=sourcefit)
|
||||
plot.xaxis.axis_label = "Age"
|
||||
plot.yaxis.axis_label = "Concept2 power"
|
||||
plot.title.text = plottitle
|
||||
|
||||
@@ -16,7 +16,7 @@ except NameError:
|
||||
import pytest
|
||||
|
||||
import warnings
|
||||
warnings.filterwarnings("error",category=UserWarning)
|
||||
#warnings.filterwarnings("error",category=UserWarning)
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from .statements import *
|
||||
nu = datetime.datetime.now()
|
||||
|
||||
from rowers.views import *
|
||||
from rowers.views.analysisviews import histodata
|
||||
|
||||
class WorkoutCompareTest(TestCase):
|
||||
def setUp(self):
|
||||
@@ -1360,7 +1361,7 @@ class WorkoutStatsTestNew(TestCase):
|
||||
|
||||
script, div = boxplotdata(workouts,options)
|
||||
script, div = trendflexdata(workouts,options)
|
||||
# script, div = histodata(workouts,options)
|
||||
script, div = histodata(workouts,options)
|
||||
script, div = flexalldata(workouts,options)
|
||||
script, div = statsdata(workouts,options)
|
||||
script, div = comparisondata(workouts,options)
|
||||
|
||||
@@ -216,6 +216,9 @@ class ViewTest(TestCase):
|
||||
}
|
||||
|
||||
form = DocumentsForm(form_data,file_data)
|
||||
if not form.is_valid():
|
||||
print(form.errors)
|
||||
self.assertTrue(form.is_valid())
|
||||
|
||||
response = self.c.post('/rowers/workout/upload/', form_data, follow=True)
|
||||
|
||||
|
||||
@@ -1108,3 +1108,10 @@ def strfdelta(tdelta):
|
||||
)
|
||||
|
||||
return res
|
||||
|
||||
def request_is_ajax(request):
|
||||
is_ajax = request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
|
||||
if settings.TESTING:
|
||||
is_ajax = True
|
||||
|
||||
return is_ajax
|
||||
|
||||
@@ -44,7 +44,7 @@ def analysis_new(request,userid=0,function='boxplot',teamid=0,id=''):
|
||||
firstworkout = None
|
||||
if id:
|
||||
firstworkout = get_workout(id)
|
||||
if not is_workout_team(request.user,firstworkout):
|
||||
if not is_workout_team(request.user,firstworkout): # pragma: no cover
|
||||
raise PermissionDenied("You are not allowed to use this workout")
|
||||
firstworkoutquery = Workout.objects.filter(id=encoder.decode_hex(id))
|
||||
|
||||
@@ -62,7 +62,7 @@ def analysis_new(request,userid=0,function='boxplot',teamid=0,id=''):
|
||||
options['userid'] = userid
|
||||
try:
|
||||
workouttypes = options['workouttypes']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
workouttypes = ['rower','dynamic','slides']
|
||||
|
||||
try:
|
||||
@@ -80,12 +80,12 @@ def analysis_new(request,userid=0,function='boxplot',teamid=0,id=''):
|
||||
|
||||
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
|
||||
|
||||
if 'startdate' in request.session:
|
||||
@@ -93,7 +93,7 @@ def analysis_new(request,userid=0,function='boxplot',teamid=0,id=''):
|
||||
else:
|
||||
startdate=timezone.now()-datetime.timedelta(days=42)
|
||||
|
||||
if function not in [c[0] for c in analysischoices]:
|
||||
if function not in [c[0] for c in analysischoices]: # pragma: no cover
|
||||
function = 'boxplot'
|
||||
|
||||
if 'enddate' in request.session:
|
||||
@@ -124,7 +124,7 @@ def analysis_new(request,userid=0,function='boxplot',teamid=0,id=''):
|
||||
waterboattype = optionsform.cleaned_data['waterboattype']
|
||||
if modality == 'all':
|
||||
modalities = [m[0] for m in mytypes.workouttypes]
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
modalities = [modality]
|
||||
if modality != 'water':
|
||||
waterboattype = [b[0] for b in mytypes.boattypes]
|
||||
@@ -132,7 +132,7 @@ def analysis_new(request,userid=0,function='boxplot',teamid=0,id=''):
|
||||
|
||||
if 'rankingonly' in optionsform.cleaned_data:
|
||||
rankingonly = optionsform.cleaned_data['rankingonly']
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
rankingonly = False
|
||||
|
||||
options['modalities'] = modalities
|
||||
@@ -156,7 +156,7 @@ def analysis_new(request,userid=0,function='boxplot',teamid=0,id=''):
|
||||
selectedworkouts = cd['workouts']
|
||||
ids = [int(w.id) for w in selectedworkouts]
|
||||
options['ids'] = ids
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
ids = []
|
||||
options['ids'] = ids
|
||||
else:
|
||||
@@ -170,14 +170,14 @@ def analysis_new(request,userid=0,function='boxplot',teamid=0,id=''):
|
||||
|
||||
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])
|
||||
|
||||
|
||||
startdate = datetime.datetime.combine(startdate,datetime.time())
|
||||
enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59))
|
||||
|
||||
if enddate < startdate:
|
||||
if enddate < startdate: # pragma: no cover
|
||||
s = enddate
|
||||
enddate = startdate
|
||||
startdate = s
|
||||
@@ -185,27 +185,27 @@ def analysis_new(request,userid=0,function='boxplot',teamid=0,id=''):
|
||||
# make sure the dates are not naive
|
||||
try:
|
||||
startdate = pytz.utc.localize(startdate)
|
||||
except (ValueError, AttributeError):
|
||||
except (ValueError, AttributeError): # pragma: no cover
|
||||
pass
|
||||
try:
|
||||
enddate = pytz.utc.localize(enddate)
|
||||
except (ValueError, AttributeError):
|
||||
except (ValueError, AttributeError): # pragma: no cover
|
||||
pass
|
||||
|
||||
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])
|
||||
|
||||
|
||||
|
||||
if theteam is not None and (theteam.viewing == 'allmembers' or theteam.manager == request.user):
|
||||
if theteam is not None and (theteam.viewing == 'allmembers' or theteam.manager == request.user): # pragma: no cover
|
||||
workouts = Workout.objects.filter(team=theteam,
|
||||
startdatetime__gte=startdate,
|
||||
startdatetime__lte=enddate,
|
||||
workouttype__in=modalities,
|
||||
)
|
||||
elif theteam is not None and theteam.viewing == 'coachonly':
|
||||
elif theteam is not None and theteam.viewing == 'coachonly': # pragma: no cover
|
||||
workouts = Workout.objects.filter(team=theteam,user=r,
|
||||
startdatetime__gte=startdate,
|
||||
startdatetime__lte=enddate,
|
||||
@@ -224,11 +224,11 @@ def analysis_new(request,userid=0,function='boxplot',teamid=0,id=''):
|
||||
).exclude(boattype__in=negtypes)
|
||||
|
||||
|
||||
if rankingonly:
|
||||
if rankingonly: # pragma: no cover
|
||||
workouts = workouts.exclude(rankingpiece=False)
|
||||
|
||||
query = request.POST.get('q')
|
||||
if query:
|
||||
if query: # pragma: no cover
|
||||
query_list = query.split()
|
||||
try:
|
||||
workouts = workouts.filter(
|
||||
@@ -334,7 +334,7 @@ def trendflexdata(workouts, options,userid=0):
|
||||
# prepare data frame
|
||||
datadf,extracols = dataprep.read_cols_df_sql(ids,fieldlist)
|
||||
|
||||
if xparam == groupby:
|
||||
if xparam == groupby: # pragma: no cover
|
||||
datadf['groupby'] = datadf[xparam]
|
||||
groupy = 'groupby'
|
||||
|
||||
@@ -376,9 +376,9 @@ def trendflexdata(workouts, options,userid=0):
|
||||
datadf[groupby].max()+binsize,
|
||||
binsize)
|
||||
groups = datadf.groupby(pd.cut(datadf[groupby],bins,labels=False))
|
||||
except (ValueError, AttributeError):
|
||||
except (ValueError, AttributeError): # pragma: no cover
|
||||
return ('','Error: not enough data')
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
bins = np.arange(datadf['days ago'].min()-binsize,
|
||||
datadf['days ago'].max()+binsize,
|
||||
binsize,
|
||||
@@ -407,7 +407,7 @@ def trendflexdata(workouts, options,userid=0):
|
||||
yerror.dropna(inplace=True)
|
||||
groupsize.dropna(inplace=True)
|
||||
|
||||
if len(groupsize) == 0:
|
||||
if len(groupsize) == 0: # pragma: no cover
|
||||
messages.error(request,'No data in selection')
|
||||
url = reverse(user_multiflex_select)
|
||||
return HttpResponseRedirect(url)
|
||||
@@ -436,15 +436,15 @@ def trendflexdata(workouts, options,userid=0):
|
||||
df['groupval'].loc[mask] = np.nan
|
||||
|
||||
groupcols = df['groupval']
|
||||
except (ValueError, AttributeError):
|
||||
except (ValueError, AttributeError): # pragma: no cover
|
||||
df['groupval'] = groups.mean()[groupby].fillna(value=0)
|
||||
df['groupval'].loc[mask] = np.nan
|
||||
groupcols = df['groupval']
|
||||
except KeyError:
|
||||
except KeyError: # pragma: no cover
|
||||
messages.error(request,'Data selection error')
|
||||
url = reverse(user_multiflex_select)
|
||||
return HttpResponseRedirect(url)
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
try:
|
||||
dates = groups.min()[groupby]
|
||||
dates.loc[mask] = np.nan
|
||||
@@ -459,7 +459,7 @@ def trendflexdata(workouts, options,userid=0):
|
||||
|
||||
groupcols = (groupcols-groupcols.min())/(groupcols.max()-groupcols.min())
|
||||
|
||||
if aantal == 1:
|
||||
if aantal == 1: # pragma: no cover
|
||||
groupcols = np.array([1.])
|
||||
|
||||
|
||||
@@ -471,7 +471,7 @@ def trendflexdata(workouts, options,userid=0):
|
||||
legcolors = range_to_color_hex(clegendx,palette=palette)
|
||||
if groupby != 'date':
|
||||
clegendy = df['groupval'].min()+clegendx*(df['groupval'].max()-df['groupval'].min())
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
clegendy = df.index.min()+clegendx*(df.index.max()-df.index.min())
|
||||
|
||||
|
||||
@@ -481,7 +481,7 @@ def trendflexdata(workouts, options,userid=0):
|
||||
|
||||
if userid == 0:
|
||||
extratitle = ''
|
||||
else:
|
||||
else: # pragma: no cover
|
||||
u = User.objects.get(id=userid)
|
||||
extratitle = ' '+u.first_name+' '+u.last_name
|
||||
|
||||
@@ -888,7 +888,8 @@ def boxplotdata(workouts,options):
|
||||
redirect_field_name=None)
|
||||
@permission_required('rower.is_coach',fn=get_user_by_userid,raise_exception=True)
|
||||
def analysis_view_data(request,userid=0):
|
||||
if not request.is_ajax():
|
||||
is_ajax = request_is_ajax(request)
|
||||
if not is_ajax:
|
||||
url = reverse('analysis_new')
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
@@ -1581,9 +1582,7 @@ def goldmedalscores_view(request,userid=0,
|
||||
startdate=timezone.now()-timezone.timedelta(days=365),
|
||||
enddate=timezone.now()):
|
||||
|
||||
is_ajax = False
|
||||
if request.is_ajax():
|
||||
is_ajax = True
|
||||
is_ajax = request_is_ajax(request)
|
||||
|
||||
therower = getrequestrower(request,userid=userid)
|
||||
theuser = therower.user
|
||||
@@ -1649,9 +1648,7 @@ def performancemanager_view(request,userid=0,mode='rower',
|
||||
startdate=timezone.now()-timezone.timedelta(days=365),
|
||||
enddate=timezone.now()):
|
||||
|
||||
is_ajax = False
|
||||
if request.is_ajax():
|
||||
is_ajax = True
|
||||
is_ajax = request_is_ajax(request)
|
||||
|
||||
|
||||
therower = getrequestrower(request,userid=userid)
|
||||
@@ -4914,7 +4911,8 @@ def alert_report_view(request,id=0,userid=0,nperiod=0):
|
||||
|
||||
stats = alert_get_stats(alert,nperiod=nperiod)
|
||||
|
||||
if request.is_ajax():
|
||||
is_ajax = request_is_ajax(request)
|
||||
if not is_ajax:
|
||||
return JSONResponse({
|
||||
"stats":stats,
|
||||
})
|
||||
|
||||
@@ -1197,7 +1197,8 @@ from rowers.utils import (
|
||||
geo_distance,serialize_list,deserialize_list,uniqify,
|
||||
str2bool,range_to_color_hex,absolute,myqueue,get_call,
|
||||
calculate_age,rankingdistances,rankingdurations,
|
||||
is_ranking_piece,my_dict_from_instance,wavg,NoTokenError
|
||||
is_ranking_piece,my_dict_from_instance,wavg,NoTokenError,
|
||||
request_is_ajax
|
||||
)
|
||||
|
||||
import rowers.datautils as datautils
|
||||
|
||||
@@ -4586,9 +4586,8 @@ def workout_map_view(request,id=0):
|
||||
# Image upload
|
||||
@permission_required('workout.change_workout',fn=get_workout_by_opaqueid,raise_exception=True)
|
||||
def workout_uploadimage_view(request,id): # pragma: no cover
|
||||
is_ajax = False # pragma: no cover
|
||||
if request.is_ajax():
|
||||
is_ajax = True
|
||||
is_ajax = request_is_ajax(request)
|
||||
|
||||
|
||||
r = getrower(request.user)
|
||||
|
||||
@@ -4727,9 +4726,8 @@ def workout_add_chart_view(request,id,plotnr=1):
|
||||
@login_required
|
||||
@permission_required('workout.change_workout',fn=get_workout_by_opaqueid,raise_exception=True)
|
||||
def workout_toggle_ranking(request,id=0):
|
||||
is_ajax = False
|
||||
if request.is_ajax(): # pragma: no cover
|
||||
is_ajax = True
|
||||
is_ajax = request_is_ajax(request)
|
||||
|
||||
|
||||
row = get_workout_by_opaqueid(request,id)
|
||||
|
||||
@@ -4980,9 +4978,7 @@ def workout_upload_view(request,
|
||||
},
|
||||
raceid=0):
|
||||
|
||||
is_ajax = False
|
||||
if request.is_ajax(): # pragma: no cover
|
||||
is_ajax = True
|
||||
is_ajax = request_is_ajax(request)
|
||||
|
||||
r = getrower(request.user)
|
||||
if r.rowerplan == 'freecoach': # pragma: no cover
|
||||
|
||||
Reference in New Issue
Block a user