Commit 5318a597 authored by user's avatar user Committed by Abbassy
Browse files

Initial commit: DTA v2 with classes/view.php structure

parent df3f0323
<?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 classes for DTA submission plugin result summary and test results
*
* @package assignsubmission_dta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright Gero Lueckemeyer and student project teams
*/
defined('MOODLE_INTERNAL') || die();
/**
* entity class for DTA submission plugin result
*
* @package assignsubmission_dta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright Gero Lueckemeyer and student project teams
*/
class DtaResult {
/**
* Broadly used in logic, parametrized for easier change.
*/
const COMPONENT_NAME = "assignsubmission_dta";
/**
* @var $packagename Package name of the test.
*/
public $packagename;
/**
* @var $classname Unit name of the test.
*/
public $classname;
/**
* @var $name Name of the test.
*/
public $name;
/**
* @var $state State is defined like below
*
* 0 UNKNOWN
* 1 SUCCESS
* 2 FAILURE
* 3 COMPILATIONERROR
*/
public $state;
/**
* @var $failuretype Type of test failure if applicable, "" otherwise.
*/
public $failuretype;
/**
* @var $failurereason Reason of test failure if applicable, "" otherwise.
*/
public $failurereason;
/**
* @var $stacktrace Stack trace of test failure if applicable, "" otherwise.
*/
public $stacktrace;
/**
* @var $columnnumber Column number of compile failure if applicable, "" otherwise.
*/
public $columnnumber;
/**
* @var $linenumber Line number of compile failure if applicable, "" otherwise.
*/
public $linenumber;
/**
* @var $position Position of compile failure if applicable, "" otherwise.
*/
public $position;
/**
* Returns the name of a state with the given number of display.
* @param int $state number of the state
* @return string name of state as defined
*/
public static function getstatename(int $state): string {
if ($state == 1) {
return get_string("tests_successful", self::COMPONENT_NAME);
} else if ($state == 2) {
return get_string("failures", self::COMPONENT_NAME);
} else if ($state == 3) {
return get_string("compilation_errors", self::COMPONENT_NAME);
} else {
return get_string("unknown_state", self::COMPONENT_NAME);
}
}
}
/**
* entity class for DTA submission plugin result
*
* @package assignsubmission_dta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright Gero Lueckemeyer and student project teams
*/
class DtaResultSummary {
/**
* @var $timestamp Result timestamp for chronological ordering and deletion of previous results.
*/
public $timestamp;
/**
* @var $globalstacktrace Global stack trace if applicable, "" otherwise.
*/
public $globalstacktrace;
/**
* @var $successfultestcompetencies Successfully tested competencies according to tests and weights, "" otherwise.
*/
public $successfultestcompetencies;
/**
* @var overalltestcompetencies Overall tested competencies according to tests and weights, "" otherwise.
*/
public $overalltestcompetencies;
/**
* @var 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 jsonString containing DtaResultSummary
* @return DtaResultSummary the result summary
*/
public static function decodejson(string $jsonstring): DtaResultSummary {
$response = json_decode($jsonstring);
$summary = new DtaResultSummary();
$summary->timestamp = $response->timestamp;
$summary->globalstacktrace = $response->globalstacktrace;
$summary->successfultestcompetencies = $response->successfulTestCompetencyProfile;
$summary->overalltestcompetencies = $response->overallTestCompetencyProfile;
$summary->results = self::decodejsonresultarray($response->results);
return $summary;
}
/**
* Decodes the array of JSON detail results returned by the backend service call into the plugin PHP data structure.
* @param array $jsonarray decoded json array of results array
* @return array of DtaResult
*/
private static function decodejsonresultarray($jsonarray): array {
$ret = [];
foreach ($jsonarray as $entry) {
$value = new DtaResult();
$value->packagename = $entry->packageName;
$value->classname = $entry->className;
$value->name = $entry->name;
$value->state = $entry->state;
$value->failuretype = $entry->failureType;
$value->failurereason = $entry->failureReason;
$value->stacktrace = $entry->stacktrace;
$value->columnnumber = $entry->columnNumber;
$value->linenumber = $entry->lineNumber;
$value->position = $entry->position;
$ret[] = $value;
}
return $ret;
}
/**
* Returns the number of detail results attached to the summary.
* @return int count of occurences
*/
public function resultcount(): 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 occurences provided state has
*/
public function stateoccurencecount(int $state): int {
$num = 0;
foreach ($this->results as $r) {
if ($r->state == $state) {
$num++;
}
}
return $num;
}
/**
* Returns the number of detail results with compilation errors attached to the summary.
* @return int count of occurences
*/
public function compilationerrorcount(): int {
return $this->stateoccurencecount(3);
}
/**
* Returns the number of detail results with test failures attached to the summary.
* @return int count of occurences
*/
public function failedcount(): int {
return $this->stateoccurencecount(2);
}
/**
* Returns the number of detail results with successful tests attached to the summary.
* @return int count of occurences
*/
public function successfulcount(): int {
return $this->stateoccurencecount(1);
}
/**
* Returns the number of detail results with an unknown result - mostly due to compile errors - attached to the summary.
* @return int count of occurences
*/
public function unknowncount(): int {
return $this->stateoccurencecount(0);
}
}
<?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 defines the admin settings for this plugin
*
* @package assignsubmission_dta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright Gero Lueckemeyer and student project teams
*/
defined('MOODLE_INTERNAL') || die();
$settings->add(new admin_setting_configcheckbox("assignsubmission_dta/default",
new lang_string("default", "assignsubmission_dta"),
new lang_string("default_help", "assignsubmission_dta"), 0));
$settings->add(new admin_setting_configtext("assignsubmission_dta/backendHost",
new lang_string("backendHost", "assignsubmission_dta"),
new lang_string("backendHost_help", "assignsubmission_dta"), "http://dtabackend:8080"));
/* Prevent word breaking in the grading table */
.dtaSubmissionSummary {
white-space: nowrap;
}
.dtaSubmissionSummary,
.dtaSubmissionDetails {
margin-top: 15px;
}
/* empty div between summary and detail table */
.dtaSpacer {
margin-top: 30px;
}
/****************************************************************
* Layout for the Detail view
****************************************************************/
.dtaTable {
display: inline-block;
max-width: 100%;
overflow: auto;
background: white !important;
border-radius: .1rem;
box-shadow: 0 .2rem .5rem rgba(0,0,0,.05),0 0 .05rem rgba(0,0,0,.1);
overflow-x: hidden;
}
.dtaTableHeaderRow {
font-weight: bold;
color: white !important;
background-color: gray !important;
}
.dtaTableRow {
background-color: unset !important;
border-top: .05rem solid lightgray;
}
.dtaTableHeaderRow th,
.dtaTableRow td {
padding: .9375em 1.25em;
}
.dtaStacktraceDetails {
max-height: 300px;
max-width: 70%;
overflow: auto;
}
.dtaResultUnknown {
border-left: 10px solid gray;
}
.dtaResultSuccess {
border-left: 10px solid green;
}
.dtaResultFailure {
border-left: 10px solid orange;
}
.dtaResultCompilationError {
border-left: 10px solid red;
}
.dtaTableRow:hover {
background-color: lightgray !important;
}
.dtaTableSpacer {
border-bottom: 2px solid darkgray;
}
<div class="card my-3">
{{#title}}<div class="card-header">{{.}}</div>{{/title}}
<div class="card-body p-0">
<table class="generaltable table table-striped m-0">
{{#headings.0}}
<thead>
<tr>
{{#headings}}<th>{{.}}</th>{{/headings}}
</tr>
</thead>
{{/headings.0}}
<tbody>
{{#rows}}
<tr>
{{#cells}}<td>{{{text}}}</td>{{/cells}}
</tr>
{{/rows}}
{{^rows}}
<tr><td colspan="{{headingscount}}">{{#str}} nothingtodisplay, core {{/str}}</td></tr>
{{/rows}}
</tbody>
</table>
</div>
</div>
<div class="card my-3">
{{#title}}<div class="card-header">{{.}}</div>{{/title}}
<div class="card-body p-0">
<table class="generaltable table table-striped m-0">
{{#headings.0}}
<thead>
<tr>
{{#headings}}
<th class="dtaTableHeader">
{{#sortable}}
<form method="post" style="display:inline">
{{text}}
<input type="submit" name="sortbutton" value="{{#sortdir}}{{#asc}}↑{{/asc}}{{^asc}}↓{{/asc}}{{/sortdir}}" class="sort-button">
<input type="hidden" name="sortby" value="{{sortby}}">
<input type="hidden" name="sortdir" value="{{#sortdir}}{{#asc}}desc{{/asc}}{{^asc}}asc{{/asc}}{{/sortdir}}">
</form>
{{/sortable}}
{{^sortable}}
{{text}}
{{/sortable}}
</th>
{{/headings}}
</tr>
</thead>
{{/headings.0}}
<tbody>
{{#rows}}
<tr>
{{#cells}}<td>{{text}}</td>{{/cells}}
</tr>
{{/rows}}
{{^rows}}
<tr><td colspan="{{headingscount}}">{{#str}} nothingtodisplay, core {{/str}}</td></tr>
{{/rows}}
</tbody>
</table>
</div>
</div>
<div class="card my-3">
{{#title}}<div class="card-header">{{.}}</div>{{/title}}
<div class="card-body p-0">
<table class="generaltable table table-striped m-0">
<tbody>
{{#rows}}
<tr{{#cssclass}} class="{{.}}"{{/cssclass}}>
<th scope="row" class="w-50">{{label}}</th>
<td>{{value}}</td>
</tr>
{{/rows}}
{{^rows}}
<tr><td colspan="2">{{#str}} nothingtodisplay, core {{/str}}</td></tr>
{{/rows}}
</tbody>
</table>
</div>
</div>
<?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 version information for the onlinetext DTA plugin
*
* @package assignsubmission_dta
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright Gero Lueckemeyer and student project teams
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2023123001;
$plugin->requires = 2020061525; // Moodle 3.9 LTS. Older unsupported versions from the 3.x branch should also work.
$plugin->component = 'assignsubmission_dta';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = "3.1.0";
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