use of cn.edu.zjnu.acm.judge.data.form.BestSubmissionForm in project judge by zjnu-acm.
the class BestSubmissionsBuilderTest method testBestSubmissions.
/**
* Test of bestSubmissions method, of class BestSubmissionsBuilder.
*/
@Test
public void testBestSubmissions() {
log.info("bestSubmissions");
for (Pageable pageable : Pageables.bestSubmission()) {
BestSubmissionForm form = BestSubmissionForm.builder().problemId(1000).build();
log.debug(BestSubmissionsBuilder.bestSubmissions(form, pageable));
}
}
use of cn.edu.zjnu.acm.judge.data.form.BestSubmissionForm in project judge by zjnu-acm.
the class SubmissionService method bestSubmission.
public Page<Submission> bestSubmission(Long contestId, long problemId, Pageable pageable, long total) {
BestSubmissionForm form = BestSubmissionForm.builder().contestId(contestId).problemId(problemId).build();
List<Submission> bestSubmissions = submissionMapper.bestSubmission(form, pageable);
return new PageImpl<>(bestSubmissions, pageable, total);
}
use of cn.edu.zjnu.acm.judge.data.form.BestSubmissionForm in project judge by zjnu-acm.
the class BestSubmissionsBuilder method bestSubmissions.
public static String bestSubmissions(@Param("form") BestSubmissionForm form, @Param("pageable") Pageable pageable) {
Long contestId = form.getContestId();
long problemId = form.getProblemId();
Set<String> dejaVu = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
Sort sort = Optional.ofNullable(pageable.getSort()).map(s -> s.and(DEFAULT_SORT)).orElse(DEFAULT_SORT);
Sort.Order[] orders = StreamSupport.stream(sort.spliterator(), false).filter(order -> ALLOW_COLUMNS.contains(order.getProperty()) && dejaVu.add(order.getProperty())).toArray(Sort.Order[]::new);
final int length = orders.length;
log.debug("{}", Arrays.asList(orders));
StringBuilder sb = new StringBuilder("select " + SubmissionMapper.LIST_COLUMNS + " from solution s where problem_id=").append(problemId).append(" and score=100 ");
if (contestId != null) {
sb.append("and contest_id=").append(contestId).append(' ');
}
for (int i = length - 1; i >= 0; --i) {
sb.append("and(user_id");
for (int j = 0; j <= i; ++j) {
sb.append(',').append(orders[j].getProperty());
}
sb.append(")in(select user_id");
for (int j = 0; j < i; ++j) {
sb.append(',').append(orders[j].getProperty());
}
sb.append(',').append(orders[i].isAscending() ? "min" : "max").append("(").append(orders[i].getProperty()).append(")").append(orders[i].getProperty()).append(" from solution where problem_id=").append(problemId).append(" and score=100 ");
if (contestId != null) {
sb.append("and contest_id=").append(contestId).append(' ');
}
}
for (int i = 0; i < length; ++i) {
sb.append("group by user_id)");
}
if (length > 0) {
sb.append(" order by ");
for (int i = 0; i < length; ++i) {
if (i > 0) {
sb.append(",");
}
sb.append(orders[i].getProperty());
if (!orders[i].isAscending()) {
sb.append(" desc");
}
}
}
return sb.append(" limit ").append(pageable.getOffset()).append(",").append(pageable.getPageSize()).toString();
}
use of cn.edu.zjnu.acm.judge.data.form.BestSubmissionForm in project judge by zjnu-acm.
the class SubmissionMapperTest method testBestSubmission.
/**
* Test of bestSubmission method, of class SubmissionMapper.
*/
@Test
public void testBestSubmission() {
log.info("bestSubmission");
long problemId = 1000;
BestSubmissionForm form = BestSubmissionForm.builder().problemId(problemId).build();
for (Pageable pageable : Pageables.bestSubmission()) {
instance.bestSubmission(form, pageable);
}
}
use of cn.edu.zjnu.acm.judge.data.form.BestSubmissionForm in project judge by zjnu-acm.
the class ProblemStatusController method status.
@GetMapping("problemstatus")
@SuppressWarnings("AssignmentToMethodParameter")
public String status(HttpServletRequest request, @RequestParam("problem_id") long id, @RequestParam(value = "language", required = false) Integer language, @PageableDefault(size = 20, sort = { "time", "memory", "code_length" }) Pageable pageable) {
log.debug("{}", pageable);
if (pageable.getPageSize() > 500) {
pageable = PageRequest.of(pageable.getPageNumber(), 500, pageable.getSort());
}
Problem problem = problemService.findOneNoI18n(id);
List<ScoreCount> list = submissionMapper.groupByScore(null, id);
ArrayList<String> scores = new ArrayList<>(list.size());
ArrayList<Long> counts = new ArrayList<>(list.size());
ArrayList<String> urls = new ArrayList<>(list.size());
for (ScoreCount scoreCount : list) {
int score = scoreCount.getScore();
scores.add(ResultType.getShowSourceString(score));
counts.add(scoreCount.getCount());
urls.add(request.getContextPath() + "/status?problem_id=" + id + "&score=" + score);
}
BestSubmissionForm form = BestSubmissionForm.builder().problemId(id).language(language).build();
Page<Submission> page = submissionService.bestSubmission(form, pageable, problem.getSubmitUser());
boolean isAdmin = UserDetailsServiceImpl.isAdministrator(request);
boolean isSourceBrowser = UserDetailsServiceImpl.isSourceBrowser(request);
boolean canView = isAdmin || isSourceBrowser;
request.setAttribute("page", page);
request.setAttribute("sa", Arrays.asList(counts, scores, urls));
request.setAttribute("problem", problem);
request.setAttribute("url", URIBuilder.fromRequest(request).replaceQueryParam("page").toString());
request.setAttribute("canView", canView);
request.setAttribute("currentUserId", SecurityUtils.getUserId());
return "problems/status";
}
Aggregations