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 print_function
from __future__ import unicode_literals 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 # The interactions with the Concept2 logbook API
# All C2 related functions should be defined here # 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 return custom_exception_handler(401,s), 0
data = s.json()['data'] data = s.json()['data']
alldata = {c2id:data}
splitdata = None splitdata = None
#with open('c2temp.json','w') as f: #with open('c2temp.json','w') as f:
# f.write(json.dumps(s.json())) # f.write(json.dumps(s.json()))
# print(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 'workout' in data:
if 'splits' in data['workout']: # pragma: no cover if 'splits' in data['workout']: # pragma: no cover
splitdata = data['workout']['splits'] splitdata = data['workout']['splits']
@@ -873,6 +895,7 @@ def get_workout(user,c2id,do_async=False):
else: # pragma: no cover else: # pragma: no cover
strokedata = pd.DataFrame() strokedata = pd.DataFrame()
return data,strokedata return data,strokedata
# Get stroke data belonging to C2 ID # Get stroke data belonging to C2 ID

View File

@@ -36,6 +36,14 @@ from iso8601 import ParseError
from json.decoder import JSONDecodeError 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_agg import FigureCanvas
#from matplotlib.backends.backend_cairo import FigureCanvasCairo as FigureCanvas #from matplotlib.backends.backend_cairo import FigureCanvasCairo as FigureCanvas
import matplotlib.pyplot as plt 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']) startdatetime = iso8601.parse_date(data['date'])
weightclass = data['weight_class'] weightclass = data['weight_class']
s = 'User {userid}, C2 ID {c2id}'.format(userid=userid,c2id=c2id)
logging.critical(s)
logging.critical(data)
try: try:
title = data['name'] title = data['name']
except KeyError: except KeyError:
@@ -3022,6 +3034,12 @@ def handle_c2_async_workout(alldata,userid,c2token,c2id,delaysec,defaulttimezone
timezone = pytz.timezone(data['timezone']) timezone = pytz.timezone(data['timezone'])
startdatetime = startdatetime.astimezone(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( workoutdate = startdatetime.astimezone(
timezone timezone

View File

@@ -34,11 +34,11 @@
<td>{{ value }}</td> <td>{{ value }}</td>
{% endif %} {% endif %}
{% if key == "id" %} {% 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 %} {% endif %}
{% endfor %} {% endfor %}
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>

View File

@@ -47,7 +47,7 @@
{% for workout in workouts %} {% for workout in workouts %}
<tr> <tr>
<td> <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:'starttime' }}</td>
<td>{{ workout|lookup:'duration' }}</td> <td>{{ workout|lookup:'duration' }}</td>
<td>{{ workout|lookup:'distance' }}</td> <td>{{ workout|lookup:'distance' }}</td>
@@ -58,7 +58,7 @@
{{ workout|lookup:'new' }} {{ workout|lookup:'new' }}
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>