Search in sources :

Example 1 with ProblemsetRankList

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

the class ShowRankListAction method execute.

/**
     * ShowRankListAction.
     * 
     * @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("showRankList.do");
    ActionForward forward = this.checkContestViewPermission(mapping, context, isProblemset, true);
    if (forward != null) {
        return forward;
    }
    AbstractContest contest = context.getContest();
    if (!isProblemset) {
        List<Problem> problems = context.getProblems();
        context.setAttribute("problems", problems);
        long roleId = Utility.parseLong(context.getRequest().getParameter("roleId"));
        RankList ranklist = StatisticsManager.getInstance().getRankList(contest.getId(), roleId);
        String export = context.getRequest().getParameter("export");
        if ("txt".equalsIgnoreCase(export)) {
            return this.export(context, contest, problems, ranklist, export);
        } else if ("xls".equalsIgnoreCase(export)) {
            return this.export(context, contest, problems, ranklist, export);
        }
        context.setAttribute("RankList", ranklist);
    } else {
        int from = Utility.parseInt(context.getRequest().getParameter("from"));
        if (from < 0) {
            from = 0;
        }
        int count = 30;
        String sort = context.getRequest().getParameter("order");
        if (sort == null || !sort.equalsIgnoreCase("submit")) {
            sort = "ac";
        }
        ProblemsetRankList ranklist = StatisticsManager.getInstance().getProblemsetRankList(contest.getId(), from, count, sort);
        if (from > 0) {
            context.setAttribute("previousFrom", from - count > 0 ? from - count : 0);
        }
        if (ranklist.getSolved().length == count) {
            context.setAttribute("nextFrom", from + count);
        }
        context.setAttribute("RankList", ranklist);
    }
    return this.handleSuccess(mapping, context, "success");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ProblemsetRankList(cn.edu.zju.acm.onlinejudge.util.ProblemsetRankList) RankList(cn.edu.zju.acm.onlinejudge.util.RankList) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ProblemsetRankList(cn.edu.zju.acm.onlinejudge.util.ProblemsetRankList) ActionForward(org.apache.struts.action.ActionForward)

Example 2 with ProblemsetRankList

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

the class SubmissionPersistenceImpl method getProblemsetRankList.

public ProblemsetRankList getProblemsetRankList(long contestId, int offset, int count, String sort) throws PersistenceException {
    Connection conn = null;
    try {
        conn = Database.createConnection();
        PreparedStatement ps = null;
        String sql = null;
        if (sort.equalsIgnoreCase("submit")) {
            sql = "SELECT u.user_profile_id, u.handle, u.nickname, up.plan, ua.solved, ua.tiebreak " + "FROM user_ac ua " + "LEFT JOIN user_profile u ON ua.user_profile_id = u.user_profile_id " + "LEFT JOIN user_preference up ON ua.user_profile_id = up.user_profile_id " + "WHERE contest_id=? ORDER BY ua.tiebreak DESC, ua.solved DESC " + "LIMIT " + offset + "," + count;
        } else {
            sql = "SELECT u.user_profile_id, u.handle, u.nickname, up.plan, ua.solved, ua.tiebreak " + "FROM user_ac ua " + "LEFT JOIN user_profile u ON ua.user_profile_id = u.user_profile_id " + "LEFT JOIN user_preference up ON ua.user_profile_id = up.user_profile_id " + "WHERE contest_id=? ORDER BY ua.solved DESC, ua.tiebreak ASC " + "LIMIT " + offset + "," + count;
        }
        List<UserProfile> users = new ArrayList<UserProfile>();
        List<Integer> solved = new ArrayList<Integer>();
        List<Integer> total = new ArrayList<Integer>();
        try {
            ps = conn.prepareStatement(sql);
            ps.setLong(1, contestId);
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                UserProfile user = new UserProfile();
                user.setId(rs.getLong(1));
                user.setHandle(rs.getString(2));
                user.setNickName(rs.getString(3));
                user.setDeclaration(rs.getString(4));
                users.add(user);
                solved.add(rs.getInt(5));
                total.add(rs.getInt(6));
            }
        } finally {
            Database.dispose(ps);
        }
        int[] solvedArray = new int[solved.size()];
        int[] totalArray = new int[solved.size()];
        for (int i = 0; i < solvedArray.length; ++i) {
            solvedArray[i] = solved.get(i);
            totalArray[i] = total.get(i);
        }
        ProblemsetRankList r = new ProblemsetRankList(offset, count);
        r.setUsers(users.toArray(new UserProfile[0]));
        r.setSolved(solvedArray);
        r.setTotal(totalArray);
        return r;
    } catch (SQLException e) {
        throw new PersistenceException("Failed to get the rank list", e);
    } finally {
        Database.dispose(conn);
    }
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) 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) ProblemsetRankList(cn.edu.zju.acm.onlinejudge.util.ProblemsetRankList)

Aggregations

ProblemsetRankList (cn.edu.zju.acm.onlinejudge.util.ProblemsetRankList)2 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)1 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)1 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)1 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)1 RankList (cn.edu.zju.acm.onlinejudge.util.RankList)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