diff --git a/libs/rating.js b/libs/rating.js index cc7e95b..8d1d21e 100644 --- a/libs/rating.js +++ b/libs/rating.js @@ -73,5 +73,5 @@ function calculateDeltas(allContestants) { module.exports = function(allContestants) { const deltas = calculateDeltas(allContestants); - return allContestants.map((contestant, i) => ({ user: contestant.user, currentRating: contestant.currentRating + deltas[i] })); + return allContestants.map((contestant, i) => ({ user: contestant.user, rank: contestant.rank, currentRating: contestant.currentRating + deltas[i] })); } \ No newline at end of file diff --git a/models/rating_history.js b/models/rating_history.js index cd2f01b..7980f46 100644 --- a/models/rating_history.js +++ b/models/rating_history.js @@ -27,6 +27,7 @@ let model = db.define('rating_history', { rating_calculation_id: { type: Sequelize.INTEGER, primaryKey: true }, user_id: { type: Sequelize.INTEGER, primaryKey: true }, rating_after: { type: Sequelize.INTEGER }, + rank: { type: Sequelize.INTEGER }, }, { timestamps: false, tableName: 'rating_history', @@ -42,11 +43,12 @@ let model = db.define('rating_history', { let Model = require('./common'); class RatingHistory extends Model { - static async create(rating_calculation_id, user_id, rating) { + static async create(rating_calculation_id, user_id, rating, rank) { return RatingHistory.fromRecord(RatingHistory.model.build({ rating_calculation_id: rating_calculation_id, user_id: user_id, - rating_after: rating + rating_after: rating, + rank: rank })); } diff --git a/modules/admin.js b/modules/admin.js index 92fdd69..e68228b 100644 --- a/modules/admin.js +++ b/modules/admin.js @@ -250,7 +250,7 @@ app.post('/admin/rating/add', async (req, res) => { const user = newRating[i].user; user.rating = newRating[i].currentRating; await user.save(); - const newHistory = await RatingHistory.create(newcalc.id, user.id, user.rating); + const newHistory = await RatingHistory.create(newcalc.id, user.id, newRating[i].currentRating, newRating[i].rank); await newHistory.save(); } diff --git a/modules/user.js b/modules/user.js index 969155b..72ee33d 100644 --- a/modules/user.js +++ b/modules/user.js @@ -20,6 +20,10 @@ 'use strict'; let User = syzoj.model('user'); +const RatingCalculation = syzoj.model('rating_calculation'); +const RatingHistory = syzoj.model('rating_history'); +const Contest = syzoj.model('contest'); +const ContestPlayer = syzoj.model('contest_player'); // Ranklist app.get('/ranklist', async (req, res) => { @@ -103,9 +107,30 @@ app.get('/user/:id', async (req, res) => { await user.renderInformation(); user.emailVisible = user.public_email || user.allowedEdit; + const ratingHistoryValues = await RatingHistory.query(null, { user_id: user.id }, [['rating_calculation_id', 'asc']]); + const ratingHistories = [{ + name: "初始积分", + value: syzoj.config.default.user.rating, + delta: null, + rank: null + }]; + ratingHistories.reverse(); + + for (const history of ratingHistoryValues) { + const contest = await Contest.fromId((await RatingCalculation.fromID(history.rating_calculation_id)).contest_id); + ratingHistories.push({ + contestName: contest.title, + value: history.rating_after, + delta: history.rating_after - ratingHistories[ratingHistories.length - 1].value, + rank: history.rank, + participants: await ContestPlayer.count({ contest_id: contest.id }) + }); + } + res.render('user', { show_user: user, - statistics: statistics + statistics: statistics, + ratingHistories: ratingHistories }); } catch (e) { syzoj.log(e); diff --git a/views/user.ejs b/views/user.ejs index 7d5ceb6..9bd5455 100644 --- a/views/user.ejs +++ b/views/user.ejs @@ -118,6 +118,36 @@ +
比赛 | +名次 | +Rating | +
---|---|---|
<%= history.contestName %> | +<%= history.rank != null ? history.rank + " / " + history.participants : '' %> | +<%= history.value %> + <% if(history.delta != null) { %> + + (<%= (history.delta < 0 ? '' : '+') + history.delta %>) + <% } %> + | +