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 get_workout(user,nkid):
|
||||||
def getdict(x):
|
def getdict(x, seatIndex=1):
|
||||||
|
seatStrokes = pd.DataFrame(x)
|
||||||
try:
|
try:
|
||||||
return x[0]
|
seatStrokes = seatStrokes.set_index('seatIndex')
|
||||||
|
return dict(seatStrokes.loc[seatIndex])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_workout(user,nkid):
|
def get_workout(user,nkid):
|
||||||
print('aap')
|
|
||||||
r = Rower.objects.get(user=user)
|
r = Rower.objects.get(user=user)
|
||||||
if (r.nktoken == '') or (r.nktoken is None):
|
if (r.nktoken == '') or (r.nktoken is None):
|
||||||
s = "Token doesn't exist. Need to authorize"
|
s = "Token doesn't exist. Need to authorize"
|
||||||
@@ -219,15 +220,20 @@ def get_workout(user,nkid):
|
|||||||
# error handling
|
# error handling
|
||||||
pass
|
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)
|
df = pd.concat([df,df2],axis=1)
|
||||||
|
|
||||||
|
print(df.info())
|
||||||
|
|
||||||
# get workout data
|
# get workout data
|
||||||
|
|
||||||
return 0,0
|
return 0,0
|
||||||
|
|||||||
@@ -758,7 +758,7 @@ def mocked_requests(*args, **kwargs):
|
|||||||
nkworkoutlistregex = '.*?nkrowlink\.com\/api\/v1\/sessions'
|
nkworkoutlistregex = '.*?nkrowlink\.com\/api\/v1\/sessions'
|
||||||
nkworkoutlisttester = re.compile(nkworkoutlistregex)
|
nkworkoutlisttester = re.compile(nkworkoutlistregex)
|
||||||
|
|
||||||
nkstrokesregex = '.*?nkrowlink\.com\/api\/v1\/strokes\?sessionIds=\d'
|
nkstrokesregex = '.*?nkrowlink\.com\/api\/v1\/sessions\/strokes'
|
||||||
nkstrokestester = re.compile(nkstrokesregex)
|
nkstrokestester = re.compile(nkstrokesregex)
|
||||||
|
|
||||||
stravaathleteregex = '.*?strava\.com\/api\/v3\/athlete$'
|
stravaathleteregex = '.*?strava\.com\/api\/v3\/athlete$'
|
||||||
@@ -927,6 +927,7 @@ def mocked_requests(*args, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
if nktester.match(args[0]):
|
if nktester.match(args[0]):
|
||||||
|
|
||||||
if 'token' in args[0]:
|
if 'token' in args[0]:
|
||||||
json_data = {
|
json_data = {
|
||||||
'access_token': 'TA3n1vrNjuQJWw0TdCDHnjSmrjIPULhTlejMIWqq',
|
'access_token': 'TA3n1vrNjuQJWw0TdCDHnjSmrjIPULhTlejMIWqq',
|
||||||
@@ -935,8 +936,10 @@ def mocked_requests(*args, **kwargs):
|
|||||||
}
|
}
|
||||||
return MockResponse(json_data,200)
|
return MockResponse(json_data,200)
|
||||||
if nkstrokestester.match(args[0]):
|
if nkstrokestester.match(args[0]):
|
||||||
|
|
||||||
return MockResponse(nkstrokedata,200)
|
return MockResponse(nkstrokedata,200)
|
||||||
if nkworkoutlisttester.match(args[0]):
|
if nkworkoutlisttester.match(args[0]):
|
||||||
|
|
||||||
return MockResponse(nkworkoutlist,200)
|
return MockResponse(nkworkoutlist,200)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -431,7 +431,7 @@ class NKObjects(DjangoTestCase):
|
|||||||
mocked_getsmallrowdata_db):
|
mocked_getsmallrowdata_db):
|
||||||
|
|
||||||
result = rowers.nkstuff.rower_nk_token_refresh(self.u)
|
result = rowers.nkstuff.rower_nk_token_refresh(self.u)
|
||||||
response = self.c.get('/rowers/workout/nkimport/12',follow=True)
|
response = self.c.get('/rowers/workout/nkimport/469',follow=True)
|
||||||
|
|
||||||
self.assertRedirects(response,
|
self.assertRedirects(response,
|
||||||
expected_url='/rowers/workout/'+encoded2+'/edit/',
|
expected_url='/rowers/workout/'+encoded2+'/edit/',
|
||||||
|
|||||||
Reference in New Issue
Block a user