From b6a2bc9f44c6cf6a6937add4c4f395ae29e1eba2 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 19 Jul 2011 19:25:28 +0200 Subject: [PATCH] When showing score stats in the reporting now we take also the scorm + a fix when showing exercise score stats see BT#2752 --- main/inc/lib/tracking.lib.php | 115 ++++++++++++++++++++-------------- main/mySpace/index.php | 8 +-- main/mySpace/myspace.lib.php | 4 +- main/tracking/courseLog.php | 5 +- 4 files changed, 75 insertions(+), 57 deletions(-) diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index 63aa9f7ef0..0e562ff6c5 100755 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -314,12 +314,13 @@ class Tracking { } /** - * This function gets the score average from all tests in a course by student - * @param int|array Student(s) id - * @param string Course code - * @param int Exercise id (optional), filtered by exercise - * @param int Session id (optional), if param $session_id is null it'll return results including sessions, 0 = session is not filtered - * @return string value (number %) Which represents a round integer about the score average. + * Gets the score average from all tests in a course by student + * + * @param mixed Student(s) id + * @param string Course code + * @param int Exercise id (optional), filtered by exercise + * @param int Session id (optional), if param $session_id is null it'll return results including sessions, 0 = session is not filtered + * @return string value (number %) Which represents a round integer about the score average. */ public static function get_avg_student_exercise_score($student_id, $course_code, $exercise_id = 0, $session_id = null) { @@ -379,17 +380,21 @@ class Tracking { AND orig_lp_id = 0 AND exe_cours_id = '$course_code' AND orig_lp_item_id = 0 $condition_session - ORDER BY exe_date DESC"; - $res = Database::query($sql); - $row = Database::fetch_array($res); - $quiz_avg_score = 0; - if (!empty($row['avg_score'])) { - $quiz_avg_score = round($row['avg_score'],2); - } - if(!empty($row['num_attempts'])) { - $quiz_avg_score = round($quiz_avg_score / $row['num_attempts'], 2); - } - return $quiz_avg_score; + ORDER BY exe_date DESC"; + + $res = Database::query($sql); + $row = Database::fetch_array($res); + $quiz_avg_score = 0; + if (!empty($row['avg_score'])) { + $quiz_avg_score = round($row['avg_score'],2); + } + if(!empty($row['num_attempts'])) { + $quiz_avg_score = round($quiz_avg_score / $row['num_attempts'], 2); + } + if (is_array($student_id)) { + $quiz_avg_score = round($quiz_avg_score / count($student_id), 2); + } + return $quiz_avg_score; } } return null; @@ -532,7 +537,9 @@ class Tracking { */ public static function get_avg_student_score($student_id, $course_code, $lp_ids = array(), $session_id = null, $return_array = false, $get_only_latest_attempt_results = false) { $debug = false; - if ($debug) echo '

get_avg_student_score

'; + if (empty($lp_ids)) { $debug = false; } + + if ($debug) echo '

Tracking::get_avg_student_score

'; // get global tables names $course_table = Database :: get_main_table(TABLE_MAIN_COURSE); $course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); @@ -541,7 +548,7 @@ class Tracking { $tbl_stats_attempts = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $course = CourseManager :: get_course_information($course_code); - + if (!empty($course['db_name'])) { // get course tables names @@ -586,7 +593,7 @@ class Tracking { $use_max_score[$row_lp['id']] = $row_lp['use_max_score']; } - if ($debug) var_dump($use_max_score); + if ($debug) { echo 'Use max score or not list '; var_dump($use_max_score);} // Init local variables that will be used through the calculation $progress = 0; @@ -595,8 +602,8 @@ class Tracking { $condition_user1 = ""; if (is_array($student_id)) { - array_walk($student_id,'intval'); - $condition_user1 =" AND user_id IN (".implode(',',$student_id).") "; + array_walk($student_id, 'intval'); + $condition_user1 =" AND user_id IN (".implode(',', $student_id).") "; } else { $condition_user1 =" AND user_id = $student_id "; } @@ -607,7 +614,7 @@ class Tracking { //@todo problem when a course have more than 1500 users $sql = "SELECT MAX(view_count) as vc, id, progress, lp_id, user_id FROM $lp_view_table WHERE lp_id IN (".implode(',',$lp_list).") $condition_user1 AND session_id = $session_id GROUP BY lp_id, user_id"; - if ($debug) var_dump($sql); + if ($debug) echo $sql; $rs_last_lp_view_id = Database::query($sql); $global_result = 0; @@ -624,7 +631,7 @@ class Tracking { $progress = $row_lp_view['progress']; $lp_id = $row_lp_view['lp_id']; $user_id = $row_lp_view['user_id']; - if ($debug) echo '

'.$lp_id.'

'; + if ($debug) echo '

LP id '.$lp_id.'

