Skip to content

Commit

Permalink
feat: Add a small waiting time bonus
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Wilms committed Oct 12, 2024
1 parent 0e3629e commit e8dac02
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
38 changes: 19 additions & 19 deletions common/match/matching.perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async function computeOldMatchings(
describe('Real World Matching Performance', () => {
test.each([
// New Algorithm
[
/* [
'new',
1000,
{
Expand Down Expand Up @@ -139,43 +139,43 @@ describe('Real World Matching Performance', () => {
'>= 56': 1016,
},
},
],
], */
[
'new',
10,
{
matchCountSum: 1045,
matchingSubjectsAvg: 1.6727272727272726,
matchingSubjectsAvg: 1.6679425837320574,
matchingSubjects: {
'>= 1': 1045,
'>= 2': 530,
'>= 3': 133,
'>= 4': 32,
'>= 5': 7,
'>= 2': 533,
'>= 3': 132,
'>= 4': 29,
'>= 5': 4,
},
matchingState: 0.3119617224880383,
matchingState: 0.3186602870813397,
pupilWaitingTimeAvg: 8.35097324007621,
pupilWaitingTime: {
'>= 0': 1045,
'>= 1': 961,
'>= 7': 431,
'>= 14': 73,
'>= 21': 53,
'>= 28': 39,
'>= 1': 960,
'>= 7': 432,
'>= 14': 76,
'>= 21': 55,
'>= 28': 41,
},
studentWaitingTimeAvg: 51.64871701057732,
studentWaitingTimeAvg: 51.60435087760287,
studentWaitingTime: {
'>= 0': 1045,
'>= 1': 1017,
'>= 7': 825,
'>= 14': 681,
'>= 14': 678,
'>= 21': 598,
'>= 28': 551,
'>= 56': 399,
'>= 28': 543,
'>= 56': 391,
},
},
],
[
/* [
'new',
1,
{
Expand Down Expand Up @@ -209,7 +209,7 @@ describe('Real World Matching Performance', () => {
'>= 56': 377,
},
},
],
], */
])('%s algorithm - Run every %s days', async (algo, runDays, expectedSummary) => {
let log = '';
let pupilIdx = 0,
Expand Down
10 changes: 5 additions & 5 deletions common/match/matching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,18 @@ export function matchScore(request: MatchRequest, offer: MatchOffer, currentDate
// just adding a small bonus is enough to achieve this for 30% of matches
const stateBonus = offer.state === request.state ? 1 : 0;

// how good a match is in (0, 1)
const score = 0.99 * subjectBonus + 0.01 * stateBonus;
const offerWaitDays = (+currentDate - +offer.requestAt) / MS_PER_DAY;
const offerWaitingBonus = offerWaitDays > 20 ? 1 : 0;

// TODO: Prefer helpers that waited longer
// how good a match is in (0, 1)
const score = 0.97 * subjectBonus + 0.02 * stateBonus + 0.01 * offerWaitingBonus;

// TODO: Fix retention for matches with only few subjects (e.g. both helper and helpee only have math as subject)
// in that case the score is not so high, and thus they are retained for a long time, although the match is perfect

// Retention: Do not directly match not so perfect matches,
// but let them wait for a few days, maybe a better match arrives
/* const offerWaitDays = (+currentDate - +offer.requestAt) / MS_PER_DAY;
const requestWaitDays = (+currentDate - +request.requestAt) / MS_PER_DAY;
/* const requestWaitDays = (+currentDate - +request.requestAt) / MS_PER_DAY;
// Keep them at most for 3 weeks, and linearily increase the chance of getting matched
const doRetention = requestWaitDays < 21;
Expand Down

0 comments on commit e8dac02

Please sign in to comment.