Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CoTA
moodle-assignsubmission_dta
Commits
15627f16
Commit
15627f16
authored
Jan 24, 2025
by
Kurzenberger
Browse files
fixed issue in dta_result_summary to show the correct summary table
parent
64cc51fa
Pipeline
#10953
passed with stage
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
dta/classes/dta_db_utils.php
View file @
15627f16
...
@@ -174,6 +174,7 @@ class dta_db_utils {
...
@@ -174,6 +174,7 @@ class dta_db_utils {
$result
->
position
=
$rr
->
position
;
$result
->
position
=
$rr
->
position
;
$summary
->
results
[]
=
$result
;
$summary
->
results
[]
=
$result
;
}
}
return
$summary
;
return
$summary
;
...
...
dta/classes/dta_view_submission_utils.php
View file @
15627f16
...
@@ -49,6 +49,7 @@ public static function assignsubmission_dta_generate_summary_html(
...
@@ -49,6 +49,7 @@ public static function assignsubmission_dta_generate_summary_html(
// 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
);
print_r
(
$summary
);
// 2) Prepare an HTML buffer.
// 2) Prepare an HTML buffer.
$html
=
''
;
$html
=
''
;
...
@@ -93,6 +94,13 @@ public static function assignsubmission_dta_generate_summary_html(
...
@@ -93,6 +94,13 @@ public static function assignsubmission_dta_generate_summary_html(
.
"<br />"
;
.
"<br />"
;
}
}
if
(
$failcount
>
0
)
{
$html
.
=
$failcount
.
get_string
(
'tests_failed'
,
self
::
ASSIGNSUBMISSION_DTA_COMPONENT_NAME
)
.
"<br />"
;
}
// 8) Competencies (like your old snippet):
// 8) Competencies (like your old snippet):
$showncompetencies
=
explode
(
';'
,
$summary
->
successfultestcompetencies
);
$showncompetencies
=
explode
(
';'
,
$summary
->
successfultestcompetencies
);
$overallcompetencies
=
explode
(
';'
,
$summary
->
overalltestcompetencies
);
$overallcompetencies
=
explode
(
';'
,
$summary
->
overalltestcompetencies
);
...
...
dta/classes/models/dta_result_summary.php
View file @
15627f16
...
@@ -3,15 +3,37 @@ namespace assignsubmission_dta\models;
...
@@ -3,15 +3,37 @@ namespace assignsubmission_dta\models;
/**
/**
* Entity class for DTA submission plugin result summary.
* 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 (successfulTestCompetencyProfile).
* - A competency profile of the total coverage for each competency (overallTestCompetencyProfile).
* - An array of DTA result objects that detail individual test results.
*/
*/
class
dta_result_summary
{
class
dta_result_summary
{
/** @var int Unix timestamp for the summary. */
public
$timestamp
;
public
$timestamp
;
/** @var string A global stacktrace if the entire run had a fatal error (optional). */
public
$globalstacktrace
;
public
$globalstacktrace
;
/** @var string Semi-colon-separated numbers for competencies actually passed. */
public
$successfultestcompetencies
;
public
$successfultestcompetencies
;
/** @var string Semi-colon-separated numbers for total tested competencies. */
public
$overalltestcompetencies
;
public
$overalltestcompetencies
;
/** @var dta_result[] Array of individual test results. */
public
$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
{
public
static
function
assignsubmission_dta_decode_json
(
string
$jsonstring
):
dta_result_summary
{
$response
=
json_decode
(
$jsonstring
);
$response
=
json_decode
(
$jsonstring
);
...
@@ -19,9 +41,11 @@ class dta_result_summary {
...
@@ -19,9 +41,11 @@ 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':
$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.
if
(
!
empty
(
$response
->
results
)
&&
is_array
(
$response
->
results
))
{
if
(
!
empty
(
$response
->
results
)
&&
is_array
(
$response
->
results
))
{
$summary
->
results
=
self
::
assignsubmission_dta_decode_json_result_array
(
$response
->
results
);
$summary
->
results
=
self
::
assignsubmission_dta_decode_json_result_array
(
$response
->
results
);
}
else
{
}
else
{
...
@@ -31,10 +55,17 @@ class dta_result_summary {
...
@@ -31,10 +55,17 @@ class dta_result_summary {
return
$summary
;
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
{
private
static
function
assignsubmission_dta_decode_json_result_array
(
array
$jsonarray
):
array
{
$ret
=
[];
$ret
=
[];
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
??
''
;
...
@@ -51,41 +82,83 @@ class dta_result_summary {
...
@@ -51,41 +82,83 @@ class dta_result_summary {
return
$ret
;
return
$ret
;
}
}
/**
* Get the total number of results (tests) recorded in this summary.
*
* @return int
*/
public
function
assignsubmission_dta_result_count
():
int
{
public
function
assignsubmission_dta_result_count
():
int
{
return
count
(
$this
->
results
);
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
{
public
function
assignsubmission_dta_state_occurence_count
(
int
$state
):
int
{
$num
=
0
;
$num
=
0
;
foreach
(
$this
->
results
as
$r
)
{
foreach
(
$this
->
results
as
$r
)
{
if
(
$r
->
state
===
$state
)
{
if
(
(
int
)
$r
->
state
===
$state
)
{
$num
++
;
$num
++
;
}
}
}
}
return
$num
;
return
$num
;
}
}
/**
* Count how many results had compilation errors (state=3).
*
* @return int
*/
public
function
assignsubmission_dta_compilation_error_count
():
int
{
public
function
assignsubmission_dta_compilation_error_count
():
int
{
return
$this
->
assignsubmission_dta_state_occurence_count
(
3
);
// State=3 => compile error
return
$this
->
assignsubmission_dta_state_occurence_count
(
3
);
}
}
/**
* Count how many results failed (state=2).
*
* @return int
*/
public
function
assignsubmission_dta_failed_count
():
int
{
public
function
assignsubmission_dta_failed_count
():
int
{
return
$this
->
assignsubmission_dta_state_occurence_count
(
2
);
// State=2 => fail
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
{
public
function
assignsubmission_dta_successful_count
():
int
{
return
$this
->
assignsubmission_dta_state_occurence_count
(
1
);
// State=1 => success
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
{
public
function
assignsubmission_dta_unknown_count
():
int
{
return
$this
->
assignsubmission_dta_state_occurence_count
(
0
);
// State=0 => unknown
return
$this
->
assignsubmission_dta_state_occurence_count
(
0
);
}
}
// OPTIONAL: A helper to safely get success rate 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.
*
* @return float A floating percentage between 0.0 and 100.0.
*/
public
function
assignsubmission_dta_success_rate
():
float
{
public
function
assignsubmission_dta_success_rate
():
float
{
$count
=
$this
->
assignsubmission_dta_result_count
();
$count
=
$this
->
assignsubmission_dta_result_count
();
if
(
$count
===
0
)
{
if
(
$count
===
0
)
{
return
0.0
;
return
0.0
;
}
}
$successful
=
$this
->
assignsubmission_dta_successful_count
();
$successful
=
$this
->
assignsubmission_dta_successful_count
();
return
(
$successful
/
$count
)
*
100.0
;
return
(
$successful
/
$count
)
*
100.0
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment