Private
Public Access
1
0

Merge branch 'feature/autoc2import' into develop

This commit is contained in:
Sander Roosendaal
2018-06-22 14:42:08 +02:00
10 changed files with 54 additions and 5 deletions

BIN
logos/ritmo_logo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

View File

@@ -34,7 +34,7 @@ import sys
import urllib import urllib
from requests import Request, Session from requests import Request, Session
from utils import myqueue from utils import myqueue,uniqify,isprorower
from rowers.types import otwtypes from rowers.types import otwtypes
@@ -114,7 +114,37 @@ def add_stroke_data(user,c2id,workoutid,startdatetime,csvfilename):
csvfilename) csvfilename)
return 1 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 # get workout metrics, then relay stroke data to an asynchronous task
def create_async_workout(alldata,user,c2id): def create_async_workout(alldata,user,c2id):
@@ -155,7 +185,7 @@ def create_async_workout(alldata,user,c2id):
w = Workout( w = Workout(
user=r, user=r,
workouttype = workouttype, workouttype = workouttype,
name = 'Imported workout', name = 'C2 Import Workout from {startdatetime}'.format(startdatetime=startdatetime),
date = workoutdate, date = workoutdate,
starttime = starttime, starttime = starttime,
startdatetime = startdatetime, startdatetime = startdatetime,

View File

@@ -1999,7 +1999,11 @@ def dataprep(rowdatadf, id=0, bands=True, barchart=True, otwpower=True,
rowdatadf.loc[row_index, ' Stroke500mPace (sec/500m)'] = 3000. rowdatadf.loc[row_index, ' Stroke500mPace (sec/500m)'] = 3000.
p = rowdatadf.ix[:, ' Stroke500mPace (sec/500m)'] 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)'] hr = rowdatadf.ix[:, ' HRCur (bpm)']
spm = rowdatadf.ix[:, ' Cadence (stokes/min)'] spm = rowdatadf.ix[:, ' Cadence (stokes/min)']
cumdist = rowdatadf.ix[:, 'cum_dist'] cumdist = rowdatadf.ix[:, 'cum_dist']

View File

@@ -978,7 +978,11 @@ def dataprep(rowdatadf,id=0,bands=True,barchart=True,otwpower=True,
rowdatadf.loc[row_index,' Stroke500mPace (sec/500m)'] = 3000. rowdatadf.loc[row_index,' Stroke500mPace (sec/500m)'] = 3000.
p = rowdatadf.ix[:,' Stroke500mPace (sec/500m)'] 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)'] hr = rowdatadf.ix[:,' HRCur (bpm)']
spm = rowdatadf.ix[:,' Cadence (stokes/min)'] spm = rowdatadf.ix[:,' Cadence (stokes/min)']
cumdist = rowdatadf.ix[:,'cum_dist'] cumdist = rowdatadf.ix[:,'cum_dist']

View File

@@ -168,7 +168,7 @@ def make_new_workout_from_email(rower, datafile, name, cntr=0,testing=False):
oarlength=oarlength, oarlength=oarlength,
title=name, title=name,
workoutsource=fileformat, workoutsource=fileformat,
notes='imported through email' notes=''
) )

View File

@@ -21,6 +21,7 @@ from rowingdata import rowingdata as rrdata
import rowers.uploads as uploads import rowers.uploads as uploads
from rowers.mailprocessing import make_new_workout_from_email, send_confirm from rowers.mailprocessing import make_new_workout_from_email, send_confirm
import rowers.polarstuff as polarstuff import rowers.polarstuff as polarstuff
import rowers.c2stuff as c2stuff
workoutmailbox = Mailbox.objects.get(name='workouts') workoutmailbox = Mailbox.objects.get(name='workouts')
failedmailbox = Mailbox.objects.get(name='Failed') failedmailbox = Mailbox.objects.get(name='Failed')
@@ -148,8 +149,14 @@ class Command(BaseCommand):
"""Run the Email processing command """ """Run the Email processing command """
def handle(self, *args, **options): def handle(self, *args, **options):
# Polar
polar_available = polarstuff.get_polar_notifications() polar_available = polarstuff.get_polar_notifications()
res = polarstuff.get_all_new_workouts(polar_available) 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) messages = Message.objects.filter(mailbox_id = workoutmailbox.id)
message_ids = [m.id for m in messages] message_ids = [m.id for m in messages]

View File

@@ -643,6 +643,7 @@ class Rower(models.Model):
tokenexpirydate = models.DateTimeField(blank=True,null=True) tokenexpirydate = models.DateTimeField(blank=True,null=True)
c2refreshtoken = models.CharField(default='',max_length=200,blank=True,null=True) c2refreshtoken = models.CharField(default='',max_length=200,blank=True,null=True)
c2_auto_export = models.BooleanField(default=False) c2_auto_export = models.BooleanField(default=False)
c2_auto_import = models.BooleanField(default=False)
sporttrackstoken = models.CharField(default='',max_length=200,blank=True,null=True) sporttrackstoken = models.CharField(default='',max_length=200,blank=True,null=True)
sporttrackstokenexpirydate = models.DateTimeField(blank=True,null=True) sporttrackstokenexpirydate = models.DateTimeField(blank=True,null=True)
sporttracksrefreshtoken = models.CharField(default='',max_length=200, sporttracksrefreshtoken = models.CharField(default='',max_length=200,
@@ -2020,6 +2021,7 @@ class RowerImportExportForm(ModelForm):
fields = [ fields = [
'polar_auto_import', 'polar_auto_import',
'c2_auto_export', 'c2_auto_export',
'c2_auto_import',
'mapmyfitness_auto_export', 'mapmyfitness_auto_export',
'runkeeper_auto_export', 'runkeeper_auto_export',
'sporttracks_auto_export', 'sporttracks_auto_export',

View File

@@ -16,6 +16,7 @@
<li> BoatCoach </li> <li> BoatCoach </li>
<li> RowingCoach </li> <li> RowingCoach </li>
<li> Quiske RowP</li> <li> Quiske RowP</li>
<li> Ritmo Time</li>
<li> Speedcoach XL (CSV)</li> <li> Speedcoach XL (CSV)</li>
<li> Speedcoach GPS (FIT and CSV)</li></ul></p> <li> Speedcoach GPS (FIT and CSV)</li></ul></p>

View File

@@ -29,6 +29,7 @@
<img src="/static/img/bcsquare.png" alt="BoatCoach icon" width="30" height="30"> <img src="/static/img/bcsquare.png" alt="BoatCoach icon" width="30" height="30">
<img src="/static/img/pssquare.png" alt="PainSled icon" width="30" height="30"> <img src="/static/img/pssquare.png" alt="PainSled icon" width="30" height="30">
<img src="/static/img/coxmate.png" alt="CoxMate icon" width="30" height="30"> <img src="/static/img/coxmate.png" alt="CoxMate icon" width="30" height="30">
<img src="/static/img/ritmo_logo.gif" alt="RitmoTime icon" width="30" height="30">
</p> </p>
</div> </div>

BIN
static/img/ritmo_logo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB