Private
Public Access
1
0

c2 import to async

This commit is contained in:
Sander Roosendaal
2021-05-20 19:55:11 +02:00
parent 668992d27a
commit affc306b18
4 changed files with 45 additions and 4 deletions

View File

@@ -3,6 +3,13 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import logging
logging.basicConfig(
filename='debuglog.log',
level=logging.DEBUG,
format='%(asctime)s %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p'
)
# The interactions with the Concept2 logbook API
# All C2 related functions should be defined here
@@ -849,11 +856,26 @@ def get_workout(user,c2id,do_async=False):
return custom_exception_handler(401,s), 0
data = s.json()['data']
alldata = {c2id:data}
splitdata = None
#with open('c2temp.json','w') as f:
# f.write(json.dumps(s.json()))
# print(s.json())
if do_async:
print('aap',alldata)
job = myqueue(queuehigh,
handle_c2_async_workout,
alldata,
r.user.id,
r.c2token,
c2id,
0,
r.defaulttimezone)
return data, pd.DataFrame()
if 'workout' in data:
if 'splits' in data['workout']: # pragma: no cover
splitdata = data['workout']['splits']
@@ -873,6 +895,7 @@ def get_workout(user,c2id,do_async=False):
else: # pragma: no cover
strokedata = pd.DataFrame()
return data,strokedata
# Get stroke data belonging to C2 ID

View File

@@ -36,6 +36,14 @@ from iso8601 import ParseError
from json.decoder import JSONDecodeError
import logging
logging.basicConfig(
filename='debuglog.log',
level=logging.CRITICAL,
format='%(asctime)s %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p'
)
from matplotlib.backends.backend_agg import FigureCanvas
#from matplotlib.backends.backend_cairo import FigureCanvasCairo as FigureCanvas
import matplotlib.pyplot as plt
@@ -2997,6 +3005,10 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone
startdatetime = iso8601.parse_date(data['date'])
weightclass = data['weight_class']
s = 'User {userid}, C2 ID {c2id}'.format(userid=userid,c2id=c2id)
logging.critical(s)
logging.critical(data)
try:
title = data['name']
except KeyError:
@@ -3022,6 +3034,12 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone
timezone = pytz.timezone(data['timezone'])
startdatetime = startdatetime.astimezone(timezone)
s = 'Time zone {timezone}, stardatetime {startdatetime}, duration {duration}'.format(
timezone=timezone,startdatetime=startdatetime,
duration=duration)
logging.critical(s)
workoutdate = startdatetime.astimezone(
timezone

View File

@@ -34,11 +34,11 @@
<td>{{ value }}</td>
{% endif %}
{% if key == "id" %}
<td><a href="/rowers/workout/c2import/{{ value }}/">Import</a></td>
<td><a href="/rowers/workout/c2import/{{ value }}/async/">Import</a></td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>

View File

@@ -47,7 +47,7 @@
{% for workout in workouts %}
<tr>
<td>
<a href="/rowers/workout/c2import/{{ workout|lookup:'id' }}/">Import</a></td>
<a href="/rowers/workout/c2import/{{ workout|lookup:'id' }}/async/">Import</a></td>
<td>{{ workout|lookup:'starttime' }}</td>
<td>{{ workout|lookup:'duration' }}</td>
<td>{{ workout|lookup:'distance' }}</td>
@@ -58,7 +58,7 @@
{{ workout|lookup:'new' }}
</td>
</tr>
{% endfor %}
</tbody>
</table>