Private
Public Access
1
0
This commit is contained in:
Sander Roosendaal
2020-05-15 17:13:07 +02:00
parent 9e3b12df57
commit e485f060e7
6 changed files with 59 additions and 3 deletions

View File

@@ -8,6 +8,33 @@ from django.utils import timezone
from django.core.management.base import BaseCommand
from rowers.models import Rower,Workout
import re
from django.db.models import Q
from rowers.dataprep import join_workouts
def name_short(name):
expr = '(.*)\s.*\(\d+\)'
match = re.findall(expr,name)
if match:
return match[0]
return name
def get_duplicates(a):
seen = {}
dupes = []
for x in a:
if x not in seen:
seen[x] = 1
else:
if seen[x] == 1:
dupes.append(x)
seen[x] += 1
return seen
class Command(BaseCommand):
def handle(self, *args, **options):
@@ -19,4 +46,19 @@ class Command(BaseCommand):
startdatetime__gte=timezone.now()-datetime.timedelta(days=2))
print('ready autojoin')
duplicates = get_duplicates(name_short(w.name) for w in workouts)
for name, count in duplicates.items():
if count > 1:
workouts = workouts.filter(
Q(name__contains=name)
)
duplicates2 = get_duplicates(w.date for w in workouts)
for dd, count in duplicates2.items():
if count > 1:
workouts = workouts.filter(date=dd)
ids = [w.id for w in workouts]
id, message = join_workouts(r,ids,title=name,
parent=workouts[0],
killparents=True)