hit-moodle / moodle-local_onlinejudge

Online Judge plugin for Moodle 2.7-4.2.
http://cms.hit.edu.cn
GNU General Public License v3.0
120 stars 59 forks source link
assignment-feedback icpc moodle moodle-plugin online-judge sphere-engine

// tip bulb definition ifdef::env-github[] :tip-caption: 💡 :warn-caption: ⚠️ endif::[] //

// sectionining configurations :idprefix: :idseparator: - :sectanchors: :sectlinks: :sectnumlevels: 6 :sectnums: :toc: macro :toclevels: 6 :toc-title: //

// variables :moodle_url: https://download.moodle.org/releases/latest/ //

[WARN] This plugin is in BETA version and NOT recommended to use in production websites

readme varies in respect to version (i.e., branch), there are https://github.com/hit-moodle/moodle-local_onlinejudge/branches[two available ones].

toc::[]

= Introduction

The Online Judge plugin for {moodle_url}[Moodle] is designed for courses involving programming. It can automatically grade submitted source code by testing them against customizable test cases https://en.wikipedia.org/wiki/International_Collegiate_Programming_Contest[(ACM-ICPC/Online Judge style)].

== Components

[%header,cols=2*] |=== h|Component h|Description

|judgelib |A local-type plugin which provides an online judge function library to any part of Moodle.

|judges |Judge engine plugins for judgelib

|clients |Although there is a developed user interface client, any kind of moodle plugins can work as the client of judgelib to provide UI to teachers and students and call the judgelib to judge submissions. |===

== Judge Engines

[%header,cols=2*] |=== h|Judge Engine h|Description

