concept2 auto import
This commit is contained in:
@@ -34,7 +34,7 @@ import sys
|
||||
import urllib
|
||||
from requests import Request, Session
|
||||
|
||||
from utils import myqueue
|
||||
from utils import myqueue,uniqify,isprorower
|
||||
|
||||
from rowers.types import otwtypes
|
||||
|
||||
@@ -114,7 +114,37 @@ def add_stroke_data(user,c2id,workoutid,startdatetime,csvfilename):
|
||||
csvfilename)
|
||||
|
||||
return 1
|
||||
|
||||
def get_c2_workouts(rower):
|
||||
|
||||
if not isprorower(rower):
|
||||
return 0
|
||||
|
||||
try:
|
||||
thetoken = c2_open(rower.user)
|
||||
except C2NoTokenError:
|
||||
return 0
|
||||
|
||||
res = get_c2_workout_list(rower.user,page=1)
|
||||
|
||||
if (res.status_code != 200):
|
||||
return 0
|
||||
else:
|
||||
c2ids = [item['id'] for item in res.json()['data']]
|
||||
alldata = {}
|
||||
for item in res.json()['data']:
|
||||
alldata[item['id']] = item
|
||||
|
||||
knownc2ids = uniqify([
|
||||
w.uploadedtoc2 for w in Workout.objects.filter(user=rower)
|
||||
])
|
||||
newids = [c2id for c2id in c2ids if not c2id in knownc2ids]
|
||||
|
||||
for c2id in newids:
|
||||
workoutid = create_async_workout(alldata,
|
||||
rower.user,c2id)
|
||||
|
||||
return 1
|
||||
|
||||
# get workout metrics, then relay stroke data to an asynchronous task
|
||||
def create_async_workout(alldata,user,c2id):
|
||||
@@ -155,7 +185,7 @@ def create_async_workout(alldata,user,c2id):
|
||||
w = Workout(
|
||||
user=r,
|
||||
workouttype = workouttype,
|
||||
name = 'Imported workout',
|
||||
name = 'C2 Import Workout from {startdatetime}'.format(startdatetime=startdatetime),
|
||||
date = workoutdate,
|
||||
starttime = starttime,
|
||||
startdatetime = startdatetime,
|
||||
|
||||
@@ -1999,7 +1999,11 @@ def dataprep(rowdatadf, id=0, bands=True, barchart=True, otwpower=True,
|
||||
rowdatadf.loc[row_index, ' Stroke500mPace (sec/500m)'] = 3000.
|
||||
|
||||
p = rowdatadf.ix[:, ' Stroke500mPace (sec/500m)']
|
||||
velo = rowdatadf.ix[:,' AverageBoatSpeed (m/s)']
|
||||
try:
|
||||
velo = rowdatadf.ix[:,' AverageBoatSpeed (m/s)']
|
||||
except KeyError:
|
||||
velo = 500./p
|
||||
|
||||
hr = rowdatadf.ix[:, ' HRCur (bpm)']
|
||||
spm = rowdatadf.ix[:, ' Cadence (stokes/min)']
|
||||
cumdist = rowdatadf.ix[:, 'cum_dist']
|
||||
|
||||
@@ -978,7 +978,11 @@ def dataprep(rowdatadf,id=0,bands=True,barchart=True,otwpower=True,
|
||||
rowdatadf.loc[row_index,' Stroke500mPace (sec/500m)'] = 3000.
|
||||
|
||||
p = rowdatadf.ix[:,' Stroke500mPace (sec/500m)']
|
||||
velo = rowdatadf.ix[:,' AverageBoatSpeed (m/s)']
|
||||
try:
|
||||
velo = rowdatadf.ix[:,' AverageBoatSpeed (m/s)']
|
||||
except KeyError:
|
||||
velo = 500./p
|
||||
|
||||
hr = rowdatadf.ix[:,' HRCur (bpm)']
|
||||
spm = rowdatadf.ix[:,' Cadence (stokes/min)']
|
||||
cumdist = rowdatadf.ix[:,'cum_dist']
|
||||
|
||||
@@ -21,6 +21,7 @@ from rowingdata import rowingdata as rrdata
|
||||
import rowers.uploads as uploads
|
||||
from rowers.mailprocessing import make_new_workout_from_email, send_confirm
|
||||
import rowers.polarstuff as polarstuff
|
||||
import rowers.c2stuff as c2stuff
|
||||
|
||||
workoutmailbox = Mailbox.objects.get(name='workouts')
|
||||
failedmailbox = Mailbox.objects.get(name='Failed')
|
||||
@@ -148,8 +149,14 @@ class Command(BaseCommand):
|
||||
|
||||
"""Run the Email processing command """
|
||||
def handle(self, *args, **options):
|
||||
# Polar
|
||||
polar_available = polarstuff.get_polar_notifications()
|
||||
res = polarstuff.get_all_new_workouts(polar_available)
|
||||
|
||||
# Concept2
|
||||
rowers = Rower.objects.filter(c2_auto_import=True)
|
||||
for r in rowers:
|
||||
c2stuff.get_c2_workouts(r)
|
||||
|
||||
messages = Message.objects.filter(mailbox_id = workoutmailbox.id)
|
||||
message_ids = [m.id for m in messages]
|
||||
|
||||
@@ -2021,6 +2021,7 @@ class RowerImportExportForm(ModelForm):
|
||||
fields = [
|
||||
'polar_auto_import',
|
||||
'c2_auto_export',
|
||||
'c2_auto_import',
|
||||
'mapmyfitness_auto_export',
|
||||
'runkeeper_auto_export',
|
||||
'sporttracks_auto_export',
|
||||
|
||||
Reference in New Issue
Block a user