Search in sources :

Example 1 with JudgeReply

use of cn.edu.zju.acm.onlinejudge.bean.enumeration.JudgeReply in project zoj by licheng.

the class JudgeClientJudgeThread method readJudgeReply.

private int readJudgeReply() throws IOException {
    int reply = this.in.readInt();
    JudgeReply r = JudgeReply.findById(reply);
    if (r == null) {
        this.logger.error("Invalid judge reply " + reply);
    } else if (r != JudgeReply.RUNNING) {
        this.logger.info(r.getDescription());
    }
    return reply;
}
Also used : JudgeReply(cn.edu.zju.acm.onlinejudge.bean.enumeration.JudgeReply)

Example 2 with JudgeReply

use of cn.edu.zju.acm.onlinejudge.bean.enumeration.JudgeReply in project zoj by licheng.

the class SubmissionSearchForm method toSubmissionCriteria.

public SubmissionCriteria toSubmissionCriteria() throws ParseException, NumberFormatException, PersistenceException {
    SubmissionCriteria criteria = new SubmissionCriteria();
    if (this.contestId != null && this.contestId.trim().length() > 0) {
        criteria.setContestId(Long.valueOf(this.contestId.trim()));
    }
    if (this.problemCode != null && this.problemCode.trim().length() > 0) {
        criteria.setProblemCode(this.problemCode);
    }
    if (this.handle != null && this.handle.trim().length() > 0) {
        criteria.setHandle(this.handle);
    }
    if (this.idStart != null && this.idStart.trim().length() > 0) {
        criteria.setIdStart(Long.valueOf(this.idStart.trim()));
    }
    if (this.idEnd != null && this.idEnd.trim().length() > 0) {
        criteria.setIdEnd(Long.valueOf(this.idEnd.trim()));
    }
    if (this.timeStart != null && this.timeStart.trim().length() > 0) {
        criteria.setTimeStart(Utility.parseTimestamp(this.timeStart));
    }
    if (this.timeEnd != null && this.timeEnd.trim().length() > 0) {
        criteria.setTimeEnd(Utility.parseTimestamp(this.timeEnd));
    }
    if (this.languageIds != null && this.languageIds.length > 0) {
        LanguagePersistence persistence = PersistenceManager.getInstance().getLanguagePersistence();
        List<Language> languages = new ArrayList<Language>();
        for (int i = 0; i < this.languageIds.length; ++i) {
            languages.add(persistence.getLanguage(Long.parseLong(this.languageIds[i])));
        }
        criteria.setLanguages(languages);
    }
    if (this.judgeReplyIds != null && this.judgeReplyIds.length > 0) {
        List<JudgeReply> judgeReplies = new ArrayList<JudgeReply>();
        for (int i = 0; i < this.judgeReplyIds.length; ++i) {
            judgeReplies.add(JudgeReply.findById(Long.parseLong(this.judgeReplyIds[i])));
        }
        criteria.setJudgeReplies(judgeReplies);
    }
    return criteria;
}
Also used : Language(cn.edu.zju.acm.onlinejudge.bean.enumeration.Language) JudgeReply(cn.edu.zju.acm.onlinejudge.bean.enumeration.JudgeReply) ArrayList(java.util.ArrayList) SubmissionCriteria(cn.edu.zju.acm.onlinejudge.bean.request.SubmissionCriteria) LanguagePersistence(cn.edu.zju.acm.onlinejudge.persistence.LanguagePersistence)

Example 3 with JudgeReply

use of cn.edu.zju.acm.onlinejudge.bean.enumeration.JudgeReply in project zoj by licheng.

the class ShowJudgeRepliesAction method execute.

/**
     * ShowJudgeRepliesAction.
     * 
     * <pre>
     * </pre>
     * 
     * @param mapping
     *            action mapping
     * @param form
     *            action form
     * @param request
     *            http servlet request
     * @param response
     *            http servlet response
     * 
     * @return action forward instance
     * 
     * @throws Exception
     *             any errors happened
     */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
    // check admin
    ActionForward forward = this.checkAdmin(mapping, context);
    if (forward != null) {
        return forward;
    }
    List<JudgeReply> judgeReplies = JudgeReply.getAllJudgeReplies();
    context.setAttribute("JudgeReplies", judgeReplies);
    return this.handleSuccess(mapping, context, "success");
}
Also used : JudgeReply(cn.edu.zju.acm.onlinejudge.bean.enumeration.JudgeReply) ActionForward(org.apache.struts.action.ActionForward)

Example 4 with JudgeReply

use of cn.edu.zju.acm.onlinejudge.bean.enumeration.JudgeReply in project zoj by licheng.

the class SubmissionPersistenceImpl method buildQuery.

/**
     * Build search query.
     * 
     * @param criteria
     * @param lastId
     * @param count
     * @param conn
     * @param ps
     * @param rs
     * @return search query.
     * @throws SQLException
     */
