From 042a70ea5abeae2e0baf23bebe265d64a382fa20 Mon Sep 17 00:00:00 2001 From: Jiati Le Date: Thu, 1 Jun 2017 02:04:50 -0400 Subject: [PATCH] 1.Add an option -l for submission command which allows user to retrive recent submission in requried programming language, if no submissino in required language, an error will be printed. If no language is specified, program will retrive retrive most recent accepted submission. 2. change behavior: when user specify a language and there are no accepted submission, program will return the most recent non accepted submission in this language 3. bug-fix: problem state is related to the latest submission regardless which language we use. When user specified a language, the status should be related to the latest submission in this language rather than problem --- lib/commands/submission.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/commands/submission.js b/lib/commands/submission.js index badb4c64..63afcf43 100644 --- a/lib/commands/submission.js +++ b/lib/commands/submission.js @@ -30,6 +30,12 @@ var cmd = { type: 'boolean', default: false, describe: 'Provide extra problem details in submission file' + }, + lang: { + alias: 'l', + type: 'string', + default: 'all', + describe: 'Programming language used for previous submission' } } }; @@ -68,21 +74,28 @@ function exportSubmission(argv, problem, cb) { if (e) return cb(e); if (submissions.length === 0) return cb('no submissions?'); - // find the latest accepted one - var submission = _.find(submissions, function(x) { - // TODO: select by lang? + // get obj list contain required filetype + var submissionInTargetType = _.filter(submissions, function(x) { + return argv.lang === 'all' || argv.lang === x.lang; + }); + if (submissionInTargetType.length === 0) { + return cb("No previous submission in required language."); + } + var submission = _.find(submissionInTargetType, function(x) { return x.status_display === 'Accepted'; }); + var submissionState = submission === undefined ? 'notac' : 'ac'; + // if no accepted, use the latest non-accepted one - submission = submission || submissions[0]; + submission = submission || submissionInTargetType[0]; var filename = sprintf('%s/%d.%s.%s.%s%s', argv.outdir, problem.id, problem.key, submission.id, - problem.state, + submissionState, h.langToExt(submission.lang)); // skip the existing cached submissions