better api processing (sets duplicate)
This commit is contained in:
@@ -1477,6 +1477,35 @@ def checkbreakthrough(w, r):
|
||||
return isbreakthrough, ishard
|
||||
|
||||
|
||||
def checkduplicates(r,workoutdate,workoutstartdatetime,workoutenddatetime):
|
||||
print(workoutdate,workoutstartdatetime,workoutenddatetime)
|
||||
duplicate = False
|
||||
ws = Workout.objects.filter(user=r,date=workoutdate,duplicate=False).exclude(
|
||||
startdatetime__gt=workoutenddatetime
|
||||
)
|
||||
|
||||
ws2 = []
|
||||
|
||||
for ww in ws:
|
||||
print(ww)
|
||||
t = ww.duration
|
||||
delta = datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)
|
||||
enddatetime = ww.startdatetime+delta
|
||||
print(enddatetime,workoutstartdatetime)
|
||||
if enddatetime > workoutstartdatetime:
|
||||
print('ja')
|
||||
ws2.append(ww)
|
||||
|
||||
|
||||
if (len(ws2) != 0):
|
||||
print('len ws2 ',len(ws2))
|
||||
message = "Warning: This workout overlaps with an existing one and was marked as a duplicate"
|
||||
duplicate = True
|
||||
return duplicate
|
||||
|
||||
return duplicate
|
||||
|
||||
|
||||
# Processes painsled CSV file to database
|
||||
def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
||||
boattype='1x',
|
||||
@@ -1685,23 +1714,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
||||
workoutenddatetime = workoutstartdatetime+delta
|
||||
|
||||
# check for duplicate start times and duration
|
||||
ws = Workout.objects.filter(user=r,date=workoutdate,duplicate=False).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
|
||||
duplicate = checkduplicates(r,workoutdate,workoutstartdatetime,workoutenddatetime)
|
||||
|
||||
# test title length
|
||||
if title is not None and len(title)>140:
|
||||
|
||||
@@ -296,6 +296,15 @@ def strokedatajson_v2(request,id):
|
||||
timestr = row.startdatetime.strftime("%Y%m%d-%H%M%S")
|
||||
csvfilename ='media/Import_'+timestr+'.csv'
|
||||
|
||||
workoutdate = row.date
|
||||
workoutstartdatetime = row.startdatetime
|
||||
workoutenddatetime = workoutstartdatetime+datetime.timedelta(seconds=data[' ElapsedTime (sec)'].max())
|
||||
|
||||
duplicate = dataprep.checkduplicates(r,workoutdate,workoutstartdatetime,workoutenddatetime)
|
||||
if duplicate:
|
||||
row.duplicate = True
|
||||
row.save()
|
||||
|
||||
res = data.to_csv(csvfilename+'.gz',index_label='index',
|
||||
compression='gzip')
|
||||
row.csvfilename = csvfilename
|
||||
|
||||
Reference in New Issue
Block a user