|<> |Compiles and executes C/C++ programs locally in a protected environment (https://github.com/openjudge/sandbox[see libsandbox]). Supports Linux 32/64-bit only.

|<> |Posts all data to sphere-engine.com which compiles and executes programs remotely. https://sphere-engine.com/supported-languages[Supports 40+ languages], such as C/C++, Java, Python, C#, JavaScript, Perl, PHP. Works on both Windows and Linux.

|Docker (under development) |Posts all data to docker image which compilers, executes, and limiting their behavior. |===

== Plugin Client

Online Judge Assignment Feedback Plugin: online judge version of the https://docs.moodle.org/dev/Assign_feedback_plugins[official feedback plugin] assignment activity.

The workflow is:

  1. Administrators install and config it.
  2. Teachers create Assignment, choose Online Judge as a feedback type, and setup testcases, etc.
  3. Students submit code in Online Judge Assignment Activities.
  4. The <> judges the submissions in background.
  5. Teachers and students get judge results in Online Judge Assignment Activities.

= Prerequisites

== Linux

=== SELinux

Ensure that SELinux allows apache to execute outgoing HTTP requests through the following command:

getsebool httpd_can_network_connect

if it is not set true, run:

setsebool -P httpd_can_network_connect on

== Windows

= Installation / Upgrading

== Cloning

git clone -b OJ_VERSION git://github.com/hit-moodle/moodle-local_onlinejudge.git onlinejudge

[TIP] OJ_VERSION is obtained from the available branches.

[TIP] MOODLE_PATH means the root path of your moodle installation.

== Judge Engines

=== Sandbox

If you would like to use sandbox judge engine, then run:

cd MOODLE_PATH/local/onlinejudge/judge/sandbox/sand/libsandbox && ./configure
cd ..
make

[TIP] Make sure the file named sand is executable, and has the following context: system_u:object_r:bin_t:s0.

=== Sphere Engine

In order to start using sphere engine, navigate to the following path:

MOODLE_PATH/local/onlinejudge/judge/sphere_engine/api/

and run:

composer install

[TIP] Sphere Engine accepts only one file. So, ensure that the "Maximum number of uploaded files" under "Submission types" is set to 1 when you create an assignment.

== Supported Platforms === Linux

  1. If the directory MOODLE_PATH/local/onlinejudge exists, remove/move it https://github.com/hit-moodle/moodle-local_onlinejudge/blob/e87e12c01f8e2e81bc66471bc0f3e960079256cb/cli/install_assign_feedback#L7-L11[(because it will be automatically removed)].
  2. Make sure the directory name of this plugin is onlinejudge. If not, rename it.
  3. Put onlinejudge into MOODLE_PATH/local/
  4. Login your site as admin and access /admin/index.php. The plugin will be installed/upgraded.
  5. Configure the maximum cpu and memory limits.
  6. Run MOODLE_PATH/local/onlinejudge/cli/install_assign_feedback to install the local plugin.
  7. Login your site as admin and access /admin/index.php. The plugin will be installed/upgraded.
  8. In shell, sudo php MOODLE_PATH/local/onlinejudge/cli/judged.php -n -v, to launch the <>.

=== Windows

  1. If the folder MOODLE_PATH\local\onlinejudge exists, remove/move it https://github.com/hit-moodle/moodle-local_onlinejudge/blob/e87e12c01f8e2e81bc66471bc0f3e960079256cb/cli/install_assign_feedback.bat#L7-L9[(because it will be automatically removed)].
  2. Make sure the folder name of this plugin is onlinejudge. If not, rename it.
  3. Put onlinejudge into MOODLE_PATH\local\
  4. Login your site as admin and access /admin/index.php. The plugins will be installed/upgraded.
  5. Configure the maximum cpu and memory limits.
  6. Navigate to MOODLE_PATH\local\onlinejudge\cli and run install_assign_feedback.bat to install the local plugin.
  7. Login your site as admin and access /admin/index.php. The plugins will be installed/upgraded.
  8. In command prompt, write php.exe MOODLE_PATH\local\onlinejudge\cli\judged.php -v, to launch the <>.

= Usage

== Online Judge Assignment Feedback Type

After installation, there will be a new assignment feedback type called Online Judge appears in the "Feedback types" while creating the assignment. Simply check that box and follow the inline help.

==== Creating an Assignment Activity

After checking the Online Judge checkbox, several options will appear:

  1. Programming Language (please note that if you installed libsandbox, there will be two instance of the C and C++ programming languages which could be judged either using libsandbox or <>, however, the ones executed by the sandbox engine will have "(run locally)" next to them).
  2. "Ratio for presentation error" (please click the question mark symbol next to that field).
  3. "Compile only" (please click the question mark symbol next to that field).
  4. "Link Math Library" (please click the question mark symbol next to that field).
  5. "Allow Warnings" (please click the question mark symbol next to that field).
  6. "Link Static Libraries" (please click the question mark symbol next to that field). It is recommended to enable that option if you are using libsandbox.
  7. "Maximum CPU time" (please click the question mark symbol next to that field).
  8. "Maximum memory usage" (please click the question mark symbol next to that field).
  9. "Sphere-Engine Client ID" (If you are using sphere engine, you can find your client id in the "API Tokens" tab)
  10. "Sphere-Engine Access Token" (If you are using sphere engine, you can find your access token in the "API Tokens" tab)

After creating the assignment, two buttons will appear in the assignment page context, Test Case Management and Rejudge All buttons.

==== Test Case Management

If you click the Test Case Management button, you will be redirected to a web form which allows you to specify several test cases which will be tested against the submitted code. You can specify these test cases either in the textarea fields or by uploading testcase files and from which the expected input or output will be read.

You may also choose to specify a grade per testcase (e.g., based on their difficulty).

=== Rejudge All

This option might come in handy if you have edited the assignment or the judging options and would like the have the edits reflected in the previously judged submissions.

If you expand the "Online Judge" tab of a submission, there will be a Force Judge button which allows you to only rejudge that submission.

== Judge Daemon

The judge daemon, which exists in https://github.com/hit-moodle/moodle-local_onlinejudge/blob/master/cli/judged.php[`cli/judged.php], has several helpful options for debugging purposes. Use--help` argument for more information.

Judge all unjudged tasks.

Options:
-h, --help            Print out this help
-n, --nodaemon        Do not run as daemon (Linux only)
-o, --once            Exit while no more to judge
-v, --verbose         Verbose output

Example:
$sudo -u www-data /usr/bin/php local/onlinejudge/cli/judged.php

= Links

[cols=2*] |===

|Home |https://github.com/hit-moodle/moodle-local_onlinejudge

|FAQ |https://github.com/hit-moodle/moodle-local_onlinejudge/wiki

|Bug reports, feature requests, help wanted and other issues: |https://github.com/hit-moodle/moodle-local_onlinejudge/issues |===