Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
KNIGHT
Asyst Moodle Plugin
Commits
b9b49ca9
Commit
b9b49ca9
authored
Nov 25, 2024
by
Artem Baranovskyi
Browse files
PHPCS fixes.
parent
d49913ac
Changes
7
Show whitespace changes
Inline
Side-by-side
.gitignore
View file @
b9b49ca9
.idea/
\ No newline at end of file
classes/api/client.php
View file @
b9b49ca9
...
@@ -29,6 +29,8 @@ namespace local_asystgrade\api;
...
@@ -29,6 +29,8 @@ namespace local_asystgrade\api;
use
Exception
;
use
Exception
;
use
local_asystgrade\api\http_client_interface
;
use
local_asystgrade\api\http_client_interface
;
use
local_asystgrade\api\http_client_interface
;
/**
/**
* Client class for handling HTTP requests to Flask ML backend.
* Client class for handling HTTP requests to Flask ML backend.
*
*
...
@@ -37,28 +39,25 @@ use local_asystgrade\api\http_client_interface;
...
@@ -37,28 +39,25 @@ use local_asystgrade\api\http_client_interface;
* @package local_asystgrade
* @package local_asystgrade
*/
*/
class
client
{
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 */
/** @var ?client This variable holds an object type for http_client */
private
static
?client
$instance
=
null
;
private
static
?client
$instance
=
null
;
/**
/**
* Client class for handling HTTP requests to Flask ML backend.
* 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
)
{
private
function
__construct
(
$this
->
endpoint
=
$endpoint
;
private
string
$endpoint
,
$this
->
httpclient
=
$httpclient
;
private
http_client_interface
$httpclient
)
{
}
}
/**
/**
* Returns the singleton instance of the client.
* Returns the singleton instance of the client.
*
*
* @param string $endpoint
* @param string $endpoint
* @param http_client_interface $http
C
lient
* @param http_client_interface $http
c
lient
* @return client
* @return client
*/
*/
public
static
function
getinstance
(
string
$endpoint
,
http_client_interface
$httpclient
):
client
{
public
static
function
getinstance
(
string
$endpoint
,
http_client_interface
$httpclient
):
client
{
...
...
js/grade.js
View file @
b9b49ca9
M
.
local_asystgrade
=
{
M
.
local_asystgrade
=
{
init
:
function
(
Y
,
js_data
)
{
init
:
function
(
Y
,
jsData
)
{
window
.
gradeData
=
js_data
;
const
isDebuggingEnabled
=
true
;
// Set this to false in production
function
log
(
message
)
{
if
(
isDebuggingEnabled
)
{
console
.
log
(
message
);
}
}
window
.
gradeData
=
jsData
;
document
.
addEventListener
(
'
DOMContentLoaded
'
,
function
()
{
document
.
addEventListener
(
'
DOMContentLoaded
'
,
function
()
{
const
apiEndpoint
=
M
.
cfg
.
wwwroot
+
'
/local/asystgrade/api.php
'
;
const
apiEndpoint
=
M
.
cfg
.
wwwroot
+
'
/local/asystgrade/api.php
'
;
const
maxmark
=
document
.
querySelectorAll
(
"
input[name$='-maxmark']
"
)[
0
].
value
;
const
maxmark
=
document
.
querySelectorAll
(
"
input[name$='-maxmark']
"
)[
0
].
value
;
...
@@ -22,13 +30,19 @@ M.local_asystgrade = {
...
@@ -22,13 +30,19 @@ M.local_asystgrade = {
.
then
(
response
=>
response
.
json
())
.
then
(
response
=>
response
.
json
())
.
then
(
data
=>
{
.
then
(
data
=>
{
if
(
data
.
success
&&
data
.
grades
)
{
if
(
data
.
success
&&
data
.
grades
)
{
console
.
log
(
data
.
grades
);
log
(
data
.
grades
);
updateMarks
(
data
.
grades
);
updateMarks
(
data
.
grades
);
}
else
{
}
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
)
{
function
updateMarks
(
grades
)
{
const
inputs
=
document
.
querySelectorAll
(
"
input[name$='_-mark']
"
);
const
inputs
=
document
.
querySelectorAll
(
"
input[name$='_-mark']
"
);
...
@@ -39,7 +53,7 @@ M.local_asystgrade = {
...
@@ -39,7 +53,7 @@ M.local_asystgrade = {
if
(
inputs
[
index
])
{
if
(
inputs
[
index
])
{
inputs
[
index
].
value
=
predictedGrade
;
inputs
[
index
].
value
=
predictedGrade
;
}
else
{
}
else
{
console
.
error
(
`No grade input found for index:
${
index
}
`
);
error
(
`No grade input found for index:
${
index
}
`
);
}
}
});
});
}
}
...
...
lang/en/local_asystgrade.php
View file @
b9b49ca9
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @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'
]
=
'API Endpoint'
;
$string
[
'apiendpoint_desc'
]
=
'The endpoint of the AsystGrade API should be changed if you set ML Backend at remote server.'
;
$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.'
;
$string
[
'privacy:metadata'
]
=
'The AsystGrade plugin does not store any personal data.'
;
lib.php
View file @
b9b49ca9
...
@@ -56,7 +56,7 @@ function local_asystgrade_before_footer(): void {
...
@@ -56,7 +56,7 @@ function local_asystgrade_before_footer(): void {
$jsdata
=
[
$jsdata
=
[
'apiendpoint'
=>
$apiendpoint
,
'apiendpoint'
=>
$apiendpoint
,
'qid'
=>
$qid
,
'qid'
=>
$qid
,
'slot'
=>
$slot
'slot'
=>
$slot
,
];
];
$PAGE
->
requires
->
js
(
new
moodle_url
(
'/local/asystgrade/js/grade.js'
,
[
'v'
=>
time
()]));
$PAGE
->
requires
->
js
(
new
moodle_url
(
'/local/asystgrade/js/grade.js'
,
[
'v'
=>
time
()]));
...
...
tests/fakedata/questions.php
View file @
b9b49ca9
...
@@ -33,8 +33,8 @@ return [
...
@@ -33,8 +33,8 @@ return [
'qtype'
=>
'essay'
,
'qtype'
=>
'essay'
,
'answers'
=>
[
'answers'
=>
[
'Die Ausführung wird schneller, weil der Prozessor zwischen verschiedenen Teilaufgaben hin- und herspringen kann und
'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
'questiontext'
=>
'Warum wird Ihr Programm durch die Verwendung von Threads schneller, auch wenn Sie nur einen
...
@@ -42,8 +42,8 @@ return [
...
@@ -42,8 +42,8 @@ return [
'qtype'
=>
'essay'
,
'qtype'
=>
'essay'
,
'answers'
=>
[
'answers'
=>
[
'Die Ausführung wird schneller, weil der Prozessor zwischen verschiedenen Teilaufgaben hin- und herspringen kann und
'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
'questiontext'
=>
'Beschreiben Sie die Struktur einer Stream-Pipeline. Woher kommen die Daten, was geschieht im Stream
...
@@ -53,8 +53,8 @@ return [
...
@@ -53,8 +53,8 @@ return [
'answers'
=>
[
'answers'
=>
[
'Datenquelle: Collections, Arrays, Generatoren (z.B. Datenbankabfragen, eigene Methoden). Verarbeitung: Filtern,
'Datenquelle: Collections, Arrays, Generatoren (z.B. Datenbankabfragen, eigene Methoden). Verarbeitung: Filtern,
Umformung, Begrenzung. Datensenke: Minimum / Maximum / Durchschnitt / Anzahl, Ausgabe in Collection oder Array /
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
'questiontext'
=>
'Welche Auswirkungen hat die Model-View-Aufteilung bei Swing-Komponenten? Nennen Sie Beispiele anhand
...
@@ -64,16 +64,16 @@ return [
...
@@ -64,16 +64,16 @@ return [
'Datenhaltung und Darstellung werden getrennt, so dass dieselben Daten flexibel dargestellt werden können. Datenhaltung
'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
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.
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?'
,
'questiontext'
=>
'Warum braucht man bei der Arbeit mit Threads Synchronisation?'
,
'qtype'
=>
'essay'
,
'qtype'
=>
'essay'
,
'answers'
=>
[
'answers'
=>
[
'Man muss vermeiden, dass verschiedene Threads gleichzeitig auf Daten oder Objekte zugreifen, weil es dadurch zur
'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
'questiontext'
=>
'Beantworten Sie kurz die 3 Fragen 1 - Was wird unter einem Thread verstanden / wann werden Threads
...
@@ -82,7 +82,7 @@ return [
...
@@ -82,7 +82,7 @@ return [
'qtype'
=>
'essay'
,
'qtype'
=>
'essay'
,
'answers'
=>
[
'answers'
=>
[
'Thread: 1 PT Ablauffaden, Ablaufeinheit, Ausführung etc. 1Pt Parallel, Quasi Parallel, Core, 1Pt Geschwindigkeit,
'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
,
]
]
,
],
],
];
];
tests/quiz_api_test.php
View file @
b9b49ca9
...
@@ -25,8 +25,16 @@
...
@@ -25,8 +25,16 @@
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @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\client
;
use
local_asystgrade\api\http_client
;
use
local_asystgrade\api\http_client
;
use
local_asystgrade
\
utils
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
defined
(
'MOODLE_INTERNAL'
)
||
die
();
...
@@ -39,7 +47,7 @@ require_once($CFG->dirroot . '/mod/quiz/tests/generator/lib.php');
...
@@ -39,7 +47,7 @@ require_once($CFG->dirroot . '/mod/quiz/tests/generator/lib.php');
* Class quiz_api_test
* Class quiz_api_test
* @package local_asystgrade
* @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.
* 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 {
...
@@ -138,6 +146,9 @@ class quiz_api_test extends advanced_testcase {
/**
/**
* Creates a question category.
* Creates a question category.
*
* @param int $contextid
* @return false|mixed|\stdClass
* @throws coding_exception
* @throws coding_exception
* @throws dml_exception
* @throws dml_exception
*/
*/
...
@@ -162,6 +173,13 @@ class quiz_api_test extends advanced_testcase {
...
@@ -162,6 +173,13 @@ class quiz_api_test extends advanced_testcase {
/**
/**
* Creates a question and adds it to a category.
* 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
)
{
private
function
create_question
(
$questiongen
,
$questiondata
,
$category
,
$modifiedby
,
$context
)
{
return
$questiongen
->
create_question
(
$questiondata
[
'qtype'
],
null
,
[
return
$questiongen
->
create_question
(
$questiondata
[
'qtype'
],
null
,
[
...
@@ -175,6 +193,11 @@ class quiz_api_test extends advanced_testcase {
...
@@ -175,6 +193,11 @@ class quiz_api_test extends advanced_testcase {
/**
/**
* Adds a question to a quiz.
* Adds a question to a quiz.
*
* @throws dml_exception
* @param $quiz
* @param $question
* @return void
* @throws dml_exception
* @throws dml_exception
*/
*/
private
function
add_question_to_quiz
(
$quiz
,
$question
)
{
private
function
add_question_to_quiz
(
$quiz
,
$question
)
{
...
@@ -198,6 +221,12 @@ class quiz_api_test extends advanced_testcase {
...
@@ -198,6 +221,12 @@ class quiz_api_test extends advanced_testcase {
/**
/**
* Creates a quiz attempt for a student.
* Creates a quiz attempt for a student.
* @throws dml_exception
* @throws dml_exception
*
* @param $quizid
* @param $userid
* @param $answer
* @return void
* @throws dml_exception
*/
*/
private
function
create_quiz_attempt
(
$quizid
,
$userid
,
$answer
)
{
private
function
create_quiz_attempt
(
$quizid
,
$userid
,
$answer
)
{
global
$DB
;
global
$DB
;
...
@@ -225,10 +254,13 @@ class quiz_api_test extends advanced_testcase {
...
@@ -225,10 +254,13 @@ class quiz_api_test extends advanced_testcase {
/**
/**
* Sends answers to the API and verifies the response.
* Sends answers to the API and verifies the response.
*
* @param $requestdata
* @return void
*/
*/
private
function
send_answers_to_api
(
$requestdata
)
{
private
function
send_answers_to_api
(
$requestdata
)
{
try
{
try
{
$apiendpoint
=
get_config
(
'local_asystgrade'
,
'
apiendpoint
'
)
?:
'http://127.0.0.1:5001/api/autograde'
;
$apiendpoint
=
utils
::
get_
api
_
endpoint
()
;
$httpclient
=
new
http_client
();
$httpclient
=
new
http_client
();
$apiclient
=
client
::
getInstance
(
$apiendpoint
,
$httpclient
);
$apiclient
=
client
::
getInstance
(
$apiendpoint
,
$httpclient
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment