Private
Public Access
1
0

untested POST version of stroke_data API

This commit is contained in:
Sander Roosendaal
2016-11-25 20:31:44 +01:00
parent 88da49a00e
commit 3ef5c40be4
4 changed files with 91 additions and 3 deletions

View File

@@ -49,7 +49,7 @@ from rowingdata import MysteryParser
from rowingdata import painsledDesktopParser,speedcoachParser,ErgStickParser
from rowingdata import SpeedCoach2Parser,FITParser,fitsummarydata
from rowingdata import make_cumvalues
from rowingdata import summarydata,get_file_type
from rowingdata import summarydata,get_file_type,totimestamp
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
@@ -4456,6 +4456,18 @@ class JSONResponse(HttpResponse):
kwargs['content_type'] = 'application/json'
super(JSONResponse, self).__init__(content, **kwargs)
def trydf(df,aantal,column):
try:
s = df[column]
if len(s) != aantal:
return np.zeros(aantal)
if not np.issubdtype(s,np.number):
return np.zeros(aantal)
except KeyError:
s = np.zeros(aantal)
return s
@login_required()
def strokedatajson(request,id):
try:
@@ -4476,9 +4488,77 @@ def strokedatajson(request,id):
return JSONResponse(datadf)
if request.method == 'POST':
checkdata,r = dataprep.getrowdata_db(id=row.id)
if not checkdata.empty:
return "Not OK"
strokedata = request.POST['strokedata']
# checking/validating and cleaning
try:
strokedata = json.loads(strokedata)
except:
return HttpResponse("Not OK")
try:
df = pd.DataFrame(strokedata)
# time, hr, pace, spm, power, drivelength, distance, drivespeed, dragfactor, strokerecoverytime, averagedriveforce, peakdriveforce, lapidx
time = df['time']
aantal = len(time)
pace = df['pace']
if len(pace) != aantal:
return "Not OK"
distance = df['distance']
if len(distance) != aantal:
return "Not OK"
spm = df['spm']
if len(spm) != aantal:
return "Not OK"
res = dataprep.testdata(time,distance,pace,spm)
if not res:
return HttpResponse("Not OK")
power = trydf(df,aantal,'power')
drivelength = trydf(df,aantal,'drivelength')
drivespeed = trydf(df,aantal,'drivespeed')
dragfactor = trydf(df,aantal,'dragfactor')
drivetime = trydf(df,aantal,'drivetime')
strokerecoverytime = trydf(df,aantal,'strokerecoverytime')
averagedriveforce = trydf(df,aantal,'averagedriveforce')
peakdriveforce = trydf(df,aantal,'peakdriveforce')
lapidx = trydf(df,aantal,'lapidx')
hr = trydf(df,aantal,'hr')
starttime = totimestamp(row.startdatetime)+time
unixtime = starttime+time
data = DataFrame({'TimeStamp (sec)':unixtime,
' Horizontal (meters)': distance,
' Cadence (stokes/min)':spm,
' HRCur (bpm)':hr,
' DragFactor':dragfactor,
' Stroke500mPace (sec/500m)':pace,
' Power (watts)':power,
' DriveLength (meters)':drivelength,
' StrokeDistance (meters)':strokedistance,
' DriveTime (ms)':drivetime,
' StrokeRecoveryTime (ms)':strokerecoverytime,
' AverageDriveForce (lbs)':averagedriveforce,
' PeakDriveForce (lbs)':peakdriveforce,
' lapIdx':lapidx,
' ElapsedTime (sec)':time,
})
timestr = time.strftime("%Y%m%d-%H%M%S")
csvfilename ='media/Import_'+timestr+'.csv'
res = df.to_csv(csvfilename,index_label='index')
row.csvfilename = csvfilename
row.save()
except:
return HttpResponse("Not OK")
# mangling
#