Package cn.edu.zju.acm.onlinejudge.bean

Examples of cn.edu.zju.acm.onlinejudge.bean.AbstractContest


        }

        context.setAttribute("ContestForm", contestForm);

        // create user profile
        AbstractContest contest = contestForm.toContest();

        contestPersistence.createContest(contest, context.getUserProfile().getId());
        ContestManager.getInstance().refreshContest(contest.getId());

        ActionMessages messages = new ActionMessages();
        messages.add("message", new ActionMessage("onlinejudge.createContest.success"));
        this.saveErrors(context.getRequest(), messages);
        context.setAttribute("back", "manageContests.do");
View Full Code Here


  /**
   * Tests getContest method
   * @throws Exception to JUnit
   */
  public void testGetContest5() throws Exception {   
    AbstractContest contest = (AbstractContest) persistence.getContest(1234567890l);
    assertNull("no such contest", contest);       
  }
View Full Code Here

                user = PersistenceManager.getInstance().getUserPersistence().getUserProfile(userId);
            }
        } else {
            user = context.getUserProfile();
        }
        AbstractContest contest = null;
        if (user != null) {
            long contestId = Utility.parseLong(context.getRequest().getParameter("contestId"));
            if (contestId == -1) {
                contestId = ShowUserStatusAction.defaultProblemSetId;
            }
            contest = ContestManager.getInstance().getContest(contestId);
        }
        if (contest != null) {
            context.setAttribute("contest", contest);
            ActionForward forward = this.checkContestViewPermission(mapping, context, null, true);
            if (forward != null) {
                contest = null;
            }
        }

        UserStatistics statistics = null;
        UserPreference pref = null;
        if (contest != null && user != null) {
          // TODO cache?
          pref = PersistenceManager.getInstance().getUserPersistence().getUserPreference(user.getId());
            statistics = StatisticsManager.getInstance().getUserStatistics(contest.getId(), user.getId());
        }

        context.setAttribute("user", user);
        context.setAttribute("preference", pref);
        context.setAttribute("contest", contest);
