added a simple analysis test but should be altered
This commit is contained in:
@@ -33,6 +33,7 @@ from bs4 import BeautifulSoup
|
|||||||
from rowers.ownapistuff import *
|
from rowers.ownapistuff import *
|
||||||
from rowers.views.apiviews import *
|
from rowers.views.apiviews import *
|
||||||
from rowers.teams import add_member, add_coach
|
from rowers.teams import add_member, add_coach
|
||||||
|
from rowers.views.analysisviews import histodata
|
||||||
|
|
||||||
class TeamFactory(factory.DjangoModelFactory):
|
class TeamFactory(factory.DjangoModelFactory):
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -305,6 +306,96 @@ class StravaPrivacy(TestCase):
|
|||||||
self.assertEqual(w.privacy,'hidden')
|
self.assertEqual(w.privacy,'hidden')
|
||||||
|
|
||||||
|
|
||||||
|
# test some analysis, should only use the workouts with workoutsource != strava
|
||||||
|
@patch('rowers.dataprep.read_data', side_effect=mocked_read_data)
|
||||||
|
def test_workouts_analysis(self, mocked_read_data):
|
||||||
|
login = self.c.login(username=self.u.username, password=self.password)
|
||||||
|
self.assertTrue(login)
|
||||||
|
|
||||||
|
url = '/rowers/history/'
|
||||||
|
response = self.c.get(url)
|
||||||
|
self.assertEqual(response.status_code,200)
|
||||||
|
|
||||||
|
url = '/rowers/history/data/'
|
||||||
|
response = self.c.get(url)
|
||||||
|
self.assertEqual(response.status_code,200)
|
||||||
|
# response.json() has a key "script" with a javascript script
|
||||||
|
# check if this is correct
|
||||||
|
self.assertTrue('script' in response.json())
|
||||||
|
|
||||||
|
# now check histogram
|
||||||
|
startdate = (self.user_workouts[0].startdatetime-datetime.timedelta(days=3)).date()
|
||||||
|
enddate = (self.user_workouts[0].startdatetime+datetime.timedelta(days=3)).date()
|
||||||
|
|
||||||
|
# make sure the dates are not naive
|
||||||
|
try:
|
||||||
|
startdate = pytz.utc.localize(startdate)
|
||||||
|
except (ValueError, AttributeError):
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
enddate = pytz.utc.localize(enddate)
|
||||||
|
except (ValueError, AttributeError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
form_data = {
|
||||||
|
'function':'histo',
|
||||||
|
'xparam':'hr',
|
||||||
|
'plotfield':'spm',
|
||||||
|
'yparam':'pace',
|
||||||
|
'groupby':'spm',
|
||||||
|
'palette':'monochrome_blue',
|
||||||
|
'xaxis':'time',
|
||||||
|
'yaxis1':'power',
|
||||||
|
'yaxis2':'hr',
|
||||||
|
'startdate':startdate,
|
||||||
|
'enddate':enddate,
|
||||||
|
'plottype':'scatter',
|
||||||
|
'spmmin':15,
|
||||||
|
'spmmax':55,
|
||||||
|
'workmin':0,
|
||||||
|
'workmax':1500,
|
||||||
|
'includereststrokes':False,
|
||||||
|
'modality':'all',
|
||||||
|
'waterboattype':['1x','2x','4x'],
|
||||||
|
'userid':self.u.id,
|
||||||
|
'workouts':[w.id for w in Workout.objects.filter(user=self.r)],
|
||||||
|
}
|
||||||
|
|
||||||
|
form = AnalysisChoiceForm(form_data)
|
||||||
|
optionsform = AnalysisOptionsForm(form_data)
|
||||||
|
dateform = DateRangeForm(form_data)
|
||||||
|
|
||||||
|
result = form.is_valid()
|
||||||
|
if not result:
|
||||||
|
print(form.errors)
|
||||||
|
|
||||||
|
self.assertTrue(form.is_valid())
|
||||||
|
self.assertTrue(optionsform.is_valid())
|
||||||
|
self.assertTrue(dateform.is_valid())
|
||||||
|
|
||||||
|
response = self.c.post('/rowers/user-analysis-select/',form_data)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code,200)
|
||||||
|
|
||||||
|
# get data from histodata function
|
||||||
|
ws = Workout.objects.filter(user=self.r)
|
||||||
|
|
||||||
|
script, div = histodata(ws,form_data)
|
||||||
|
# script has a line starting with 'data = [ ... ]'
|
||||||
|
# we need to get that line
|
||||||
|
data = [line for line in script.split('\n') if line.startswith('data = [')][0]
|
||||||
|
# the line should be a list of float values
|
||||||
|
self.assertTrue(data.startswith('data = ['))
|
||||||
|
self.assertTrue(data.endswith(']'))
|
||||||
|
# count the number of commas between the brackets
|
||||||
|
self.assertEqual(data.count(','),1377)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# try and fail to submit a workout with workoutsource = strava to a challenge
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class OwnApi(TestCase):
|
class OwnApi(TestCase):
|
||||||
|
|||||||
@@ -2276,6 +2276,8 @@ def history_view_data(request, userid=0):
|
|||||||
ddf = ddf.with_columns(pl.col("time").diff().clip(lower_bound=0).alias("deltat"))
|
ddf = ddf.with_columns(pl.col("time").diff().clip(lower_bound=0).alias("deltat"))
|
||||||
except KeyError: # pragma: no cover
|
except KeyError: # pragma: no cover
|
||||||
pass
|
pass
|
||||||
|
except ColumnNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
ddf = dataprep.clean_df_stats_pl(ddf, workstrokesonly=False,
|
ddf = dataprep.clean_df_stats_pl(ddf, workstrokesonly=False,
|
||||||
ignoreadvanced=True)
|
ignoreadvanced=True)
|
||||||
@@ -2288,6 +2290,8 @@ def history_view_data(request, userid=0):
|
|||||||
ddict['hrmax'] = int(ddf['hr'].max())
|
ddict['hrmax'] = int(ddf['hr'].max())
|
||||||
except (KeyError, ValueError, AttributeError): # pragma: no cover
|
except (KeyError, ValueError, AttributeError): # pragma: no cover
|
||||||
ddict['hrmax'] = 0
|
ddict['hrmax'] = 0
|
||||||
|
except ColumnNotFoundError:
|
||||||
|
ddict['hrmax'] = 0
|
||||||
|
|
||||||
ddict['powermean'] = int(wavg(ddf, 'power', 'deltat'))
|
ddict['powermean'] = int(wavg(ddf, 'power', 'deltat'))
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user