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");
}
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);
}
}
Aggregations