'; if ($get_only_latest_attempt_results) { //if (1) { @@ -670,7 +677,7 @@ class Tracking { $max_score_item_view = $row_max_score['max_score_item_view']; //Came from the lp_item_view $score = $row_max_score['score']; - if ($debug) var_dump($row_max_score['item_type']); + if ($debug) echo '

Item Type: ' .$row_max_score['item_type'].'

'; if ($row_max_score['item_type'] == 'sco') { //var_dump($row_max_score); @@ -687,9 +694,9 @@ class Tracking { } //Avoid division by zero errors if (!empty($max_score)) { - //$lp_partial_total += $score/$max_score; - } - if ($debug) echo ''.$lp_partial_total.' '.$score.' '.$max_score.'
'; + $lp_partial_total += $score/$max_score; + } + if ($debug) echo '$lp_partial_total, $score, $max_score '.$lp_partial_total.' '.$score.' '.$max_score.'
'; } else { // Case of a TOOL_QUIZ element $item_id = $row_max_score['iid']; @@ -733,12 +740,11 @@ class Tracking { if (!empty($max_score)) { $lp_partial_total += $score/$max_score; } - if ($debug) echo ''.$lp_partial_total.' '.$score.' '.$max_score.'
'; + if ($debug) echo '$lp_partial_total, $score, $max_score '.$lp_partial_total.' '.$score.' '.$max_score.'
'; } } - if ($row_max_score['item_type'] == 'quiz') { - + if (in_array($row_max_score['item_type'], array('quiz','sco'))) { // Normal way if ($use_max_score[$lp_id]) { $count_items++; @@ -749,26 +755,24 @@ class Tracking { } if ($debug) echo '$count_items: '.$count_items; } - - } //end for + $score_of_scorm_calculate += $count_items?(($lp_partial_total/$count_items)*100):0; - + + if ($debug) echo '

$count_items '.$count_items.'

'; if ($debug) echo '

$score_of_scorm_calculate '.$score_of_scorm_calculate.'

'; // var_dump($score_of_scorm_calculate); $global_result += $score_of_scorm_calculate; - if ($debug) echo '

$$global_result '.$global_result.'

'; + if ($debug) echo '

$global_result '.$global_result.'

'; } // end while } $lp_with_quiz = 0; - $total_lp = 0; if ($debug) var_dump($lp_list); foreach($lp_list as $lp_id) { - //check if LP have a score - // OR item_type = 'sco' - $sql = "SELECT count(id) as count FROM $lp_item_table WHERE item_type = 'quiz' AND lp_id = ".$lp_id; + //Check if LP have a score we asume that all SCO have an score + $sql = "SELECT count(id) as count FROM $lp_item_table WHERE (item_type = 'quiz' OR item_type = 'sco') AND lp_id = ".$lp_id; if ($debug) echo $sql; $result_have_quiz = Database::query($sql); @@ -777,16 +781,20 @@ class Tracking { if (is_numeric($row['count']) && $row['count'] != 0) { $lp_with_quiz ++; } - } - $total_lp ++; + } } - if ($debug) var_dump($lp_with_quiz); + + if ($debug) echo '

$lp_with_quiz '.$lp_with_quiz.'

'; + if ($debug) echo '

Final return

'; if ($lp_with_quiz != 0 ) { if (!$return_array) { - //var_dump($global_result,$lp_with_quiz ); $score_of_scorm_calculate = round(($global_result/$lp_with_quiz),2); - //var_dump($global_result, $lp_with_quiz); + if ($debug) var_dump($score_of_scorm_calculate); + if (empty($lp_ids)) { + //$score_of_scorm_calculate = round($score_of_scorm_calculate/count($lp_list),2); + if ($debug) echo '

All lps fix: '.$score_of_scorm_calculate.'

