Skip to content

Commit 285cca2

Browse files
committed
fix: coalition member count included dropouts
1 parent 90ec60c commit 285cca2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/utils.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,18 @@ export const getCoalitionScore = async function(prisma: PrismaClient, coalitionI
498498
const activeScores = normalDist.dataPoints.filter(s => s >= minScore);
499499
const fairScore = Math.floor(activeScores.reduce((a, b) => a + b, 0) / activeScores.length);
500500

501-
const totalMembers = await prisma.intraCoalitionUser.count({
501+
const totalActiveMembers = await prisma.intraCoalitionUser.count({
502502
where: {
503503
coalition_id: coalitionId,
504+
user: {
505+
// only count users with an active 42cursus
506+
cursus_users: {
507+
some: {
508+
cursus_id: CURSUS_ID,
509+
end_at: null,
510+
}
511+
}
512+
},
504513
},
505514
});
506515

@@ -512,8 +521,8 @@ export const getCoalitionScore = async function(prisma: PrismaClient, coalitionI
512521
stdDevPoints: normalDist.stdDev,
513522
minActivePoints: minScore,
514523
score: Math.floor(normalDist.mean), // fairScore can jump down too easily when there are a couple of really well scoring students on top of the leaderboard (scores dataset is not a normal distribution)
515-
totalContributors: Math.min(normalDist.dataPoints.length, totalMembers),
516-
activeContributors: Math.min(activeScores.length, totalMembers),
524+
totalContributors: Math.min(normalDist.dataPoints.length, totalActiveMembers),
525+
activeContributors: Math.min(activeScores.length, totalActiveMembers),
517526
};
518527
};
519528

0 commit comments

Comments
 (0)