From 08eb7155b4bc711414b3649b106432919a857a77 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 31 Mar 2010 17:06:32 -0500 Subject: [PATCH] Modifiying the tracking::get_avg_student_score function to count only the LP that have an exercise to get the average not ALL the LPs --- main/inc/lib/tracking.lib.php | 184 +++++++++++++++++++++++++--------- main/mySpace/course.php | 9 +- main/mySpace/index.php | 8 +- main/mySpace/myStudents.php | 32 +++--- main/mySpace/myspace.lib.php | 15 ++- main/mySpace/student.php | 5 +- main/newscorm/lp_stats.php | 18 +++- 7 files changed, 195 insertions(+), 76 deletions(-) mode change 100644 => 100755 main/mySpace/index.php diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index 5b21da113c..419f336fd5 100755 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -1,13 +1,11 @@ (Score average fixes) -============================================================================== */ class Tracking { @@ -324,6 +322,7 @@ class Tracking { AND exe_cours_id = '$course_code' AND orig_lp_item_id = 0 ORDER BY exe_date DESC"; + $res = Database::query($sql); $row = Database::fetch_array($res); $quiz_avg_score = 0; @@ -473,29 +472,32 @@ class Tracking { * @return string Value (number %) Which represents a round integer explain in got in 3. */ public static function get_avg_student_score($student_id, $course_code, $lp_ids=array(), $session_id = null) { + // get global tables names - $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_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'])) { // get course tables names - $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']); - $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW,$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']); + $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW,$course['db_name']); + + // Compose a filter based on optional learning paths list given $condition_lp = ""; if(count($lp_ids) > 0) { $condition_lp =" WHERE id IN(".implode(',',$lp_ids).") "; - } + } // Compose a filter based on optional session id $condition_session = ""; @@ -515,11 +517,12 @@ class Tracking { $lp_list = array(); while ($row_lp = Database::fetch_array($res_row_lp)) { $lp_list[] = $row_lp[0]; - } + } // Init local variables that will be used through the calculation $lp_scorm_score_total = 0; $lp_scorm_result_score_total = 0; + $lp_scorm_loop=0; $lp_count = 0; $progress = 0; @@ -532,26 +535,38 @@ class Tracking { } else { $condition_user1 =" AND user_id = '$student_id' "; } - + //var_dump($student_id); if ($count_row_lp>0 && !empty($student_id)) { + + // Getting the total count of LP + $sql = "SELECT count(id) as count FROM $lp_table WHERE session_id = ".api_get_session_id(); + $my_res = Database::query($sql); + $my_row = Database::fetch_array($my_res); + $count_views = $my_row['count']; + + $rs_last_lp_view_id = Database::query($sql); // Get all views through learning paths filter $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 GROUP BY lp_id,user_id"; - $rs_last_lp_view_id = Database::query($sql); - - $count_views = 0; - $score_of_scorm_calculate = 0; + + $rs_last_lp_view_id = Database::query($sql); + + $global_count_item = 0; + $real_count_views = 0 ; + $global_result = 0; + if (Database::num_rows($rs_last_lp_view_id) > 0) { // Cycle through each line of the results (grouped by lp_id, user_id) + while ($row_lp_view = Database::fetch_array($rs_last_lp_view_id)) { $lp_view_id = $row_lp_view['id']; - $progress = $row_lp_view['progress']; - $lp_id = $row_lp_view['lp_id']; - $user_id = $row_lp_view['user_id']; + $progress = $row_lp_view['progress']; + $lp_id = $row_lp_view['lp_id']; + $user_id = $row_lp_view['user_id']; // For the currently analysed view, get the score and // max_score of each item if it is a sco or a TOOL_QUIZ @@ -562,13 +577,19 @@ class Tracking { " AND (lp_i.item_type='sco' ". " OR lp_i.item_type='".TOOL_QUIZ."') ". " WHERE lp_view_id='$lp_view_id'"; - + //echo $sql_max_score; echo '
'; + $res_max_score = Database::query($sql_max_score); $count_total_loop = 0; $num_rows_max_score = Database::num_rows($res_max_score); // Go through each scorable element of this view $count_items = 0; + //4 -2 ------ 4 - 1 + //echo '
'; + $lp_partial_total = 0; + $score_of_scorm_calculate = 0; + while ($row_max_score = Database::fetch_array($res_max_score)) { $max_score = $row_max_score['max_score']; $score = $row_max_score['score']; @@ -613,29 +634,68 @@ class Tracking { if (!empty($row_max_score_bis['maxscore'])) { $max_score = $row_max_score_bis['maxscore']; } - $lp_scorm_result_score_total = ($score/$max_score); + $lp_scorm_result_score_total += ($score/$max_score); + $lp_partial_total += ($score/$max_score); + //echo '
'; echo $lp_scorm_result_score_total.' - '."$score/$max_score"; echo '
'; + + //echo $lp_scorm_result_score_total; + //var_dump($score,$max_score); $current_value = $score/$max_score; } else { //$lp_scorm_result_score_total += 0; } } - $count_items++; - } - - $score_of_scorm_calculate += $count_items?round((($lp_scorm_result_score_total/$count_items)*100),2):0; - $count_views++; - - } + $count_items++; + } //end while + $global_count_item +=$count_items; + //echo 'lp_view '.$lp_view_id.' - $count_items '.$count_items.' lp partiual '.$lp_partial_total.'-
'; + + $score_of_scorm_calculate += $count_items?round((($lp_partial_total/$count_items)*100),2):0; + $global_result += $score_of_scorm_calculate; + $real_count_views++; + } // end while + + /*echo '
$lp_scorm_result_score_total:'.($global_result); echo '
'; + echo ("lp score :".($score_of_scorm_calculate)); + echo '
'; */ } - - if ( $count_views > 0 ) { - $score_of_scorm_calculate = round(($score_of_scorm_calculate/$count_views),2); + + if ($real_count_views == 1) { + $count_views = 1; + } + + $lp_with_quiz = 0; + $total_lp = 0; + + foreach($lp_list as $lp_id) { + //check if LP have a score + $sql = "SELECT count(id) as count FROM $lp_item_table + WHERE item_type = 'quiz' AND lp_id = ".$lp_id." "; + $result_have_quiz = Database::query($sql); + + if (Database::num_rows($result_have_quiz) > 0 ) { + $row = Database::fetch_array($result_have_quiz,'ASSOC'); + if (is_numeric($row['count']) && $row['count'] != 0) { + $lp_with_quiz ++; + } + } + $total_lp ++; } - return $score_of_scorm_calculate; + //var_dump($lp_with_quiz); + if ($lp_with_quiz != 0 ) { + + $score_of_scorm_calculate = round(($global_result/$lp_with_quiz),2); + return $score_of_scorm_calculate; + + } else { + return '-'; + } + } } return null; } + /** * This function gets time spent in learning path for a student inside a course @@ -1544,7 +1604,7 @@ class Tracking { } /** - * allow get average of test and scorm inside a learning path + * Gets the average of test and scorm inside a learning path * @param int User id * @param string Course id * @return float average of test @@ -1553,18 +1613,20 @@ class Tracking { public static function get_average_test_scorm_and_lp ($user_id,$course_id) { //the score inside the Reporting table - $course_info=api_get_course_info($course_id); - $lp_table = Database :: get_course_table(TABLE_LP_MAIN,$course_info['dbName']); - $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW,$course_info['dbName']); + $course_info = api_get_course_info($course_id); + $lp_table = Database :: get_course_table(TABLE_LP_MAIN,$course_info['dbName']); + $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW,$course_info['dbName']); $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW,$course_info['dbName']); $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM,$course_info['dbName']); - $sql_type='SELECT id,lp_type FROM '.$lp_table; + $sql_type='SELECT id, lp_type FROM '.$lp_table; $rs_type=Database::query($sql_type); $average_data=0; $count_loop=0; + $lp_list = array(); while ($row_type=Database::fetch_array($rs_type)) { - - if ($row_type['lp_type']==1) {//lp dokeos + $lp_list[] = $row_type['id']; + if ($row_type['lp_type']==1) { + //lp dokeos $sql = "SELECT id FROM $lp_view_table WHERE user_id = '".intval($user_id)."' and lp_id='".$row_type['id']."'"; $rs_last_lp_view_id = Database::query($sql); @@ -1612,8 +1674,26 @@ class Tracking { $average_data1=0; $count_loop++; } - if ((int)$count_loop > 0) { - $avg_student_score = round(($average_data_sum / $count_loop * 100), 2); + + //We only count the LP that have an exercise to get the average + $lp_with_quiz = 0; + foreach($lp_list as $lp_id) { + + //check if LP have a score + $sql = "SELECT count(id) as count FROM $lp_item_table + WHERE item_type = 'quiz' AND lp_id = ".$lp_id." "; + $result_have_quiz = Database::query($sql); + + if (Database::num_rows($result_have_quiz) > 0 ) { + $row = Database::fetch_array($result_have_quiz,'ASSOC'); + if (is_numeric($row['count']) && $row['count'] != 0) { + $lp_with_quiz++; + } + } + } + + if ($lp_with_quiz > 0) { + $avg_student_score = round(($average_data_sum / $lp_with_quiz * 100), 2); } return $avg_student_score; } @@ -2081,12 +2161,18 @@ class TrackingCourseLog { $row[2] = $user[3]; } $row[3] = api_time_to_hms(Tracking::get_time_spent_on_the_course($user[0], $course_code, $session_id)); + $avg_student_score = Tracking::get_avg_student_score($user[0], $course_code, array(), $session_id); - $avg_student_progress = Tracking::get_avg_student_progress($user[0], $course_code, array(), $session_id); - if (empty($avg_student_score)) {$avg_student_score=0;} + //echo 'student '.$user[0].' $avg_student_score: '.$avg_student_score; echo '
'; + $avg_student_progress = Tracking::get_avg_student_progress($user[0], $course_code, array(), $session_id); if (empty($avg_student_progress)) {$avg_student_progress=0;} $row[4] = $avg_student_progress.'%'; - $row[5] = $avg_student_score.'%'; + //if (empty($avg_student_score)) {$avg_student_score=0;} + if(is_numeric($avg_student_score)) { + $row[5] = $avg_student_score.'%'; + } else { + $row[5] = $avg_student_score; + } $row[6] = Tracking::count_student_assignments($user[0], $course_code, $session_id); $row[7] = Tracking::count_student_messages($user[0], $course_code, $session_id); $row[8] = Tracking::get_first_connection_date_on_the_course($user[0], $course_code, $session_id); diff --git a/main/mySpace/course.php b/main/mySpace/course.php index 5c1f790e0d..f47c7c4e47 100755 --- a/main/mySpace/course.php +++ b/main/mySpace/course.php @@ -201,7 +201,10 @@ if (is_array($a_courses)) { $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course); $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2); - $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2); + + if (is_numeric($avg_score_in_course)) { + $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2).'%'; + } } else { $avg_time_spent_in_course = null; @@ -228,7 +231,7 @@ if (is_array($a_courses)) { $table_row[] = is_null($avg_time_spent_in_course)?'-':$avg_time_spent_in_course; $table_row[] = $tematic_advance_progress; $table_row[] = is_null($avg_progress_in_course) ? '-' : $avg_progress_in_course.'%'; - $table_row[] = is_null($avg_score_in_course) ? '-' : $avg_score_in_course.'%'; + $table_row[] = is_null($avg_score_in_course) ? '-' : $avg_score_in_course; $table_row[] = is_null($messages_in_course)?'-':$messages_in_course; $table_row[] = is_null($assignments_in_course)?'-':$assignments_in_course; $table_row[] = ''; @@ -239,7 +242,7 @@ if (is_array($a_courses)) { $avg_time_spent_in_course, $tematic_advance_csv, is_null($avg_progress_in_course) ? null : $avg_progress_in_course.'%', - is_null($avg_score_in_course) ? null : $avg_score_in_course.'%', + is_null($avg_score_in_course) ? null : $avg_score_in_course, $messages_in_course, $assignments_in_course, ); diff --git a/main/mySpace/index.php b/main/mySpace/index.php old mode 100644 new mode 100755 index f85b7588ba..1bc1a35a12 --- a/main/mySpace/index.php +++ b/main/mySpace/index.php @@ -258,8 +258,12 @@ if ($view == 'coach' || $view == 'drh') { $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); - $avg_student_score += Tracking :: get_avg_student_score($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; + if ($nb_posts !== null && $nb_assignments !== null && $avg_student_progress !== null && $avg_student_score !== null) { //if one of these scores is null, it means that we had a problem connecting to the right database, so don't count it in $nb_courses_student++; diff --git a/main/mySpace/myStudents.php b/main/mySpace/myStudents.php index cbf2c4142f..47595662a6 100755 --- a/main/mySpace/myStudents.php +++ b/main/mySpace/myStudents.php @@ -246,8 +246,7 @@ if (!empty ($_GET['student'])) { $avg_student_score = Tracking::get_avg_student_score($info_user['user_id'], $course_id, array(), $session_id); } $avg_student_progress = round($avg_student_progress, 2); - $avg_student_score = round($avg_student_score, 2); - + // time spent on the course $time_spent_on_the_course = api_time_to_hms(Tracking :: get_time_spent_on_the_course($info_user['user_id'], $course_id, $session_id)); @@ -295,7 +294,7 @@ if (!empty ($_GET['student'])) { strip_tags($last_connection_date), $time_spent_on_the_course, $avg_student_progress . '%', - $avg_student_score . '%' + $avg_student_score ); ?> @@ -437,7 +436,7 @@ if ($timezone !== null) { Display :: display_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array ('align' => 'absmiddle', 'hspace' => '3px')); ?> - + @@ -580,8 +579,11 @@ if ($timezone !== null) { // Get progress in lp $progress = Tracking::get_avg_student_progress($student_id, $course_code, array($lp_id)); - if ($progress === null) $progress = '0%'; - else $any_result = true; + if ($progress === null) { + $progress = '0%'; + } else { + $any_result = true; + } // Get time in lp $total_time = Tracking::get_time_spent_in_lp($student_id, $course_code, array($lp_id)); @@ -604,7 +606,7 @@ if ($timezone !== null) { api_html_entity_decode(stripslashes($lp_name), ENT_QUOTES, $charset), api_time_to_hms($total_time), $score . '%', - $progress, + $progress.'%', date('Y-m-d h:i:s', $start_time) ); ?> @@ -619,20 +621,18 @@ if ($timezone !== null) { - +
'.round(Tracking :: get_avg_student_progress($user_id, $row[0]), 2).'
'; // student score - $return .= '
'.round(Tracking :: get_avg_student_score($user_id, $row[0]), 2).'
'; + $avg_score = Tracking :: get_avg_student_score($user_id, $row[0]); + if (is_numeric($avg_score)) { + $avg_score = round($avg_score,2); + } else { + $$avg_score = '-'; + } + + $return .= '
'.$avg_score.'
'; // student tes score //$return .= '
'.round(Tracking :: get_avg_student_exercise_score ($user_id, $row[0]),2).'%
'; // student messages @@ -555,7 +562,9 @@ class MySpace { $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); - $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2); + if (is_numeric($avg_score_in_course)) { + $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2); + } $avg_score_in_exercise = round($avg_score_in_exercise / $nb_students_in_course, 2); $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course); @@ -584,7 +593,7 @@ class MySpace { $nb_students_in_course, $avg_time_spent_in_course, is_null($avg_progress_in_course) ? null : $avg_progress_in_course.'%', - is_null($avg_score_in_course) ? null : $avg_score_in_course.'%', + is_null($avg_score_in_course) ? null : is_numeric($avg_score_in_course) ? $avg_score_in_course.'%' : $avg_score_in_course , is_null($avg_score_in_exercise) ? null : $avg_score_in_exercise.'%', $avg_messages_in_course, $avg_assignments_in_course, diff --git a/main/mySpace/student.php b/main/mySpace/student.php index 56b5b5a20b..f6ddd32855 100755 --- a/main/mySpace/student.php +++ b/main/mySpace/student.php @@ -241,7 +241,10 @@ if ($isCoach || api_is_platform_admin() || api_is_drh()) { foreach ($courses as $course_code) { if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) { $avg_time_spent += Tracking :: get_time_spent_on_the_course($student_id, $course_code, $_GET['id_session']); - $avg_student_score += Tracking :: get_avg_student_score($student_id, $course_code); + $my_average = Tracking :: get_avg_student_score($student_id, $course_code); + if(is_numeric($my_average)) { + $avg_student_score += $my_average; + } $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code); $total_assignments += Tracking :: count_student_assignments($student_id, $course_code); $total_messages += Tracking :: count_student_messages($student_id, $course_code); diff --git a/main/newscorm/lp_stats.php b/main/newscorm/lp_stats.php index 490105c462..8b535a1a40 100755 --- a/main/newscorm/lp_stats.php +++ b/main/newscorm/lp_stats.php @@ -715,7 +715,18 @@ if (!empty($a_my_id)) { } $total_score = Tracking::get_avg_student_score($my_studen_id, $my_course_id, $a_my_id); } else { - $total_score = 0; + + if ($origin == 'tracking') { + $my_studen_id = $student_id; + $my_course_id = Database::escape_string($_GET['course']); + if (!empty($my_studen_id) && !empty($my_course_id)) { + $total_score = Tracking::get_avg_student_score($my_studen_id, $my_course_id, array(intval($_GET['lp_id']))); + } else { + $total_score = 0; + } + } else { + $total_score = 0; + } } $total_time = learnpathItem :: get_scorm_time('js', $total_time); @@ -727,7 +738,10 @@ $total_percent = 0; if(!$is_allowed_to_edit && $result_disabled_ext_all) { $final_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting')); } else { - $final_score = $total_score.'%'; + if (is_numeric($total_score)) + $final_score = $total_score.'%'; + else + $final_score = $total_score; } if (($counter % 2) == 0) {