Browse Source

Show submit time in contest ranklist

master
Menci 8 years ago
parent
commit
9a99fec24a
  1. 2
      models/contest.js
  2. 7
      modules/contest.js
  3. 4
      modules/discussion.js
  4. 13
      utility.js
  5. 2
      views/contest_list.ejs
  6. 18
      views/contest_ranklist.ejs
  7. 4
      views/edit_contest.ejs

2
models/contest.js

@ -131,7 +131,7 @@ class Contest extends Model {
}
async isRunning(now) {
if (!now) now = syzoj.utils.getCurrentTime();
if (!now) now = syzoj.utils.getCurrentDate();
return now >= this.start_time && now < this.end_time;
}

7
modules/contest.js

@ -91,8 +91,8 @@ app.post('/contest/:id/edit', async (req, res) => {
if (!Array.isArray(req.body.problems)) req.body.problems = [req.body.problems];
contest.problems = req.body.problems.join('|');
contest.information = req.body.information;
contest.start_time = syzoj.utils.parseTime(req.body.start_time);
contest.end_time = syzoj.utils.parseTime(req.body.end_time);
contest.start_time = syzoj.utils.parseDate(req.body.start_time);
contest.end_time = syzoj.utils.parseDate(req.body.end_time);
await contest.save();
@ -174,6 +174,9 @@ app.get('/contest/:id/ranklist', async (req, res) => {
let ranklist = await players_id.mapAsync(async player_id => {
let player = await ContestPlayer.fromID(player_id);
for (let i in player.score_details) {
player.score_details[i].judge_state = await JudgeState.fromID(player.score_details[i].judge_id);
}
let user = await User.fromID(player.user_id);

4
modules/discussion.js

@ -111,7 +111,7 @@ app.post('/article/:id/edit', async (req, res) => {
let id = parseInt(req.params.id);
let article = await Article.fromID(id);
let time = syzoj.utils.getCurrentTime();
let time = syzoj.utils.getCurrentDate();
if (!article) {
article = await Article.create();
article.user_id = res.locals.user.id;
@ -176,7 +176,7 @@ app.post('/article/:id/comment', async (req, res) => {
content: req.body.comment,
article_id: id,
user_id: res.locals.user.id,
public_time: syzoj.utils.getCurrentTime()
public_time: syzoj.utils.getCurrentDate()
});
await comment.save();

13
utility.js

@ -24,6 +24,7 @@ Array.prototype.forEachAsync = Array.prototype.mapAsync = async function (fn) {
};
let path = require('path');
let util = require('util');
let renderer = require('moemark-renderer');
let moment = require('moment');
let url = require('url');
@ -95,10 +96,18 @@ module.exports = {
m.locale('zh-cn');
return m.format(format || 'L H:mm:ss');
},
parseTime(s) {
formatTime(x) {
function toStringWithPad(x) {
x = parseInt(x);
if (x < 10) return '0' + x.toString();
else return x.toString();
}
return util.format('%s:%s:%s', toStringWithPad(x / 3600), toStringWithPad(x / 60 % 60), toStringWithPad(x % 60));
},
parseDate(s) {
return parseInt(+new Date(s) / 1000);
},
getCurrentTime() {
getCurrentDate() {
return parseInt(+new Date / 1000);
},
makeUrl(req_params, form) {

2
views/contest_list.ejs

@ -22,7 +22,7 @@
<tbody>
<%
for (let contest of contests) {
let now = syzoj.utils.getCurrentTime();
let now = syzoj.utils.getCurrentDate();
let tag = '';
%>
<tr>

18
views/contest_ranklist.ejs

@ -1,5 +1,11 @@
<%= this.title = '排名 - ' + contest.title %>
<% include header %>
<style>
.submit_time {
font-size: 0.8em;
margin-top: 5px;
}
</style>
<div class="padding">
<table class="ui very basic center aligned table">
<thead>
@ -16,7 +22,7 @@
</thead>
<tbody>
<%
let i = 0;
let i = 0, latest = contest.start_time;
for (let item of ranklist) {
i++
%>
@ -45,7 +51,12 @@
<span class="score score_<%= parseInt((item.player.score_details[problem.id].score / 10) || 0) %>">
<%= item.player.score_details[problem.id].score %>
</span>
</a></td>
</a>
<div class="submit_time">
<%= syzoj.utils.formatTime(item.player.score_details[problem.id].judge_state.submit_time - contest.start_time) %>
<% latest = Math.max(latest, item.player.score_details[problem.id].judge_state.submit_time) %>
</div>
</td>
<% } else { %>
<td></td>
<% } %>
@ -54,6 +65,9 @@
<span class="score score_<%= parseInt((item.player.score / ranklist[0].player.score * 10) || 0) %>">
<%= item.player.score %>
</span>
<div class="submit_time">
<%= syzoj.utils.formatTime(latest - contest.start_time) %>
</div>
</td>
</tr>
<% } %>

4
views/edit_contest.ejs

@ -20,11 +20,11 @@
</div>
<div class="field">
<label>开始时间</label>
<input type="text" name="start_time" value="<%= syzoj.utils.formatDate(contest.start_time || syzoj.utils.getCurrentTime()) %>">
<input type="text" name="start_time" value="<%= syzoj.utils.formatDate(contest.start_time || syzoj.utils.getCurrentDate()) %>">
</div>
<div class="field">
<label>结束时间</label>
<input type="text" name="end_time" value="<%= syzoj.utils.formatDate(contest.end_time || syzoj.utils.getCurrentTime()) %>">
<input type="text" name="end_time" value="<%= syzoj.utils.formatDate(contest.end_time || syzoj.utils.getCurrentDate()) %>">
</div>
<button type="submit" class="ui button">提交</button>
</form>

Loading…
Cancel
Save