private PreparedStatement buildQuery(String perfix, SubmissionCriteria criteria, long firstId, long lastId, int count, Connection conn) throws SQLException {
    // String userIndex = "index_submission_user";
    // String problemIndex = "index_submission_problem";
    String userIndex = "index_submission_user_reply_contest";
    String problemIndex = "index_submission_problem_reply";
    String judgeReplyIndex = "fk_submission_reply";
    String languageIndex = "index_submission_contest_language_order";
    String defaultIndex = "index_submission_contest_order";
    Set<String> easyProblems = new HashSet<String>(Arrays.asList(new String[] { "2060", "1180", "1067", "1292", "1295", "1951", "1025", "2095", "2105", "1008", "1005", "1152", "1240", "2107", "1037", "1205", "1113", "1045", "1489", "1241", "1101", "1049", "1057", "1003", "1151", "1048", "1002", "1115", "1001" }));
    Set<JudgeReply> easyJudgeReply = new HashSet<JudgeReply>(Arrays.asList(new JudgeReply[] { JudgeReply.ACCEPTED, JudgeReply.WRONG_ANSWER, JudgeReply.TIME_LIMIT_EXCEEDED, JudgeReply.MEMORY_LIMIT_EXCEEDED, JudgeReply.SEGMENTATION_FAULT, JudgeReply.COMPILATION_ERROR, JudgeReply.PRESENTATION_ERROR }));
    /*
         * INDEX optimization If user id presents, use fk_submission_user If problem id presents and submission number <
         * 5000, use fk_submission_problem; If judge_reply_id presents and none of id is 4,5,6,7,12,13 or 16, use
         * fk_submission_reply when otherwise use index_submission_contest_order;
         */
    String order = firstId == -1 ? "DESC" : "ASC";
    if (criteria.getIdStart() != null && firstId < criteria.getIdStart() - 1) {
        firstId = criteria.getIdStart() - 1;
    }
    if (criteria.getIdEnd() != null && lastId > criteria.getIdEnd() + 1) {
        lastId = criteria.getIdEnd() + 1;
    }
    StringBuilder query = new StringBuilder();
    query.append(perfix);
    query.append(" AND s.contest_id=" + criteria.getContestId());
    query.append(" AND contest_order BETWEEN " + (firstId + 1) + " and " + (lastId - 1));
    String index = null;
    if (criteria.getUserId() != null) {
        query.append(" AND s.user_profile_id=" + criteria.getUserId());
        index = userIndex;
    }
    if (criteria.getProblemId() != null) {
        query.append(" AND s.problem_id=" + criteria.getProblemId());
        if (index == null && !easyProblems.contains(criteria.getProblemCode())) {
            index = problemIndex;
        }
    }
    String inCondition = null;
    if (criteria.getJudgeReplies() != null) {
        if (criteria.getJudgeReplies().size() == 0) {
            return null;
        }
        List<Long> judgeRepliesIds = new ArrayList<Long>();
        boolean easy = false;
        for (JudgeReply judgeReply : criteria.getJudgeReplies()) {
            judgeRepliesIds.add(judgeReply.getId());
            if (easyJudgeReply.contains(judgeReply)) {
                easy = true;
            }
        }
        inCondition = " AND s.judge_reply_id IN " + Database.createNumberValues(judgeRepliesIds);
        query.append(inCondition);
        if (index == null && !easy) {
            if (criteria.getProblemId() != null) {
                index = problemIndex;
            } else {
                index = judgeReplyIndex;
            }
        }
    }
    PreparedStatement ps = null;
    if (index == null && criteria.getJudgeReplies() != null && criteria.getProblemId() != null) {
        try {
            ps = conn.prepareStatement("SELECT count(*) from submission s where problem_id=" + criteria.getProblemId() + inCondition);
            ResultSet rs = ps.executeQuery();
            rs.next();
            long cnt = rs.getLong(1);
            if (cnt < 10000) {
                index = problemIndex;
            }
        } finally {
            Database.dispose(ps);
        }
    }
    if (criteria.getLanguages() != null) {
        if (criteria.getLanguages().size() == 0) {
            return null;
        }
        List<Long> languageIds = new ArrayList<Long>();
        for (Language language : criteria.getLanguages()) {
            languageIds.add(language.getId());
        }
        query.append(" AND s.language_id IN " + Database.createNumberValues(languageIds));
        if (index == null)
            index = languageIndex;
    }
    query.append(" ORDER BY contest_order " + order);
    query.append(" LIMIT " + count);
    if (index == null) {
        index = defaultIndex;
    }
    String queryString = query.toString().replace("FORCE_INDEX", "USE INDEX (" + index + ")");
    return conn.prepareStatement(queryString);
}
Also used : ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) Language(cn.edu.zju.acm.onlinejudge.bean.enumeration.Language) JudgeReply(cn.edu.zju.acm.onlinejudge.bean.enumeration.JudgeReply) ResultSet(java.sql.ResultSet) HashSet(java.util.HashSet)

Example 5 with JudgeReply

use of cn.edu.zju.acm.onlinejudge.bean.enumeration.JudgeReply in project zoj by licheng.

the class SubmissionPersistenceImplTest method testDeleteJudgeReply.

/**
	 * Tests deleteJudgeReply method
	 * @throws Exception to JUnit
	 */
public void testDeleteJudgeReply() throws Exception {
    List judgeReplies = persistence.getAllJudgeReplies();
    for (int i = 0; i < 3; ++i) {
        JudgeReply judgeReply = (JudgeReply) judgeReplies.get(i);
        long id = judgeReply.getId();
        persistence.deleteJudgeReply(id, 10);
    }
    judgeReplies = persistence.getAllJudgeReplies();
    assertEquals("wrong size", 0, judgeReplies.size());
}
Also used : JudgeReply(cn.edu.zju.acm.onlinejudge.bean.enumeration.JudgeReply) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

JudgeReply (cn.edu.zju.acm.onlinejudge.bean.enumeration.JudgeReply)14 ArrayList (java.util.ArrayList)7 List (java.util.List)5 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)3 SubmissionCriteria (cn.edu.zju.acm.onlinejudge.bean.request.SubmissionCriteria)2 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)1 LanguagePersistence (cn.edu.zju.acm.onlinejudge.persistence.LanguagePersistence)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 HashSet (java.util.HashSet)1 ActionForward (org.apache.struts.action.ActionForward)1