Commit f484bd97 authored by mamunozgil's avatar mamunozgil
Browse files

Updated coding style and recommendations

parent 07cd8123
Showing with 1850 additions and 160 deletions
+1850 -160
# You can override the included template(s) by including variable overrides
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
# Note that environment variables can be set in several places
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
stages:
- test
sast:
stage: test
include:
- template: Security/SAST.gitlab-ci.yml
......@@ -45,7 +45,7 @@ After approval, install the plugin directly from the Moodle Plugins Directory vi
Before that or alternatively: zip the plugin code from https://transfer.hft-stuttgart.de/gitlab/HFTSoftwareProject/moodledta (here). The readily-zipped current version also sits in the repository’s main directory. Then install the plugin from zip via Site Administration/Plugins/Install Plugins, or by extracting the plugin archive to {Moodle_Root}/mod/assign/submission/dta and visiting the admins notifications page.
Visit Site Administration/Plugins/Plugin Overview and select Settings next to the Moodle Dockerized Test Agent (MoDTA) entry to enter the URI of your backend as shown in Fig. 1. ![Fig. 1: Plugin List](doc/install_conf_1.png) Finally, configure via Site Administration/Security/HTTP Security settings permitting communication with the backend URI and port as seen in Fig. 2. ![Fig. 2: DTA Configuration Dialog](doc/install_conf_2.png) The plugin requires the external DTA REST webservice backend.
Visit Site Administration/Plugins/Plugin Overview and select Settings next to the Moodle Dockerized Test Agent (MoDTA) entry to enter the URI of your backend as shown in Fig. 1. ![Fig. 1: Plugin List](.assets/install_conf_1.png) Finally, configure via Site Administration/Security/HTTP Security settings permitting communication with the backend URI and port as seen in Fig. 2. ![Fig. 2: DTA Configuration Dialog](.assets/install_conf_2.png) The plugin requires the external DTA REST webservice backend.
Notes:
......@@ -59,7 +59,7 @@ With the MoDTA plugin installed and configured backend URI (including Moodle Sec
### Teacher
When creating an assignment, a teacher can select the MoDTA exercise as a new assignment type via an additional checkbox on the assignment creation page as shown at the bottom of Fig. 3. ![Fig. 3: Moodle DTA Activation Checkbox](doc/usage_teacher_1.png) A new standard file upload field appears as indicated in Fig. 4. ![Fig. 4: Moodle DTA Upload File Area](doc/usage_teacher_2.png). There, the teacher must upload a text file with the git repository URI containing the tests as shown in Fig. 5. ![Fig. 5: Moodle DTA Teacher Text File Upload](doc/usage_teacher_3.png) The text file has to adhere to the following format also given in the example repository:
When creating an assignment, a teacher can select the MoDTA exercise as a new assignment type via an additional checkbox on the assignment creation page as shown at the bottom of Fig. 3. ![Fig. 3: Moodle DTA Activation Checkbox](.assets/usage_teacher_1.png) A new standard file upload field appears as indicated in Fig. 4. ![Fig. 4: Moodle DTA Upload File Area](.assets/usage_teacher_2.png). There, the teacher must upload a text file with the git repository URI containing the tests as shown in Fig. 5. ![Fig. 5: Moodle DTA Teacher Text File Upload](.assets/usage_teacher_3.png) The text file has to adhere to the following format also given in the example repository:
The text file has to contain the following, each separated by ::
- dtt as the URI-type
......@@ -76,9 +76,9 @@ Students use the same format, just without the runner part at the end.
### Student
Students use an additional MoDTA standard file upload field in the standard submission processs in Moodle like in Fig. 6. [Fig. 6: Moodle DTA Student File Upload](doc/usage_student_1.png) There, they place either a zip archive or a text file adhering to the same format as the teacher’s file with their code repository URI and optionally credentials and/or a ticketing system URI as shown in Fig. 7. ![Fig. 7: Moodle DTA Student Text File Upload](doc/usage_student_2.png)
Students use an additional MoDTA standard file upload field in the standard submission processs in Moodle like in Fig. 6. [Fig. 6: Moodle DTA Student File Upload](.assets/usage_student_1.png) There, they place either a zip archive or a text file adhering to the same format as the teacher’s file with their code repository URI and optionally credentials and/or a ticketing system URI as shown in Fig. 7. ![Fig. 7: Moodle DTA Student Text File Upload](.assets/usage_student_2.png)
Upon completion, students see a summarized overview of their test results in an additional column of the submission feedback table like in Fig. 8. ![Fig. 8: Moodle DTA Submission Result Summay](doc/usage_student_3.png) Clicking on a new expansion icon in that column, they reach a detailed feedback dialog including stack traces of compile errors and test failures as in Fig. 9. ![Fig. 9: Moodle DTA Student Detail Result View](doc/usage_student_4.png) Optionally, the MoDTA backend creates tickets for compile failures in the ticketing system under the URI provided by the student upon hand-in.
Upon completion, students see a summarized overview of their test results in an additional column of the submission feedback table like in Fig. 8. ![Fig. 8: Moodle DTA Submission Result Summay](.assets/usage_student_3.png) Clicking on a new expansion icon in that column, they reach a detailed feedback dialog including stack traces of compile errors and test failures as in Fig. 9. ![Fig. 9: Moodle DTA Student Detail Result View](.assets/usage_student_4.png) Optionally, the MoDTA backend creates tickets for compile failures in the ticketing system under the URI provided by the student upon hand-in.
Note: Teachers have access to the Moodle submission result view to assess student results. However, teacher control and grading are not the focus of MoDTA.
......@@ -145,11 +145,11 @@ The "assign_submission_plugin" class serves as an abstract foundation that all a
The following provides brief descriptions of a selection of functions to illustrate the types of hooks available:
• get_settings(): This function comes into play during the creation of the assignment settings page. For the MoDTA plugin, this involves adding a file manager that permits teachers to upload their test repo and docker Image URI as a textfile. This function is overridden from the assign_plugin class.
assignsubmission_dta_get_settings(): This function comes into play during the creation of the assignment settings page. For the MoDTA plugin, this involves adding a file manager that permits teachers to upload their test repo and docker Image URI as a textfile. This function is overridden from the assign_plugin class.
save_settings(): The save_settings function is invoked when the assignment settings page is submitted, whether for a new assignment or the modification of an existing one. In the MoDTA plugin, this function is responsible for preserving the text file chosen by the teacher and transmitting the file to the backend web service. Like the previous function, this one is overridden from the assign_plugin class.
assignsubmission_dta_save_settings(): The assignsubmission_dta_save_settings function is invoked when the assignment settings page is submitted, whether for a new assignment or the modification of an existing one. In the MoDTA plugin, this function is responsible for preserving the text file chosen by the teacher and transmitting the file to the backend web service. Like the previous function, this one is overridden from the assign_plugin class.
• get_form_elements_for_user(): During the construction of the submission form, this function plays a similar role to the get_settings() function for settings. In the context of the MoDTA plugin, it adds a file manager to enable students to upload their text or zip file. Once again, this function is overridden from the assign_plugin class.
• get_form_elements_for_user(): During the construction of the submission form, this function plays a similar role to the assignsubmission_dta_get_settings() function for settings. In the context of the MoDTA plugin, it adds a file manager to enable students to upload their text or zip file. Once again, this function is overridden from the assign_plugin class.
• save():This function is invoked to save a user's submission. Within the MoDTA plugin, this function sends the student's submission to the backend and receives the result as the response. For details see the technical details section above.
......@@ -162,3 +162,9 @@ This file serves as the gateway to various standard Moodle APIs designed for plu
### util folder
The folder contains various utility files, e.g. displaying the new test summary pages is delegated from the locallib.php for brevity of that source.
### Code Checking
The Moodle Plugin Directory offers a helpful tool for developers to ensure their code adheres to Moodle's coding conventions. This tool, named "Code Checker," can be found via the following link:
https://moodle.org/plugins/local_codechecker
\ No newline at end of file
version: '2'
services:
services:
mariadb-dtt:
container_name: moodledb-dtt
image: docker.io/bitnami/mariadb:11.1
environment:
# ALLOW_EMPTY_PASSWORD is recommended only for development.
- ALLOW_EMPTY_PASSWORD=yes
- MARIADB_USER=bn_moodle
- MARIADB_DATABASE=bitnami_moodle
- MARIADB_CHARACTER_SET=utf8mb4
- MARIADB_COLLATE=utf8mb4_unicode_ci
volumes:
- 'mariadb_data_dtt:/bitnami/mariadb'
moodle-dtt:
container_name: moodle-dtt
image: docker.io/bitnami/moodle:4.3
ports:
- '81:8080'
- '444:8443'
environment:
- MOODLE_DATABASE_HOST=mariadb-dtt
- MOODLE_DATABASE_PORT_NUMBER=3306
- MOODLE_DATABASE_USER=bn_moodle
- MOODLE_DATABASE_NAME=bitnami_moodle
# ALLOW_EMPTY_PASSWORD is recommended only for development.
- ALLOW_EMPTY_PASSWORD=yes
volumes:
- 'moodle_data_dtt:/bitnami/moodle'
- 'moodledata_data_dtt:/bitnami/moodledata'
depends_on:
- mariadb-dtt
backend:
container_name: backendcomposedtt
image: hftstuttgart/dta-backend:beta
user: "${UID}:${GID}"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- '/tmp/dta-tests:/tmp/dta-tests'
volumes:
mariadb_data_dtt:
driver: local
moodle_data_dtt:
driver: local
moodledata_data_dtt:
driver: local
\ No newline at end of file
dta.zip 0 → 100644
File added
......@@ -145,11 +145,11 @@ The "assign_submission_plugin" class serves as an abstract foundation that all a
The following provides brief descriptions of a selection of functions to illustrate the types of hooks available:
• get_settings(): This function comes into play during the creation of the assignment settings page. For the MoDTA plugin, this involves adding a file manager that permits teachers to upload their test repo and docker Image URI as a textfile. This function is overridden from the assign_plugin class.
assignsubmission_dta_get_settings(): This function comes into play during the creation of the assignment settings page. For the MoDTA plugin, this involves adding a file manager that permits teachers to upload their test repo and docker Image URI as a textfile. This function is overridden from the assign_plugin class.
save_settings(): The save_settings function is invoked when the assignment settings page is submitted, whether for a new assignment or the modification of an existing one. In the MoDTA plugin, this function is responsible for preserving the text file chosen by the teacher and transmitting the file to the backend web service. Like the previous function, this one is overridden from the assign_plugin class.
assignsubmission_dta_save_settings(): The assignsubmission_dta_save_settings function is invoked when the assignment settings page is submitted, whether for a new assignment or the modification of an existing one. In the MoDTA plugin, this function is responsible for preserving the text file chosen by the teacher and transmitting the file to the backend web service. Like the previous function, this one is overridden from the assign_plugin class.
• get_form_elements_for_user(): During the construction of the submission form, this function plays a similar role to the get_settings() function for settings. In the context of the MoDTA plugin, it adds a file manager to enable students to upload their text or zip file. Once again, this function is overridden from the assign_plugin class.
• get_form_elements_for_user(): During the construction of the submission form, this function plays a similar role to the assignsubmission_dta_get_settings() function for settings. In the context of the MoDTA plugin, it adds a file manager to enable students to upload their text or zip file. Once again, this function is overridden from the assign_plugin class.
• save():This function is invoked to save a user's submission. Within the MoDTA plugin, this function sends the student's submission to the backend and receives the result as the response. For details see the technical details section above.
......
<?php
// This file is part of Moodle - http://moodle.org/.
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the backend webservice contact functionality for the DTA plugin.
*
* @package assignsubmission_dta
* @copyright 2023 Your Name
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignsubmission_dta;
/**
* Backend webservice contact utility class.
*
* @package assignsubmission_dta
* @copyright 2023 Your Name
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dta_backend_utils {
/**
* Component name for the plugin.
*/
public const ASSIGNSUBMISSION_DTA_COMPONENT_NAME = 'assignsubmission_dta';
/**
* Returns the base URL of the backend webservice as configured in the administration settings.
*
* @return string Backend host base URL.
*/
private static function assignsubmission_dta_get_backend_baseurl(): string {
$backendaddress = get_config(
self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME,
'backendHost'
);
if (empty($backendaddress)) {
\core\notification::error(
get_string('backendHost_not_set', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
);
}
return $backendaddress;
}
/**
* Sends the configuration text file uploaded by the teacher to the backend.
*
* @param \assign $assignment Assignment this test-config belongs to.
* @param \stored_file $file Uploaded test-config.
* @return bool True if no error occurred.
*/
public static function assignsubmission_dta_send_testconfig_to_backend($assignment, $file): bool {
$backendaddress = self::assignsubmission_dta_get_backend_baseurl();
if (empty($backendaddress)) {
return true;
}
// Set endpoint for test upload.
$url = $backendaddress . '/v1/unittest';
// Prepare params.
$params = [
'unitTestFile' => $file,
'assignmentId' => $assignment->get_instance()->id,
];
// If request returned null, return false to indicate failure.
if (is_null(self::assignsubmission_dta_post($url, $params))) {
return false;
} else {
return true;
}
}
/**
* Sends submission config or archive to backend to be tested.
*
* @param \assign $assignment Assignment for the submission.
* @param int $submissionid Submission ID of the current file.
* @param \stored_file $file Submission config file or archive with submission.
* @return string|null JSON string with test results or null on error.
*/
public static function assignsubmission_dta_send_submission_to_backend(
$assignment,
int $submissionid,
$file
): ?string {
$backendaddress = self::assignsubmission_dta_get_backend_baseurl();
if (empty($backendaddress)) {
return null;
}
// Set endpoint for submission upload.
$url = $backendaddress . '/v1/task/' . $submissionid;
// Prepare params.
$params = [
'taskFile' => $file,
'assignmentId' => $assignment->get_instance()->id,
];
return self::assignsubmission_dta_post($url, $params);
}
/**
* Posts the given params to the given URL and returns the response as a string.
*
* @param string $url Full URL to request.
* @param array $params Parameters for HTTP request.
* @return string|null Received body on success or null on error.
*/
private static function assignsubmission_dta_post(string $url, array $params): ?string {
if (!isset($url) || !isset($params)) {
return null;
}
$options = ['CURLOPT_RETURNTRANSFER' => true];
$curl = new \curl();
$response = $curl->post($url, $params, $options);
// Check state of request, if response code is 2xx, return the answer.
$info = $curl->get_info();
if ($info['http_code'] >= 200 && $info['http_code'] < 300) {
return $response;
}
// Something went wrong, return null and display an error message.
$msg = self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME
. ': Post file to server was not successful. HTTP code='
. $info['http_code'];
debugging($msg);
if ($info['http_code'] >= 400 && $info['http_code'] < 500) {
\core\notification::error(
get_string('http_client_error_msg', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
);
return null;
} else if ($info['http_code'] >= 500 && $info['http_code'] < 600) {
\core\notification::error(
get_string('http_server_error_msg', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
);
return null;
} else {
$unknownmsg = get_string('http_unknown_error_msg', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
. $info['http_code'] . ' ' . $response;
\core\notification::error($unknownmsg);
return null;
}
}
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace assignsubmission_dta;
use assignsubmission_dta\dta_backend_utils;
use assignsubmission_dta\dta_view_submission_utils;
use assignsubmission_dta\models\dta_result;
use assignsubmission_dta\models\dta_result_summary;
use assignsubmission_dta\models\dta_recommendation;
/**
* Class dta_db_utils
*
* Persistence layer utility class for storing and retrieving
* DTA plugin data (results, summaries, recommendations).
*
* @package assignsubmission_dta
* @copyright 2023 Gero Lueckemeyer
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dta_db_utils {
/**
* Summary database table name.
*/
private const ASSIGNSUBMISSION_DTA_TABLE_SUMMARY = 'assignsubmission_dta_summary';
/**
* Result database table name.
*/
private const ASSIGNSUBMISSION_DTA_TABLE_RESULT = 'assignsubmission_dta_result';
/**
* Recommendations database table name.
*/
private const ASSIGNSUBMISSION_DTA_TABLE_RECOMMENDATIONS = 'assignsubmission_dta_recommendations';
/**
* Returns an array of recommendations from the database.
*
* @param int $assignmentid The assignment ID.
* @param int $submissionid The submission ID.
* @return array An array of recommendation records.
*/
public static function assignsubmission_dta_get_recommendations_from_database(
int $assignmentid,
int $submissionid
): array {
global $DB, $USER;
$userid = $USER->id;
// Step 1: Retrieve all recommendations.
$records = $DB->get_records(
self::ASSIGNSUBMISSION_DTA_TABLE_RECOMMENDATIONS,
[
'assignment_id' => $assignmentid,
'submission_id' => $submissionid,
]
);
// Step 2: Retrieve module ID for 'assign'.
$module = $DB->get_record('modules', ['name' => 'assign'], 'id');
if (!$module) {
// Handle error case if the module is not found.
return $records;
}
$moduleid = $module->id;
// Step 3: Check each record.
foreach ($records as $key => $record) {
// Get the name of the exercise from the record.
$exercisename = $record->exercise_name;
// Find the assignment with this name.
$assign = $DB->get_record('assign', ['name' => $exercisename], 'id');
if ($assign) {
// Get the course module ID for this assignment.
$cm = $DB->get_record(
'course_modules',
[
'module' => $moduleid,
'instance' => $assign->id,
],
'id'
);
if ($cm) {
// Check the completion status for this course module and user.
$completion = $DB->get_record(
'course_modules_completion',
[
'coursemoduleid' => $cm->id,
'userid' => $userid,
],
'completionstate'
);
// If the completion state is 1, remove the record from $records.
if ($completion && (int)$completion->completionstate === 1) {
unset($records[$key]);
}
}
}
}
// Return the filtered records.
return $records;
}
/**
* Gets a summary with all corresponding result entries.
*
* @param int $assignmentid Assignment ID to search for.
* @param int $submissionid Submission ID to search for.
* @return dta_result_summary Summary representing the submission.
*/
public static function assignsubmission_dta_get_result_summary_from_database(
int $assignmentid,
int $submissionid
): dta_result_summary {
global $DB;
// Fetch data from database.
$summaryrecord = $DB->get_record(
self::ASSIGNSUBMISSION_DTA_TABLE_SUMMARY,
[
'assignment_id' => $assignmentid,
'submission_id' => $submissionid,
]
);
$resultsarray = $DB->get_records(
self::ASSIGNSUBMISSION_DTA_TABLE_RESULT,
[
'assignment_id' => $assignmentid,
'submission_id' => $submissionid,
]
);
// Create a summary instance.
$summary = new dta_result_summary();
$summary->timestamp = $summaryrecord->timestamp;
$summary->globalstacktrace = $summaryrecord->global_stacktrace;
$summary->successfultestcompetencies = $summaryrecord->successful_competencies;
$summary->overalltestcompetencies = $summaryrecord->tested_competencies;
$summary->results = [];
// Create result instances and add to array of summary instance.
foreach ($resultsarray as $rr) {
$result = new dta_result();
$result->packagename = $rr->package_name;
$result->classname = $rr->class_name;
$result->name = $rr->name;
$result->state = $rr->state;
$result->failuretype = $rr->failure_type;
$result->failurereason = $rr->failure_reason;
$result->stacktrace = $rr->stacktrace;
$result->columnnumber = $rr->column_number;
$result->linenumber = $rr->line_number;
$result->position = $rr->position;
$summary->results[] = $result;
}
return $summary;
}
/**
* Stores an array of recommendations in the database.
*
* @param int $assignmentid The assignment ID.
* @param int $submissionid The submission ID.
* @param array $recommendations An array of dta_recommendation objects.
*/
public static function assignsubmission_dta_store_recommendations_to_database(
int $assignmentid,
int $submissionid,
array $recommendations
): void {
global $DB;
// Debug output (you can remove or adapt this if unneeded).
debugging('Recommendations array: ' . json_encode($recommendations));
// If recommendations already exist, delete old values beforehand.
$existingrecords = $DB->get_records(
'assignsubmission_dta_recommendations',
[
'assignment_id' => $assignmentid,
'submission_id' => $submissionid,
]
);
if ($existingrecords) {
$DB->delete_records(
'assignsubmission_dta_recommendations',
[
'assignment_id' => $assignmentid,
'submission_id' => $submissionid,
]
);
}
// Create new recommendation entries.
foreach ($recommendations as $recommendation) {
// Check if $recommendation is an instance of dta_recommendation.
if ($recommendation instanceof dta_recommendation) {
// Add assignment and submission IDs to the recommendation object.
$recommendation->assignment_id = $assignmentid;
$recommendation->submission_id = $submissionid;
debugging('Inserting new recommendation record: ' . json_encode($recommendation));
// Insert the recommendation into the database.
$DB->insert_record('assignsubmission_dta_recommendations', $recommendation);
} else {
// Handle the case where $recommendation is not a dta_recommendation instance.
debugging('Invalid recommendation object encountered.');
}
}
}
/**
* Saves the given result summary and single results to the database
* under the specified assignment and submission ID.
*
* @param int $assignmentid Assignment this submission is linked to.
* @param int $submissionid Submission ID for these results.
* @param dta_result_summary $summary Summary instance to persist.
*/
public static function assignsubmission_dta_store_result_summary_to_database(
int $assignmentid,
int $submissionid,
dta_result_summary $summary
): void {
global $DB;
// Prepare new database entries.
$summaryrecord = new dta_result_summary();
$summaryrecord->assignment_id = $assignmentid;
$summaryrecord->submission_id = $submissionid;
$summaryrecord->timestamp = $summary->timestamp;
$summaryrecord->global_stacktrace = $summary->globalstacktrace;
$summaryrecord->successful_competencies = $summary->successfultestcompetencies;
$summaryrecord->tested_competencies = $summary->overalltestcompetencies;
// Prepare results to persist.
$resultrecords = [];
foreach ($summary->results as $r) {
$record = new dta_result();
$record->assignment_id = $assignmentid;
$record->submission_id = $submissionid;
$record->package_name = $r->packagename;
$record->class_name = $r->classname;
$record->name = $r->name;
$record->state = $r->state;
$record->failure_type = $r->failuretype;
$record->failure_reason = $r->failurereason;
$record->stacktrace = $r->stacktrace;
$record->column_number = $r->columnnumber;
$record->line_number = $r->linenumber;
$record->position = $r->position;
$resultrecords[] = $record;
}
// If results already exist, delete old values beforehand.
$submission = $DB->get_record(
self::ASSIGNSUBMISSION_DTA_TABLE_SUMMARY,
[
'assignment_id' => $assignmentid,
'submission_id' => $submissionid,
]
);
if ($submission) {
$DB->delete_records(
self::ASSIGNSUBMISSION_DTA_TABLE_RESULT,
[
'assignment_id' => $assignmentid,
'submission_id' => $submissionid,
]
);
$DB->delete_records(
self::ASSIGNSUBMISSION_DTA_TABLE_SUMMARY,
[
'assignment_id' => $assignmentid,
'submission_id' => $submissionid,
]
);
}
// Create summary and single result entries.
$DB->insert_record(self::ASSIGNSUBMISSION_DTA_TABLE_SUMMARY, $summaryrecord);
foreach ($resultrecords as $rr) {
$DB->insert_record(self::ASSIGNSUBMISSION_DTA_TABLE_RESULT, $rr);
}
}
/**
* Cleans up database if plugin is uninstalled.
*/
public static function assignsubmission_dta_uninstall_plugin_cleaup(): void {
global $DB;
$DB->delete_records(self::ASSIGNSUBMISSION_DTA_TABLE_RESULT, null);
$DB->delete_records(self::ASSIGNSUBMISSION_DTA_TABLE_SUMMARY, null);
$DB->delete_records(self::ASSIGNSUBMISSION_DTA_TABLE_RECOMMENDATIONS, null);
}
}
This diff is collapsed.
<?php
// This file is part of Moodle - http://moodle.org/.
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Entity class for DTA submission plugin recommendation.
*
* @package assignsubmission_dta
* @copyright 2023 Gero Lueckemeyer
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignsubmission_dta\models;
/**
* Entity class for DTA submission plugin recommendation.
*
* @package assignsubmission_dta
* @copyright 2023
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dta_recommendation {
/**
* @var string $topic Topic of the recommendation.
*/
public $topic;
/**
* @var string $exercisename Name of the exercise.
*/
public $exercisename;
/**
* @var string $url URL of the exercise.
*/
public $url;
/**
* @var int $difficulty Difficulty level of the exercise.
*/
public $difficulty;
/**
* @var int $score Score associated with the recommendation.
*/
public $score;
/**
* Decodes the JSON recommendations returned by the backend service call into an array of dta_recommendation objects.
*
* @param string $jsonstring JSON string containing recommendations.
* @return array Array of dta_recommendation objects.
*/
public static function assignsubmission_dta_decode_json_recommendations(string $jsonstring): array {
$response = json_decode($jsonstring);
$recommendations = [];
// Check if recommendations exist.
if (!empty($response->recommendations)) {
foreach ($response->recommendations as $recommendation) {
$rec = new dta_recommendation();
$rec->topic = $recommendation->topic ?? null;
// Map correct fields to the renamed variable names.
$rec->exercisename = $recommendation->url ?? null;
$rec->url = $recommendation->exerciseName ?? null;
$rec->difficulty = $recommendation->difficulty ?? null;
$rec->score = $recommendation->score ?? null;
$recommendations[] = $rec;
}
}
return $recommendations;
}
}
<?php
// This file is part of Moodle - http://moodle.org/.
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Entity class for DTA submission plugin result.
*
* @package assignsubmission_dta
* @copyright 2023 Gero Lueckemeyer and student project teams
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignsubmission_dta\models;
/**
* Entity class for DTA submission plugin result.
*
* @package assignsubmission_dta
* @copyright 2023 Gero Lueckemeyer and student project teams
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class dta_result {
/**
* Broadly used in logic, parametrized for easier change.
*/
public const ASSIGNSUBMISSION_DTA_COMPONENT_NAME = 'assignsubmission_dta';
/**
* @var string $packagename Package name of the test.
*/
public $packagename;
/**
* @var string $classname Unit name of the test.
*/
public $classname;
/**
* @var string $name Name of the test.
*/
public $name;
/**
* @var int $state State is defined as:
* 0 UNKNOWN
* 1 SUCCESS
* 2 FAILURE
* 3 COMPILATIONERROR
*/
public $state;
/**
* @var string $failuretype Type of test failure if applicable, empty string otherwise.
*/
public $failuretype;
/**
* @var string $failurereason Reason of test failure if applicable, empty string otherwise.
*/
public $failurereason;
/**
* @var string $stacktrace Stack trace of test failure if applicable, empty string otherwise.
*/
public $stacktrace;
/**
* @var int|string $columnnumber Column number of compile failure if applicable, empty string otherwise.
*/
public $columnnumber;
/**
* @var int|string $linenumber Line number of compile failure if applicable, empty string otherwise.
*/
public $linenumber;
/**
* @var int|string $position Position of compile failure if applicable, empty string otherwise.
*/
public $position;
/**
* Returns the name of a state with the given number for display.
*
* @param int $state Number of the state.
* @return string Name of state as defined.
*/
public static function assignsubmission_dta_get_statename(int $state): string {
if ($state === 1) {
return get_string('tests_successful', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME);
} else if ($state === 2) {
return get_string('failures', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME);
} else if ($state === 3) {
return get_string('compilation_errors', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME);
} else {
return get_string('unknown_state', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME);
}
}
}
<?php
// This file is part of Moodle - http://moodle.org/.
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the DTA submission plugin result summary entity class.
*
* @package assignsubmission_dta
* @copyright 2023 Your Name
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace assignsubmission_dta\models;
/**
* Entity class for DTA submission plugin result summary.
*
* This class holds:
* - A timestamp for when the summary was generated.
* - An optional global stack trace (in case the entire process failed).
* - A competency profile of how many tests passed for each competency.
* - A competency profile of the total coverage for each competency.
* - An array of dta_result objects that detail individual test results.
*
* @package assignsubmission_dta
*/
class dta_result_summary {
/** @var int Unix timestamp for the summary. */
public $timestamp;
/** @var string A global stacktrace if the entire run had a fatal error (optional). */
public $globalstacktrace;
/** @var string Semi-colon-separated numbers for competencies actually passed. */
public $successfultestcompetencies;
/** @var string Semi-colon-separated numbers for total tested competencies. */
public $overalltestcompetencies;
/** @var dta_result[] Array of individual test results. */
public $results;
/**
* Decodes a JSON string into a dta_result_summary object.
*
* @param string $jsonstring JSON that includes timestamp, globalstacktrace, competency profiles, and results.
* @return dta_result_summary
*/
public static function assignsubmission_dta_decode_json(string $jsonstring): dta_result_summary {
$response = json_decode($jsonstring);
$summary = new dta_result_summary();
$summary->timestamp = $response->timestamp ?? 0;
$summary->globalstacktrace = $response->globalstacktrace ?? '';
// If your JSON keys are 'successfulTestCompetencyProfile' and 'overallTestCompetencyProfile'.
$summary->successfultestcompetencies = $response->successfulTestCompetencyProfile ?? '';
$summary->overalltestcompetencies = $response->overallTestCompetencyProfile ?? '';
// Decode the "results" array into an array of dta_result objects.
if (!empty($response->results) && is_array($response->results)) {
$summary->results = self::assignsubmission_dta_decode_json_result_array($response->results);
} else {
$summary->results = [];
}
return $summary;
}
/**
* Helper that transforms a list of JSON objects into an array of dta_result objects.
*
* @param array $jsonarray Array of JSON-decoded result objects.
* @return dta_result[]
*/
private static function assignsubmission_dta_decode_json_result_array(array $jsonarray): array {
$ret = [];
foreach ($jsonarray as $entry) {
$value = new dta_result();
$value->packagename = $entry->packageName ?? '';
$value->classname = $entry->className ?? '';
$value->name = $entry->name ?? '';
$value->state = $entry->state ?? 0;
$value->failuretype = $entry->failureType ?? '';
$value->failurereason = $entry->failureReason ?? '';
$value->stacktrace = $entry->stacktrace ?? '';
$value->columnnumber = $entry->columnNumber ?? 0;
$value->linenumber = $entry->lineNumber ?? 0;
$value->position = $entry->position ?? 0;
$ret[] = $value;
}
return $ret;
}
/**
* Get the total number of results (tests) recorded in this summary.
*
* @return int
*/
public function assignsubmission_dta_result_count(): int {
return count($this->results);
}
/**
* Generic helper to count how many results have the given $state.
*
* States can be:
* 0 => unknown
* 1 => success
* 2 => fail
* 3 => compilation error
*
* @param int $state The numeric state code to match.
* @return int Number of results with that state.
*/
public function assignsubmission_dta_state_occurence_count(int $state): int {
$num = 0;
foreach ($this->results as $r) {
if ((int)$r->state === $state) {
$num++;
}
}
return $num;
}
/**
* Count how many results had compilation errors (state=3).
*
* @return int
*/
public function assignsubmission_dta_compilation_error_count(): int {
return $this->assignsubmission_dta_state_occurence_count(3);
}
/**
* Count how many results failed (state=2).
*
* @return int
*/
public function assignsubmission_dta_failed_count(): int {
return $this->assignsubmission_dta_state_occurence_count(2);
}
/**
* Count how many results were successful (state=1).
*
* @return int
*/
public function assignsubmission_dta_successful_count(): int {
return $this->assignsubmission_dta_state_occurence_count(1);
}
/**
* Count how many results are unknown (state=0).
*
* @return int
*/
public function assignsubmission_dta_unknown_count(): int {
return $this->assignsubmission_dta_state_occurence_count(0);
}
/**
* Computes the success rate as a percentage of all results (0..100).
* Note: This includes tests that might have compile errors or unknown states.
*
* @return float A floating percentage between 0.0 and 100.0.
*/
public function assignsubmission_dta_success_rate(): float {
$count = $this->assignsubmission_dta_result_count();
if ($count === 0) {
return 0.0;
}
$successful = $this->assignsubmission_dta_successful_count();
return ($successful / $count) * 100.0;
}
}
......@@ -16,6 +16,8 @@
namespace assignsubmission_dta\privacy;
use assign_submission_dta;
use assignsubmission_dta\dta_db_utils;
use core_privacy\local\metadata\collection;
use core_privacy\local\request\writer;
use core_privacy\local\request\contextlist;
......@@ -57,6 +59,7 @@ class provider implements \core_privacy\local\metadata\provider,
'global_stacktrace' => 'privacy:metadata:assignsubmission_dta_summary:global_stacktrace',
'successful_competencies' => 'privacy:metadata:assignsubmission_dta_summary:successful_competencies',
'tested_competencies' => 'privacy:metadata:assignsubmission_dta_summary:tested_competencies',
],
'privacy:metadata:assignsubmission_dta_summary'
);
......@@ -80,6 +83,20 @@ class provider implements \core_privacy\local\metadata\provider,
'privacy:metadata:assignsubmission_dta_result'
);
$collection->add_database_table(
'assignsubmission_dta_recommendations',
[
'assignmentid' => 'privacy:metadata:assignsubmission_dta_summary:assignmentid',
'submissionid' => 'privacy:metadata:assignsubmission_dta_summary:submissionid',
'topic' => 'privacy:metadata:assignsubmission_dta_recommendations:topic',
'exercise_name' => 'privacy:metadata:assignsubmission_dta_recommendations:exercise_name',
'url' => 'privacy:metadata:assignsubmission_dta_recommendations:url',
'difficulty' => 'privacy:metadata:assignsubmission_dta_recommendations:difficulty',
'score' => 'privacy:metadata:assignsubmission_dta_recommendations:score',
],
'privacy:metadata:assignsubmission_dta_recommendations'
);
$collection->add_external_location_link('dta_backend', [
'assignmentid' => 'privacy:metadata:assignsubmission_dta_summary:assignmentid',
'submissionid' => 'privacy:metadata:assignsubmission_dta_summary:submissionid',
......@@ -138,7 +155,7 @@ class provider implements \core_privacy\local\metadata\provider,
$files = get_files($submission, $user);
foreach ($files as $file) {
$userid = $exportdata->get_pluginobject()->userid;
$dtaresultsummary = DBUtils::getresultsummaryfromdatabase($assign->id, $submission->id);
$dtaresultsummary = dta_db_utils::dta_get_result_summary_from_database($assign->id, $submission->id);
// Submitted file.
writer::with_context($exportdata->get_context())->export_file($exportdata->get_subcontext(), $file)
// DTA result.
......@@ -173,6 +190,8 @@ class provider implements \core_privacy\local\metadata\provider,
// Delete records from assignsubmission_dta tables.
$DB->delete_records('assignsubmission_dta_result', ['assignmentid' => $assignmentid]);
$DB->delete_records('assignsubmission_dta_summary', ['assignmentid' => $assignmentid]);
$DB->delete_records('assignsubmission_dta_recommendations', ['assignmentid' => $assignmentid]);
}
/**
......@@ -201,6 +220,10 @@ class provider implements \core_privacy\local\metadata\provider,
'assignmentid' => $assignmentid,
'submissionid' => $submissionid,
]);
$DB->delete_records('assignsubmission_dta_recommendations', [
'assignmentid' => $assignmentid,
'submissionid' => $submissionid,
]);
}
/**
......@@ -228,6 +251,7 @@ class provider implements \core_privacy\local\metadata\provider,
$params['assignid'] = $deletedata->get_assignid();
$DB->delete_records_select('assignsubmission_dta_result', "assignmentid = :assignid AND submissionid $sql", $params);
$DB->delete_records_select('assignsubmission_dta_summary', "assignmentid = :assignid AND submissionid $sql", $params);
$DB->delete_records_select('assignsubmission_dta_recommendations', "assignmentid = :assignid AND submissionid $sql", $params);
}
/**
......
......@@ -20,6 +20,23 @@
<KEY NAME="fk_submission" TYPE="foreign" FIELDS="submission_id" REFTABLE="assign_submission" REFFIELDS="id" COMMENT="The submission this summary relates to."/>
</KEYS>
</TABLE>
<TABLE NAME="assignsubmission_dta_recommendations" COMMENT="Stores recommendation data">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" COMMENT="Primary Key" />
<FIELD NAME="assignment_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="submission_id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="topic" TYPE="char" LENGTH="255" NOTNULL="true" COMMENT="Recommendation Topic" />
<FIELD NAME="exercise_name" TYPE="char" LENGTH="255" NOTNULL="true" COMMENT="Exercise Name" />
<FIELD NAME="url" TYPE="char" LENGTH="255" NOTNULL="true" COMMENT="Exercise URL" />
<FIELD NAME="difficulty" TYPE="number" LENGTH="10" NOTNULL="true" COMMENT="Exercise Difficulty" />
<FIELD NAME="score" TYPE="number" LENGTH="10" NOTNULL="true" COMMENT="Exercise Score" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="fk_assignment" TYPE="foreign" FIELDS="assignment_id" REFTABLE="assign" REFFIELDS="id" COMMENT="The assignment instance this recommendations relates to"/>
<KEY NAME="fk_submission" TYPE="foreign" FIELDS="submission_id" REFTABLE="assign_submission" REFFIELDS="id" COMMENT="The submission this recommendations relates to."/>
</KEYS>
</TABLE>
<TABLE NAME="assignsubmission_dta_result" COMMENT="DTA testrun single test results">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
......
......@@ -92,22 +92,22 @@ $string["comp14"] = $string["comp_simple"];
$string["comp15"] = $string["comp_abstraction"];
// Competency explanations.
$string["comp_statement_expl"] = "formulate a syntactically correct statement that contributes to the solution of the given problem.";
$string["comp_block_expl"] = "structure code into syntactically correct small unnamed units that contribute to the solution of the given problem.";
$string["comp_flow_expl"] = "formulate syntax elements guiding the control flow such that it contributes to the solution of the given problem.";
$string["comp_loop_expl"] = "use syntax elements repeating statements such that it contributes to the solution of the given problem.";
$string["comp_const_expl"] = "identify and syntactically correctly define constants that contribute to the understanding and solution of the given problem.";
$string["comp_var_expl"] = "identify and syntactically correctly define variables that contribute to the solution of the given problem.";
$string["comp_type_expl"] = "define and/or choose appropriate data types for data elements such that they contribute to the solution of the given problem.";
$string["comp_datastructure_expl"] = "define and/or choose appropriate data structures for data elements such that they contribute to the solution of the given problem.";
$string["comp_interface_expl"] = "define and use interfaces for larger units of code such that it contributes to the solution of the given problem.";
$string["comp_unit_expl"] = "define and larger units of code such that it contributes to the solution of the given problem.";
$string["comp_proc_usage_expl"] = "use existing named structure blocks with a pre-defined behavior and signature such that it contributes to the solution of the given problem.";
$string["comp_proc_sign_expl"] = "define named structure blocks with a pre-defined behavior and signature such that it contributes to the solution of the given problem.";
$string["comp_library_expl"] = "use existing larger collections of named structure blocks with a pre-defined behavior and signature such that it contributes to the solution of the given problem.";
$string["comp_ext_api_expl"] = "use standardized existing external collections of named structure blocks with a pre-defined behavior and signature such that it contributes to the solution of the given problem.";
$string["comp_simple_expl"] = "create a simple solution of the given problem.";
$string["comp_abstraction_expl"] = "create a sufficiently abstract solution for the given problem.";
$string["comp_statement_expl"] = "Formulate a syntactically correct statement that contributes to the solution of the given problem.";
$string["comp_block_expl"] = "Structure code into syntactically correct small unnamed units that contribute to the solution of the given problem.";
$string["comp_flow_expl"] = "Formulate syntax elements guiding the control flow such that it contributes to the solution of the given problem.";
$string["comp_loop_expl"] = "Use syntax elements repeating statements such that it contributes to the solution of the given problem.";
$string["comp_const_expl"] = "Identify and syntactically correctly define constants that contribute to the understanding and solution of the given problem.";
$string["comp_var_expl"] = "Identify and syntactically correctly define variables that contribute to the solution of the given problem.";
$string["comp_type_expl"] = "Define and/or choose appropriate data types for data elements such that they contribute to the solution of the given problem.";
$string["comp_datastructure_expl"] = "Define and/or choose appropriate data structures for data elements such that they contribute to the solution of the given problem.";
$string["comp_interface_expl"] = "Define and use interfaces for larger units of code such that it contributes to the solution of the given problem.";
$string["comp_unit_expl"] = "Define and larger units of code such that it contributes to the solution of the given problem.";
$string["comp_proc_usage_expl"] = "Use existing named structure blocks with a pre-defined behavior and signature such that it contributes to the solution of the given problem.";
$string["comp_proc_sign_expl"] = "Define named structure blocks with a pre-defined behavior and signature such that it contributes to the solution of the given problem.";
$string["comp_library_expl"] = "Use existing larger collections of named structure blocks with a pre-defined behavior and signature such that it contributes to the solution of the given problem.";
$string["comp_ext_api_expl"] = "Use standardized existing external collections of named structure blocks with a pre-defined behavior and signature such that it contributes to the solution of the given problem.";
$string["comp_simple_expl"] = "Create a simple solution of the given problem.";
$string["comp_abstraction_expl"] = "Create a sufficiently abstract solution for the given problem.";
// Competency explanations for index calculations.
$string["comp_expl0"] = $string["comp_statement_expl"];
......@@ -164,3 +164,12 @@ $string["privacy:metadata:assignsubmission_dta_result:line_number"] = "Line numb
$string["privacy:metadata:assignsubmission_dta_result:position"] = "Position of failed individual compilation or test";
$string["privacy:metadata:assignsubmission_dta_result"] = "Individual Dockerized Test Agent (DTA) results";
$string["privacy:metadata:dta_backend"] = "Dockerized Test Agent (DTA) backend ReST web service";
//PLUGIN
$string['recommendations'] = 'Recommendations';
$string['topic'] = 'Topic';
$string['exercise_name'] = 'Exercise Name';
$string['url'] = 'URL';
$string['difficulty'] = 'Difficulty';
$string['score'] = 'Score';
This diff is collapsed.
dtt::https://transfer.hft-stuttgart.de/gitlab/dtt/example_openjdk11-junit5-calculator-test.git::none::none::hftstuttgart/dta-jdk17-junit5-testrunner:latest
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