'; + } return $score_of_scorm_calculate; } else { if ($debug) var_dump($global_result, $lp_with_quiz); @@ -2234,9 +2242,10 @@ class Tracking { $session_name = api_get_session_name($session_id); $html .= Display::tag('h2', $course_info['title']); $html .=''; - $html .= Display::tag('th', get_lang('Learnpaths'), array('class'=>'head', 'style'=>'color:#000')); + $html .= Display::tag('th', get_lang('Learnpaths'), array('class'=>'head', 'style'=>'color:#000')); $html .= Display::tag('th', get_lang('Time'), array('class'=>'head', 'style'=>'color:#000')); $html .= Display::tag('th', get_lang('Progress'), array('class'=>'head', 'style'=>'color:#000')); + $html .= Display::tag('th', get_lang('Score'), array('class'=>'head', 'style'=>'color:#000')); $html .= Display::tag('th', get_lang('LastConnexion'), array('class'=>'head', 'style'=>'color:#000')); $html .= ''; @@ -2252,6 +2261,13 @@ class Tracking { $progress = Tracking::get_avg_student_progress($user_id, $course, array($learnpath['id']), $session_id); $last_connection_in_lp = Tracking::get_last_connection_time_in_lp($user_id, $course, $learnpath['id'], $session_id); $time_spent_in_lp = Tracking::get_time_spent_in_lp($user_id, $course, array($learnpath['id']), $session_id); + $percentage_score = Tracking::get_avg_student_score($user_id, $course, array($learnpath['id']), $session_id); + if (is_numeric($percentage_score)) { + $percentage_score = $percentage_score.'%'; + } else { + $percentage_score = '0%'; + } + $time_spent_in_lp = api_time_to_hms($time_spent_in_lp); $html .= ''; @@ -2259,8 +2275,10 @@ class Tracking { $html .= Display::tag('td', $time_spent_in_lp, array('align'=>'center')); if (is_numeric($progress)) { $progress = $progress.'%'; - } + } $html .= Display::tag('td', $progress, array('align'=>'center')); + $html .= Display::tag('td', $percentage_score); + $last_connection = '-'; if (!empty($last_connection_in_lp)) { $last_connection = api_convert_and_format_date($last_connection_in_lp, DATE_TIME_FORMAT_LONG); @@ -2398,7 +2416,7 @@ class Tracking { require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php'; require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php'; require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php'; - //var_dump($names, $my_results, $average); + $cache = new pCache(); // Dataset definition @@ -3247,7 +3265,8 @@ class TrackingCourseLog { } $user['time'] = api_time_to_hms(Tracking::get_time_spent_on_the_course($user['user_id'], $course_code, $session_id)); - $avg_student_score = Tracking::get_avg_student_score($user['user_id'], $course_code, array(), $session_id); + $avg_student_score = Tracking::get_avg_student_score($user['user_id'], $course_code, array(), $session_id); + $avg_student_progress = Tracking::get_avg_student_progress($user['user_id'], $course_code, array(), $session_id); if (empty($avg_student_progress)) { $avg_student_progress=0; } $user['average_progress'] = $avg_student_progress.'%'; diff --git a/main/mySpace/index.php b/main/mySpace/index.php index 327c374f3c..7b98f4d6ef 100755 --- a/main/mySpace/index.php +++ b/main/mySpace/index.php @@ -291,10 +291,10 @@ if ($view == 'coach' || $view == 'drh') { foreach ($courses as $course_code) { if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) { $nb_courses_student++; - $nb_posts += Tracking :: count_student_messages($student_id, $course_code); - $nb_assignments += Tracking :: count_student_assignments($student_id, $course_code); - $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code); - $myavg_temp = Tracking :: get_avg_student_score($student_id, $course_code); + $nb_posts += Tracking :: count_student_messages($student_id, $course_code); + $nb_assignments += Tracking :: count_student_assignments($student_id, $course_code); + $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code); + $myavg_temp = Tracking :: get_avg_student_score($student_id, $course_code); if (is_numeric($myavg_temp)) $avg_student_score += $myavg_temp; diff --git a/main/mySpace/myspace.lib.php b/main/mySpace/myspace.lib.php index dd18f90a79..159b5251e8 100755 --- a/main/mySpace/myspace.lib.php +++ b/main/mySpace/myspace.lib.php @@ -8,8 +8,6 @@ require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'; class MySpace { - /* For licensing terms, see /dokeos_license.txt */ - /** * This function serves exporting data in CSV format. * @param array $header The header labels. @@ -1277,7 +1275,7 @@ class MySpace { $avg_progress_in_course = Tracking::get_avg_student_progress($users, $course_code, array(), $session_id); $avg_score_in_course = Tracking::get_avg_student_score($users, $course_code, array(), $session_id); $avg_score_in_exercise = Tracking::get_avg_student_exercise_score($users, $course_code, 0, $session_id); - + $avg_time_spent_in_course = Tracking::get_time_spent_on_the_course($users, $course_code, $session_id); $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2); diff --git a/main/tracking/courseLog.php b/main/tracking/courseLog.php index e78714869a..075f044f02 100755 --- a/main/tracking/courseLog.php +++ b/main/tracking/courseLog.php @@ -218,13 +218,14 @@ if ($_GET['studentlist'] == 'false') { $csv_content[] = array('', ''); $csv_content[] = $temp; } - + if (count($flat_list) > 0) { foreach ($flat_list as $lp_id => $lp) { $lp_avg_progress = 0; foreach ($a_students as $student_id => $student) { // get the progress in learning pathes $lp_avg_progress += Tracking::get_avg_student_progress($student_id, $course_code, array($lp_id), $session_id); + } if ($nbStudents > 0) { $lp_avg_progress = $lp_avg_progress / $nbStudents; @@ -275,7 +276,7 @@ if ($_GET['studentlist'] == 'false') { $quiz_avg_score = 0; if ($count_students > 0) { foreach ($student_ids as $student_id) { - $avg_student_score = Tracking::get_avg_student_exercise_score($student_id, $course_code, $quiz['id'], $session_id); + $avg_student_score = Tracking::get_avg_student_exercise_score($student_id, $course_code, $quiz['id'], $session_id); $quiz_avg_score += $avg_student_score; } }