Search in sources :

Example 1 with ContestStatistics

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

the class ShowStatisticsAction method execute.

/**
     * ShowStatisticsAction.
     * 
     * @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 contest
    boolean isProblemset = context.getRequest().getRequestURI().endsWith("showStatistics.do");
    ActionForward forward = this.checkContestViewPermission(mapping, context, isProblemset, true);
    if (forward != null) {
        return forward;
    }
    AbstractContest contest = context.getContest();
    ContestStatistics statistics = StatisticsManager.getInstance().getContestStatistics(contest.getId());
    context.setAttribute("ContestStatistics", statistics);
    return this.handleSuccess(mapping, context, "success");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ActionForward(org.apache.struts.action.ActionForward) ContestStatistics(cn.edu.zju.acm.onlinejudge.util.ContestStatistics)

Example 2 with ContestStatistics

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

the class SubmissionPersistenceImpl method getContestStatistics.

public ContestStatistics getContestStatistics(List<Problem> problems) throws PersistenceException {
    Connection conn = null;
    ContestStatistics statistics = new ContestStatistics(problems);
    if (problems.size() == 0) {
        return statistics;
    }
    try {
        conn = Database.createConnection();
        List<Long> problemIds = new ArrayList<Long>();
        for (Problem problem : problems) {
            problemIds.add(new Long(((Problem) problem).getId()));
        }
        String inProblemIds = Database.createNumberValues(problemIds);
        String query = "SELECT problem_id, judge_reply_id, count(*) FROM submission " + "WHERE problem_id IN " + inProblemIds + " GROUP BY problem_id, judge_reply_id";
        /*
             * String query = "SELECT problem_id, judge_reply_id, count FROM problem_statistics " +
             * "WHERE problem_id IN " + inProblemIds;
             */
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement(query);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                long problemId = rs.getLong(1);
                long judgeReplyId = rs.getLong(2);
                int value = rs.getInt(3);
                statistics.setCount(problemId, judgeReplyId, value);
            }
            return statistics;
        } finally {
            Database.dispose(ps);
        }
    } catch (SQLException e) {
        throw new PersistenceException("Failed to get the statistics", e);
    } finally {
        Database.dispose(conn);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ResultSet(java.sql.ResultSet) PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ContestStatistics(cn.edu.zju.acm.onlinejudge.util.ContestStatistics)

Example 3 with ContestStatistics

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

the class ShowProblemsAction method execute.

/**
     * ShowProblemsAction.
     * 
     * @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 contest
    //System.out.println("in show problems");
    boolean isProblemset = context.getRequest().getRequestURI().endsWith("showProblems.do");
    //boolean isCourse=context.getRequest().getRequestURI().endsWith("showCourseProblems.do");
    ActionForward forward = this.checkContestViewPermission(mapping, context, isProblemset, true);
    if (forward != null) {
        return forward;
    }
    AbstractContest contest = context.getContest();
    //System.out.println("" + contest.getId());
    long problemsCount = ContestManager.getInstance().getProblemsCount(contest.getId());
    long pageNumber = Utility.parseLong(context.getRequest().getParameter("pageNumber"));
    if (pageNumber < 1) {
        pageNumber = 1;
    }
    long problemsPerPage = 100;
    if (problemsCount <= (pageNumber - 1) * problemsPerPage) {
        pageNumber = 1;
    }
    long totalPages = 1;
    if (problemsCount > 0) {
        totalPages = (problemsCount - 1) / problemsPerPage + 1;
    }
    List<Problem> oproblems = ContestManager.getInstance().getContestProblems(contest.getId(), (int) ((pageNumber - 1) * problemsPerPage), (int) problemsPerPage);
    List<Problem> problems = new ArrayList<Problem>();
    problems.addAll(oproblems);
    ContestStatistics contestStatistics = null;
    contestStatistics = StatisticsManager.getInstance().getContestStatistics(contest.getId(), (int) ((pageNumber - 1) * problemsPerPage), (int) problemsPerPage);
    for (int i = 0; i < problems.size(); ++i) {
        Problem p = (Problem) problems.get(i);
        int ac = contestStatistics.getCount(i, 0);
        int total = contestStatistics.getProblemCount(i);
        p.setTotal(total);
        p.setAC(ac);
        if (total == 0) {
            p.setRatio(0);
        } else {
            p.setRatio((double) ac / (double) total);
        }
    }
    String order = context.getRequest().getParameter("order");
    if (order != null) {
        if (order.equalsIgnoreCase("ratio")) {
            Collections.sort(problems, new Comparator() {

                public int compare(Object o1, Object o2) {
                    return (((Problem) o2).getRatio() - ((Problem) o1).getRatio()) > 0 ? 1 : -1;
                }
            });
        } else if (order.equalsIgnoreCase("ac")) {
            Collections.sort(problems, new Comparator() {

                public int compare(Object o1, Object o2) {
                    return ((Problem) o2).getAC() - ((Problem) o1).getAC();
                }
            });
        } else if (order.equalsIgnoreCase("all")) {
            Collections.sort(problems, new Comparator() {

                public int compare(Object o1, Object o2) {
                    return ((Problem) o2).getTotal() - ((Problem) o1).getTotal();
                }
            });
        }
    }
    UserStatistics userStatistics = null;
    if (context.getUserProfile() != null && problems.size() > 0) {
        userStatistics = StatisticsManager.getInstance().getUserStatistics(contest.getId(), context.getUserProfile().getId());
    }
    context.setAttribute("problems", problems);
    context.setAttribute("pageNumber", (new Long(pageNumber)).toString());
    context.setAttribute("ContestStatistics", contestStatistics);
    context.setAttribute("UserStatistics", userStatistics);
    context.setAttribute("totalPages", new Long(totalPages));
    context.setAttribute("currentPage", new Long(pageNumber));
    if (this.checkContestAdminPermission(mapping, context, isProblemset, true) == null && "true".equalsIgnoreCase(context.getRequest().getParameter("check"))) {
        List<String> checkMessages = new ArrayList<String>();
        for (Object obj : problems) {
            Problem p = (Problem) obj;
            this.checkExists("Text", this.getReferenceLength(p, ReferenceType.DESCRIPTION), "ERROR", checkMessages, p);
            this.checkExists("Input", this.getReferenceLength(p, ReferenceType.INPUT), "ERROR", checkMessages, p);
            if (p.isChecker()) {
                this.checkExists("Output", this.getReferenceLength(p, ReferenceType.OUTPUT), "WARNING", checkMessages, p);
                // checkExists("Checker", getReferenceLength(p, ReferenceType.CHECKER), "WARNING", checkMessages,
                // p);
                this.checkExists("Checker source", this.getReferenceLength(p, ReferenceType.CHECKER_SOURCE), "ERROR", checkMessages, p);
            } else {
                this.checkExists("Output", this.getReferenceLength(p, ReferenceType.OUTPUT), "ERROR", checkMessages, p);
            }
            this.checkExists("Judge solution", this.getReferenceLength(p, ReferenceType.JUDGE_SOLUTION), "WARNING", checkMessages, p);
        }
        context.setAttribute("CheckMessages", checkMessages);
    }
    return this.handleSuccess(mapping, context, "success");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ArrayList(java.util.ArrayList) ActionForward(org.apache.struts.action.ActionForward) UserStatistics(cn.edu.zju.acm.onlinejudge.util.UserStatistics) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ContestStatistics(cn.edu.zju.acm.onlinejudge.util.ContestStatistics)

Aggregations

ContestStatistics (cn.edu.zju.acm.onlinejudge.util.ContestStatistics)3 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)2 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)2 ArrayList (java.util.ArrayList)2 ActionForward (org.apache.struts.action.ActionForward)2 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)1 UserStatistics (cn.edu.zju.acm.onlinejudge.util.UserStatistics)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1