Commit 64cc51fa authored by Kurzenberger's avatar Kurzenberger
Browse files

fixed version with enhanced provider.php and checked with codeChecker

parent 4e16f800
1 merge request!1Coding style and recommendations
Pipeline #10777 passed with stage
Showing with 206 additions and 238 deletions
+206 -238
......@@ -81,7 +81,7 @@ class dta_backend_utils {
];
// If request returned null, return false to indicate failure.
if (is_null(self::dta_post($url, $params))) {
if (is_null(self::assignsubmission_dta_post($url, $params))) {
return false;
} else {
return true;
......
File moved
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 result summary.
*
* @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 summary.
*
* @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_summary {
/**
* @var int $timestamp Timestamp for ordering and deletion of previous results.
*/
public $timestamp;
/**
* @var string $globalstacktrace Global stack trace if applicable, empty otherwise.
*/
public $globalstacktrace;
/**
* @var string $successfultestcompetencies Successfully tested competencies (tests and weights), or empty string.
*/
public $successfultestcompetencies;
/**
* @var string $overalltestcompetencies Overall tested competencies (tests and weights), or empty string.
*/
public $overalltestcompetencies;
/**
* @var array $results List of detail results.
*/
public $results;
/**
* Decodes the JSON result summary returned by the backend service call into the plugin PHP data structure.
*
* @param string $jsonstring JSON string containing DtaResultSummary.
* @return dta_result_summary The 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;
$summary->globalstacktrace = $response->globalstacktrace;
$summary->timestamp = $response->timestamp ?? 0;
$summary->globalstacktrace = $response->globalstacktrace ?? '';
$summary->successfultestcompetencies = $response->successfulTestCompetencyProfile ?? '';
$summary->overalltestcompetencies = $response->overallTestCompetencyProfile ?? '';
$summary->overalltestcompetencies = $response->overallTestCompetencyProfile ?? '';
$summary->results = self::assignsubmission_dta_decode_json_result_array($response->results);
if (!empty($response->results) && is_array($response->results)) {
$summary->results = self::assignsubmission_dta_decode_json_result_array($response->results);
} else {
$summary->results = [];
}
return $summary;
}
/**
* Decodes an array of JSON detail results into the plugin PHP data structure.
*
* @param array $jsonarray Decoded JSON array of results.
* @return array Array of dta_result objects.
*/
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 ?? '';
$value->linenumber = $entry->lineNumber ?? '';
$value->position = $entry->position ?? '';
$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;
}
/**
* Returns the number of detail results attached to the summary.
*
* @return int Count of occurrences.
*/
public function assignsubmission_dta_result_count(): int {
return count($this->results);
}
/**
* Returns the number of detail results with the given state attached to the summary.
*
* @param int $state State ordinal number.
* @return int Count of occurrences for the provided state.
*/
public function assignsubmission_dta_state_occurence_count(int $state): int {
$num = 0;
foreach ($this->results as $r) {
......@@ -130,39 +65,29 @@ class dta_result_summary {
return $num;
}
/**
* Returns the number of detail results with compilation errors attached to the summary.
*
* @return int Count of occurrences.
*/
public function assignsubmission_dta_compilation_error_count(): int {
return $this->assignsubmission_dta_state_occurence_count(3);
return $this->assignsubmission_dta_state_occurence_count(3); // State=3 => compile error
}
/**
* Returns the number of detail results with test failures attached to the summary.
*
* @return int Count of occurrences.
*/
public function assignsubmission_dta_failed_count(): int {
return $this->assignsubmission_dta_state_occurence_count(2);
return $this->assignsubmission_dta_state_occurence_count(2); // State=2 => fail
}
/**
* Returns the number of detail results with successful tests attached to the summary.
*
* @return int Count of occurrences.
*/
public function assignsubmission_dta_successful_count(): int {
return $this->assignsubmission_dta_state_occurence_count(1);
return $this->assignsubmission_dta_state_occurence_count(1); // State=1 => success
}
/**
* Returns the number of detail results with an unknown result attached to the summary.
*
* @return int Count of occurrences.
*/
public function assignsubmission_dta_unknown_count(): int {
return $this->assignsubmission_dta_state_occurence_count(0);
return $this->assignsubmission_dta_state_occurence_count(0); // State=0 => unknown
}
// OPTIONAL: A helper to safely get success rate 0..100
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;
}
}
......@@ -190,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]);
}
/**
......@@ -218,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,
]);
}
/**
......@@ -245,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);
}
/**
......
......@@ -55,7 +55,7 @@ class assign_submission_dta extends assign_submission_plugin {
*
* @return string
*/
public function assignsubmission_dta_get_name(): string {
public function get_name(): string {
return get_string('pluginname', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME);
}
......@@ -65,7 +65,7 @@ class assign_submission_dta extends assign_submission_plugin {
* @param MoodleQuickForm $mform Form to add elements to.
* @return void
*/
public function assignsubmission_dta_get_settings(MoodleQuickForm $mform): void {
public function get_settings(MoodleQuickForm $mform): void {
// Add draft filemanager to form.
$mform->addElement(
'filemanager',
......@@ -131,7 +131,7 @@ class assign_submission_dta extends assign_submission_plugin {
* @param stdClass $data Form data.
* @return bool
*/
public function assignsubmission_dta_save_settings(stdClass $data): bool {
public function save_settings(stdClass $data): bool {
// If the assignment has no filemanager for our plugin, just leave.
$draftfilemanagerid = self::ASSIGNSUBMISSION_DTA_DRAFT_FILEAREA_TEST;
if (!isset($data->$draftfilemanagerid)) {
......@@ -232,8 +232,8 @@ class assign_submission_dta extends assign_submission_plugin {
* @param stdClass $submission Submission to check.
* @return bool True if file count is zero.
*/
public function assignsubmission_dta_is_empty(stdClass $submission): bool {
return ($this->assignsubmission_dta_count_files(
public function is_empty(stdClass $submission): bool {
return ($this->count_files(
$submission->id,
self::ASSIGNSUBMISSION_DTA_FILEAREA_SUBMISSION
) === 0);
......@@ -246,7 +246,7 @@ class assign_submission_dta extends assign_submission_plugin {
* @param string $areaid Filearea id to count.
* @return int Number of files submitted in the filearea.
*/
private function assignsubmission_dta_count_files(int $submissionid, $areaid): int {
private function count_files(int $submissionid, $areaid): int {
$fs = get_file_storage();
$files = $fs->get_area_files(
$this->assignment->get_context()->id,
......@@ -279,7 +279,7 @@ class assign_submission_dta extends assign_submission_plugin {
);
// If submission is empty, leave directly.
if ($this->assignsubmission_dta_is_empty($submission)) {
if ($this->is_empty($submission)) {
return true;
}
......
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