Commit 207e72b6 authored by Kurzenberger's avatar Kurzenberger
Browse files

fixed the code checker requierments

parent 51e12764
Pipeline #10966 passed with stage
Showing with 181 additions and 157 deletions
+181 -157
<?php <?php
// This file is part of Moodle - http://moodle.org/. // This file is part of Moodle - http://moodle.org/.
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// Moodle is distributed in the hope that it will be useful, // Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
......
<?php <?php
// This file is part of Moodle - http://moodle.org/. // This file is part of Moodle - http://moodle.org/
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
...@@ -14,6 +14,14 @@ ...@@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // 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; namespace assignsubmission_dta;
use assignsubmission_dta\dta_db_utils; use assignsubmission_dta\dta_db_utils;
...@@ -25,8 +33,8 @@ use assignsubmission_dta\models\dta_recommendation; ...@@ -25,8 +33,8 @@ use assignsubmission_dta\models\dta_recommendation;
/** /**
* Utility class for DTA submission plugin result display. * Utility class for DTA submission plugin result display.
* *
* @package assignsubmission_dta * @package assignsubmission_dta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class dta_view_submission_utils { class dta_view_submission_utils {
...@@ -35,105 +43,102 @@ class dta_view_submission_utils { ...@@ -35,105 +43,102 @@ class dta_view_submission_utils {
*/ */
public const ASSIGNSUBMISSION_DTA_COMPONENT_NAME = 'assignsubmission_dta'; public const ASSIGNSUBMISSION_DTA_COMPONENT_NAME = 'assignsubmission_dta';
/** /**
* Generates a short summary HTML (like your old plugin). * Generates a short summary HTML (like your old plugin).
* *
* @param int $assignmentid The assignment ID. * @param int $assignmentid The assignment ID.
* @param int $submissionid The submission ID to create a report for. * @param int $submissionid The submission ID to create a report for.
* @return string The HTML summary. * @return string The HTML summary.
*/ */
public static function assignsubmission_dta_generate_summary_html( public static function assignsubmission_dta_generate_summary_html(
int $assignmentid, int $assignmentid,
int $submissionid int $submissionid
): string { ): string {
// 1) Retrieve the summary data from the DB (adjust your DB-utils class as needed).
// 1) Retrieve the summary data from the DB (adjust your DB-utils class as needed). $summary = dta_db_utils::assignsubmission_dta_get_result_summary_from_database($assignmentid, $submissionid);
$summary = dta_db_utils::assignsubmission_dta_get_result_summary_from_database($assignmentid, $submissionid);
// 2) Prepare an HTML buffer.
$html = '';
// 3) Extract counts from your new method names:
$unknowncount = $summary->assignsubmission_dta_unknown_count();
$compilecount = $summary->assignsubmission_dta_compilation_error_count();
$successcount = $summary->assignsubmission_dta_successful_count();
$failcount = $summary->assignsubmission_dta_failed_count();
$totalcount = $summary->assignsubmission_dta_result_count();
// 4) Compute success rate if no unknown/compile errors and total>0.
$successrate = '?';
if ($unknowncount === 0 && $compilecount === 0 && $totalcount > 0) {
$successrate = round(($successcount / $totalcount) * 100, 2);
}
// 5) “X/Y (Z%) tests successful” line: // 2) Prepare an HTML buffer.
// If either compile errors or unknown exist -> we show "?" $html = '';
// else X/Y (rate%).
$html .= $successcount . '/';
if ($compilecount === 0 && $unknowncount === 0) {
$html .= ($totalcount > 0)
? ($totalcount . ' (' . $successrate . '%)')
: ('0 (' . $successrate . ')');
} else {
$html .= '?';
}
$html .= get_string('tests_successful', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME) . "<br />";
// 6) If there are compilation errors, show them: // 3) Extract counts from your new method names.
if ($compilecount > 0) { $unknowncount = $summary->assignsubmission_dta_unknown_count();
$html .= $compilecount $compilecount = $summary->assignsubmission_dta_compilation_error_count();
. get_string('compilation_errors', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME) $successcount = $summary->assignsubmission_dta_successful_count();
. "<br />"; $failcount = $summary->assignsubmission_dta_failed_count();
} $totalcount = $summary->assignsubmission_dta_result_count();
// 7) If there are unknown results, show them: // 4) Compute success rate if no unknown/compile errors and total>0.
if ($unknowncount > 0) { $successrate = '?';
$html .= $unknowncount if ($unknowncount === 0 && $compilecount === 0 && $totalcount > 0) {
. get_string('unknown_state', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME) $successrate = round(($successcount / $totalcount) * 100, 2);
. "<br />"; }
}
if ($failcount > 0) { // 5) "X/Y (Z%) tests successful" line:
$html .= $failcount // If either compile errors or unknown exist -> show "?", else X/Y (rate%).
. get_string('tests_failed', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME) $html .= $successcount . '/';
. "<br />"; if ($compilecount === 0 && $unknowncount === 0) {
} $html .= ($totalcount > 0)
? ($totalcount . ' (' . $successrate . '%)')
: ('0 (' . $successrate . ')');
// 8) Competencies (like your old snippet): } else {
$showncompetencies = explode(';', $summary->successfultestcompetencies); $html .= '?';
$overallcompetencies = explode(';', $summary->overalltestcompetencies); }
$html .= get_string('tests_successful', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME) . "<br />";
$tmp = '';
$size = count($showncompetencies);
for ($i = 0; $i < $size; $i++) {
$shown = $showncompetencies[$i];
$comp = $overallcompetencies[$i];
// If the competency was actually used (non-zero?), show a row.
if ($shown !== '0') {
$shownval = floatval($shown);
$compval = floatval($comp);
// Guard division by zero:
$pct = 0;
if ($compval > 0) {
$pct = 100.0 * $shownval / $compval;
}
// “compX XX%<br />” // 6) If there are compilation errors, show them.
$tmp .= get_string('comp' . $i, self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME) if ($compilecount > 0) {
. ' ' . round($pct, 2) . '%<br />'; $html .= $compilecount
. get_string('compilation_errors', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
. "<br />";
} }
}
$html .= get_string('success_competencies', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME) // 7) If there are unknown results, show them.
. "<br />" . $tmp . "<br />"; if ($unknowncount > 0) {
$html .= $unknowncount
. get_string('unknown_state', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
. "<br />";
}
// 9) Wrap it in a DIV for styling, and return. // If there are failed tests, show them.
return \html_writer::div($html, "dtaSubmissionSummary"); if ($failcount > 0) {
} $html .= $failcount
. get_string('tests_failed', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
. "<br />";
}
// 8) Competencies (like your old snippet).
$showncompetencies = explode(';', $summary->successfultestcompetencies);
$overallcompetencies = explode(';', $summary->overalltestcompetencies);
$tmp = '';
$size = count($showncompetencies);
for ($i = 0; $i < $size; $i++) {
$shown = $showncompetencies[$i];
$comp = $overallcompetencies[$i];
// If the competency was actually used (non-zero?), show a row.
if ($shown !== '0') {
$shownval = (float) $shown;
$compval = (float) $comp;
// Guard division by zero.
$pct = 0;
if ($compval > 0) {
$pct = 100.0 * $shownval / $compval;
}
// "compX XX%<br />"
$tmp .= get_string('comp' . $i, self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
. ' ' . round($pct, 2) . '%<br />';
}
}
$html .= get_string('success_competencies', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)
. "<br />" . $tmp . "<br />";
// 9) Wrap it in a DIV for styling, and return.
return \html_writer::div($html, 'dtaSubmissionSummary');
}
/** /**
* Generates detailed view HTML. * Generates detailed view HTML.
...@@ -158,7 +163,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -158,7 +163,7 @@ public static function assignsubmission_dta_generate_summary_html(
$html = ''; $html = '';
// *** Summary Table *** // Summary table.
$tableheaderrowattributes = ['class' => 'dtaTableHeaderRow']; $tableheaderrowattributes = ['class' => 'dtaTableHeaderRow'];
$tablerowattributes = ['class' => 'dtaTableRow']; $tablerowattributes = ['class' => 'dtaTableRow'];
$resultrowattributes = $tablerowattributes; $resultrowattributes = $tablerowattributes;
...@@ -188,21 +193,19 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -188,21 +193,19 @@ public static function assignsubmission_dta_generate_summary_html(
$unknowncount = $summary->assignsubmission_dta_unknown_count(); $unknowncount = $summary->assignsubmission_dta_unknown_count();
// Total items. // Total items.
$tmp = ''; $tmp = \html_writer::tag(
$tmp .= \html_writer::tag(
'td', 'td',
get_string('total_items', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME), get_string('total_items', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
$attributes $attributes
); );
$tmp .= \html_writer::tag('td', $resultcount, $attributes); $tmp .= \html_writer::tag('td', $resultcount, $attributes);
$resultrowattributes = $tablerowattributes; $resultrowattributes = $tablerowattributes;
// Original code colors this row as unknown by default: // Original code colors this row as unknown by default.
$resultrowattributes['class'] .= ' ' . $unknownattributes; $resultrowattributes['class'] .= ' ' . $unknownattributes;
$body .= \html_writer::tag('tr', $tmp, $resultrowattributes); $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
// Tests successful. // Tests successful.
$tmp = ''; $tmp = \html_writer::tag(
$tmp .= \html_writer::tag(
'td', 'td',
get_string('tests_successful', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME), get_string('tests_successful', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
$attributes $attributes
...@@ -228,8 +231,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -228,8 +231,7 @@ public static function assignsubmission_dta_generate_summary_html(
$body .= \html_writer::tag('tr', $tmp, $resultrowattributes); $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
// Failures. // Failures.
$tmp = ''; $tmp = \html_writer::tag(
$tmp .= \html_writer::tag(
'td', 'td',
get_string('failures', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME), get_string('failures', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
$attributes $attributes
...@@ -244,8 +246,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -244,8 +246,7 @@ public static function assignsubmission_dta_generate_summary_html(
$body .= \html_writer::tag('tr', $tmp, $resultrowattributes); $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
// Compilation errors. // Compilation errors.
$tmp = ''; $tmp = \html_writer::tag(
$tmp .= \html_writer::tag(
'td', 'td',
get_string('compilation_errors', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME), get_string('compilation_errors', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
$attributes $attributes
...@@ -260,8 +261,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -260,8 +261,7 @@ public static function assignsubmission_dta_generate_summary_html(
$body .= \html_writer::tag('tr', $tmp, $resultrowattributes); $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
// Unknown state. // Unknown state.
$tmp = ''; $tmp = \html_writer::tag(
$tmp .= \html_writer::tag(
'td', 'td',
get_string('unknown_state', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME), get_string('unknown_state', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
$attributes $attributes
...@@ -276,8 +276,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -276,8 +276,7 @@ public static function assignsubmission_dta_generate_summary_html(
$body .= \html_writer::tag('tr', $tmp, $resultrowattributes); $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
// Success rate row. // Success rate row.
$tmp = ''; $tmp = \html_writer::tag(
$tmp .= \html_writer::tag(
'td', 'td',
\html_writer::tag('b', get_string('success_rate', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)), \html_writer::tag('b', get_string('success_rate', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME)),
$attributes $attributes
...@@ -291,7 +290,6 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -291,7 +290,6 @@ public static function assignsubmission_dta_generate_summary_html(
\html_writer::tag('b', $successfulcount . '/' . $suffix), \html_writer::tag('b', $successfulcount . '/' . $suffix),
$attributes $attributes
); );
$resultrowattributes = $tablerowattributes; $resultrowattributes = $tablerowattributes;
if ($compilationcount == 0 && $unknowncount == 0 && $resultcount > 0) { if ($compilationcount == 0 && $unknowncount == 0 && $resultcount > 0) {
if ($successrate !== '?' && $successrate < 50) { if ($successrate !== '?' && $successrate < 50) {
...@@ -314,12 +312,13 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -314,12 +312,13 @@ public static function assignsubmission_dta_generate_summary_html(
// Spacing after the summary table. // Spacing after the summary table.
$html .= \html_writer::empty_tag('div', ['class' => 'dtaSpacer']); $html .= \html_writer::empty_tag('div', ['class' => 'dtaSpacer']);
// *** Recommendations Table *** // Recommendations table.
if (!empty($recommendations)) { if (!empty($recommendations)) {
$allowedsortfields = ['topic', 'exercise_name', 'difficulty', 'score']; $allowedsortfields = ['topic', 'exercise_name', 'difficulty', 'score'];
$allowedsortdirs = ['asc', 'desc']; $allowedsortdirs = ['asc', 'desc'];
$sortby = $_POST['sortby'] ?? 'score'; // Make sure only one space before ??
$sortby = $_POST['sortby'] ?? 'score';
$sortdir = $_POST['sortdir'] ?? 'asc'; $sortdir = $_POST['sortdir'] ?? 'asc';
if (!in_array($sortby, $allowedsortfields)) { if (!in_array($sortby, $allowedsortfields)) {
...@@ -370,7 +369,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -370,7 +369,7 @@ public static function assignsubmission_dta_generate_summary_html(
]); ]);
// Hidden inputs. // Hidden inputs.
$hiddeninputs = \html_writer::empty_tag('input', [ $hiddeninputs = \html_writer::empty_tag('input', [
'type' => 'hidden', 'type' => 'hidden',
'name' => 'sortby', 'name' => 'sortby',
'value' => $columnname, 'value' => $columnname,
...@@ -381,7 +380,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -381,7 +380,7 @@ public static function assignsubmission_dta_generate_summary_html(
'value' => $newsortdir, 'value' => $newsortdir,
]); ]);
$form = \html_writer::start_tag('form', [ $form = \html_writer::start_tag('form', [
'method' => 'post', 'method' => 'post',
'style' => 'display:inline', 'style' => 'display:inline',
]); ]);
...@@ -443,15 +442,14 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -443,15 +442,14 @@ public static function assignsubmission_dta_generate_summary_html(
$html .= \html_writer::empty_tag('div', ['class' => 'dtaSpacer']); $html .= \html_writer::empty_tag('div', ['class' => 'dtaSpacer']);
} }
// *** Competency Assessment Table *** // Competency assessment table.
$body = ''; $body = '';
$tmp = ''; $tmp = \html_writer::tag(
$tmp .= \html_writer::tag(
'th', 'th',
get_string('competencies', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME), get_string('competencies', self::ASSIGNSUBMISSION_DTA_COMPONENT_NAME),
['class' => 'dtaTableHeader'] ['class' => 'dtaTableHeader']
); );
$tmp .= \html_writer::empty_tag('th', ['class' => 'dtaTableHeader']); $tmp .= \html_writer::empty_tag('th', ['class' => 'dtaTableHeader']);
$header = \html_writer::tag('tr', $tmp, $tableheaderrowattributes); $header = \html_writer::tag('tr', $tmp, $tableheaderrowattributes);
$header = \html_writer::tag('thead', $header); $header = \html_writer::tag('thead', $header);
...@@ -462,12 +460,12 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -462,12 +460,12 @@ public static function assignsubmission_dta_generate_summary_html(
$comp = $overallcompetencies[$index]; $comp = $overallcompetencies[$index];
$shown = $showncompetencies[$index]; $shown = $showncompetencies[$index];
// If the competency was actually assessed, add a row in the table. // If the competency was actually assessed, add a row.
if ($comp !== '0') { if ($comp !== '0') {
$compval = floatval($comp); $compval = (float) $comp;
$shownval = floatval($shown); $shownval = (float) $shown;
// Guard division by zero: // Guard division by zero.
$pct = 0; $pct = 0;
if ($compval > 0) { if ($compval > 0) {
$pct = (100.0 * $shownval / $compval); $pct = (100.0 * $shownval / $compval);
...@@ -499,7 +497,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -499,7 +497,7 @@ public static function assignsubmission_dta_generate_summary_html(
// Add empty div for spacing. // Add empty div for spacing.
$html .= \html_writer::empty_tag('div', ['class' => 'dtaSpacer']); $html .= \html_writer::empty_tag('div', ['class' => 'dtaSpacer']);
// *** Details Table *** // Details table.
$tmp = ''; $tmp = '';
$tmp .= \html_writer::tag( $tmp .= \html_writer::tag(
'th', 'th',
...@@ -513,7 +511,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -513,7 +511,7 @@ public static function assignsubmission_dta_generate_summary_html(
$body = ''; $body = '';
$spacerrow = null; $spacerrow = null;
foreach ($summary->results as $r) { foreach ($summary->results as $r) {
// Add spacer first if not null. // Add spacer row before each new entry (after the first).
if (!is_null($spacerrow)) { if (!is_null($spacerrow)) {
$body .= $spacerrow; $body .= $spacerrow;
} }
...@@ -565,7 +563,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -565,7 +563,7 @@ public static function assignsubmission_dta_generate_summary_html(
); );
$body .= \html_writer::tag('tr', $tmp, $resultrowattributes); $body .= \html_writer::tag('tr', $tmp, $resultrowattributes);
// If state != 1, show additional info. // If state != 1 (not successful), show additional info.
if ($r->state !== 1) { if ($r->state !== 1) {
$tmp = ''; $tmp = '';
$tmp .= \html_writer::tag( $tmp .= \html_writer::tag(
...@@ -633,6 +631,7 @@ public static function assignsubmission_dta_generate_summary_html( ...@@ -633,6 +631,7 @@ public static function assignsubmission_dta_generate_summary_html(
} }
if (is_null($spacerrow)) { if (is_null($spacerrow)) {
// Reuse this spacer row between subsequent items.
$spacerrow = \html_writer::empty_tag('tr', ['class' => 'dtaTableSpacer']); $spacerrow = \html_writer::empty_tag('tr', ['class' => 'dtaTableSpacer']);
} }
} }
......
<?php <?php
// This file is part of Moodle - http://moodle.org/. // This file is part of Moodle - http://moodle.org/.
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// Moodle is distributed in the hope that it will be useful, // Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
...@@ -39,9 +39,9 @@ class dta_recommendation { ...@@ -39,9 +39,9 @@ class dta_recommendation {
public $topic; public $topic;
/** /**
* @var string $exerciseName Name of the exercise. * @var string $exercisename Name of the exercise.
*/ */
public $exerciseName; public $exercisename;
/** /**
* @var string $url URL of the exercise. * @var string $url URL of the exercise.
...@@ -73,8 +73,9 @@ class dta_recommendation { ...@@ -73,8 +73,9 @@ class dta_recommendation {
foreach ($response->recommendations as $recommendation) { foreach ($response->recommendations as $recommendation) {
$rec = new dta_recommendation(); $rec = new dta_recommendation();
$rec->topic = $recommendation->topic ?? null; $rec->topic = $recommendation->topic ?? null;
// Map correct fields to the renamed variable names:
$rec->exerciseName = $recommendation->url ?? null; // Map correct fields to the renamed variable names.
$rec->exercisename = $recommendation->url ?? null;
$rec->url = $recommendation->exerciseName ?? null; $rec->url = $recommendation->exerciseName ?? null;
$rec->difficulty = $recommendation->difficulty ?? null; $rec->difficulty = $recommendation->difficulty ?? null;
$rec->score = $recommendation->score ?? null; $rec->score = $recommendation->score ?? null;
......
<?php <?php
// This file is part of Moodle - http://moodle.org/. // This file is part of Moodle - http://moodle.org/.
// //
// Moodle is free software: you can redistribute it and/or modify // Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// Moodle is distributed in the hope that it will be useful, // Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
......
<?php <?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; namespace assignsubmission_dta\models;
/** /**
...@@ -7,9 +30,11 @@ namespace assignsubmission_dta\models; ...@@ -7,9 +30,11 @@ namespace assignsubmission_dta\models;
* This class holds: * This class holds:
* - A timestamp for when the summary was generated. * - A timestamp for when the summary was generated.
* - An optional global stack trace (in case the entire process failed). * - An optional global stack trace (in case the entire process failed).
* - A competency profile of how many tests passed for each competency (successfulTestCompetencyProfile). * - A competency profile of how many tests passed for each competency.
* - A competency profile of the total coverage for each competency (overallTestCompetencyProfile). * - A competency profile of the total coverage for each competency.
* - An array of DTA result objects that detail individual test results. * - An array of dta_result objects that detail individual test results.
*
* @package assignsubmission_dta
*/ */
class dta_result_summary { class dta_result_summary {
...@@ -41,9 +66,9 @@ class dta_result_summary { ...@@ -41,9 +66,9 @@ class dta_result_summary {
$summary->timestamp = $response->timestamp ?? 0; $summary->timestamp = $response->timestamp ?? 0;
$summary->globalstacktrace = $response->globalstacktrace ?? ''; $summary->globalstacktrace = $response->globalstacktrace ?? '';
// If your JSON keys are 'successfulTestCompetencyProfile' and 'overallTestCompetencyProfile': // If your JSON keys are 'successfulTestCompetencyProfile' and 'overallTestCompetencyProfile'.
$summary->successfultestcompetencies = $response->successfulTestCompetencyProfile ?? ''; $summary->successfultestcompetencies = $response->successfulTestCompetencyProfile ?? '';
$summary->overalltestcompetencies = $response->overallTestCompetencyProfile ?? ''; $summary->overalltestcompetencies = $response->overallTestCompetencyProfile ?? '';
// Decode the "results" array into an array of dta_result objects. // Decode the "results" array into an array of dta_result objects.
if (!empty($response->results) && is_array($response->results)) { if (!empty($response->results) && is_array($response->results)) {
...@@ -66,16 +91,16 @@ class dta_result_summary { ...@@ -66,16 +91,16 @@ class dta_result_summary {
foreach ($jsonarray as $entry) { foreach ($jsonarray as $entry) {
$value = new dta_result(); $value = new dta_result();
$value->packagename = $entry->packageName ?? ''; $value->packagename = $entry->packageName ?? '';
$value->classname = $entry->className ?? ''; $value->classname = $entry->className ?? '';
$value->name = $entry->name ?? ''; $value->name = $entry->name ?? '';
$value->state = $entry->state ?? 0; $value->state = $entry->state ?? 0;
$value->failuretype = $entry->failureType ?? ''; $value->failuretype = $entry->failureType ?? '';
$value->failurereason = $entry->failureReason ?? ''; $value->failurereason = $entry->failureReason ?? '';
$value->stacktrace = $entry->stacktrace ?? ''; $value->stacktrace = $entry->stacktrace ?? '';
$value->columnnumber = $entry->columnNumber ?? 0; $value->columnnumber = $entry->columnNumber ?? 0;
$value->linenumber = $entry->lineNumber ?? 0; $value->linenumber = $entry->lineNumber ?? 0;
$value->position = $entry->position ?? 0; $value->position = $entry->position ?? 0;
$ret[] = $value; $ret[] = $value;
} }
...@@ -151,7 +176,7 @@ class dta_result_summary { ...@@ -151,7 +176,7 @@ class dta_result_summary {
/** /**
* Computes the success rate as a percentage of all results (0..100). * Computes the success rate as a percentage of all results (0..100).
* Note: This includes tests that might have compile errors, unknown states, etc. * Note: This includes tests that might have compile errors or unknown states.
* *
* @return float A floating percentage between 0.0 and 100.0. * @return float A floating percentage between 0.0 and 100.0.
*/ */
......
...@@ -306,8 +306,7 @@ class assign_submission_dta extends assign_submission_plugin { ...@@ -306,8 +306,7 @@ class assign_submission_dta extends assign_submission_plugin {
$file = reset($files); $file = reset($files);
// Send file to backend (split across lines to avoid exceeding length). // Send file to backend (split across lines to avoid exceeding length).
$response = \assignsubmission_dta\dta_backend_utils:: $response = \assignsubmission_dta\dta_backend_utils::assignsubmission_dta_send_submission_to_backend(
assignsubmission_dta_send_submission_to_backend(
$this->assignment, $this->assignment,
$submission->id, $submission->id,
$file $file
......
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