diff --git a/logos/ritmo_logo.gif b/logos/ritmo_logo.gif new file mode 100644 index 00000000..b5d6454c Binary files /dev/null and b/logos/ritmo_logo.gif differ diff --git a/rowers/c2stuff.py b/rowers/c2stuff.py index c1df31d8..dca87e85 100644 --- a/rowers/c2stuff.py +++ b/rowers/c2stuff.py @@ -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, diff --git a/rowers/dataprep.py b/rowers/dataprep.py index c98edd6c..ddcb0b05 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -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'] diff --git a/rowers/dataprepnodjango.py b/rowers/dataprepnodjango.py index 2e2b523e..3828afdb 100644 --- a/rowers/dataprepnodjango.py +++ b/rowers/dataprepnodjango.py @@ -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'] diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index fc1e88c6..057c97d0 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -2214,16 +2214,18 @@ def interactive_chart(id=0,promember=0,intervaldata = {}): intervaldf = pd.DataFrame(intervaldata) intervaldf['itime'] = intervaldf['itime']*1.e3 intervaldf['time'] = intervaldf['itime'].cumsum() - intervaldf['time_r'] = intervaldf['time'] +intervaldf['itime'].shift(-1) - intervaldf['value'] = 10 + intervaldf['time'] = intervaldf['time'].shift(1) + intervaldf.ix[0,'time'] = 0 + intervaldf['time_r'] = intervaldf['time'] +intervaldf['itime'] + intervaldf['value'] = 100 mask = intervaldf['itype'] == 3 - intervaldf.loc[mask,'value'] = 45 + intervaldf.loc[mask,'value'] = 0 intervaldf['bottom'] = 10 intervalsource = ColumnDataSource( intervaldf ) - + plot.quad(left='time',top='value',bottom='bottom', right='time_r',source=intervalsource,color='mediumvioletred', y_range_name='spmax',fill_alpha=0.2,line_alpha=0.2) diff --git a/rowers/mailprocessing.py b/rowers/mailprocessing.py index ffedcf99..4223dce6 100644 --- a/rowers/mailprocessing.py +++ b/rowers/mailprocessing.py @@ -168,7 +168,7 @@ def make_new_workout_from_email(rower, datafile, name, cntr=0,testing=False): oarlength=oarlength, title=name, workoutsource=fileformat, - notes='imported through email' + notes='' ) diff --git a/rowers/management/commands/processemail.py b/rowers/management/commands/processemail.py index c8c3f2f9..e8f7f8d8 100644 --- a/rowers/management/commands/processemail.py +++ b/rowers/management/commands/processemail.py @@ -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] diff --git a/rowers/models.py b/rowers/models.py index 247c42fc..b237088a 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -643,6 +643,7 @@ class Rower(models.Model): tokenexpirydate = models.DateTimeField(blank=True,null=True) c2refreshtoken = models.CharField(default='',max_length=200,blank=True,null=True) 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) sporttrackstokenexpirydate = models.DateTimeField(blank=True,null=True) sporttracksrefreshtoken = models.CharField(default='',max_length=200, @@ -2020,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', diff --git a/rowers/templates/compatibility.html b/rowers/templates/compatibility.html index a1bc1297..2c15856f 100644 --- a/rowers/templates/compatibility.html +++ b/rowers/templates/compatibility.html @@ -16,6 +16,7 @@
  • BoatCoach
  • RowingCoach
  • Quiske RowP
  • +
  • Ritmo Time
  • Speedcoach XL (CSV)
  • Speedcoach GPS (FIT and CSV)
  • diff --git a/rowers/templates/frontpage.html b/rowers/templates/frontpage.html index 4a07ae9b..7ecd5fdc 100644 --- a/rowers/templates/frontpage.html +++ b/rowers/templates/frontpage.html @@ -29,6 +29,7 @@ BoatCoach icon PainSled icon CoxMate icon + RitmoTime icon

    diff --git a/static/img/ritmo_logo.gif b/static/img/ritmo_logo.gif new file mode 100644 index 00000000..b5d6454c Binary files /dev/null and b/static/img/ritmo_logo.gif differ