//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);