diff --git a/libs/judger.js b/libs/judger.js index 38cb20c..5c308f6 100644 --- a/libs/judger.js +++ b/libs/judger.js @@ -48,6 +48,11 @@ async function connect () { judge_state.result = convertedResult.result; await judge_state.save(); await judge_state.updateRelatedInfo(); + } else if(data.type === interface.ProgressReportType.Progress) { + if(!judge_state) return; + judge_state.score = convertedResult.score; + judge_state.total_time = convertedResult.time; + judge_state.max_memory = convertedResult.memory; } else if(data.type == interface.ProgressReportType.Compiled) { if(!judge_state) return; judge_state.compilation = data.progress; diff --git a/libs/submissions_process.js b/libs/submissions_process.js index 2eeb679..61d4d4c 100644 --- a/libs/submissions_process.js +++ b/libs/submissions_process.js @@ -6,7 +6,7 @@ const getSubmissionInfo = (s, displayConfig) => ({ problemName: s.problem.title, problemId: s.problem_id, language: displayConfig.showCode ? ((s.language != null && s.language !== '') ? syzoj.languages[s.language].show : null) : null, - codeSize: displayConfig.showCode ? syzoj.utils.formatSize(s.code_length) : null, + codeSize: displayConfig.showCode ? s.code_length : null, submitTime: syzoj.utils.formatDate(s.submit_time), }); @@ -18,8 +18,7 @@ const getRoughResult = (x, displayConfig) => { return { result: x.status, time: displayConfig.showUsage ? x.total_time : null, - memory: displayConfig.showUsage ? syzoj.utils.formatSize((x.max_memory * 1024) || 0, 2) : null, - precise_memory: displayConfig.showUsage ? x.max_memory : null, + memory: displayConfig.showUsage ? x.max_memory : null, score: displayConfig.showScore ? x.score : null }; } diff --git a/modules/socketio.js b/modules/socketio.js index cc0fc7e..be6d258 100644 --- a/modules/socketio.js +++ b/modules/socketio.js @@ -232,6 +232,13 @@ exports.updateCompileStatus = updateCompileStatus; function updateProgress(taskId, data) { winston.verbose(`Updating progress for #${taskId}`); currentJudgeList[taskId] = data; + const finalResult = judgeResult.convertResult(taskId, data); + const roughResult = { + result: "Running", + time: finalResult.time, + memory: finalResult.memory, + score: finalResult.score + }; forAllClients(detailProgressNamespace, taskId, (client) => { winston.debug(`Pushing progress update to ${client}`); if (clientDetailProgressList[client] && clientDisplayConfigList[client]) { @@ -242,7 +249,8 @@ function updateProgress(taskId, data) { taskId: taskId, from: version, to: version + 1, - delta: diff.diff(original, updated) + delta: diff.diff(original, updated), + roughResult: roughResult }); clientDetailProgressList[client].version++; } diff --git a/modules/submission.js b/modules/submission.js index 499e085..fe5601d 100644 --- a/modules/submission.js +++ b/modules/submission.js @@ -97,7 +97,10 @@ app.get('/submissions', async (req, res) => { let paginate = syzoj.utils.paginate(await JudgeState.count(where), req.query.page, syzoj.config.page.judge_state); let judge_state = await JudgeState.query(paginate, where, [['id', 'desc']], true); - await judge_state.forEachAsync(async obj => obj.loadRelationships()); + await judge_state.forEachAsync(async obj => { + await obj.loadRelationships(); + obj.code_length = obj.code.length; + }) res.render('submissions', { // judge_state: judge_state, @@ -147,7 +150,7 @@ app.get('/submission/:id', async (req, res) => { await judge.loadRelationships(); if (judge.problem.type !== 'submit-answer') { - judge.codeLength = judge.code.length; + judge.code_length = judge.code.length; let key = syzoj.utils.getFormattedCodeKey(judge.code, judge.language); if (key) { diff --git a/modules/user.js b/modules/user.js index 39731cb..15de195 100644 --- a/modules/user.js +++ b/modules/user.js @@ -187,7 +187,6 @@ app.post('/user/:id/edit', async (req, res) => { user.information = req.body.information; user.sex = req.body.sex; user.public_email = (req.body.public_email === 'on'); - console.log(req.body); user.prefer_formatted_code = (req.body.prefer_formatted_code === 'on'); await user.save(); diff --git a/package.json b/package.json index afd270b..d1928b3 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "gravatar": "^1.8.0", "javascript-time-ago": "^1.0.30", "js-yaml": "^3.9.0", - "jsondiffpatch": "0.3.11", + "jsondiffpatch": "0.2.5", "jsonwebtoken": "^8.4.0", "katex": "^0.10.0", "mathjax-node": "^2.1.1", diff --git a/utility.js b/utility.js index a5c7b1d..4122aa8 100644 --- a/utility.js +++ b/utility.js @@ -92,11 +92,11 @@ module.exports = { return sgn + util.format('%s:%s:%s', toStringWithPad(x / 3600), toStringWithPad(x / 60 % 60), toStringWithPad(x % 60)); }, formatSize(x, precision) { - let res = filesize(x, { fixed: precision || 1 }).calculate(); - if (res.result === parseInt(res.result)) res.fixed = res.result.toString(); - if (res.suffix.startsWith('Byte')) res.suffix = 'B'; - else res.suffix = res.suffix.replace('iB', ''); - return res.fixed + ' ' + res.suffix; + if (typeof x !== 'number') return '0 B'; + let unit = 'B', units = ['K', 'M', 'G', 'T']; + for (let i in units) if (x > 1024) x /= 1024, unit = units[i]; + var fixed = x === Math.round(x) ? x.toString() : x.toFixed(precision); + return fixed + ' ' + unit; }, getFormattedCodeKey(code, lang) { if (syzoj.languages[lang].format) { diff --git a/views/status_label.ejs b/views/status_label.ejs index 6118921..be0e9d2 100644 --- a/views/status_label.ejs +++ b/views/status_label.ejs @@ -10,6 +10,7 @@ const iconList = { 'File Error': 'file outline', 'Waiting': 'hourglass half', 'Running': 'spinner', + 'Compiling': 'spinner', 'Compile Error': 'code', 'Submitted': 'checkmark', // NOI contests 'System Error': 'server', @@ -31,10 +32,6 @@ Vue.component('status-label', { }, colorClass() { return (this.indetail ? 'status_detail ' : '') + this.status.toLowerCase().split(' ').join('_'); - }, - outputStatus() { - if (this.status === 'Running' && this.progress) return 'Running ' + this.progress.finished + '/' + this.progress.total; - else return this.status; } } }) @@ -42,6 +39,11 @@ Vue.component('status-label', { diff --git a/views/submission.ejs b/views/submission.ejs index 04d472e..ae9ba96 100644 --- a/views/submission.ejs +++ b/views/submission.ejs @@ -47,7 +47,7 @@ - + @@ -66,7 +66,7 @@ -
+