oioioi.problems.controllers

Module Contents

Classes

ProblemController

Defines rules for handling specific problem.

Attributes

oioioi.problems.controllers.logger[source]
class oioioi.problems.controllers.ProblemController(problem)[source]

Bases: oioioi.base.utils.RegisteredSubclassesBase, oioioi.base.utils.ObjectWithMixins

Defines rules for handling specific problem.

Every method should:

  • be called from contest controller

  • or be specific for problems that this controller controls

Please note that a global problem instance exists for each problem. That problem instance has no contest (contest is None), so methods can’t be overridden by a contest controller which means they behave in a default way.

modules_with_subclasses = ['controllers'][source]
abstract = True[source]
adjust_problem()[source]

Called whan a (usually new) problem has just got the controller attached or after the problem has been modified.

get_default_submission_kind(request, problem_instance)[source]

Returns default kind of newly created submission by the current user.

The default implementation returns 'IGNORED' for problem admins. In other cases it returns 'NORMAL'.

get_submissions_limit(request, problem_instance, kind='NORMAL')[source]
can_submit(request, problem_instance, check_round_times=True)[source]

Determines if the current user is allowed to submit a solution for the given problem.

The default implementation checks if the user is not anonymous. Subclasses should also call this default implementation.

is_submissions_limit_exceeded(request, problem_instance, kind)[source]
get_submissions_left(request, problem_instance, kind='NORMAL')[source]

Returns number of submissions left until reaching problem limit

abstract fill_evaluation_environ(environ, submission, **kwargs)[source]

Fills a minimal environment with evaluation receipt and other values required by the evaluation machinery.

Passed environ should already contain entries for the actiual data to be judged (for example the source file to evaluate).

Details on which keys need to be present should be specified by particular subclasses.

As the result, environ will be filled at least with a suitable evaluation recipe.

finalize_evaluation_environment(environ)[source]

This method gets called right before the environ becomes scheduled in the queue. It gets called only for submissions send without a contest

This hook exists for inserting extra handlers to the recipe before judging the solution.

judge(submission, extra_args=None, is_rejudge=False)[source]
mixins_for_admin()[source]

Returns an iterable of mixins to add to the default oioioi.problems.admin.ProblemAdmin for this particular problem.

The default implementation returns an empty tuple.

update_user_result_for_problem(result)[source]

Updates a UserResultForProblem.

Usually this involves looking at submissions and aggregating scores from them. Default implementation takes the latest submission which has a score and copies it to the result.

Saving the result is a responsibility of the caller.

update_problem_statistics(problem_statistics, user_statistics, submission)[source]

Updates ProblemStatistics and UserStatistics with data from a new Submission.

This is called when a new submission is checked, and for performance reasons performs as few database queries as possible. The default implementation only checks the submission report kind, and retrieves the score report for the submission.

By default, only ACTIVE and NORMAL submissions are counted for statistics. If you change this behaviour make sure to also update change_submission_kind().

Saving both statistics objects is a responsibility of the caller.

recalculate_statistics_for_user(user)[source]

Recalculates user’s statistics for this problem controller’s problem

Sometimes (for example when a submission’s type changes) we can’t update user statistics quickly, and need to recalculate them. This function by default erases the user statistics for the problem and recalculates them from all of this user’s submissions to every probleminstance of the problem.

static recalculate_statistics_on_submission_deleted(instance, **kwargs)[source]
_activate_newest_report(submission, queryset, kind=None)[source]

Activates the newest report.

Previously active reports are set to SUPERSEDED. Reports which are neither INACTIVE, ACTIVE nor SUPERSEDED are not changed.

Ptype kind

str, list, tuple or None

Parameters

kind – If specified, only reports of the given kind(s) will be considered.

update_report_statuses(submission, queryset)[source]

Updates statuses of reports for the newly judged submission.

Usually this involves looking at reports and deciding which should be ACTIVE and which should be SUPERSEDED.

Parameters
update_user_results(user, problem_instance)[source]

Updates score for problem instance.

Usually this method creates instances (if they don’t exist) of: * UserResultForProblem

and then calls proper methods of ProblemController to update them.

validate_submission_form(request, problem_instance, form, cleaned_data)[source]
adjust_submission_form(request, form, problem_instance)[source]
abstract create_submission(request, problem_instance, form_data, **kwargs)[source]
render_submission_date(submission, shortened=False)[source]

Returns a human-readable representation of the submission date.

In some contests it is more reasonable to show time elapsed since the contest start, in others it’s better to just show the wall clock time.

The default implementation returns the wall clock time.

render_submission_score(submission)[source]

Returns a human-readable representation of the submission score.

The default implementation returns the Unicode representation of submission.score.

get_supported_extra_args(submission)[source]

Returns dict of all values which can be provided in extra_args argument to the judge method.

Renders the given submission footer to HTML.

Footer is shown under the submission reports. The default implementation returns an empty string.

render_report(request, report)[source]

Renders the given report to HTML.

Default implementation supports only rendering reports of kind FAILURE and raises NotImplementedError otherwise.

filter_visible_reports(request, submission, queryset)[source]

Determines which reports the user should be able to see.

It needs to check whether the submission is visible to the user and submission is submitted without contest.

Parameters
  • request – Django request

  • submission – instance of Submission

  • queryset – a queryset, initially filtered at least to select only given submission’s reports

Returns

updated queryset

valid_kinds_for_submission(submission)[source]

Returns list of all valid kinds we can change to for the given submission.

Default implementation supports only kinds NORMAL, IGNORED, SUSPECTED, ‘IGNORED_HIDDEN’.

results_visible(request, submission)[source]

Determines whether it is a good time to show the submission’s results.

This method is not used directly in any code outside of the controllers. It’s a helper method used in a number of other controller methods, as described.

The default implementations returns True.

can_see_submission_status(request, submission)[source]

Determines whether a user can see one of his/her submissions’ status.

Default implementation delegates to :meth: results_visible().

Return type

bool

can_see_submission_score(request, submission)[source]

Determines whether a user can see one of his/her submissions’ score.

Default implementation delegates to :meth: results_visible().

Return type

bool

can_see_submission_comment(request, submission)[source]

Determines whether a user can see one of his/her submissions’ comment.

Default implementation delegates to :meth: results_visible().

Return type

bool

change_submission_kind(submission, kind)[source]

Changes kind of the submission, updates user reports for problem, round and contest which may contain given submission, and updates statistics for the submission’s user if necessary.

_is_partial_score(test_report)[source]
filter_my_visible_submissions(request, queryset, filter_user=True)[source]

Returns the submissions which the user should see in the problemset in “My submissions” view.

The default implementation returns all submissions belonging to the user for current problem except for author, who gets all his submissions.

Should return the updated queryset.

get_extra_problem_site_actions(problem)[source]

Returns a list of tuples (url, name) that will be displayed under actions in ProblemSite.

supports_problem_statement()[source]

If the ProblemController supports problem statement, opening the problem in a contest shows the associated problem statement or an information that it doesn’t have one. On the other hand, if it doesn’t support the problem statement, opening the problem redirects to submit solution page.

get_notification_message_submission_judged(submission)[source]

Returns a message to show in a notification when a submission has been judged. It doesn’t validate any permissions.