View Full Code Here

    public AbstractContest getContest(long id) throws PersistenceException {
      Connection conn = null;
        try {
            conn = Database.createConnection();
            PreparedStatement ps = null;
            AbstractContest contest;
            try {
                ps =
                        conn.prepareStatement(ContestPersistenceImpl.GET_CONTEST + " AND " +
                            DatabaseConstants.CONTEST_CONTEST_ID + "=" + id);
                ResultSet rs = ps.executeQuery();
View Full Code Here

     * @param rs
     * @return an AbstractContest instance
     * @throws SQLException
     */
    private AbstractContest populateContest(ResultSet rs) throws SQLException {
      AbstractContest contest = null;
        int contestType=rs.getInt(DatabaseConstants.CONTEST_PROBLEMSET);
        if (contestType==1) {
            contest = new Problemset();
        } else if (contestType==0) {
            contest = new Contest();
        } else {
            contest = new Course();
        }
        if (rs.getTimestamp(DatabaseConstants.CONTEST_START_TIME) != null) {
            contest.setStartTime(new Date(rs.getTimestamp(DatabaseConstants.CONTEST_START_TIME).getTime()));
        }
        if (rs.getTimestamp(DatabaseConstants.CONTEST_END_TIME) != null) {
            contest.setEndTime(new Date(rs.getTimestamp(DatabaseConstants.CONTEST_END_TIME).getTime()));
        }
        contest.setId(rs.getLong(DatabaseConstants.CONTEST_CONTEST_ID));
        contest.setTitle(rs.getString(DatabaseConstants.CONTEST_TITLE));
        contest.setDescription(rs.getString(DatabaseConstants.CONTEST_DESCRIPTION));
        contest.setForumId(rs.getLong(DatabaseConstants.CONTEST_FORUM_ID));
        contest.setCheckIp(rs.getBoolean(DatabaseConstants.CONTEST_CHECK_IP));

        Limit limit = new Limit();
        limit.setId(rs.getLong(DatabaseConstants.LIMITS_LIMITS_ID));
        limit.setTimeLimit(rs.getInt(DatabaseConstants.LIMITS_TIME_LIMIT));
        limit.setMemoryLimit(rs.getInt(DatabaseConstants.LIMITS_MEMORY_LIMIT));
        limit.setSubmissionLimit(rs.getInt(DatabaseConstants.LIMITS_SUBMISSION_LIMIT));
        limit.setOutputLimit(rs.getInt(DatabaseConstants.LIMITS_OUTPUT_LIMIT));

        contest.setLimit(limit);
        return contest;
    }
View Full Code Here

                        conn.prepareStatement(ContestPersistenceImpl.GET_CONTEST + " AND " +
                            DatabaseConstants.CONTEST_PROBLEMSET + "=" + contestType +
                            " ORDER BY start_time DESC");
                ResultSet rs = ps.executeQuery();
                while (rs.next()) {
                    AbstractContest contest = this.populateContest(rs);
                    contests.add(contest);
                }
            } finally {
                Database.dispose(ps);
            }
View Full Code Here

        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="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);
View Full Code Here

        //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);
View Full Code Here

        ActionForward forward = this.checkProblemParticipatePermission(mapping, context, isProblemset);
        if (forward != null) {
            return forward;
        }

        AbstractContest contest = context.getContest();
        Problem problem = context.getProblem();

        long languageId = Utility.parseLong(context.getRequest().getParameter("languageId"));
        Language language = PersistenceManager.getInstance().getLanguagePersistence().getLanguage(languageId);
        if (language == null) {
            return this.handleSuccess(mapping, context, "submit");
        }
        String source = context.getRequest().getParameter("source");
        if (source == null || source.length() == 0) {
            return this.handleSuccess(mapping, context, "submit");
        }
       
        List refrance = PersistenceManager.getInstance().getReferencePersistence().getProblemReferences(problem.getId(), ReferenceType.HEADER);
        if(refrance.size()!=0) {
          Reference r = (Reference)refrance.get(0);
          String percode = new String(r.getContent());
          source=percode+"\n"+source;
        }
       
        UserProfile user = context.getUserProfile();
        if (submitCache != null && submitCache.contains(user.getId())) {
          
          ActionMessages messages = new ActionMessages();      
            messages.add("message", new ActionMessage("onlinejudge.submit.interval"));
            this.saveErrors(context.getRequest(), messages);
           
            context.setAttribute("source", source);
           
          return handleSuccess(mapping, context, "submit");
        }
       
        if (contest.isCheckIp()) {
            forward = this.checkLastLoginIP(mapping, context, isProblemset);
            if (forward != null) {
                return forward;
            }
        }
        Submission submission = new Submission();
        submission.setContestId(contest.getId());
        submission.setLanguage(language);
        submission.setProblemId(problem.getId());
        submission.setUserProfileId(user.getId());
        submission.setContent(source);
        submission.setMemoryConsumption(0);
        submission.setTimeConsumption(0);
        submission.setSubmitDate(new Date());
        SubmissionPersistence submissionPersistence = PersistenceManager.getInstance().getSubmissionPersistence();

        if (contest.getEndTime() != null && new Date().after(contest.getEndTime())) {
            submission.setJudgeReply(JudgeReply.OUT_OF_CONTEST_TIME);
            submissionPersistence.createSubmission(submission, user.getId());
        } else if (source.getBytes().length > problem.getLimit().getSubmissionLimit() * 1024) {
            submission.setContent(source.substring(0, problem.getLimit().getSubmissionLimit() * 1024));
            submission.setJudgeReply(JudgeReply.SUBMISSION_LIMIT_EXCEEDED);
View Full Code Here

    }

    public AbstractContest getContest(long contestId) throws PersistenceException {
        Object key = new Long(contestId);
        synchronized (this.contestCache) {
            AbstractContest contest = this.contestCache.get(key);
            if (contest == null) {
                ContestPersistence contestPersistence = PersistenceManager.getInstance().getContestPersistence();
                contest = contestPersistence.getContest(contestId);
                this.contestCache.put(key, contest);
            }
View Full Code Here

TOP

Related Classes of cn.edu.zju.acm.onlinejudge.bean.AbstractContest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.