-
Notifications
You must be signed in to change notification settings - Fork 0
/
ejudge_database.py
27 lines (22 loc) · 1020 Bytes
/
ejudge_database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import logging
class EjudgeSubmitInfo:
def __init__(self, problem_id, user_id, lang_id, timestamp):
self.problem_id = problem_id
self.user_id = user_id
self.lang_id = lang_id
self.timestamp = timestamp
class EjudgeDatabase:
def __init__(self, ejudge_cursor):
self.data = {}
self.db_cursor = ejudge_cursor
def get_submit_info(self, contest_id, submit_id):
query = ('SELECT prob_id,user_id,lang_id,create_time '
'FROM ejudge.runs '
'WHERE contest_id=%(contest)s AND run_id=%(submit)s')
self.db_cursor.execute(query, {'contest': contest_id, 'submit': submit_id})
response = self.db_cursor.fetchone()
if response is None:
logging.warning('Submit {} from contest {} not found in database'.format(submit_id, contest_id))
return None
problem_id, user_id, lang_id, timestamp = list(response)
return EjudgeSubmitInfo(problem_id, user_id, lang_id, timestamp)