Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new penalty rules #3349

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,6 @@ google-credentials.json

# vscode
.vscode/

# mac
.DS_Store
Copy link
Contributor

@falbru falbru Sep 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.DS_Store
**/.DS_Store

Your current code only removes the .DS_Store in the root directory

Binary file added lego/.DS_Store
Arashfa0301 marked this conversation as resolved.
Show resolved Hide resolved
Arashfa0301 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this .DS_STORE file

Binary file not shown.
34 changes: 3 additions & 31 deletions lego/apps/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,11 @@ def get_earliest_registration_time(
if len(pools) == 0:
return None
reg_time: date = min(pool.activation_date for pool in pools)

if self.heed_penalties:
if penalties is None:
penalties = user.number_of_penalties()
if penalties == 2:
return reg_time + timedelta(hours=12)
elif penalties == 1:
return reg_time + timedelta(hours=3)
return reg_time + timedelta(hours=5) if penalties >= 1 else reg_time
Arashfa0301 marked this conversation as resolved.
Show resolved Hide resolved
return reg_time

def get_possible_pools(
Expand Down Expand Up @@ -328,9 +326,6 @@ def register(self, registration: Registration) -> Registration:
# Make the user follow the event
FollowEvent.objects.get_or_create(follower=user, target=self)

if penalties >= 3:
return registration.add_to_waiting_list()

# If the event is merged or has only one pool we can skip a lot of logic
if all_pools.count() == 1:
return registration.add_to_pool(possible_pools[0])
Expand Down Expand Up @@ -469,8 +464,6 @@ def early_bump(self, opening_pool: Pool) -> None:
for reg in self.waiting_registrations:
if opening_pool.is_full:
break
if self.heed_penalties and reg.user.number_of_penalties() >= 3:
continue
if self.can_register(reg.user, opening_pool, future=True):
reg.pool = opening_pool
reg.save()
Expand All @@ -491,8 +484,6 @@ def bump_on_pool_creation_or_expansion(self) -> None:
for reg in self.waiting_registrations:
if self.is_full or pool.is_full:
break
if self.heed_penalties and reg.user.number_of_penalties() >= 3:
continue
if self.can_register(reg.user, pool, future=True):
reg.pool = pool
reg.save()
Expand Down Expand Up @@ -576,28 +567,9 @@ def pop_from_waiting_list(

if to_pool:
for registration in self.waiting_registrations:
if self.heed_penalties:
penalties: int = registration.user.number_of_penalties()
earliest_reg: Optional[date] = self.get_earliest_registration_time(
registration.user, [to_pool], penalties
)
if penalties < 3 and earliest_reg and earliest_reg < timezone.now():
if self.can_register(registration.user, to_pool):
return registration
elif self.can_register(registration.user, to_pool):
Arashfa0301 marked this conversation as resolved.
Show resolved Hide resolved
if self.can_register(registration.user, to_pool):
return registration
return None

if self.heed_penalties:
for registration in self.waiting_registrations:
penalties = registration.user.number_of_penalties()
earliest_reg = self.get_earliest_registration_time(
registration.user, None, penalties
)
if penalties < 3 and earliest_reg and earliest_reg < timezone.now():
return registration
return None

return self.waiting_registrations.first()

@staticmethod
Expand Down
54 changes: 0 additions & 54 deletions lego/apps/events/tests/test_async_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,36 +223,6 @@ def test_isnt_bumped_without_permission(self):
self.assertEqual(self.pool_two.registrations.count(), 0)
self.assertEqual(self.event.waiting_registrations.count(), 1)

def test_isnt_bumped_with_penalties(self):
"""Users should not be bumped if they have 3 penalties."""
self.event.start_time = timezone.now() + timedelta(days=1)
self.event.merge_time = timezone.now() + timedelta(hours=12)
self.event.save()

self.pool_one.activation_date = timezone.now() - timedelta(days=1)
self.pool_one.save()

self.pool_two.activation_date = timezone.now() + timedelta(minutes=30)
self.pool_two.save()

users = get_dummy_users(2)

Penalty.objects.create(
user=users[1], reason="test", weight=3, source_event=self.event
)

for user in users:
AbakusGroup.objects.get(name="Webkom").add_user(user)
registration = Registration.objects.get_or_create(
event=self.event, user=user
)[0]
self.event.register(registration)

bump_waiting_users_to_new_pool()

self.assertEqual(self.pool_two.registrations.count(), 0)
self.assertEqual(self.event.waiting_registrations.count(), 1)

def test_isnt_bumped_if_activation_is_far_into_the_future(self):
"""Users should not be bumped if the pool is activated more than
35 minutes in the future."""
Expand Down Expand Up @@ -419,30 +389,6 @@ def test_is_bumped_with_multiple_penalties(self):
self.assertIsNotNone(Registration.objects.get(id=registration.id).pool)
self.assertEqual(self.event.number_of_registrations, 1)

def test_isnt_bumped_with_too_many_penalties(self):
"""Tests that a user isn't bumped when going from 4 to 3 active penalties"""

user = get_dummy_users(1)[0]
AbakusGroup.objects.get(name="Abakus").add_user(user)

p1 = Penalty.objects.create(
user=user, reason="test", weight=1, source_event=self.event
)
Penalty.objects.create(
user=user, reason="test2", weight=3, source_event=self.event
)

registration = Registration.objects.get_or_create(event=self.event, user=user)[
0
]
async_register(registration.id)

make_penalty_expire(p1)
check_events_for_registrations_with_expired_penalties.delay()

self.assertIsNone(Registration.objects.get(id=registration.id).pool)
self.assertEqual(self.event.number_of_registrations, 0)

def test_isnt_bumped_when_full(self):
"""Tests that a user isnt bumped when the event is full when penalties expire."""

Expand Down
Loading