duplicates concept
This commit is contained in:
1
rowers/.#models.py
Normal file
1
rowers/.#models.py
Normal file
@@ -0,0 +1 @@
|
||||
E408191@CZ27LT9RCGN72.21348:1542056188
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user