Exercise: Add radar results option #3644

pull/3651/head^2
Julio Montoya 6 years ago
parent 138854be25
commit c7a50210a3
  1. 93
      main/exercise/TestCategory.php
  2. 42
      main/exercise/exercise.class.php
  3. 14
      main/exercise/exercise_show.php
  4. 1
      main/inc/lib/api.lib.php
  5. 15
      main/inc/lib/exercise.lib.php
  6. 1
      main/lang/english/trad4all.inc.php

@ -748,23 +748,27 @@ class TestCategory
/**
* Returns a category summary report.
*
* @param int $exerciseId
* @param array $category_list
* @param Exercise $exercise
* @param array $category_list
* pre filled array with the category_id, score, and weight
* example: array(1 => array('score' => '10', 'total' => 20));
*
* @return string
*/
public static function get_stats_table_by_attempt(
$exerciseId,
$category_list = []
) {
public static function get_stats_table_by_attempt($exercise, $category_list = [])
{
$exerciseId = $exercise->iId;
if (empty($category_list)) {
return null;
}
$category_name_list = self::getListOfCategoriesNameForTest($exerciseId);
$categoryNameList = self::getListOfCategoriesNameForTest($exerciseId);
$table = new HTML_Table(['class' => 'table table-hover table-striped table-bordered', 'id' => 'category_results']);
$table = new HTML_Table(
[
'class' => 'table table-hover table-striped table-bordered',
'id' => 'category_results',
]
);
$table->setHeaderContents(0, 0, get_lang('Categories'));
$table->setHeaderContents(0, 1, get_lang('AbsoluteScore'));
$table->setHeaderContents(0, 2, get_lang('RelativeScore'));
@ -781,9 +785,13 @@ class TestCategory
$total = $category_list['total'];
unset($category_list['total']);
}
if (count($category_list) > 1) {
$radar = '';
$countCategories = count($category_list);
if ($countCategories > 1) {
$resultsArray = [];
foreach ($category_list as $category_id => $category_item) {
$table->setCellContents($row, 0, $category_name_list[$category_id]);
$table->setCellContents($row, 0, $categoryNameList[$category_id]);
$table->setCellContents(
$row,
1,
@ -804,9 +812,72 @@ class TestCategory
true
)
);
$resultsArray[] = round($category_item['score']/$category_item['total']*10);
$row++;
}
// Radar requires more than 3 categories.
if ($countCategories > 2 && RESULT_DISABLE_RADAR === (int) $exercise->results_disabled) {
$categoryNameToJson = json_encode(array_column($categoryNameList, 'title'));
$resultsToJson = json_encode($resultsArray);
$radar = "
<canvas id='categoryRadar' width='400' height='200'></canvas>
<script>
var data = {
labels: $categoryNameToJson,
datasets: [{
fill:true,
label: '".get_lang('Categories')."',
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgb(255, 99, 132)',
pointBackgroundColor: 'rgb(255, 99, 132)',
pointBorderColor: '#fff',
pointHoverBackgroundColor:'#fff',
pointHoverBorderColor: 'rgb(255, 99, 132)',
pointRadius: 6,
pointBorderWidth: 3,
pointHoverRadius: 10,
data: $resultsToJson
}]
}
var options = {
scale: {
angleLines: {
display: false
},
ticks: {
beginAtZero: true,
min: 0,
max: 10,
stepSize: 1
},
pointLabels: {
fontSize: 14,
//fontStyle: 'bold'
},
},
elements: {
line: {
tension:0,
borderWidth:3
}
},
legend: {
//position: 'bottom'
display: false
}
};
var ctx = document.getElementById('categoryRadar').getContext('2d');
var myRadarChart = new Chart(ctx, {
type: 'radar',
data: data,
options: options
});
</script>
";
}
if (!empty($none_category)) {
$table->setCellContents($row, 0, get_lang('None'));
$table->setCellContents(
@ -855,7 +926,7 @@ class TestCategory
);
}
return $table->toHtml();
return $radar.$table->toHtml();
}
return '';

@ -8662,10 +8662,13 @@ class Exercise
*
* @param int $categoryId
* @param string $keyword
* @param int $userId Optional.
* @param int $courseId Optional.
* @param int $sessionId Optional.
* @param bool $returnData Optional.
* @param int $userId
* @param int $courseId
* @param int $sessionId
* @param bool $returnData
* @param int $minCategories
* @param int $filterByResultDisabled
* @param int $filterByAttempt
*
* @return string
*/
@ -8675,10 +8678,13 @@ class Exercise
$userId = 0,
$courseId = 0,
$sessionId = 0,
$returnData = false
$returnData = false,
$minCategories = 0,
$filterByResultDisabled = 0,
$filterByAttempt = 0
) {
$allowDelete = Exercise::allowAction('delete');
$allowClean = Exercise::allowAction('clean_results');
$allowClean = self::allowAction('clean_results');
$TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
@ -8747,6 +8753,19 @@ class Exercise
$keywordCondition = " AND title LIKE '%$keyword%' ";
}
$filterByResultDisabledCondition = '';
/*$filterByResultDisabled = (int) $filterByResultDisabled;
if (!empty($filterByResultDisabled)) {
$filterByResultDisabledCondition = ' AND e.results_disabled = '.$filterByResultDisabled;
}*/
$filterByAttemptCondition = '';
/*$filterByAttempt = (int) $filterByAttempt;
if (!empty($filterByAttempt)) {
$filterByResultDisabledCondition = ' AND e.result_disabled = '.$filterByResultDisabled;
}*/
/*$minCategories = 0,
$filterByAttempt = 0*/
// Only for administrators
if ($is_allowedToEdit) {
$total_sql = "SELECT count(iid) as count
@ -8757,6 +8776,7 @@ class Exercise
$condition_session
$categoryCondition
$keywordCondition
$filterByResultDisabledCondition
";
$sql = "SELECT * FROM $TBL_EXERCISES e
WHERE
@ -8765,6 +8785,7 @@ class Exercise
$condition_session
$categoryCondition
$keywordCondition
$filterByResultDisabledCondition
ORDER BY title
LIMIT $from , $limit";
} else {
@ -10872,6 +10893,15 @@ class Exercise
['id' => 'result_disabled_8']
);
$resultDisabledGroup[] = $form->createElement(
'radio',
'results_disabled',
null,
get_lang('ExerciseCategoriesRadarMode'),
RESULT_DISABLE_RADAR,
['id' => 'result_disabled_9']
);
return $form->addGroup(
$resultDisabledGroup,
null,

@ -171,6 +171,10 @@ if ($allowRecordAudio && $allowTeacherCommentAudio) {
$htmlHeadXtra[] = api_get_js('record_audio/record_audio.js');
}
if (RESULT_DISABLE_RADAR === (int) $objExercise->results_disabled) {
$htmlHeadXtra[] = api_get_js('chartjs/Chart.min.js');
}
if ($action !== 'export') {
$scoreJsCode = ExerciseLib::getJsCode();
if ($origin !== 'learnpath') {
@ -907,13 +911,15 @@ if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
echo $chartMultiAnswer;
}
if (!empty($category_list) && ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt)) {
// Adding total
if (!empty($category_list) &&
($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt)
) {
// Adding total.
$category_list['total'] = [
'score' => $myTotalScoreTemp,
'total' => $totalWeighting,
];
echo TestCategory::get_stats_table_by_attempt($objExercise->id, $category_list);
echo TestCategory::get_stats_table_by_attempt($objExercise, $category_list);
}
if (in_array(
@ -922,7 +928,7 @@ if (in_array(
)) {
echo Display::page_header(get_lang('Ranking'), null, 'h4');
echo ExerciseLib::displayResultsInRanking(
$objExercise->iId,
$objExercise,
$student_id,
$courseInfo['real_id'],
$sessionId

@ -487,6 +487,7 @@ define('RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAY
define('RESULT_DISABLE_RANKING', 6);
define('RESULT_DISABLE_SHOW_ONLY_IN_CORRECT_ANSWER', 7);
define('RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING', 8);
define('RESULT_DISABLE_RADAR', 9);
define('EXERCISE_MAX_NAME_SIZE', 80);

@ -4918,7 +4918,7 @@ EOT;
'score' => $total_score,
'total' => $total_weight,
];
echo TestCategory::get_stats_table_by_attempt($objExercise->id, $category_list);
echo TestCategory::get_stats_table_by_attempt($objExercise, $category_list);
}
if ($show_all_but_expected_answer) {
@ -5000,7 +5000,7 @@ EOT;
)) {
echo Display::page_header(get_lang('Ranking'), null, 'h4');
echo self::displayResultsInRanking(
$objExercise->iId,
$objExercise,
api_get_user_id(),
$courseId,
$sessionId
@ -5045,15 +5045,16 @@ EOT;
/**
* Display the ranking of results in a exercise.
*
* @param int $exerciseId
* @param int $currentUserId
* @param int $courseId
* @param int $sessionId
* @param Exercise $exercise
* @param int $currentUserId
* @param int $courseId
* @param int $sessionId
*
* @return string
*/
public static function displayResultsInRanking($exerciseId, $currentUserId, $courseId, $sessionId = 0)
public static function displayResultsInRanking($exercise, $currentUserId, $courseId, $sessionId = 0)
{
$exerciseId = $exercise->iId;
$data = self::exerciseResultsInRanking($exerciseId, $courseId, $sessionId);
$table = new HTML_Table(['class' => 'table table-hover table-striped table-bordered']);

@ -8702,4 +8702,5 @@ $Tariff = "Tariff";
$ToInvoice = "To invoice";
$LearningPathItemByAuthor = "LP item by author";
$DeleteExerciseAttempts = "Delete also the exercise attempts. If not check then the exercise results will still be available in the exercise tool.";
$ExerciseCategoriesRadarMode = "Only show a radar of scores by category, instead of a table of categories. Do not show individual scores or feedback.";
?>
Loading…
Cancel
Save