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

PHPCS fixes.

parent d49913ac
.idea/
\ No newline at end of file
......@@ -29,6 +29,8 @@ namespace local_asystgrade\api;
use Exception;
use local_asystgrade\api\http_client_interface;
use local_asystgrade\api\http_client_interface;
/**
* Client class for handling HTTP requests to Flask ML backend.
*
......@@ -37,28 +39,25 @@ use local_asystgrade\api\http_client_interface;
* @package local_asystgrade
*/
class client {
/** @var string This variable holds a domain or IP to attached flask ML backend */
private string $endpoint;
/** @var http_client_interface This variable holds an interface for http_client */
private http_client_interface $httpclient;
/** @var ?client This variable holds an object type for http_client */
private static ?client $instance = null;
/**
* Client class for handling HTTP requests to Flask ML backend.
* @param string $endpoint This variable holds a domain or IP to attached flask ML backend
* @param \local_asystgrade\api\http_client_interface $httpclient This variable holds an interface for http_client
*/
private function __construct(string $endpoint, http_client_interface $httpclient) {
$this->endpoint = $endpoint;
$this->httpclient = $httpclient;
private function __construct(
private string $endpoint,
private http_client_interface $httpclient
) {
}
/**
* Returns the singleton instance of the client.
*
* @param string $endpoint
* @param http_client_interface $httpClient
* @param http_client_interface $httpclient
* @return client
*/
public static function getinstance(string $endpoint, http_client_interface $httpclient): client {
......
M.local_asystgrade = {
init: function(Y, js_data) {
window.gradeData = js_data;
init: function(Y, jsData) {
const isDebuggingEnabled = true; // Set this to false in production
function log(message) {
if (isDebuggingEnabled) {
console.log(message);
}
}
window.gradeData = jsData;
document.addEventListener('DOMContentLoaded', function() {
const apiEndpoint = M.cfg.wwwroot + '/local/asystgrade/api.php';
const maxmark = document.querySelectorAll("input[name$='-maxmark']")[0].value;
......@@ -22,13 +30,19 @@ M.local_asystgrade = {
.then(response => response.json())
.then(data => {
if (data.success && data.grades) {
console.log(data.grades);
log(data.grades);
updateMarks(data.grades);
} else {
console.error('Error in grade response:', data.error);
error('Error in grade response:', data.error);
}
// Return the data to keep the Promise chain intact
return data;
})
.catch(error => console.error('Error:', error));
.catch(error => {
error('Error:', error);
// Return the error to keep the Promise chain intact
throw error;
});
function updateMarks(grades) {
const inputs = document.querySelectorAll("input[name$='_-mark']");
......@@ -39,7 +53,7 @@ M.local_asystgrade = {
if (inputs[index]) {
inputs[index].value = predictedGrade;
} else {
console.error(`No grade input found for index: ${index}`);
error(`No grade input found for index: ${index}`);
}
});
}
......
......@@ -24,7 +24,7 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'ASYST API Moodle integration plugin';
$string['apiendpoint'] = 'API Endpoint';
$string['apiendpoint_desc'] = 'The endpoint of the AsystGrade API should be changed if you set ML Backend at remote server.';
$string['pluginname'] = 'ASYST API Moodle integration plugin';
$string['privacy:metadata'] = 'The AsystGrade plugin does not store any personal data.';
......@@ -56,7 +56,7 @@ function local_asystgrade_before_footer(): void {
$jsdata = [
'apiendpoint' => $apiendpoint,
'qid' => $qid,
'slot' => $slot
'slot' => $slot,
];
$PAGE->requires->js(new moodle_url('/local/asystgrade/js/grade.js', ['v' => time()]));
......
......@@ -33,8 +33,8 @@ return [
'qtype' => 'essay',
'answers' => [
'Die Ausführung wird schneller, weil der Prozessor zwischen verschiedenen Teilaufgaben hin- und herspringen kann und
so z.B. Wartezeiten auf Daten in einem Thread zur Bearbeitung anderer Threads genutzt werden können.' => 1
]
so z.B. Wartezeiten auf Daten in einem Thread zur Bearbeitung anderer Threads genutzt werden können.' => 1,
],
],
[
'questiontext' => 'Warum wird Ihr Programm durch die Verwendung von Threads schneller, auch wenn Sie nur einen
......@@ -42,8 +42,8 @@ return [
'qtype' => 'essay',
'answers' => [
'Die Ausführung wird schneller, weil der Prozessor zwischen verschiedenen Teilaufgaben hin- und herspringen kann und
so z.B. Wartezeiten auf Daten in einem Thread zur Bearbeitung anderer Threads genutzt werden können.' => 1
]
so z.B. Wartezeiten auf Daten in einem Thread zur Bearbeitung anderer Threads genutzt werden können.' => 1,
],
],
[
'questiontext' => 'Beschreiben Sie die Struktur einer Stream-Pipeline. Woher kommen die Daten, was geschieht im Stream
......@@ -53,8 +53,8 @@ return [
'answers' => [
'Datenquelle: Collections, Arrays, Generatoren (z.B. Datenbankabfragen, eigene Methoden). Verarbeitung: Filtern,
Umformung, Begrenzung. Datensenke: Minimum / Maximum / Durchschnitt / Anzahl, Ausgabe in Collection oder Array /
Reduktion / Auswertung.' => 1
]
Reduktion / Auswertung.' => 1,
],
],
[
'questiontext' => 'Welche Auswirkungen hat die Model-View-Aufteilung bei Swing-Komponenten? Nennen Sie Beispiele anhand
......@@ -64,16 +64,16 @@ return [
'Datenhaltung und Darstellung werden getrennt, so dass dieselben Daten flexibel dargestellt werden können. Datenhaltung
findet in der Klasse TableModel statt: Welche Information steht in welcher Zelle? Information z.B. über die
Editierbarkeit der Zellen, den zu verwendenden Editor und die Spaltenreihenfolge werden in JTable bzw.
TableColumnModel gehalten.' => 3
]
TableColumnModel gehalten.' => 3,
],
],
[
'questiontext' => 'Warum braucht man bei der Arbeit mit Threads Synchronisation?',
'qtype' => 'essay',
'answers' => [
'Man muss vermeiden, dass verschiedene Threads gleichzeitig auf Daten oder Objekte zugreifen, weil es dadurch zur
Zerstörung von Werten und zu inkonsistenten Zuständen kommen kann.' => 1
]
Zerstörung von Werten und zu inkonsistenten Zuständen kommen kann.' => 1,
],
],
[
'questiontext' => 'Beantworten Sie kurz die 3 Fragen 1 - Was wird unter einem Thread verstanden / wann werden Threads
......@@ -82,7 +82,7 @@ return [
'qtype' => 'essay',
'answers' => [
'Thread: 1 PT Ablauffaden, Ablaufeinheit, Ausführung etc. 1Pt Parallel, Quasi Parallel, Core, 1Pt Geschwindigkeit,
Resourcenauslastung, parallele Ausführung' => 7
]
Resourcenauslastung, parallele Ausführung' => 7,
],
],
];
......@@ -25,8 +25,16 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_asystgrade;
use advanced_testcase;
use coding_exception;
use context_course;
use dml_exception;
use Exception;
use local_asystgrade\api\client;
use local_asystgrade\api\http_client;
use local_asystgrade\utils;
defined('MOODLE_INTERNAL') || die();
......@@ -39,7 +47,7 @@ require_once($CFG->dirroot . '/mod/quiz/tests/generator/lib.php');
* Class quiz_api_test
* @package local_asystgrade
*/
class quiz_api_test extends advanced_testcase {
final class quiz_api_test extends advanced_testcase {
/**
* Sets up the test environment by resetting the database and truncating quiz-related tables.
......@@ -138,6 +146,9 @@ class quiz_api_test extends advanced_testcase {
/**
* Creates a question category.
*
* @param int $contextid
* @return false|mixed|\stdClass
* @throws coding_exception
* @throws dml_exception
*/
......@@ -162,19 +173,31 @@ class quiz_api_test extends advanced_testcase {
/**
* Creates a question and adds it to a category.
*
* @param $questiongen
* @param $questiondata
* @param $category
* @param $modifiedby
* @param $context
* @return mixed
*/
private function create_question($questiongen, $questiondata, $category, $modifiedby, $context) {
return $questiongen->create_question($questiondata['qtype'], null, [
'category' => $category->id,
'questiontext' => ['text' => $questiondata['questiontext'], 'format' => FORMAT_HTML],
'name' => 'Test Question',
'contextid' => $context->id,
'modifiedby' => $modifiedby,
'category' => $category->id,
'questiontext' => ['text' => $questiondata['questiontext'], 'format' => FORMAT_HTML],
'name' => 'Test Question',
'contextid' => $context->id,
'modifiedby' => $modifiedby,
]);
}
/**
* Adds a question to a quiz.
*
* @throws dml_exception
* @param $quiz
* @param $question
* @return void
* @throws dml_exception
*/
private function add_question_to_quiz($quiz, $question) {
......@@ -198,6 +221,12 @@ class quiz_api_test extends advanced_testcase {
/**
* Creates a quiz attempt for a student.
* @throws dml_exception
*
* @param $quizid
* @param $userid
* @param $answer
* @return void
* @throws dml_exception
*/
private function create_quiz_attempt($quizid, $userid, $answer) {
global $DB;
......@@ -225,10 +254,13 @@ class quiz_api_test extends advanced_testcase {
/**
* Sends answers to the API and verifies the response.
*
* @param $requestdata
* @return void
*/
private function send_answers_to_api($requestdata) {
try {
$apiendpoint = get_config('local_asystgrade', 'apiendpoint') ?: 'http://127.0.0.1:5001/api/autograde';
$apiendpoint = utils::get_api_endpoint();
$httpclient = new http_client();
$apiclient = client::getInstance($apiendpoint, $httpclient);
......
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