Skip to content

Add an option for user to retrieve recent submission in certain programming language #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions lib/commands/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
};
Expand Down Expand Up @@ -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
Expand Down