本文整理汇总了Python中cms.db.Task.get_from_id方法的典型用法代码示例。如果您正苦于以下问题:Python Task.get_from_id方法的具体用法?Python Task.get_from_id怎么用?Python Task.get_from_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cms.db.Task
的用法示例。
在下文中一共展示了Task.get_from_id方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dataset_updated
# 需要导入模块: from cms.db import Task [as 别名]
# 或者: from cms.db.Task import get_from_id [as 别名]
def dataset_updated(self, task_id):
"""Notice that the active dataset of a task has been changed.
Usually called by AdminWebServer when the contest administrator
changed the active dataset of a task. This means that we should
update all the scores for the task using the submission results
on the new active dataset. If some of them are not available
yet we keep the old scores (we don't delete them!) and wait for
ScoringService to notify us that the new ones are available.
task_id (int): the ID of the task whose dataset has changed.
"""
with SessionGen() as session:
task = Task.get_from_id(task_id, session)
dataset = task.active_dataset
logger.info("Dataset update for task %d (dataset now is %d)." % (
task.id, dataset.id))
# max_score and/or extra_headers might have changed.
self.reinitialize()
for submission in task.submissions:
# Update RWS.
if not submission.user.hidden and \
submission.get_result().scored():
self.send_score(submission)
示例2: extract_complexity
# 需要导入模块: from cms.db import Task [as 别名]
# 或者: from cms.db.Task import get_from_id [as 别名]
def extract_complexity(task_id, file_lengther=None):
"""Extract the complexity of all submissions of the task. The
results are stored in a file task_<id>.info
task_id (int): the id of the task we are interested in.
file_lengther (type): a File-like object that tell the dimension
of the input (see example above for how to write one).
return (int): 0 if operation was successful.
"""
with SessionGen() as session:
task = Task.get_from_id(task_id, session)
if task is None:
return -1
# Extracting the length of the testcase.
file_cacher = FileCacher()
testcases_lengths = [file_length(testcase.input,
file_cacher, file_lengther)
for testcase in task.testcases]
file_cacher.purge_cache()
# Compute the complexity of the solutions.
with open("task_%s.info" % task_id, "wt") as info:
for submission in task.contest.get_submissions():
if submission.task_id == task_id and \
submission.evaluated():
print submission.user.username
result = extract_complexity_submission(testcases_lengths,
submission)
if result[1] is None:
continue
info.write("Submission: %s" % submission.id)
info.write(" - user: %15s" % submission.user.username)
info.write(" - task: %s" % task.name)
if result[0] is not None:
info.write(" - score: %6.2lf" % result[0])
info.write(" - complexity: %20s" %
complexity_to_string(result[1]))
if result[2] is not None:
info.write(" - confidence %5.1lf" % result[2])
info.write("\n")
return 0
示例3: dataset_updated
# 需要导入模块: from cms.db import Task [as 别名]
# 或者: from cms.db.Task import get_from_id [as 别名]
def dataset_updated(self, task_id):
"""This function updates RWS with new data about a task. It should be
called after the live dataset of a task is changed.
task_id (int): id of the task whose dataset has changed.
"""
with SessionGen(commit=False) as session:
task = Task.get_from_id(task_id, session)
dataset = task.active_dataset
logger.info("Dataset update for task %d (dataset now is %d)." % (
task.id, dataset.id))
for submission in task.submissions:
# Update RWS.
if submission.get_result().scored():
self.rankings_send_score(submission)