diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 8d5f9473..b454942a 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -820,6 +820,43 @@ def new_workout_from_file(r,f2, return (id,message,f2) +def split_workout(r,parent,splitsecond,splitmode): + data,row = getrowdata_db(id=parent.id) + + data['time'] = data['time']/1000. + + data1 = data[data['time']<=splitsecond].copy() + data2 = data[data['time']>splitsecond].copy() + + + messages = [] + ids = [] + + if 'keep first' in splitmode: + id,message = new_workout_from_df(r,data1, + title=parent.name+' First Part', + parent=parent) + messages.append(message) + ids.append(id) + if 'keep second' in splitmode: + data2['cumdist'] = data2['cumdist'] - data2['cumdist'].min() + data2['time'] = data2['time'] - data2['time'].min() + id,message = new_workout_from_df(r,data2, + title=parent.name+' Second Part', + parent=parent) + messages.append(message) + ids.append(id) + + if not 'keep original' in splitmode: + if 'keep second' in splitmode or 'keep first' in splitmode: + parent.delete() + messages.append('Deleted Workout: '+parent.name) + else: + messages.append('That would delete your workout') + ids.append(parent.id) + + return ids,messages + # Create new workout from data frame and store it in the database # This routine should be used everywhere in views.py and mailprocessing.py # Currently there is code duplication @@ -853,6 +890,7 @@ def new_workout_from_df(r,df, df.rename(columns = columndict,inplace=True) + starttimeunix = mktime(startdatetime.utctimetuple()) df[' ElapsedTime (sec)'] = df['TimeStamp (sec)'] df['TimeStamp (sec)'] = df['TimeStamp (sec)']+starttimeunix diff --git a/rowers/forms.py b/rowers/forms.py index 732097e4..59d85ebf 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -110,6 +110,21 @@ class TeamUploadOptionsForm(forms.Form): class Meta: fields = ['make_plot','plottype'] +# This form is used on the Workout Split page +class WorkoutSplitForm(forms.Form): + splitchoices = ( + ('keep original','Keep Original'), + ('keep first','Keep First Part'), + ('keep second','Keep Second Part'), + ) + splittime = forms.TimeField(input_formats=['%H:%M:%S.%f','%H:%M:%S','%M:%S.%f']) + splitmode = forms.MultipleChoiceField( + initial=['keep original', + 'keep first', + 'keep second'], + label='Split Mode', + choices=splitchoices) + # This form is used on the Analysis page to add a custom distance/time # trial and predict the pace class PredictedPieceForm(forms.Form): diff --git a/rowers/templates/splitworkout.html b/rowers/templates/splitworkout.html new file mode 100644 index 00000000..3d9b1fda --- /dev/null +++ b/rowers/templates/splitworkout.html @@ -0,0 +1,113 @@ +{% extends "base.html" %} +{% load staticfiles %} +{% load rowerfilters %} +{% load tz %} + +{% block title %}Change Workout {% endblock %} + +{% block content %} +
+ Please correct the error{{ form.errors|pluralize }} below. +
+ {% endif %} + ++ Edit +
++ Export + +
++ Advanced +
+ Advanced Functionality (More interactive Charts) + +| Date/Time: | {{ workout.startdatetime }} | +|
|---|---|---|
| Distance: | {{ workout.distance }}m | +|
| Duration: | {{ workout.duration |durationprint:"%H:%M:%S.%f" }} | +|
| Public link to this workout | ++ https://rowsandall.com/rowers/workout/{{ workout.id }} + | + |
| Public link to interactive chart | ++ https://rowsandall.com/rowers/workout/{{ workout.id }}/interactiveplot + | + |
Split your workout in half
+ + +