Skip to content

Commit

Permalink
matching: prefer confirmed participants
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrindt committed Sep 10, 2024
1 parent d2b9272 commit 4f4900b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
21 changes: 17 additions & 4 deletions ephios/core/services/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ def participation_for_position(self, position_id):


def score_pairing(
participant: AbstractParticipant, position: Position, number_of_participants=1_000_000
participant: AbstractParticipant,
position: Position,
confirmed_participants,
number_of_participants=1_000_000,
):
"""
Score the pairing of participant and position.
Expand All @@ -119,10 +122,11 @@ def score_pairing(
padded_participant_count = 10 + 2 * number_of_participants
base_score = 1.0
preferred_value = 3.0
max_skill_value = 1.0
max_aux_value = 2.0
confirmed_value = 2.0
max_skill_value = 1.0
required_value = padded_participant_count * sum(
(base_score, preferred_value, max_skill_value, max_aux_value)
(base_score, preferred_value, max_skill_value, confirmed_value, max_aux_value)
)
designated_value = required_value**2
unqualified_penalty = designated_value**2
Expand All @@ -140,6 +144,8 @@ def score_pairing(
score += preferred_value
if position.required:
score += required_value
if participant in confirmed_participants:
score += confirmed_value
score += position.skill_level * max_skill_value
score += position.aux_score * max_aux_value
return score
Expand All @@ -148,13 +154,20 @@ def score_pairing(
def match_participants_to_positions(
participants: Collection[AbstractParticipant],
positions: Collection[Position],
confirmed_participants: Collection[AbstractParticipant] = None,
) -> Matching:
participants = list(participants)
positions = list(positions)
confirmed_participants = list(confirmed_participants) if confirmed_participants else []
costs = csr_matrix(
[
[
-score_pairing(participant, position, number_of_participants=len(participants))
-score_pairing(
participant,
position,
number_of_participants=len(participants),
confirmed_participants=confirmed_participants,
)
for position in positions
]
for participant in participants
Expand Down
11 changes: 9 additions & 2 deletions ephios/plugins/complexsignup/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,16 @@ class ComplexShiftStructure(
signup_form_class = ComplexSignupForm

def _match(self, participations):
participants = {participation.participant for participation in participations}
participants = [participation.participant for participation in participations]
confirmed_participants = [
participation.participant
for participation in participations
if participation.state == AbstractParticipation.States.CONFIRMED
]
all_positions, structure = convert_blocks_to_positions(self._base_blocks, participations)
matching = match_participants_to_positions(participants, all_positions)
matching = match_participants_to_positions(
participants, all_positions, confirmed_participants=confirmed_participants
)
matching.attach_participations(participations)

# let's work up the blocks again, but now with matching
Expand Down

0 comments on commit 4f4900b

Please sign in to comment.