Skip to content

Commit

Permalink
feat: Introduce score to quickly assess quality of an assignment run.
Browse files Browse the repository at this point in the history
The score is the sum of fulfilled priorities across all participants.

Example: Participants had to specify six priorities and should be assigned to two activities. If somebody gets their first and fifth priority fulfilled they are scored with 6. If somebody only gets their second priority fulfilled they get a score of 8, because missing assignments are scored with the number of priorities.
  • Loading branch information
bjorndown committed Feb 11, 2024
1 parent 8372ec2 commit 8460652
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/components/Statistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MatchResult } from '../core/matcher'
import { FunctionComponent } from 'react'
import _range from 'lodash/range'
import { ParticipantsConfig } from '../core/model'
import {Explanation} from './Explanation'

type Props = {
result: MatchResult
Expand Down Expand Up @@ -117,6 +118,17 @@ export const Statistics: FunctionComponent<Props> = ({
)}
totalParticipants={result.participants.length}
/>
<h3>Gesamtbewertung</h3>
<p>
<>
{result.participants.reduce(
(scoreSum, participant) =>
scoreSum + participant.score(),
0
)}
<Explanation text="Je tiefer dieser Wert ist, desto besser. Er ist die Summe der erfüllten Prioritäten pro Teilnehmer:in. Beispiel: Wird jemand seiner 1. und 5. Priorität zugewiesen, dann ist ihre Bewertung 1 + 5 = 6. Eine fehlende Zuweisung wird mit der Anzahl Prioritäten gewertet."/>
</>
</p>
</section>
</article>
<style jsx>{`
Expand Down
4 changes: 3 additions & 1 deletion src/components/UnassignableParticipants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const UnassignableParticipants: FunctionComponent<Props> = ({
).map((index) => (
<th>Kurs {index + 1}</th>
))}
<th>Bewertung</th>
</tr>
</thead>
<tbody>
Expand All @@ -63,7 +64,7 @@ export const UnassignableParticipants: FunctionComponent<Props> = ({
: participant.needsMoreActivities()
)
.sort((a, b) => {
return a.activities.length - b.activities.length
return b.score() - a.score()
})
.map((participant, index) => (
<tr
Expand Down Expand Up @@ -121,6 +122,7 @@ export const UnassignableParticipants: FunctionComponent<Props> = ({
<td key={index} />
)
})}
<td>{participant.score()}</td>
</tr>
))}
</tbody>
Expand Down
15 changes: 15 additions & 0 deletions src/core/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type Participant = {
}

export class AssignableParticipant {
// TODO maybe store priority here, too. we keep resolving that all over the place..
public activities: { activity: AssignableActivity; execution: number }[] =
[]

Expand Down Expand Up @@ -121,6 +122,20 @@ export class AssignableParticipant {
.flat()
.filter(({ canBeAssigned }) => canBeAssigned)
}

score(): number {
const assignedActivitiesScore = this.activities
.map((assignedActivity) =>
this.priorities.indexOf(assignedActivity.activity.id) + 1
)
.reduce((sum, priority) => sum + priority, 0)

const missingActivitiesScore =
(this.config.activitiesPerPerson - this.activities.length) *
this.priorities.length

return assignedActivitiesScore + missingActivitiesScore
}
}

export class AssignableActivity {
Expand Down

0 comments on commit 8460652

Please sign in to comment.