Search in sources :

Example 41 with Problem

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

the class MockProblemDAO method cloneProblem.

private Problem cloneProblem(Problem problem) {
    Problem ret = new Problem();
    ret.setId(problem.getId());
    ret.setRevision(problem.getRevision());
    ret.setLimit(cloneLimit(problem.getLimit()));
    ret.setChecker(problem.isChecker());
    return ret;
}
Also used : Problem(cn.edu.zju.acm.onlinejudge.bean.Problem)

Example 42 with Problem

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

the class UserStatistics method isSolved.

public boolean isSolved(long id) {
    Problem p = new Problem();
    p.setId(id);
    return this.isSolved(p);
}
Also used : Problem(cn.edu.zju.acm.onlinejudge.bean.Problem)

Example 43 with Problem

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

the class SubmissionPersistenceImpl method getUserStatistics.

public UserStatistics getUserStatistics(long contestId, long userId) throws PersistenceException {
    Connection conn = null;
    try {
        UserStatistics statistics = new UserStatistics(userId, contestId);
        conn = Database.createConnection();
        PreparedStatement ps = null;
        /*String sql =
                    "SELECT DISTINCT p.problem_id, p.code, p.title, s.judge_comment " +
                        SubmissionPersistenceImpl.GET_SUBMISSION_FROM_PART +
                        " AND s.user_profile_id=? AND s.judge_reply_id=? AND s.contest_id=?";*/
        String sql = "SELECT p.problem_id, p.code, p.title, s.judge_comment " + SubmissionPersistenceImpl.GET_SUBMISSION_FROM_PART + " AND s.user_profile_id=? AND s.judge_reply_id=? AND s.contest_id=?";
        sql = sql.replace("FORCE_INDEX", "USE INDEX (index_submission_user_reply_contest)");
        HashSet<Long> solvedid = new HashSet<Long>();
        HashSet<Long> confirmedid = new HashSet<Long>();
        List<Problem> solved = new ArrayList<Problem>();
        List<Problem> confirmed = new ArrayList<Problem>();
        try {
            ps = conn.prepareStatement(sql);
            ps.setLong(1, userId);
            ps.setLong(2, JudgeReply.ACCEPTED.getId());
            ps.setLong(3, contestId);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                Long probemid = new Long(rs.getLong("problem_id"));
                if (!solvedid.contains(probemid)) {
                    Problem p = new Problem();
                    p.setContestId(contestId);
                    p.setId(rs.getLong("problem_id"));
                    p.setCode(rs.getString("code"));
                    p.setTitle(rs.getString("title"));
                    solved.add(p);
                    solvedid.add(probemid);
                }
                String comment = rs.getString("judge_comment");
                if (!confirmed.contains(probemid) && "Yes".equals(comment)) {
                    Problem p = new Problem();
                    p.setContestId(contestId);
                    p.setId(rs.getLong("problem_id"));
                    p.setCode(rs.getString("code"));
                    p.setTitle(rs.getString("title"));
                    confirmed.add(p);
                    confirmedid.add(probemid);
                }
            }
        } finally {
            Database.dispose(ps);
        }
        statistics.setSolved(new TreeSet<Problem>(solved));
        statistics.setConfirmed(new TreeSet<Problem>(confirmed));
        try {
            ps = conn.prepareStatement("SELECT judge_reply_id, count(*) FROM submission WHERE contest_id=? AND user_profile_id=? GROUP BY judge_reply_id");
            ps.setLong(1, contestId);
            ps.setLong(2, userId);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                long jid = rs.getLong(1);
                int count = rs.getInt(2);
                statistics.setCount(jid, count);
            }
            return statistics;
        } finally {
            Database.dispose(ps);
        }
    } catch (SQLException e) {
        throw new PersistenceException("Failed to get the user statistics", e);
    } finally {
        Database.dispose(conn);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) UserStatistics(cn.edu.zju.acm.onlinejudge.util.UserStatistics) ResultSet(java.sql.ResultSet) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) HashSet(java.util.HashSet)

Example 44 with Problem

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

the class ContestManager method searchProblems.

public List<Problem> searchProblems(ProblemCriteria criteria, int offset, int count) throws PersistenceException {
    List<Object> key = new ArrayList<Object>();
    key.add(criteria);
    key.add(new Integer(offset));
    key.add(new Integer(count));
    synchronized (this.contestProblemsCache) {
        List<Problem> problems = this.contestProblemsCache.get(key);
        if (problems == null) {
            ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
            problems = problemPersistence.searchProblems(criteria, offset, count);
            this.contestProblemsCache.put(key, problems);
        }
        return problems;
    }
}
Also used : ArrayList(java.util.ArrayList) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ProblemPersistence(cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)

Aggregations

Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)44 ActionForward (org.apache.struts.action.ActionForward)11 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)10 ArrayList (java.util.ArrayList)9 Limit (cn.edu.zju.acm.onlinejudge.bean.Limit)8 ActionMessage (org.apache.struts.action.ActionMessage)7 ProblemPersistence (cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)6 ActionMessages (org.apache.struts.action.ActionMessages)6 Reference (cn.edu.zju.acm.onlinejudge.bean.Reference)5 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)5 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)4 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)3 RankListEntry (cn.edu.zju.acm.onlinejudge.util.RankListEntry)3 List (java.util.List)3 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)2 ProblemForm (cn.edu.zju.acm.onlinejudge.form.ProblemForm)2