Private
Public Access
1
0

bug fixes

This commit is contained in:
Sander Roosendaal
2020-02-18 21:37:13 +01:00
parent fc6dd7e347
commit 38094d7b13
6 changed files with 35 additions and 33 deletions

View File

@@ -15,6 +15,7 @@ from rowingdata import rowingdata as rrdata
from rowingdata import rower as rrower from rowingdata import rower as rrower
import yaml
import shutil import shutil
from shutil import copyfile from shutil import copyfile
@@ -1469,7 +1470,8 @@ def new_workout_from_file(r, f2,
title='Workout', title='Workout',
boattype='1x', boattype='1x',
makeprivate=False, makeprivate=False,
notes=''): notes='',
uploadoptions={'boattype':'1x','workouttype':'rower'}):
message = "" message = ""
impeller = False impeller = False
try: try:
@@ -1483,12 +1485,14 @@ def new_workout_from_file(r, f2,
oarlength = 2.89 oarlength = 2.89
inboard = 0.88 inboard = 0.88
if len(fileformat) == 3 and fileformat[0] == 'zip': if len(fileformat) == 3 and fileformat[0] == 'zip':
uploadoptions['fromuploadform'] = True
bodyyaml = yaml.safe_dump(uploadoptions,default_flow_style=False)
f_to_be_deleted = f2 f_to_be_deleted = f2
impeller = False impeller = False
workoutsbox = Mailbox.objects.filter(name='workouts')[0] workoutsbox = Mailbox.objects.filter(name='workouts')[0]
msg = Message(mailbox=workoutsbox, msg = Message(mailbox=workoutsbox,
from_header=r.user.email, from_header=r.user.email,
subject = title) subject = title,body=bodyyaml)
msg.save() msg.save()
f3 = 'media/mailbox_attachments/'+f2[6:] f3 = 'media/mailbox_attachments/'+f2[6:]
copyfile(f2,f3) copyfile(f2,f3)

View File

@@ -83,6 +83,8 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
users = User.objects.filter(username=uploadoptions['username']) users = User.objects.filter(username=uploadoptions['username'])
if len(users)==1: if len(users)==1:
therower = users[0].rower therower = users[0].rower
elif uploadoptions['username'] == '':
therower = rower
else: else:
return 0 return 0
else: else:
@@ -94,7 +96,6 @@ def processattachment(rower, fileobj, title, uploadoptions,testing=False):
uploadoptions['file'] = 'media/'+filename uploadoptions['file'] = 'media/'+filename
uploadoptions['title'] = title uploadoptions['title'] = title
url = settings.UPLOAD_SERVICE_URL url = settings.UPLOAD_SERVICE_URL
if not testing: if not testing:
response = requests.post(url,data=uploadoptions) response = requests.post(url,data=uploadoptions)
@@ -239,24 +240,19 @@ class Command(BaseCommand):
attachment.delete() attachment.delete()
for rower in rowers: for rower in rowers:
if 'zip' in extension: if 'zip' in extension:
try: zip_file = zipfile.ZipFile(attachment.document)
zip_file = zipfile.ZipFile(attachment.document) for id,filename in enumerate(zip_file.namelist()):
for id,filename in enumerate(zip_file.namelist()): datafile = zip_file.extract(
datafile = zip_file.extract( filename, path='media/')
filename, path='media/') if id>0:
if id>0: title = name+' ('+str(id+1)+')'
title = name+' ('+str(id+1)+')' else:
else: title = name
title = name workoutid = processattachment(
rower, datafile, title, uploadoptions,
testing=testing
)
workoutid = processattachment(
rower, datafile, title, uploadoptions,
testing=testing
)
print(workoutid)
except:
print("Bad ZIP file")
print(attachment.document.name)
else: else:
# move attachment and make workout # move attachment and make workout
if testing: if testing:

View File

@@ -509,7 +509,7 @@ def make_private(w,options):
def do_sync(w,options): def do_sync(w,options):
try: try:
if options['stravaid'] != 0: if options['stravaid'] != 0 and options['stravaid'] != '':
w.uploadedtostrava = options['stravaid'] w.uploadedtostrava = options['stravaid']
options['upload_to_Strava'] = False options['upload_to_Strava'] = False
w.save() w.save()

View File

@@ -19,7 +19,7 @@ def strokedataform(request,id=0):
w = Workout.objects.get(id=id) w = Workout.objects.get(id=id)
except Workout.DoesNotExist: except Workout.DoesNotExist:
raise Http404("Workout doesn't exist") raise Http404("Workout doesn't exist")
if request.method == 'GET': if request.method == 'GET':
form = StrokeDataForm() form = StrokeDataForm()
return render(request, 'strokedata_form.html', return render(request, 'strokedata_form.html',
@@ -52,7 +52,9 @@ def strokedatajson(request,id):
POST: Add Stroke data to workout POST: Add Stroke data to workout
GET: Get stroke data of workout GET: Get stroke data of workout
""" """
row = get_workout_permitted(request.user,id) row = get_object_or_404(Workout,pk=id)
if row.user != request.user.rower:
raise PermissionDenied("You have no access to this workout")
try: try:
id = int(id) id = int(id)
@@ -61,7 +63,7 @@ def strokedatajson(request,id):
if request.method == 'GET': if request.method == 'GET':
# currently only returns a subset. # currently only returns a subset.
columns = ['spm','time','hr','pace','power','distance'] columns = ['spm','time','hr','pace','power','distance']
datadf = dataprep.getsmallrowdata_db(columns,ids=[id]) datadf = dataprep.getsmallrowdata_db(columns,ids=[id])
with open('media/apilog.log','a') as logfile: with open('media/apilog.log','a') as logfile:
@@ -95,7 +97,7 @@ def strokedatajson(request,id):
distance = df['distance'] distance = df['distance']
if len(distance) != aantal: if len(distance) != aantal:
return HttpResponse("Distance array has incorrect length",status=400) return HttpResponse("Distance array has incorrect length",status=400)
spm = df['spm'] spm = df['spm']
if len(spm) != aantal: if len(spm) != aantal:
return HttpResponse("SPM array has incorrect length",status=400) return HttpResponse("SPM array has incorrect length",status=400)
@@ -103,7 +105,7 @@ def strokedatajson(request,id):
res = dataprep.testdata(time,distance,pace,spm) res = dataprep.testdata(time,distance,pace,spm)
if not res: if not res:
return HttpResponse("Data are not numerical",status=400) return HttpResponse("Data are not numerical",status=400)
power = trydf(df,aantal,'power') power = trydf(df,aantal,'power')
drivelength = trydf(df,aantal,'drivelength') drivelength = trydf(df,aantal,'drivelength')
drivespeed = trydf(df,aantal,'drivespeed') drivespeed = trydf(df,aantal,'drivespeed')
@@ -127,7 +129,7 @@ def strokedatajson(request,id):
with open('media/apilog.log','a') as logfile: with open('media/apilog.log','a') as logfile:
logfile.write(str(starttime)+": ") logfile.write(str(starttime)+": ")
logfile.write(request.user.username+"(POST) \r\n") logfile.write(request.user.username+"(POST) \r\n")
data = pd.DataFrame({'TimeStamp (sec)':unixtime, data = pd.DataFrame({'TimeStamp (sec)':unixtime,
' Horizontal (meters)': distance, ' Horizontal (meters)': distance,
' Cadence (stokes/min)':spm, ' Cadence (stokes/min)':spm,
@@ -155,7 +157,7 @@ def strokedatajson(request,id):
timestr = row.startdatetime.strftime("%Y%m%d-%H%M%S") timestr = row.startdatetime.strftime("%Y%m%d-%H%M%S")
csvfilename ='media/Import_'+timestr+'.csv' csvfilename ='media/Import_'+timestr+'.csv'
res = data.to_csv(csvfilename+'.gz',index_label='index', res = data.to_csv(csvfilename+'.gz',index_label='index',
compression='gzip') compression='gzip')
row.csvfilename = csvfilename row.csvfilename = csvfilename
@@ -169,14 +171,14 @@ def strokedatajson(request,id):
ftp = float(r.ftp) ftp = float(r.ftp)
if row.workouttype in mytypes.otwtypes: if row.workouttype in mytypes.otwtypes:
ftp = ftp*(100.-r.otwslack)/100. ftp = ftp*(100.-r.otwslack)/100.
rr = rrower(hrmax=r.max,hrut2=r.ut2, rr = rrower(hrmax=r.max,hrut2=r.ut2,
hrut1=r.ut1,hrat=r.at, hrut1=r.ut1,hrat=r.at,
hrtr=r.tr,hran=r.an,ftp=ftp, hrtr=r.tr,hran=r.an,ftp=ftp,
powerperc=powerperc,powerzones=r.powerzones) powerperc=powerperc,powerzones=r.powerzones)
rowdata = rdata(row.csvfilename,rower=rr).df rowdata = rdata(row.csvfilename,rower=rr).df
datadf = dataprep.dataprep(rowdata,id=row.id,bands=True,barchart=True,otwpower=True,empower=True) datadf = dataprep.dataprep(rowdata,id=row.id,bands=True,barchart=True,otwpower=True,empower=True)
# mangling # mangling
# #

View File

@@ -82,7 +82,7 @@ def workout_strava_upload_view(request,id=0):
return HttpResponseRedirect("/rowers/me/stravaauthorize/") return HttpResponseRedirect("/rowers/me/stravaauthorize/")
else: else:
# ready to upload. Hurray # ready to upload. Hurray
w = get_workout_permitted(request.user,id) w = get_workout_by_opaqueid(request,id)
r = w.user r = w.user
try: try:

View File

@@ -4406,7 +4406,6 @@ def workout_upload_api(request):
except (KeyError,JSONDecodeError): except (KeyError,JSONDecodeError):
post_data = request.POST post_data = request.POST
# only allow local host # only allow local host
hostt = request.get_host().split(':') hostt = request.get_host().split(':')
if hostt[0] not in ['localhost','127.0.0.1','dev.rowsandall.com','rowsandall.com']: if hostt[0] not in ['localhost','127.0.0.1','dev.rowsandall.com','rowsandall.com']:
@@ -4491,6 +4490,7 @@ def workout_upload_api(request):
makeprivate=makeprivate, makeprivate=makeprivate,
title = t, title = t,
notes=notes, notes=notes,
uploadoptions=post_data,
) )
if id == 0: if id == 0: