Permalink
Browse files

finish status icon

  • Loading branch information...
1 parent 424bf4b commit 8c61cfa8f43086818eb3aa7d3ac9fddc7ba762fc @fanzeyi committed Mar 16, 2012
Showing with 74 additions and 10 deletions.
  1. +19 −1 contest.py
  2. +1 −1 handlers.py
  3. +11 −1 judge/db/__init__.py
  4. +30 −1 judge/filters/__init__.py
  5. +5 −2 problem.py
  6. +2 −2 tpl/contest.html
  7. +1 −1 tpl/contest_list.html
  8. +3 −1 tpl/macros.html
  9. +2 −0 tpl/problem_list.html
View
@@ -2,7 +2,7 @@
# AUTHOR: Zeray Rice <fanzeyi1994@gmail.com>
# FILE: contest.py
# CREATED: 15:46:17 15/03/2012
-# MODIFIED: 03:19:13 16/03/2012
+# MODIFIED: 14:50:32 16/03/2012
import datetime
@@ -13,6 +13,21 @@
from judge.db import ContestDBMixin
from judge.base import BaseHandler
+def get_contest_status(contest):
+ status = 0
+ now = datetime.datetime.now()
+ if now >= contest.start_time and now <= contest.end_time:
+ status = 1 #"Running"
+ elif now <= contest.start_time:
+ status = 2 #"Waiting"
+ elif now >= contest.end_time:
+ status = 3 #"Finished"
+ if contest.invisible:
+ status = 4 #"Invisible"
+ if not status:
+ status = 5 #"Unknown"
+ return status
+
class ViewContestHandler(BaseHandler, ContestDBMixin):
@authenticated
def get(self, cid):
@@ -24,6 +39,7 @@ def get(self, cid):
if not contest:
raise HTTPError(404)
now = datetime.datetime.now()
+ contest.status = get_contest_status(contest)
problems = self.select_contest_problem_by_contest_id(cid)
for problem in problems:
problem.submit = self.select_contest_submit_by_contest_id_problem_id_user_id(cid, problem.problem_id)
@@ -51,6 +67,8 @@ def get(self):
breadcrumb.append((self._('Home'), '/'))
breadcrumb.append((self._('Contest'), '/contest'))
pages = self.get_page_count(count)
+ for contest in contests:
+ contest.status = get_contest_status(contest)
self.render("contest_list.html", locals())
__all__ = ["ViewContestHandler", "ListContestHandlder"]
View
@@ -2,7 +2,7 @@
# AUTHOR: Zeray Rice <fanzeyi1994@gmail.com>
# FILE: handlers.py
# CREATED: 01:41:06 08/03/2012
-# MODIFIED: 01:14:36 16/03/2012
+# MODIFIED: 21:52:34 16/03/2012
# DESCRIPTION: URL Route
from api import *
View
@@ -2,7 +2,7 @@
# AUTHOR: Zeray Rice <fanzeyi1994@gmail.com>
# FILE: judge/db/__init__.py
# CREATED: 02:01:23 08/03/2012
-# MODIFIED: 03:13:19 16/03/2012
+# MODIFIED: 14:00:26 16/03/2012
# DESCRIPTION: Database Table Object
import uuid
@@ -238,6 +238,10 @@ def _new_problem_tag(self, row):
problem_tag = ProblemTag()
problem_tag._init_row(row)
return problem_tag
+ def _new_submit(self, row):
+ submit = Submit()
+ submit._init_row(row)
+ return submit
''' COUNT '''
def count_problem(self):
count = self.db.get("""SELECT COUNT(*) FROM `problem`""")
@@ -272,6 +276,12 @@ def select_visible_problem_order_by_id(self, count = 10, start = 0):
for row in rows:
result.append(self._new_problem(row))
return result
+ def select_last_submit_by_problem_id_member_id(self, problem_id):
+ row = self.db.get("""SELECT * FROM `submit` WHERE `problem_id` = %s AND `member_id` = %s ORDER BY `id` DESC LIMIT 1""", \
+ problem_id, self.current_user.id)
+ if row:
+ return self._new_submit(row)
+ return None
''' INSERT '''
def insert_problem(self, problem):
problem.id = self.db.execute("""INSERT INTO `problem` (`title`, `shortname`, `content`, \
View
@@ -2,11 +2,12 @@
# AUTHOR: Zeray Rice <fanzeyi1994@gmail.com>
# FILE: judge/filters/__init__.py
# CREATED: 01:48:10 08/03/2012
-# MODIFIED: 16:00:06 15/03/2012
+# MODIFIED: 14:50:10 16/03/2012
# DESCRIPTION: jinja2 filters
import re
import string
+import datetime
# Configuration for urlize() function
LEADING_PUNCTUATION = ['(', '<', '&lt;']
@@ -21,6 +22,23 @@
'|'.join([re.escape(x) for x in TRAILING_PUNCTUATION])))
simple_email_re = re.compile(r'^\S+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+$')
+CONTEST_STATUS = {
+ 1 : ("success", "Running"),
+ 2 : ("info", "Waiting"),
+ 3 : ("default", "Finished"),
+ 4 : ("warning", "Invisible"),
+ 5 : ("important", "Unknown"),
+}
+SUBMIT_STATUS = {
+ 0 : ("info", "Pending"),
+ 1 : ("success", "Accepted"),
+ 2 : ("important", "Wrong Answer"),
+ 3 : ("warning", "Time Limit Exceeded"),
+ 4 : ("warning", "Memory Limit Exceeded"),
+ 5 : ("inverse", "Runtime Error"),
+ 6 : ("default", "Compile Error"),
+}
+
def autolink(text, trim_url_limit=None, nofollow=False):
"""
Converts any URLs in text into clickable links. Works on http://, https:// and
@@ -99,11 +117,22 @@ def get_page_nav(pages, start):
def datetimeformat(value, format='%m/%d/%Y %H:%M'):
return value.strftime(format)
+def get_contest_status(contest):
+ return "<span class=\"label label-%s\">%s</span>" % (CONTEST_STATUS[contest.status])
+
+def get_submit_status(submit):
+ if not submit:
+ return "-"
+ cla, status = SUBMIT_STATUS[submit.status]
+ return "<span class=\"label label-%s\">%s</span>" % (cla, status)
+
filters = {
'autolink' : autolink,
'avatar_img' : avatar_img,
'get_prev_page' : get_prev_page,
'get_next_page' : get_next_page,
'get_page_nav' : get_page_nav,
'datetimeformat' : datetimeformat,
+ 'get_contest_status' : get_contest_status,
+ 'get_submit_status' : get_submit_status,
}
View
@@ -2,7 +2,7 @@
# AUTHOR: Zeray Rice <fanzeyi1994@gmail.com>
# FILE: problem.py
# CREATED: 04:04:57 15/03/2012
-# MODIFIED: 01:14:52 16/03/2012
+# MODIFIED: 14:00:51 16/03/2012
from tornado.web import HTTPError
@@ -45,8 +45,11 @@ def get(self):
problems = self.select_problem_order_by_id(10, start)
else:
count = self.count_visible_problem()
- problems = self.select_problem_order_by_id_visible(10, start)
+ problems = self.select_visible_problem_order_by_id(10, start)
pages = self.get_page_count(count)
+ if self.current_user:
+ for problem in problems:
+ problem.submit = self.select_last_submit_by_problem_id_member_id(problem.id)
self.render("problem_list.html", locals())
__all__ = ["ViewProblemHandler", "ListProblemHandler"]
View
@@ -25,7 +25,7 @@
</tr>
<tr>
<th>{{ _('Status') }}</th>
- <td></td>
+ <td>{{ contest | get_contest_status }}</td>
</tr>
</table>
</div>
@@ -67,7 +67,7 @@
</table>
</div>
</div>
-{% if user %}
+{% if (user and contest.status == 1) or user.admin %}
<form class="form-horizontal cell">
<fieldset>
<div class="title">{{ _('Submit Problem') }}</div>
View
@@ -22,7 +22,7 @@
<td><a href="/contest/{{ contest.id }}">{{ contest.title }}</a></td>
<td>{{ contest.start_time }}</td>
<td>{{ contest.end_time }}</td>
- <td></td>
+ <td>{{ contest | get_contest_status }}</td>
</tr>
{% endif %}
{% endfor %}
View
@@ -1,3 +1,5 @@
+{#================ List ================#}
+
{% macro show_error_list(error) %}
{%- if error -%}
<div class="alert alert-error">
@@ -35,7 +37,7 @@
{% macro show_contest_list(contest_list) %}
{% endmacro %}
-{#================ Form ================#}
+{#================ Form ================#}
{% macro input(name, label, value = '', type = 'TEXT', class = 'input-xlarge', default = '', addon = '') %}
<div class="control-group">
View
@@ -12,6 +12,7 @@
<th style="width:100px;">{{ _('Time') }}</th>
<th style="width:100px;">{{ _('Memory') }}</th>
<th style="width:100px;">{{ _('Short Name') }}</th>
+ {% if user %}<th style="width:160px;">{{ _('Status') }}</th>{% endif %}
</tr>
</thead>
<tbody>
@@ -23,6 +24,7 @@
<td>{{ problem.timelimit }} ms</td>
<td>{{ problem.memlimit }} MB</td>
<td>{{ problem.shortname }}</td>
+ {% if user %}<td>{{ problem.submit | get_submit_status }}</td>{% endif %}
</tr>
{% endif %}
{% endfor %}

0 comments on commit 8c61cfa

Please sign in to comment.