Search in sources :

Example 1 with ProblemStatistics

use of cn.edu.zju.acm.onlinejudge.util.ProblemStatistics in project zoj by licheng.

the class ShowProblemStatusAction method execute.

/*
     * Generated Methods
     */
/**
     * Method execute
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
    // check contest
    boolean isProblemset = context.getRequest().getRequestURI().endsWith("showProblemStatus.do");
    ActionForward forward = this.checkProblemViewPermission(mapping, context, isProblemset);
    if (forward != null) {
        return forward;
    }
    Problem problem = context.getProblem();
    String orderBy = context.getRequest().getParameter("orderBy");
    if (!"date".equals(orderBy) && !"memory".equals(orderBy)) {
        orderBy = "time";
    }
    if (problem != null) {
        ProblemStatistics statistics = StatisticsManager.getInstance().getProblemStatistics(problem.getId(), orderBy, 20);
        context.setAttribute("ProblemStatistics", statistics);
    }
    return this.handleSuccess(mapping, context, "success");
}
Also used : ProblemStatistics(cn.edu.zju.acm.onlinejudge.util.ProblemStatistics) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ActionForward(org.apache.struts.action.ActionForward)

Example 2 with ProblemStatistics

use of cn.edu.zju.acm.onlinejudge.util.ProblemStatistics in project zoj by licheng.

the class SubmissionPersistenceImpl method getProblemStatistics.

public ProblemStatistics getProblemStatistics(long problemId, String orderBy, int count) throws PersistenceException {
    Connection conn = null;
    String ob = null;
    ProblemStatistics ret = null;
    if ("time".equals(orderBy)) {
        ob = "s.time_consumption ASC,memory_consumption ASC,s.submission_date ASC";
        ret = new ProblemStatistics(problemId, "time");
    } else if ("memory".equals(orderBy)) {
        ob = "s.memory_consumption ASC,s.time_consumption ASC,submission_date ASC";
        ret = new ProblemStatistics(problemId, "memory");
    } else {
        ob = "s.submission_date ASC,s.time_consumption ASC,memory_consumption ASC";
        ret = new ProblemStatistics(problemId, "date");
    }
    Map<Long, Language> languageMap = PersistenceManager.getInstance().getLanguagePersistence().getLanguageMap();
    try {
        conn = Database.createConnection();
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement("SELECT judge_reply_id, count(*) FROM submission WHERE problem_id=? GROUP BY judge_reply_id");
            ps.setLong(1, problemId);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                long jid = rs.getLong(1);
                int c = rs.getInt(2);
                ret.setCount(jid, c);
            }
        } finally {
            Database.dispose(ps);
        }
        String sql = SubmissionPersistenceImpl.GET_SUBMISSIONS + " AND s.problem_id=? AND s.judge_reply_id=? ORDER BY " + ob + " LIMIT " + count;
        sql = sql.replace("FORCE_INDEX", "USE INDEX (index_submission_problem_reply)");
        try {
            ps = conn.prepareStatement(sql);
            ps.setLong(1, problemId);
            ps.setLong(2, JudgeReply.ACCEPTED.getId());
            ResultSet rs = ps.executeQuery();
            List<Submission> submissions = new ArrayList<Submission>();
            while (rs.next()) {
                Submission submission = this.populateSubmission(rs, false, languageMap);
                submissions.add(submission);
            }
            ret.setBestRuns(submissions);
            return ret;
        } finally {
            Database.dispose(ps);
        }
    } catch (SQLException e) {
        throw new PersistenceException("Failed to get the QQs", e);
    } finally {
        Database.dispose(conn);
    }
}
Also used : ProblemStatistics(cn.edu.zju.acm.onlinejudge.util.ProblemStatistics) Submission(cn.edu.zju.acm.onlinejudge.bean.Submission) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) Language(cn.edu.zju.acm.onlinejudge.bean.enumeration.Language) ResultSet(java.sql.ResultSet) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)

Aggregations

ProblemStatistics (cn.edu.zju.acm.onlinejudge.util.ProblemStatistics)2 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)1 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)1 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)1 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 ActionForward (org.apache.struts.action.ActionForward)1