moved user and workout permission checks to rules
updated workoutviews, rest of views not done doesn't pass tests
This commit is contained in:
@@ -109,7 +109,7 @@ def get_call():
|
||||
</p>
|
||||
</div>
|
||||
""" % (call1, call2)
|
||||
|
||||
|
||||
return call
|
||||
|
||||
def absolute(request):
|
||||
@@ -131,7 +131,7 @@ def trcolors(r1,g1,b1,r2,g2,b2):
|
||||
h1,s1,v1 = colorsys.rgb_to_hsv(r1,g1,b1)
|
||||
h2,s2,v2 = colorsys.rgb_to_hsv(r2,g2,b2)
|
||||
|
||||
|
||||
|
||||
return 360*h1,360*(h2-h1),s1,(s2-s1),v1,(v2-v1)
|
||||
|
||||
palettes = {
|
||||
@@ -167,7 +167,7 @@ def is_ranking_piece(workout):
|
||||
return True
|
||||
elif workout.duration in rankingdurations:
|
||||
return True
|
||||
|
||||
|
||||
return False
|
||||
|
||||
def range_to_color_hex(groupcols,palette='monochrome_blue'):
|
||||
@@ -176,20 +176,20 @@ def range_to_color_hex(groupcols,palette='monochrome_blue'):
|
||||
plt = palettes[palette]
|
||||
except KeyError:
|
||||
plt = palettes['monochrome_blue']
|
||||
|
||||
|
||||
rgb = [colorsys.hsv_to_rgb((plt[0]+plt[1]*x)/360.,
|
||||
plt[2]+plt[3]*x,
|
||||
plt[4]+plt[5]*x) for x in groupcols]
|
||||
|
||||
RGB = [(int(255.*r),int(255.*g),int(255.*b)) for (r, g, b) in rgb]
|
||||
colors = ["#%02x%02x%02x" % (r, g, b) for (r, g, b) in RGB]
|
||||
|
||||
|
||||
return colors
|
||||
|
||||
def str2bool(v):
|
||||
return v.lower() in ("yes", "true", "t", "1")
|
||||
|
||||
def uniqify(seq, idfun=None):
|
||||
def uniqify(seq, idfun=None):
|
||||
# order preserving
|
||||
if idfun is None:
|
||||
def idfun(x): return x
|
||||
@@ -222,12 +222,12 @@ def geo_distance(lat1,lon1,lat2,lon2):
|
||||
This is a slight underestimate but is close enough for our purposes,
|
||||
We're never moving more than 10 meters between trackpoints
|
||||
|
||||
Bearing calculation fails if one of the points is a pole.
|
||||
(Hey, from the North pole you can walk South, East, North and end up
|
||||
Bearing calculation fails if one of the points is a pole.
|
||||
(Hey, from the North pole you can walk South, East, North and end up
|
||||
on the same spot!)
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
||||
# radius of our earth in km --> should be moved to settings if
|
||||
# rowing takes off on other planets
|
||||
R = 6373.0
|
||||
@@ -257,7 +257,7 @@ def geo_distance(lat1,lon1,lat2,lon2):
|
||||
|
||||
return [distance,bearing]
|
||||
|
||||
|
||||
|
||||
|
||||
def isbreakthrough(delta,cpvalues,p0,p1,p2,p3,ratio):
|
||||
pwr = abs(p0)/(1+(delta/abs(p2)))
|
||||
@@ -268,7 +268,7 @@ def isbreakthrough(delta,cpvalues,p0,p1,p2,p3,ratio):
|
||||
|
||||
pwr *= ratio
|
||||
|
||||
|
||||
|
||||
delta = delta.values.astype(int)
|
||||
cpvalues = cpvalues.values.astype(int)
|
||||
pwr = pwr.astype(int)
|
||||
@@ -276,7 +276,7 @@ def isbreakthrough(delta,cpvalues,p0,p1,p2,p3,ratio):
|
||||
res = np.sum(cpvalues>pwr)
|
||||
res2 = np.sum(cpvalues>pwr2)
|
||||
|
||||
|
||||
|
||||
btdf = pd.DataFrame(
|
||||
{
|
||||
'delta':delta[cpvalues>pwr],
|
||||
@@ -288,7 +288,7 @@ def isbreakthrough(delta,cpvalues,p0,p1,p2,p3,ratio):
|
||||
|
||||
btdf.sort_values('delta',axis=0,inplace=True)
|
||||
|
||||
|
||||
|
||||
return res>1,btdf,res2>1
|
||||
|
||||
|
||||
@@ -300,7 +300,7 @@ def myqueue(queue,function,*args,**kwargs):
|
||||
|
||||
def revoke(self):
|
||||
return 1
|
||||
|
||||
|
||||
if settings.TESTING:
|
||||
return MockJob()
|
||||
elif settings.CELERY:
|
||||
@@ -310,7 +310,7 @@ def myqueue(queue,function,*args,**kwargs):
|
||||
else:
|
||||
if settings.DEBUG:
|
||||
kwargs['debug'] = True
|
||||
|
||||
|
||||
job_id = str(uuid.uuid4())
|
||||
kwargs['job_id'] = job_id
|
||||
kwargs['jobkey'] = job_id
|
||||
@@ -335,7 +335,7 @@ def my_dict_from_instance(instance,model):
|
||||
thedict['id'] = instance.id
|
||||
|
||||
for f in instance._meta.fields:
|
||||
|
||||
|
||||
fname = f.name
|
||||
|
||||
try:
|
||||
@@ -405,24 +405,13 @@ def totaltime_sec_to_string(totaltime):
|
||||
|
||||
return duration
|
||||
|
||||
def isprorower(r):
|
||||
result = False
|
||||
result = r.rowerplan in ['pro','coach','plan']
|
||||
|
||||
if not result and r.protrialexpires:
|
||||
result = r.rowerplan == 'basic' and r.protrialexpires >= datetime.date.today()
|
||||
if not result and r.rowerplan == 'freecoach':
|
||||
if r.mycoachgroup is not None:
|
||||
result = len(r.mycoachgroup)>=4
|
||||
|
||||
return result
|
||||
|
||||
def iscoach(m,r):
|
||||
result = False
|
||||
result = m in r.coaches
|
||||
|
||||
return result
|
||||
|
||||
|
||||
# Exponentially weighted moving average
|
||||
# Used for data smoothing of the jagged data obtained by Strava
|
||||
# See bitbucket issue 72
|
||||
@@ -433,7 +422,7 @@ def ewmovingaverage(interval,window_size):
|
||||
intervaldf = pd.DataFrame({'v':interval})
|
||||
idf_ewma1 = intervaldf.ewm(span=window_size)
|
||||
idf_ewma2 = intervaldf[::-1].ewm(span=window_size)
|
||||
|
||||
|
||||
i_ewma1 = idf_ewma1.mean().loc[:,'v']
|
||||
i_ewma2 = idf_ewma2.mean().loc[:,'v']
|
||||
|
||||
@@ -478,7 +467,7 @@ def custom_exception_handler(exc,message):
|
||||
res.json = json.dumps(response)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def get_strava_stream(r,metric,stravaid,series_type='time',fetchresolution='high'):
|
||||
authorizationstring = str('Bearer ' + r.stravatoken)
|
||||
headers = {'Authorization': authorizationstring,
|
||||
@@ -503,7 +492,7 @@ def get_strava_stream(r,metric,stravaid,series_type='time',fetchresolution='high
|
||||
return np.array(data['data'])
|
||||
except TypeError:
|
||||
return None
|
||||
|
||||
|
||||
return None
|
||||
|
||||
def allmonths(startdate,enddate):
|
||||
@@ -518,4 +507,3 @@ def allsundays(startdate,enddate):
|
||||
while d<=enddate:
|
||||
yield d
|
||||
d += datetime.timedelta(days=7)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user