Commit 14748951 authored by Artem Baranovskyi's avatar Artem Baranovskyi
Browse files

Fixed maximum mark issue.

Added phpunit setup to infrastructure.
parent ae352101
...@@ -17,7 +17,7 @@ ENV MOODLE_BASE_DIR_DATA ${MOODLE_BASE_DIR_DATA} ...@@ -17,7 +17,7 @@ ENV MOODLE_BASE_DIR_DATA ${MOODLE_BASE_DIR_DATA}
# Installing necessary packages # Installing necessary packages
RUN apt-get update && apt-get upgrade -y && \ RUN apt-get update && apt-get upgrade -y && \
apt-get install -y apache2 php libapache2-mod-php php-mysqli php-mysql php-xml php-pdo php-pdo-mysql mariadb-client mariadb-server wget unzip p7zip-full python3 python3-pip iputils-ping php-mbstring graphviz aspell ghostscript clamav php8.2-pspell php8.2-curl php8.2-gd php8.2-intl php8.2-mysql php8.2-xml php8.2-xmlrpc php8.2-ldap php8.2-zip php8.2-soap php8.2-mbstring openssl git nano supervisor php-xdebug ca-certificates && \ apt-get install -y apache2 php libapache2-mod-php php-mysqli php-mysql php-xml php-pdo php-pdo-mysql mariadb-client mariadb-server wget unzip p7zip-full python3 python3-pip iputils-ping php-mbstring graphviz aspell ghostscript clamav php8.2-pspell php8.2-curl php8.2-gd php8.2-intl php8.2-mysql php8.2-xml php8.2-xmlrpc php8.2-ldap php8.2-zip php8.2-soap php8.2-mbstring openssl git nano supervisor php-xdebug && \
apt-get clean && rm -rf /var/lib/apt/lists/* apt-get clean && rm -rf /var/lib/apt/lists/*
# Setting necessary php params # Setting necessary php params
...@@ -126,18 +126,6 @@ RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 \ ...@@ -126,18 +126,6 @@ RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-out /etc/ssl/certs/apache-selfsigned.crt \ -out /etc/ssl/certs/apache-selfsigned.crt \
-subj "/C=EU/ST=Berlin/L=Berlin/O=HFT/CN=www.moodle.loc" -subj "/C=EU/ST=Berlin/L=Berlin/O=HFT/CN=www.moodle.loc"
# Установка корневых сертификатов
RUN update-ca-certificates
RUN curl -O https://curl.se/ca/cacert.pem \
&& mv cacert.pem /etc/ssl/certs/cacert.pem \
# Настройка php.ini для OpenSSL
RUN echo "openssl.cafile=/etc/ssl/certs/ca-certificates.crt" >> /etc/php/8.2/cli/php.ini \
&& echo "openssl.capath=/etc/ssl/certs" >> /etc/php/8.2/cli/php.ini \
&& echo "openssl.cafile=/etc/ssl/certs/ca-certificates.crt" >> /etc/php/8.2/apache2/php.ini \
&& echo "openssl.capath=/etc/ssl/certs" >> /etc/php/8.2/apache2/php.ini \
# Configure SSL virtual host # Configure SSL virtual host
RUN echo \ RUN echo \
"<VirtualHost *:443>\n" \ "<VirtualHost *:443>\n" \
......
File mode changed from 100644 to 100755
...@@ -36,7 +36,6 @@ defined('MOODLE_INTERNAL') || die(); ...@@ -36,7 +36,6 @@ defined('MOODLE_INTERNAL') || die();
function local_asystgrade_before_footer() function local_asystgrade_before_footer()
{ {
global $PAGE; global $PAGE;
// Obtaining parameters from URL // Obtaining parameters from URL
$qid = optional_param('qid', null, PARAM_INT); $qid = optional_param('qid', null, PARAM_INT);
$slot = optional_param('slot', false, PARAM_INT); $slot = optional_param('slot', false, PARAM_INT);
...@@ -51,7 +50,7 @@ function local_asystgrade_before_footer() ...@@ -51,7 +50,7 @@ function local_asystgrade_before_footer()
$question_attempts = $quizQuery->get_question_attempts($qid, $slot); $question_attempts = $quizQuery->get_question_attempts($qid, $slot);
$referenceAnswer = $quizQuery->get_reference_answer($qid); $referenceAnswer = $quizQuery->get_reference_answer($qid);
$maxmark = (float)$question_attempts->current()->maxmark;
$data = prepare_api_data($quizQuery, $question_attempts, $referenceAnswer); $data = prepare_api_data($quizQuery, $question_attempts, $referenceAnswer);
foreach (array_keys($data['studentData']) as $studentId) { foreach (array_keys($data['studentData']) as $studentId) {
...@@ -92,7 +91,7 @@ function local_asystgrade_before_footer() ...@@ -92,7 +91,7 @@ function local_asystgrade_before_footer()
error_log('After API call'); error_log('After API call');
pasteGradedMarks($grades, $inputNames); pasteGradedMarks($grades, $inputNames, $maxmark);
error_log('URL matches /mod/quiz/report.php in page_init'); error_log('URL matches /mod/quiz/report.php in page_init');
} }
...@@ -100,17 +99,20 @@ function local_asystgrade_before_footer() ...@@ -100,17 +99,20 @@ function local_asystgrade_before_footer()
/** /**
* Adds JavasScript scrypt to update marks * Adds JavasScript scrypt to update marks
* * @param array $grades
* @param mixed $grades * @param array $inputNames
* @param mixed $inputNames * @param float $maxmark
* @return void * @return void
*/ */
function pasteGradedMarks(mixed $grades, mixed $inputNames): void
function pasteGradedMarks(array $grades, array $inputNames, float $maxmark): void
{ {
echo generate_script($grades, $inputNames);; echo generate_script($grades, $inputNames, $maxmark);
} }
/** /**
* Processes question attempts and answers to prepare for API a data to estimate answers
*
* @param QuizQuery $database * @param QuizQuery $database
* @param $question_attempts * @param $question_attempts
* @param $referenceAnswer * @param $referenceAnswer
...@@ -153,17 +155,18 @@ function prepare_api_data(QuizQuery $database, $question_attempts, $referenceAns ...@@ -153,17 +155,18 @@ function prepare_api_data(QuizQuery $database, $question_attempts, $referenceAns
/** /**
* Builds JavasScript scrypt to update marks using DOM manipulations * Builds JavasScript scrypt to update marks using DOM manipulations
* *
* @param $grades * @param array $grades
* @param $inputNames * @param array $inputNames
* @param float $maxmark
* @return string * @return string
*/ */
function generate_script($grades, $inputNames) { function generate_script(array $grades, array $inputNames, float $maxmark) {
$script = "<script type='text/javascript'> $script = "<script type='text/javascript'>
document.addEventListener('DOMContentLoaded', function() {"; document.addEventListener('DOMContentLoaded', function() {";
foreach ($grades as $index => $grade) { foreach ($grades as $index => $grade) {
if (isset($grade['predicted_grade'])) { if (isset($grade['predicted_grade'])) {
$predicted_grade = $grade['predicted_grade'] == 'correct' ? 1 : 0; $predicted_grade = $grade['predicted_grade'] == 'correct' ? $maxmark : 0;
$input_name = $inputNames[$index]; $input_name = $inputNames[$index];
$script .= " $script .= "
console.log('Trying to update input: {$input_name} with grade: {$predicted_grade}'); console.log('Trying to update input: {$input_name} with grade: {$predicted_grade}');
......
...@@ -13,6 +13,17 @@ require_once($CFG->dirroot . '/mod/quiz/tests/generator/lib.php'); ...@@ -13,6 +13,17 @@ require_once($CFG->dirroot . '/mod/quiz/tests/generator/lib.php');
class quiz_api_test extends advanced_testcase class quiz_api_test extends advanced_testcase
{ {
protected function setUp(): void
{
global $DB;
$this->resetAfterTest();
parent::setUp();
$DB->execute('TRUNCATE TABLE {quiz_attempts}');
$DB->execute('TRUNCATE TABLE {quiz_slots}');
}
/** /**
* @throws Exception * @throws Exception
*/ */
...@@ -299,7 +310,6 @@ class quiz_api_test extends advanced_testcase ...@@ -299,7 +310,6 @@ class quiz_api_test extends advanced_testcase
return $DB->get_record('question_categories', array('id' => $categoryid)); return $DB->get_record('question_categories', array('id' => $categoryid));
} }
private function create_quiz_attempt($quizid, $userid, $questionid, $exapmle_answers, $student_id) private function create_quiz_attempt($quizid, $userid, $questionid, $exapmle_answers, $student_id)
{ {
global $DB; global $DB;
...@@ -385,15 +395,4 @@ class quiz_api_test extends advanced_testcase ...@@ -385,15 +395,4 @@ class quiz_api_test extends advanced_testcase
echo "Error inserting quiz attempt: " . $e->getMessage() . "\n"; echo "Error inserting quiz attempt: " . $e->getMessage() . "\n";
} }
} }
protected function setUp(): void
{
global $DB;
$this->resetAfterTest();
parent::setUp();
$DB->execute('TRUNCATE TABLE {quiz_attempts}');
$DB->execute('TRUNCATE TABLE {quiz_slots}');
}
} }
...@@ -48,7 +48,19 @@ docker-compose exec moodle php ${MOODLE_BASE_DIR}/admin/cli/install.php \ ...@@ -48,7 +48,19 @@ docker-compose exec moodle php ${MOODLE_BASE_DIR}/admin/cli/install.php \
fi fi
# Composer installation to run phpunit tests # Composer installation to run phpunit tests
docker-compose exec moodle composer install docker-compose exec moodle php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
docker-compose exec moodle php composer-setup.php --install-dir=/usr/local/bin --filename=composer
docker-compose exec moodle php -r "unlink('composer-setup.php');"
docker-compose exec moodle php composer install --no-interaction \
--no-plugins \
--no-scripts \
--no-dev \
--prefer-dist && composer dump-autoload
docker-compose exec moodle apt-get update && apt-get install -y locales && \
echo "en_AU.UTF-8 UTF-8" >> /etc/locale.gen && \
locale-gen
# Next, configure PHPUnit for Moodle: # Next, configure PHPUnit for Moodle:
docker-compose exec moodle php admin/tool/phpunit/cli/init.php docker-compose exec moodle php admin/tool/phpunit/cli/init.php
......
...@@ -12,6 +12,10 @@ Use these creds to access Moodle admin page ...@@ -12,6 +12,10 @@ Use these creds to access Moodle admin page
admin:rootpassword admin:rootpassword
These creds could be easily changed as other environmental variables at .env These creds could be easily changed as other environmental variables at .env
After installation the Database will have all necessary entities to check plugins functionality (Cource / Test / Students / QuizAttempts ...).
For demo, it's quite enough to get the link https://www.moodle.loc/mod/quiz/report.php?id=2&mode=grading&slot=1&qid=1&grade=needsgrading and wait for auto answer valuation.
## Development tips ## Development tips
To facilitate DB monitoring at IDE set such a Database connection URL: To facilitate DB monitoring at IDE set such a Database connection URL:
~~~bash ~~~bash
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment