Private
Public Access
1
0

another batch of files with a light sprinkle of comments

This commit is contained in:
Sander Roosendaal
2017-01-15 16:06:14 +01:00
parent 737ac5fd3f
commit e5810dbf62
11 changed files with 64 additions and 11 deletions

View File

@@ -1,3 +1,4 @@
# Processes emails sent to workouts@rowsandall.com
import time
from django.conf import settings
from rowers.tasks import handle_sendemail_unrecognized
@@ -21,7 +22,9 @@ from scipy.signal import savgol_filter
import zipfile
import os
import rowers.dataprep as dataprep
# Sends a confirmation with a link to the workout
def send_confirm(u,name,link):
fullemail = u.email
subject = 'Workout added: '+name
@@ -38,6 +41,7 @@ def send_confirm(u,name,link):
return 1
# Reads a "rowingdata" object, plus some error protections
def rdata(file,rower=rrower()):
try:
res = rrdata(file,rower=rower)
@@ -49,13 +53,18 @@ def rdata(file,rower=rrower()):
return res
# Some error protection around process attachments
def safeprocessattachments():
try:
return processattachments()
except:
return [0]
# This is duplicated in management/commands/processemail
# Need to double check the code there, update here, and only
# use the code here.
def processattachments():
# in res, we store the ids of the new workouts
res = []
attachments = MessageAttachment.objects.all()
for a in attachments:
@@ -73,7 +82,6 @@ def processattachments():
try:
wid = [make_new_workout_from_email(rr,a.document,name)]
res += wid
print wid
link = 'https://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit'
dd = send_confirm(u,name,link)
except:
@@ -92,6 +100,7 @@ def processattachments():
# no attachments, so can be deleted
m.delete()
# Delete remaining messages (which should not have attachments)
mm = Message.objects.all()
for m in mm:
if m.attachments.exists()==False:
@@ -99,6 +108,7 @@ def processattachments():
return res
# As above, but with some print commands for debugging purposes
def processattachments_debug():
res = []
attachments = MessageAttachment.objects.all()
@@ -144,7 +154,9 @@ def processattachments_debug():
return res
# Process the attachment file, create new workout
# The code here is duplication of the code in views.py (workout_upload_view)
# Need to move the code to a subroutine used both in views.py and here
def make_new_workout_from_email(rr,f2,name,cntr=0):
workouttype = 'rower'
f2 = f2.name
@@ -305,6 +317,16 @@ def make_new_workout_from_email(rr,f2,name,cntr=0):
startdatetime=row.rowdatetime)
w.save()
print w.id
print row.df.info()
# put stroke data in database
res = dataprep.dataprep(row.df,id=w.id,
bands=True,barchart=True,
otwpower=True,empower=True)
return w.id