gets a valid DF out of NK
This commit is contained in:
@@ -182,16 +182,17 @@ def get_nk_workout_list(user,fake=False):
|
||||
|
||||
#
|
||||
#def get_workout(user,nkid):
|
||||
def getdict(x):
|
||||
def getdict(x, seatIndex=1):
|
||||
seatStrokes = pd.DataFrame(x)
|
||||
try:
|
||||
return x[0]
|
||||
seatStrokes = seatStrokes.set_index('seatIndex')
|
||||
return dict(seatStrokes.loc[seatIndex])
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
return {}
|
||||
|
||||
def get_workout(user,nkid):
|
||||
print('aap')
|
||||
r = Rower.objects.get(user=user)
|
||||
if (r.nktoken == '') or (r.nktoken is None):
|
||||
s = "Token doesn't exist. Need to authorize"
|
||||
@@ -219,15 +220,20 @@ def get_workout(user,nkid):
|
||||
# error handling
|
||||
pass
|
||||
|
||||
data = response.json()[str(nkid)]
|
||||
jsonData = response.json()
|
||||
#print(jsonData)
|
||||
strokeData = jsonData[str(nkid)]
|
||||
|
||||
df = pd.DataFrame.from_dict(strokeData)
|
||||
oarlockData = df['oarlockStrokes']
|
||||
oarlockData = oarlockData.apply(lambda x:getdict(x, seatIndex=1))
|
||||
df2 = pd.DataFrame.from_records(oarlockData.values)
|
||||
df2 = df2.rename(columns={"timestamp":"ts"})
|
||||
|
||||
df = pd.DataFrame.from_dict(data)
|
||||
ol = df['oarlockStrokes']
|
||||
ol = ol.apply(lambda x:getdict(x))
|
||||
df2 = pd.DataFrame.from_records(ol.values)
|
||||
df2 = df2.rename(colunms={"timestamp":"ts"})
|
||||
df = pd.concat([df,df2],axis=1)
|
||||
|
||||
print(df.info())
|
||||
|
||||
# get workout data
|
||||
|
||||
return 0,0
|
||||
|
||||
Reference in New Issue
Block a user