diff --git a/rowers/c2stuff.py b/rowers/c2stuff.py index c0a79f30..7ecea39e 100644 --- a/rowers/c2stuff.py +++ b/rowers/c2stuff.py @@ -56,7 +56,8 @@ def c2_open(user): return thetoken -def add_stroke_data(user,c2id,workoutid,startdatetime,csvfilename): +def add_stroke_data(user,c2id,workoutid,startdatetime,csvfilename, + workouttype='rower'): r = Rower.objects.get(user=user) if (r.c2token == '') or (r.c2token is None): return custom_exception_handler(401,s) @@ -73,7 +74,7 @@ def add_stroke_data(user,c2id,workoutid,startdatetime,csvfilename): c2id, workoutid, starttimeunix, - csvfilename) + csvfilename,workouttype=workouttype) return 1 @@ -164,7 +165,8 @@ def create_async_workout(alldata,user,c2id): # Check if workout has stroke data, and get the stroke data - result = add_stroke_data(user,c2id,w.id,startdatetime,csvfilename) + result = add_stroke_data(user,c2id,w.id,startdatetime,csvfilename, + workouttype = w.workouttype) return w.id @@ -392,6 +394,8 @@ def createc2workoutdata(w): d[0] = d[1] p = abs(10*row.df.ix[:,' Stroke500mPace (sec/500m)'].values) p = np.clip(p,0,3600) + if w.workouttype == 'bike': + p = 2.0*p t = t.astype(int) d = d.astype(int) p = p.astype(int) @@ -830,6 +834,9 @@ def add_workout_from_data(user,importid,data,strokedata, pace = pace.replace(0,300) velo = 500./pace + if workouttype == 'bike': + velo = 1000./pace + pace = 500./velo power = 2.8*velo**3 diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 23294e2b..1f23f6ec 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -871,8 +871,6 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower', # auto smoothing pace = row.df[' Stroke500mPace (sec/500m)'].values velo = 500. / pace - if workouttype == 'bikeerg': - velo = 1000. / pace f = row.df['TimeStamp (sec)'].diff().mean() if f != 0 and not np.isnan(f): diff --git a/rowers/dataprepnodjango.py b/rowers/dataprepnodjango.py index 57f13d2f..77b5b8fc 100644 --- a/rowers/dataprepnodjango.py +++ b/rowers/dataprepnodjango.py @@ -205,7 +205,7 @@ def create_c2_stroke_data_db( # Saves C2 stroke data to CSV and database def add_c2_stroke_data_db(strokedata,workoutid,starttimeunix,csvfilename, - debug=False): + debug=False,workouttype='rower'): res = make_cumvalues(0.1*strokedata['t']) cum_time = res[0] @@ -246,7 +246,10 @@ def add_c2_stroke_data_db(strokedata,workoutid,starttimeunix,csvfilename, pace = pace.replace(0,300) velo = 500./pace + if workouttype == 'bike': + velo = 1000./pace + # This may be wrong for the bike erg power = 2.8*velo**3 # save csv diff --git a/rowers/tasks.py b/rowers/tasks.py index 67910935..1581d28c 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -89,7 +89,12 @@ def handle_c2_import_stroke_data(c2token, c2id,workoutid, starttimeunix, csvfilename,debug=True,**kwargs): - + + if 'workouttype' in kwargs: + workouttype = kwargs['workouttype'] + else: + workouttype = 'rower' + authorizationstring = str('Bearer ' + c2token) headers = {'Authorization': authorizationstring, 'user-agent': 'sanderroosendaal', @@ -100,7 +105,7 @@ def handle_c2_import_stroke_data(c2token, strokedata = pd.DataFrame.from_dict(s.json()['data']) result = add_c2_stroke_data_db( strokedata,workoutid,starttimeunix, - csvfilename,debug=debug, + csvfilename,debug=debug,workouttype=workouttype ) return 1 diff --git a/rowers/templates/document_form.html b/rowers/templates/document_form.html index 67e38300..ab8a59f3 100644 --- a/rowers/templates/document_form.html +++ b/rowers/templates/document_form.html @@ -87,6 +87,7 @@ $( document ).ready(function() { || $(this).val() == 'dynamic' || $(this).val() == 'slides' || $(this).val() == 'paddle' + || $(this).val() == 'bike' || $(this).val() == 'snow' ) { $('#id_boattype').toggle(false); diff --git a/rowers/templates/manualadd.html b/rowers/templates/manualadd.html index b5dff315..ef7ecc78 100644 --- a/rowers/templates/manualadd.html +++ b/rowers/templates/manualadd.html @@ -21,6 +21,7 @@ $( document ).ready(function() { || $(this).val() == 'dynamic' || $(this).val() == 'slides' || $(this).val() == 'paddle' + || $(this).val() == 'bike' || $(this).val() == 'snow' ) { $('#id_boattype').toggle(false); diff --git a/rowers/templates/workout_form.html b/rowers/templates/workout_form.html index fcd4b1d7..9cdb027c 100644 --- a/rowers/templates/workout_form.html +++ b/rowers/templates/workout_form.html @@ -29,6 +29,7 @@ $( document ).ready(function() { || $(this).val() == 'slides' || $(this).val() == 'paddle' || $(this).val() == 'snow' + || $(this).val() == 'bike' ) { $('#id_boattype').toggle(false); $('#id_boattype').val('1x'); diff --git a/rowers/views.py b/rowers/views.py index 023bb26f..5b2c47d5 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -9757,7 +9757,7 @@ def workout_getimportview(request,externalid,source = 'c2'): w = Workout.objects.get(id=id) w.uploadedtoc2 = c2id w.name = 'Imported from C2' - w.workouttype = 'rower' + w.workouttype = workouttype w.save() message = "This workout does not have any stroke data associated with it. We created synthetic stroke data."