[svn r16032] get_avg_student_score function fixed to get the real average score in My Reporting. 2 Info Icons added.

skala
Julio Montoya 16 years ago
parent 5cc989e666
commit fd8bdf4c00
  1. 69
      main/inc/lib/tracking.lib.php
  2. 70
      main/mySpace/myStudents.php

@ -30,6 +30,7 @@
* Include/require it in your code to use its functionality.
*
* @package dokeos.library
* @author Julio Montoya <gugli100@gmail.com> (Score average fixes)
==============================================================================
*/
@ -272,15 +273,31 @@ class Tracking {
return null;
}
}
/**
* This function gets:
* 1. The score average from all SCORM Test items in all LP in a course-> All the answers / All the max score.
* 2. The score average from all Tests (quiz) in all LP in a course-> All the answers / All the max score.
* 3. And finally it will return the average between 1. and 2.
* This function does not take the results of a Test out of a LP
*
* @param User id
* @param Course id
* @return string value (number %) Which represents a round integer explain in got in 3.
*/
function get_avg_student_score($student_id, $course_code) {
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$table_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$tbl_stats_attempts= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$course = CourseManager :: get_course_information($course_code);
if(!empty($course['db_name']))
{
$tbl_quiz_questions= Database :: get_course_table(TABLE_QUIZ_QUESTION,$course['db_name']);
$lp_table = Database :: get_course_table(TABLE_LP_MAIN,$course['db_name']);
$lp_item_table = Database :: get_course_table(TABLE_LP_ITEM,$course['db_name']);
$lp_view_table = Database :: get_course_table(TABLE_LP_VIEW,$course['db_name']);
@ -293,7 +310,7 @@ class Tracking {
$lp_scorm_weighting_total = 0;
if(Database::num_rows($sql_result_lp)>0){
//Scorm
//Scorm test
while($a_learnpath = Database::fetch_array($sql_result_lp)){
$sql = 'SELECT id, max_score
FROM '.$lp_item_table.' AS lp_item
@ -324,11 +341,22 @@ class Tracking {
}
}
}
//mysql_data_seek() moves the internal row pointer of the MySQL result associated with the specified result identifier to point to the specified row number.
//The next call to a MySQL fetch function, such as mysql_fetch_assoc(), would return that row.
mysql_data_seek($sql_result_lp,0);
//Quizz in LP
//Quizz in a LP
while($a_learnpath = Database::fetch_array($sql_result_lp)){
//we got the maxscore this is wrong
/*
echo $sql = 'SELECT id as item_id, max_score
FROM '.$lp_item_table.' AS lp_item
WHERE lp_id='.$a_learnpath['id'].'
AND item_type="quiz"';
*/
$sql = 'SELECT id as item_id, max_score
//Path is the exercise id
$sql = 'SELECT path, id as item_id, max_score
FROM '.$lp_item_table.' AS lp_item
WHERE lp_id='.$a_learnpath['id'].'
AND item_type="quiz"';
@ -345,6 +373,7 @@ class Tracking {
{
while($item = Database :: fetch_array($rsItems, 'ASSOC'))
{
// we take the score from a LP because we have lp_view_id
$sql = 'SELECT score as student_score
FROM '.$lp_item_view_table.' as lp_view_item
WHERE lp_view_item.lp_item_id = '.$item['item_id'].'
@ -352,10 +381,39 @@ class Tracking {
';
$rsScores = api_sql_query($sql, __FILE__, __LINE__);
// Real max score - this was implemented because of the random exercises
$sql_last_attempt = 'SELECT exe_id FROM '. $tbl_stats_exercices. ' ' .
'WHERE exe_exo_id="' .$item['path']. '" AND exe_user_id="' . $student_id . '" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1';
$resultLastAttempt = api_sql_query($sql_last_attempt, __FILE__, __LINE__);
$num = Database :: num_rows($resultLastAttempt);
if ($num > 0){
if ($num > 1){
while ($rowLA = Database :: fetch_row($resultLastAttempt)) {
$id_last_attempt = $rowLA[0];
}
} else {
$id_last_attempt = Database :: result($resultLastAttempt, 0, 0);
}
}
$sql = "SELECT SUM(t.ponderation) as maxscore from ( SELECT distinct question_id, marks,ponderation FROM $tbl_stats_attempts as at " .
"INNER JOIN $tbl_quiz_questions as q on(q.id = at.question_id) where exe_id ='$id_last_attempt' ) as t";
$result = api_sql_query($sql, __FILE__, __LINE__);
$row_max_score = Database :: fetch_array($result);
$maxscore = $row_max_score['maxscore'];
if ($maxscore=='')
{
$maxscore = $item['max_score'];
}
if(Database::num_rows($rsScores)>0)
{
$total_score += Database::result($rsScores, 0, 0);
$total_weighting += $item['max_score'];
//echo $total_weighting += $item['max_score'];
$total_weighting += $maxscore;
if($total_weighting>0)
{
@ -376,7 +434,6 @@ class Tracking {
{
$pourcentageScore = round(($totalScore * 100) / $lp_scorm_weighting_total);
}
return $pourcentageScore;
}
else

@ -1,4 +1,4 @@
<?php //$Id: myStudents.php 15663 2008-06-30 22:06:41Z juliomontoya $
<?php //$Id: myStudents.php 16032 2008-08-20 17:22:01Z juliomontoya $
/*
==============================================================================
Dokeos - elearning and course management software
@ -23,14 +23,14 @@
// name of the language file that needs to be included
$language_file = array ('registration', 'index', 'tracking', 'exercice','admin');
$cidReset=true;
include ('../inc/global.inc.php');
$cidReset=true;
include ('../inc/global.inc.php');
include_once(api_get_path(LIBRARY_PATH).'tracking.lib.php');
include_once(api_get_path(LIBRARY_PATH).'export.lib.inc.php');
include_once(api_get_path(LIBRARY_PATH).'usermanager.lib.php');
include_once(api_get_path(LIBRARY_PATH).'course.lib.php');
include_once('../newscorm/learnpath.class.php');
include_once(api_get_path(LIBRARY_PATH).'tracking.lib.php');
include_once(api_get_path(LIBRARY_PATH).'export.lib.inc.php');
include_once(api_get_path(LIBRARY_PATH).'usermanager.lib.php');
include_once(api_get_path(LIBRARY_PATH).'course.lib.php');
include_once('../newscorm/learnpath.class.php');
$export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
@ -252,6 +252,7 @@ if(!empty($_GET['student']))
{
$nb_courses++;
$avg_student_progress += Tracking :: get_avg_student_progress($a_infosUser['user_id'],$course_code);
//the score inside the Reporting table
$avg_student_score += Tracking :: get_avg_student_score($a_infosUser['user_id'],$course_code);
}
}
@ -413,7 +414,10 @@ if(!empty($_GET['student']))
</tr>
<tr>
<td class="none" align="right">
<?php echo get_lang('Score') ?>
<?php
echo get_lang('Score');
Display :: display_icon('info2.gif',get_lang('ScormAndLPTestTotalAverage') , array ('style' => 'margin-bottom:-5px;'));
?>
</td>
<td class="none" align="left">
<?php echo $avg_student_score.' %' ?>
@ -564,7 +568,10 @@ if(!empty($_GET['student']))
<?php echo get_lang('Time'); ?>
</th>
<th>
<?php echo get_lang('Score'); ?>
<?php
echo get_lang('Score');
Display :: display_icon('info3.gif',get_lang('LPTestScore') , array ('style' => 'margin-bottom:-5px;'));
?>
</th>
<th>
<?php echo get_lang('Progress'); ?>
@ -583,6 +590,11 @@ if(!empty($_GET['student']))
$t_lpi = Database::get_course_table(TABLE_LP_ITEM,$a_infosCours['db_name']);
$t_lpv = Database::get_course_table(TABLE_LP_VIEW,$a_infosCours['db_name']);
$t_lpiv = Database::get_course_table(TABLE_LP_ITEM_VIEW,$a_infosCours['db_name']);
$tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$tbl_stats_attempts= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$tbl_quiz_questions= Database :: get_course_table(TABLE_QUIZ_QUESTION,$a_infosCours['db_name']);
$sqlLearnpath = "SELECT lp.name,lp.id
FROM $t_lp AS lp ORDER BY lp.name ASC
";
@ -639,13 +651,13 @@ if(!empty($_GET['student']))
}
//QUIZZ IN LP
$sql = 'SELECT id as item_id, max_score
//Path is the exercise id we need this to search the last attempt
$sql = 'SELECT id as item_id, path,max_score
FROM '.$t_lpi.' AS lp_item
WHERE lp_id='.$a_learnpath['id'].'
AND item_type="quiz"';
$rsItems = api_sql_query($sql, __FILE__, __LINE__);
//We get the last view id of this LP
$sql='SELECT max(id) as id FROM '.$t_lpv.' WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($_GET['student']).'"';
$rs_last_lp_view_id = api_sql_query($sql, __FILE__, __LINE__);
@ -668,15 +680,43 @@ if(!empty($_GET['student']))
$rsScores = api_sql_query($sql, __FILE__, __LINE__);
// Real max score we search into the stats
$sql_last_attempt = 'SELECT exe_id FROM '. $tbl_stats_exercices. ' ' .
'WHERE exe_exo_id="' .$item['path']. '" AND exe_user_id="' . $student_id . '" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1';
$resultLastAttempt = api_sql_query($sql_last_attempt, __FILE__, __LINE__);
$num = Database :: num_rows($resultLastAttempt);
if ($num > 0){
if ($num > 1){
while ($rowLA = Database :: fetch_row($resultLastAttempt)) {
$id_last_attempt = $rowLA[0];
}
} else {
$id_last_attempt = Database :: result($resultLastAttempt, 0, 0);
}
}
$sql = "SELECT SUM(t.ponderation) as maxscore from ( SELECT distinct question_id, marks,ponderation FROM $tbl_stats_attempts as at " .
"INNER JOIN $tbl_quiz_questions as q on(q.id = at.question_id) where exe_id ='$id_last_attempt' ) as t";
$result = api_sql_query($sql, __FILE__, __LINE__);
$row_max_score = Database :: fetch_array($result);
$maxscore = $row_max_score['maxscore'];
if ($maxscore=='')
{
$maxscore = $item['max_score'];
}
if (Database::num_rows($rsScores) > 0)
{
$total_score += Database::result($rsScores, 0, 0);
}
$total_weighting += $item['max_score'];
//$total_weighting += $item['max_score'];
$total_weighting += $maxscore;
}
$any_result = true;
}
$sql = 'SELECT id, max_score
FROM '.$t_lpi.' AS lp_item
WHERE lp_id='.$a_learnpath['id'].'
@ -686,7 +726,9 @@ if(!empty($_GET['student']))
if(Database::num_rows($rs_lp_item_id_scorm)>0){
$lp_item_id = Database::result($rs_lp_item_id_scorm,0,'id');
$lp_item__max_score = Database::result($rs_lp_item_id_scorm,0,'max_score');
$total_weighting+=$lp_item__max_score;
//We get the last view id of this LP
@ -694,7 +736,9 @@ if(!empty($_GET['student']))
$rs_last_lp_view_id = api_sql_query($sql, __FILE__, __LINE__);
$lp_view_id = Database::result($rs_last_lp_view_id,0,'id');
// this will get the FINAL SCORE
$sql='SELECT SUM(score)/count(lp_item_id) as score FROM '.$t_lpiv.' WHERE lp_view_id="'.$lp_view_id.'" GROUP BY lp_view_id';
$rs_score = api_sql_query($sql, __FILE__, __LINE__);
if(Database::num_rows($rs_score)>0)
{

Loading…
Cancel
Save