Skip to content

Commit 87e9ac5

Browse files
committed
fix: total & active contributors can exceed amount of coalition members
1 parent 98e9b12 commit 87e9ac5

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/utils.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,20 @@ export interface CoalitionScore {
490490
minActivePoints: number; // Minimum score for a user to be considered active
491491
totalContributors: number;
492492
activeContributors: number;
493-
}
493+
};
494494

495495
export const getCoalitionScore = async function(prisma: PrismaClient, coalitionId: number, atDateTime: Date = new Date()): Promise<CoalitionScore> {
496496
const normalDist = await getScoresNormalDistribution(prisma, coalitionId, atDateTime);
497497
const minScore = Math.floor(normalDist.mean - normalDist.stdDev);
498498
const activeScores = normalDist.dataPoints.filter(s => s >= minScore);
499499
const fairScore = Math.floor(activeScores.reduce((a, b) => a + b, 0) / activeScores.length);
500+
501+
const totalMembers = await prisma.intraCoalitionUser.count({
502+
where: {
503+
coalition_id: coalitionId,
504+
},
505+
});
506+
500507
return {
501508
coalition_id: coalitionId,
502509
totalPoints: normalDist.dataPoints.reduce((a, b) => a + b, 0),
@@ -505,8 +512,8 @@ export const getCoalitionScore = async function(prisma: PrismaClient, coalitionI
505512
stdDevPoints: normalDist.stdDev,
506513
minActivePoints: minScore,
507514
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)
508-
totalContributors: normalDist.dataPoints.length,
509-
activeContributors: activeScores.length,
515+
totalContributors: Math.min(normalDist.dataPoints.length, totalMembers),
516+
activeContributors: Math.min(activeScores.length, totalMembers),
510517
};
511518
};
512519

0 commit comments

Comments
 (0)