Skip to content

Commit 03e237b

Browse files
committed
feat: add table of last 25 big contributions to profiles
and increase other "last 50 contributions" to "last 100 contributions"
1 parent 8dd4e37 commit 03e237b

5 files changed

Lines changed: 80 additions & 11 deletions

File tree

src/routes/home.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import passport from 'passport';
33
import { CodamCoalition, PrismaClient } from '@prisma/client';
44
import { isQuizAvailable } from './quiz';
55
import { ExpressIntraUser } from '../sync/oauth';
6-
import { getCoalitionScore, CoalitionScore, getRanking, SingleRanking, getBlocAtDate, scoreSumsToRanking, getCoalitionTopContributors } from '../utils';
6+
import { getCoalitionScore, CoalitionScore, getRanking, SingleRanking, getBlocAtDate, scoreSumsToRanking, getCoalitionTopContributors, SMALL_CONTRIBUTION_TYPES } from '../utils';
77

88
export const setupHomeRoutes = function(app: Express, prisma: PrismaClient): void {
99
app.get('/', passport.authenticate('session', {
@@ -198,14 +198,14 @@ export const setupHomeRoutes = function(app: Express, prisma: PrismaClient): voi
198198
take: 50,
199199
});
200200

201-
const latestTopScores = await prisma.codamCoalitionScore.findMany({
201+
const latestBigScores = await prisma.codamCoalitionScore.findMany({
202202
where: {
203203
coalition_id: coalition.id,
204204
OR: [
205205
{
206206
NOT: {
207207
fixed_type_id: {
208-
in: ['logtime', 'evaluation', 'idle_logout', 'ranking_bonus'], // Exclude logtime, ranking bonus and evaluation scores, they are usually low individual scores
208+
in: SMALL_CONTRIBUTION_TYPES, // Exclude usually low individual scores
209209
}
210210
},
211211
},
@@ -270,7 +270,7 @@ export const setupHomeRoutes = function(app: Express, prisma: PrismaClient): voi
270270
topContributors,
271271
topContributorsWeek,
272272
latestScores,
273-
latestTopScores,
273+
latestBigScores,
274274
staff,
275275
});
276276
});

src/routes/profile.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { PrismaClient } from '@prisma/client';
22
import { Express } from 'express';
33
import { ExpressIntraUser } from '../sync/oauth';
4-
import { getUserScores, getUserRankingAcrossAllRankings, getUserTournamentRanking } from '../utils';
4+
import { getUserScores, getUserRankingAcrossAllRankings, getUserTournamentRanking, SMALL_CONTRIBUTION_TYPES } from '../utils';
55

66
export const setupProfileRoutes = function(app: Express, prisma: PrismaClient): void {
77
app.get('/profile/:login', async (req, res) => {
@@ -39,7 +39,7 @@ export const setupProfileRoutes = function(app: Express, prisma: PrismaClient):
3939
orderBy: {
4040
created_at: 'desc',
4141
},
42-
take: 50,
42+
take: 100,
4343
include: {
4444
coalition: {
4545
select: {
@@ -54,12 +54,51 @@ export const setupProfileRoutes = function(app: Express, prisma: PrismaClient):
5454
},
5555
});
5656

57+
const latestBigScores = await prisma.codamCoalitionScore.findMany({
58+
where: {
59+
user_id: profileUser.id,
60+
OR: [
61+
{
62+
NOT: {
63+
fixed_type_id: {
64+
in: SMALL_CONTRIBUTION_TYPES, // Exclude usually low individual scores
65+
}
66+
},
67+
},
68+
{
69+
fixed_type_id: null, // Do include scores that are not fixed types
70+
}
71+
],
72+
amount: {
73+
gt: 0,
74+
},
75+
},
76+
orderBy: {
77+
created_at: 'desc',
78+
},
79+
include: {
80+
user: {
81+
select: {
82+
intra_user: {
83+
select: {
84+
login: true,
85+
usual_full_name: true,
86+
image: true,
87+
},
88+
},
89+
},
90+
},
91+
},
92+
take: 25,
93+
});
94+
5795
// Get user ranking across all rankings
5896
const userRankings = await getUserRankingAcrossAllRankings(prisma, profileUser.id);
5997

6098
return res.render('profile.njk', {
6199
profileUser,
62100
latestScores,
101+
latestBigScores,
63102
userScores,
64103
totalScore,
65104
ranking,

src/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { CURSUS_ID } from "./env";
66
import NodeCache from "node-cache";
77
import { Request } from "express";
88

9+
export const RANKING_MAX = 100; // Maximum number of users to consider for rankings
10+
export const SMALL_CONTRIBUTION_TYPES = ['logtime', 'evaluation', 'idle_logout', 'ranking_bonus']; // Types of contributions that are usually small individual scores
11+
912
export const getAPIClient = async function(): Promise<Fast42> {
1013
if (!api) {
1114
throw new Error('API not initialized');
@@ -503,8 +506,6 @@ export const getCoalitionScore = async function(prisma: PrismaClient, coalitionI
503506
};
504507
};
505508

506-
export const RANKING_MAX = 100; // Maximum number of users to consider for rankings
507-
508509
export interface SingleRanking {
509510
rankingName: string;
510511
user: IntraUser;

templates/coalition.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
<th scope="col">Reason</th>
117117
</thead>
118118
<tbody>
119-
{% for score in latestTopScores %}
119+
{% for score in latestBigScores %}
120120
<tr>
121121
<td title="{{ score.created_at }}">{{ score.created_at | timeAgo }}</td>
122122
<td><a href="/profile/{{ score.user.intra_user.login | striptags(true) | escape }}">{{ score.user.intra_user.login | striptags(true) | escape }}</a></td>

templates/profile.njk

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,41 @@
5858
</div>
5959
</div>
6060

61-
<!-- point history table (last 50 contributions) -->
61+
<!-- point history table (last 25 big contributions) -->
6262
<div class="row ms-0 me-0 mb-4">
6363
<div class="col">
6464
<div class="card h-100">
6565
<div class="card-header">
66-
<h5 class="card-title mb-0">Last 50 contributions</h5>
66+
<h5 class="card-title mb-0">Last 25 big contributions</h5>
67+
</div>
68+
<div class="card-body p-0">
69+
<table class="table coalition-colored mb-0">
70+
<thead>
71+
<th scope="col">Date</th>
72+
<th scope="col">Points</th>
73+
<th scope="col">Reason</th>
74+
</thead>
75+
<tbody>
76+
{% for score in latestBigScores %}
77+
<tr style="background: {{ score.coalition.intra_coalition.color | rgba(0.25) }}">
78+
<td title="{{ score.created_at }}">{{ score.created_at | timeAgo }}</td>
79+
<td>{{ score.amount | thousands }}</td>
80+
<td style="white-space: normal; word-wrap: break-word;">{{ score.reason | striptags(true) | escape }}</td>
81+
</tr>
82+
{% endfor %}
83+
</tbody>
84+
</table>
85+
</div>
86+
</div>
87+
</div>
88+
</div>
89+
90+
<!-- point history table (last 100 contributions) -->
91+
<div class="row ms-0 me-0 mb-4">
92+
<div class="col">
93+
<div class="card h-100">
94+
<div class="card-header">
95+
<h5 class="card-title mb-0">Last 100 contributions</h5>
6796
</div>
6897
<div class="card-body p-0">
6998
<table class="table coalition-colored mb-0">

0 commit comments

Comments
 (0)