Merge branch 'feature/physicsprogress' into develop
This commit is contained in:
+51
-8
@@ -16,7 +16,9 @@ from matplotlib.backends.backend_agg import FigureCanvas
|
||||
#from matplotlib.backends.backend_cairo import FigureCanvasCairo as FigureCanvas
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
from rowsandall_app.settings import SITE_URL
|
||||
from rowsandall_app.settings_dev import SITE_URL as SITE_URL_DEV
|
||||
from rowsandall_app.settings import PROGRESS_CACHE_SECRET
|
||||
|
||||
import pandas as pd
|
||||
|
||||
@@ -296,11 +298,17 @@ def handle_sendemailtcx(first_name, last_name, email, tcxfile,debug=False):
|
||||
@app.task
|
||||
def handle_zip_file(emailfrom, subject, file,debug=False):
|
||||
message = "... zip processing ... "
|
||||
if debug:
|
||||
print message
|
||||
email = EmailMessage(subject, message,
|
||||
emailfrom,
|
||||
['workouts@rowsandall.com'])
|
||||
email.attach_file(file)
|
||||
if debug:
|
||||
print "attaching"
|
||||
res = email.send()
|
||||
if debug:
|
||||
print "sent"
|
||||
time.sleep(60)
|
||||
return 1
|
||||
|
||||
@@ -338,12 +346,36 @@ def handle_sendemailcsv(first_name, last_name, email, csvfile,debug=False):
|
||||
# Calculate wind and stream corrections for OTW rowing
|
||||
|
||||
|
||||
@app.task
|
||||
def handle_otwsetpower(f1, boattype, weightvalue,
|
||||
first_name, last_name, email, workoutid, ps=[
|
||||
1, 1, 1, 1],
|
||||
ratio=1.0,
|
||||
debug=False):
|
||||
@app.task(bind=True)
|
||||
def handle_otwsetpower(self,f1, boattype, weightvalue,
|
||||
first_name, last_name, email, workoutid,
|
||||
**kwargs):
|
||||
# ps=[
|
||||
# 1, 1, 1, 1],
|
||||
# ratio=1.0,
|
||||
# debug=False):
|
||||
job = self.request
|
||||
job_id = job.id
|
||||
|
||||
if 'jobkey' in kwargs:
|
||||
job_id = kwargs.pop('jobkey')
|
||||
if 'ps' in kwargs:
|
||||
ps = kwargs['ps']
|
||||
else:
|
||||
ps = [1,1,1,1]
|
||||
|
||||
if 'ratio' in kwargs:
|
||||
ratio = kwargs['ratio']
|
||||
else:
|
||||
ratio = 1.0
|
||||
if 'debug' in kwargs:
|
||||
debug = kwargs['debug']
|
||||
else:
|
||||
debug = False
|
||||
|
||||
kwargs['jobid'] = job_id
|
||||
|
||||
|
||||
try:
|
||||
rowdata = rdata(f1)
|
||||
except IOError:
|
||||
@@ -377,8 +409,19 @@ def handle_otwsetpower(f1, boattype, weightvalue,
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
progressurl = SITE_URL
|
||||
if debug:
|
||||
progressurl = SITE_URL_DEV
|
||||
secret = PROGRESS_CACHE_SECRET
|
||||
|
||||
progressurl += "/rowers/record-progress/"
|
||||
progressurl += job_id
|
||||
|
||||
rowdata.otw_setpower_silent(skiprows=5, mc=weightvalue, rg=rg,
|
||||
powermeasured=powermeasured)
|
||||
powermeasured=powermeasured,
|
||||
progressurl=progressurl,
|
||||
secret=secret
|
||||
)
|
||||
|
||||
# save data
|
||||
rowdata.write_csv(f1, gzip=True)
|
||||
|
||||
@@ -144,6 +144,8 @@ urlpatterns = [
|
||||
url(r'^test-job/(?P<aantal>\d+)$',views.test_job_view),
|
||||
url(r'^test-job2/(?P<aantal>\d+)$',views.test_job_view2),
|
||||
url(r'^record-progress/(?P<value>\d+)/(?P<id>.*)$',views.post_progress),
|
||||
url(r'^record-progress/(?P<id>.*)$',views.post_progress),
|
||||
url(r'^record-progress$',views.post_progress),
|
||||
url(r'^list-graphs/$',views.graphs_view),
|
||||
url(r'^(?P<theuser>\d+)/ote-bests/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.rankings_view),
|
||||
url(r'^(?P<theuser>\d+)/ote-bests/(?P<deltadays>\d+)$',views.rankings_view),
|
||||
|
||||
@@ -222,11 +222,17 @@ def isbreakthrough(delta,cpvalues,p0,p1,p2,p3,ratio):
|
||||
def myqueue(queue,function,*args,**kwargs):
|
||||
if settings.DEBUG:
|
||||
kwargs['debug'] = True
|
||||
|
||||
print 'myqueue'
|
||||
print args
|
||||
print kwargs
|
||||
|
||||
job = function.delay(*args,**kwargs)
|
||||
else:
|
||||
job_id = str(uuid.uuid4())
|
||||
kwargs['job_id'] = job_id
|
||||
kwargs['jobkey'] = job_id
|
||||
|
||||
job = queue.enqueue(function,*args,**kwargs)
|
||||
|
||||
return job
|
||||
|
||||
+22
-9
@@ -194,9 +194,9 @@ redis_connection = StrictRedis()
|
||||
r = Redis()
|
||||
|
||||
# this doesn't yet work on production
|
||||
if settings.DEBUG:
|
||||
client = SessionTaskListener(r,['tasks'])
|
||||
client.start()
|
||||
#if settings.DEBUG:
|
||||
# client = SessionTaskListener(r,['tasks'])
|
||||
# client.start()
|
||||
|
||||
|
||||
rq_registry = StartedJobRegistry(queue.name,connection=redis_connection)
|
||||
@@ -367,19 +367,32 @@ def test_job_view2(request,aantal=100):
|
||||
@csrf_exempt
|
||||
def post_progress(request,id=None,value=0):
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
secret = request.POST['secret']
|
||||
except KeyError:
|
||||
return HttpResponse('Access Denied',status=401)
|
||||
if secret == settings.PROGRESS_CACHE_SECRET:
|
||||
if id:
|
||||
if not id:
|
||||
try:
|
||||
id = request.POST['id']
|
||||
except KeyError:
|
||||
return HttpResponse('Invalid request',400)
|
||||
try:
|
||||
value = request.POST['value']
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
cache.set(id,value,3600)
|
||||
# test
|
||||
result = cache.get(id)
|
||||
|
||||
return HttpResponse('progress cached '+str(result),status=200)
|
||||
else:
|
||||
return HttpResponse('access denied',status=400)
|
||||
return HttpResponse('progress cached '+str(result),
|
||||
status=201)
|
||||
else: # secret not given
|
||||
return HttpResponse('access denied',status=401)
|
||||
|
||||
else:
|
||||
return HttpResponse('hi',status=200)
|
||||
else: # request method is not POST
|
||||
return HttpResponse('GET method not allowed',status=405)
|
||||
|
||||
def get_all_queued_jobs(userid=0):
|
||||
r = StrictRedis()
|
||||
|
||||
Reference in New Issue
Block a user