Remove hardcoded "A" and "I" #7
1 changed files with 12 additions and 8 deletions
|
@ -6,11 +6,14 @@ from events.models import Event, EventRegistration
|
|||
from users.models import CustomUser
|
||||
|
||||
|
||||
def calc_score(user: CustomUser):
|
||||
registrations_last_month = EventRegistration.objects.all().filter(user_id=user.id,
|
||||
event__date__gt=date.today() - timedelta(days=30),
|
||||
event__date__lte=date.today(),
|
||||
state__exact='A')
|
||||
def calc_score(user: CustomUser, for_date):
|
||||
registrations_last_month = EventRegistration.objects.filter(
|
||||
user_id=user.id,
|
||||
event__date__gt=for_date - timedelta(days=30),
|
||||
event__date__lte=for_date,
|
||||
state=EventRegistration.ADMITTED
|
||||
)
|
||||
|
||||
score = 0
|
||||
for r in registrations_last_month:
|
||||
days_ago = (date.today() - r.event.date.date()).days
|
||||
|
@ -22,7 +25,7 @@ def calc_score(user: CustomUser):
|
|||
@app.task(bind=True)
|
||||
def assign_reservations(self):
|
||||
"""
|
||||
Chech if there are any events the next day.
|
||||
Check if there are any events tomorrow.
|
||||
If so, calculate the current score for every interested user and assign the ones with the lowest scores.
|
||||
:param self:
|
||||
:return:
|
||||
|
@ -33,9 +36,10 @@ def assign_reservations(self):
|
|||
events = Event.objects.all().filter(date__date=date.today() + timedelta(days=1))
|
||||
|
||||
# Reservations
|
||||
registrations: List[EventRegistration] = EventRegistration.objects.all().filter(
|
||||
registrations: List[EventRegistration] = EventRegistration.objects.filter(
|
||||
event_id__in=map(lambda event: event.id, events),
|
||||
state__exact='I')
|
||||
state=EventRegistration.INTERESTED)
|
||||
|
||||
if len(registrations) == 0:
|
||||
print("NO REGISTRATIONS?")
|
||||
|
||||
|
|
Loading…
Reference in a new issue