Private
Public Access
1
0

duplicates concept

This commit is contained in:
Sander Roosendaal
2018-11-14 09:50:38 +01:00
parent 0211bfc866
commit 779a07c96b
4 changed files with 33 additions and 7 deletions

1
rowers/.#models.py Normal file
View File

@@ -0,0 +1 @@
E408191@CZ27LT9RCGN72.21348:1542056188

View File

@@ -999,13 +999,30 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
maxhr = np.nan_to_num(maxhr)
averagehr = np.nan_to_num(averagehr)
duplicate = True
t = datetime.datetime.strptime(duration,"%H:%M:%S.%f")
delta = datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)
workoutenddatetime = workoutstartdatetime+delta
# check for duplicate start times and duration
ws = Workout.objects.filter(startdatetime=workoutstartdatetime,
distance=totaldist,
user=r)
if (len(ws) != 0):
message = "Warning: This workout probably already exists in the database"
privacy = 'hidden'
ws = Workout.objects.filter(user=r,date=workoutdate).exclude(
startdatetime__gt=workoutenddatetime
)
ws2 = []
for ww in ws:
t = ww.duration
delta = datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)
enddatetime = ww.startdatetime+delta
if enddatetime > workoutstartdatetime:
ws2.append(ww)
if (len(ws2) != 0):
message = "Warning: This workout overlaps with an existing one and was marked as a duplicate"
duplicate = True
w = Workout(user=r, name=title, date=workoutdate,
@@ -1014,6 +1031,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
duration=duration, distance=totaldist,
weightcategory=r.weightcategory,
starttime=workoutstarttime,
duplicate=duplicate,
workoutsource=workoutsource,
rankingpiece=rankingpiece,
forceunit=forceunit,

View File

@@ -2134,6 +2134,7 @@ class Workout(models.Model):
privacy = models.CharField(default='visible',max_length=30,
choices=privacychoices)
rankingpiece = models.BooleanField(default=False,verbose_name='Ranking Piece')
duplicate = models.BooleanField(default=False,verbose_name='Duplicate Workout')
def __unicode__(self):
@@ -2404,7 +2405,7 @@ class WorkoutForm(ModelForm):
# duration = forms.TimeInput(format='%H:%M:%S.%f')
class Meta:
model = Workout
fields = ['name','date','starttime','timezone','duration','distance','workouttype','boattype','weightcategory','notes','rankingpiece']
fields = ['name','date','starttime','timezone','duration','distance','workouttype','boattype','weightcategory','notes','rankingpiece','duplicate']
widgets = {
'date': AdminDateWidget(),
'notes': forms.Textarea,

View File

@@ -3381,6 +3381,11 @@ def addmanual_view(request):
except KeyError:
rankingpiece = False
try:
duplicate = form.cleaned_data['duplicate']
except KeyError:
duplicate = False
if private:
privacy = 'private'
else:
@@ -3403,6 +3408,7 @@ def addmanual_view(request):
avghr=avghr,
rankingpiece=rankingpiece,
avgpwr=avgpwr,
duplicate=duplicate,
avgspm=avgspm,
title = name,
notes=notes,