diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php index b01c195172..5bfba6bb06 100755 --- a/main/exercice/exercise.lib.php +++ b/main/exercice/exercise.lib.php @@ -3,6 +3,8 @@ /** * Exercise library + * @todo convert this lib into a static class + * * shows a question and its answers * @package dokeos.exercise * @author Olivier Brouckaert @@ -1139,10 +1141,9 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) { * @param bool use or not the platform settings * @return string an html with the score modified */ -function show_score($score, $weight, $show_porcentage = true, $use_platform_settings = true) { +function show_score($score, $weight, $show_percentage = true, $use_platform_settings = true) { $html = ''; - $score_rounded = $score; - + $score_rounded = $score; $max_note = api_get_setting('exercise_max_score'); $min_note = api_get_setting('exercise_min_score'); @@ -1152,41 +1153,53 @@ function show_score($score, $weight, $show_porcentage = true, $use_platform_sett $score = $min_note + ($max_note - $min_note) * $score /$weight; } else { $score = $min_note; - } - $score_rounded = float_format($score, 1); + } $weight = $max_note; } - } - if ($show_porcentage) { + } + $score_rounded = float_format($score, 1); + $weight = float_format($weight, 1); + if ($show_percentage) { $html = float_format(($score / ($weight != 0 ? $weight : 1)) * 100, 1) . '% (' . $score_rounded . ' / ' . $weight . ')'; - } else { - $weight = float_format($weight, 1); + } else { $html = $score_rounded . ' / ' . $weight; - } + } return $html; } /** - * Converts a score to the platform scale + * Converts a numeric value in a percentage example 0.66666 to 66.67 % + * @param $value + * @return unknown_type + */ +function convert_to_percentage($value) { + $return = '-'; + if ($value != '') { + $return = float_format($value * 100, 1).' %'; + } + return $return; +} + +/** + * Converts a score/weight values to the platform scale * @param float score * @param float weight * @return float the score rounded converted to the new range */ -function convert_score($score, $weight) { - if ($score != '' && $weight != '') { - $max_note = api_get_setting('exercise_max_score'); - $min_note = api_get_setting('exercise_min_score'); - if ($max_note != '' && $min_note != '') { - +function convert_score($score, $weight) { + $max_note = api_get_setting('exercise_max_score'); + $min_note = api_get_setting('exercise_min_score'); + + if ($score != '' && $weight != '') { + if ($max_note != '' && $min_note != '') { if (!empty($weight)) { - $score = $min_note + ($max_note - $min_note) * $score /$weight; + $score = $min_note + ($max_note - $min_note) * $score / $weight; } else { $score = $min_note; - } - + } } - } - $score_rounded = round($score, 2); + } + $score_rounded = float_format($score, 1); return $score_rounded; } @@ -1217,7 +1230,8 @@ function get_all_exercises($course_info = null, $session_id = 0) { } /** - * Gets the position of the score based in a given score (result/weight) and the exe_id + * Gets the position of the score based in a given score (result/weight) and the exe_id + * (NO Exercises in LPs ) * @param float user score to be compared attention => score/weight * @param int exe id of the exercise (this is necesary because if 2 students have the same score the one with the minor exe_id will have a best position, just to be fair and FIFO) * @param int exercise id @@ -1270,6 +1284,9 @@ function get_exercise_result_ranking($my_score, $my_exe_id, $exercise_id, $cours } } +/* + * Get the best score in a exercise (NO Exercises in LPs ) + */ function get_best_score($exercise_id, $course_code, $session_id) { $user_results = get_all_exercise_results($exercise_id, $course_code, $session_id); $best_score_data = array(); @@ -1287,3 +1304,50 @@ function get_best_score($exercise_id, $course_code, $session_id) { } return $best_score_data; } + +/** + * Get average score (NO Exercises in LPs ) + * @param int exercise id + * @param string course code + * @param int session id + * @return + */ +function get_average_score($exercise_id, $course_code, $session_id) { + $user_results = get_all_exercise_results($exercise_id, $course_code, $session_id); + $avg_score_data = array(); + $avg_score = 0; + if (!empty($user_results)) { + foreach($user_results as $result) { + if ($result['exe_weighting'] != '') { + $score = $result['exe_result']/$result['exe_weighting']; + $avg_score +=$score; + } + } + $avg_score = float_format($avg_score / count($user_results), 1); + } + return $avg_score; +} + +/** + * Get average score by score (NO Exercises in LPs ) + * @param int exercise id + * @param string course code + * @param int session id + * @return + */ +function get_average_score_by_course($course_code, $session_id) { + $user_results = get_all_exercise_results_by_course($course_code, $session_id, false); + $avg_score = 0; + if (!empty($user_results)) { + foreach($user_results as $result) { + if ($result['exe_weighting'] != '') { + $score = $result['exe_result']/$result['exe_weighting']; + $avg_score +=$score; + } + } + //We asume that all exe_weighting + //$avg_score = show_score( $avg_score / count($user_results) , $result['exe_weighting']); + $avg_score = convert_to_percentage($avg_score / count($user_results)); + } + return $avg_score; +} diff --git a/main/inc/lib/events.lib.inc.php b/main/inc/lib/events.lib.inc.php index 17eeb89576..353cfedac3 100755 --- a/main/inc/lib/events.lib.inc.php +++ b/main/inc/lib/events.lib.inc.php @@ -710,6 +710,46 @@ function get_all_exercise_results($exercise_id, $course_code, $session_id = 0) { return $list; } + + +/** + * Gets all exercise results (NO Exercises in LPs ) from a given exercise id, course, session + * @param int exercise id + * @param string course code + * @param int session id + * @return array with the results + * + */ +function get_all_exercise_results_by_course($course_code, $session_id = 0, $get_count = true) { + $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); + $course_code = Database::escape_string($course_code); + + $session_id = intval($session_id); + $select = '*'; + if ($get_count) { + $select = 'count(*) as count'; + } + $sql = "SELECT $select FROM $TABLETRACK_EXERCICES WHERE status = '' AND exe_cours_id = '$course_code' AND session_id = $session_id AND orig_lp_id =0 AND orig_lp_item_id = 0 ORDER BY exe_id"; + $res = Database::query($sql); + if ($get_count) { + $row = Database::fetch_array($res,'ASSOC'); + return $row['count']; + } else { + $list = array(); + while($row = Database::fetch_array($res,'ASSOC')) { + $list[$row['exe_id']] = $row; + $sql = "SELECT * FROM $TBL_TRACK_ATTEMPT WHERE exe_id = {$row['exe_id']}"; + $res_question = Database::query($sql); + while($row_q = Database::fetch_array($res_question,'ASSOC')) { + $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q; + } + } + return $list; + } +} + + /** * Gets all exercise results (NO Exercises in LPs) from a given exercise id, course, session * @param int exercise id diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index af9098a09d..58a5397c93 100755 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -1908,16 +1908,10 @@ class Tracking { $rs = Database::query($sql); while($row = Database :: fetch_array($rs)) { $course_in_session[$row['session_id']][$row['course_code']] = CourseManager::get_course_information($row['course_code']); - } - + } $html = ''; - if ($show_courses) { - - /*echo '
'; - echo $nameTools; - echo '
';*/ - + if ($show_courses) { if (!empty($courses)) { $html = ''; @@ -1982,6 +1976,7 @@ class Tracking { } } + //Courses in a session if (!empty($course_in_session)) { $html .= '
'; $html .= Display::tag('h1',get_lang('Sessions')); @@ -1998,17 +1993,19 @@ class Tracking { $html .= ' - '.Display::tag('th', get_lang('Time') , array('class'=>'head')).' - '.Display::tag('th', get_lang('Progress') , array('class'=>'head')).' + '.Display::tag('th', get_lang('PublishedExercises'),array('class'=>'head')).' + '.Display::tag('th', get_lang('DoneExercises'), array('class'=>'head')).' + '.Display::tag('th', get_lang('AverageExerciseResult'), array('class'=>'head')).' + '.Display::tag('th', get_lang('Time') , array('class'=>'head')).' + '.Display::tag('th', get_lang('LPProgress') , array('class'=>'head')).' '.Display::tag('th', get_lang('Score').Display :: return_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array ('align' => 'absmiddle', 'hspace' => '3px')), array('class'=>'head')).' - '.Display::tag('th', get_lang('LastConnexion'), array('class'=>'head')).' - '.Display::tag('th', get_lang('Details'), array('class'=>'head')).' + '.Display::tag('th', get_lang('LastConnexion'), array('class'=>'head')).' + '.Display::tag('th', get_lang('Details'), array('class'=>'head')).' '; foreach ($session as $enreg) { $weighting = 0; $last_connection = Tracking :: get_last_connection_date_on_the_course($user_id, $enreg['code'], $key); - $progress = Tracking :: get_avg_student_progress($user_id, $enreg['code'],array(), $key); - + $progress = Tracking :: get_avg_student_progress($user_id, $enreg['code'],array(), $key); $total_time_login = Tracking :: get_time_spent_on_the_course($user_id, $enreg['code'], $key); $time = api_time_to_hms($total_time_login); $percentage_score = Tracking :: get_avg_student_score($user_id, $enreg['code'], array(), $key); @@ -2019,35 +2016,45 @@ class Tracking { $html .= ''; } + $html .= Display::tag('td', $enreg['title']); + //All exercises in the course + $exercises = get_all_exercises($enreg, $key); + //Count of user results + $done_exercises = get_all_exercise_results_by_course($enreg['code'], $key); + //Averaga + $averate = get_average_score_by_course($enreg['code'], $key); + + $html .= Display::tag('td', count($exercises)); + $html .= Display::tag('td', $done_exercises); + $html .= Display::tag('td', $averate); - $html .= ''; - $html .= ''; + $html .= Display::tag('td', $time, array('align'=>'center')); if (is_numeric($progress)) { $progress = $progress.'%'; } else { $progress = '0%'; } - - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; + $details .= ''; + + $html .= Display::tag('td', $details, array('align'=>'center')); + $i = $i ? 0 : 1; $html .= ''; } @@ -2142,7 +2149,7 @@ class Tracking { //$tableTitle = $course_info['title'].' | '.get_lang('Coach').' : '.$course_info['tutor_name'].((!empty($session_name)) ? ' | '.get_lang('Session').' : '.$session_name : ''); $session_name = api_get_session_name($session_id); - $tableTitle = ((!empty($session_name)) ? ' '.get_lang('Session').' : '.$session_name.' | ' : '').''.$course_info['title']; + $tableTitle = $course_info['title']; $html .='
'.get_lang('Course').'
'.$enreg['title'].' '.$time.''.$progress.''; + $html .= Display::tag('td', $progress, array('align'=>'center')); if (is_numeric($percentage_score)) { - $html .= $percentage_score.'%'; + $percentage_score = $percentage_score.'%'; } else { - $html .= '0%'; + $percentage_score = '0%'; } - $html .= ''.$last_connection.''; + $html .= Display::tag('td', $percentage_score, array('align'=>'center')); + $html .= Display::tag('td', $last_connection, array('align'=>'center')); + if ($enreg['code'] == $_GET['course'] && $_GET['session_id'] == $key) { - $html .= ''; - $html .=Display::return_icon('2rightarrow_na.gif', get_lang('Details')); + $details = ''; + $details .=Display::return_icon('2rightarrow_na.gif', get_lang('Details')); } else { - $html .= ''; - $html .=Display::return_icon('2rightarrow.gif', get_lang('Details')); + $details = ''; + $details .=Display::return_icon('2rightarrow.gif', get_lang('Details')); } - $html .= ''; - $html .= '
@@ -2210,14 +2217,13 @@ class Tracking { $sql_exercices = "SELECT quiz.title,id, results_disabled FROM ".$tbl_course_quiz." AS quiz WHERE active='1' AND session_id = 0"; } else { $sql_exercices = "SELECT quiz.title,id, results_disabled FROM ".$tbl_course_quiz." AS quiz WHERE active='1'"; - } - + } $html .= ' - + '; $result_exercices = Database::query($sql_exercices); if (Database::num_rows($result_exercices) > 0) { @@ -2226,8 +2232,7 @@ class Tracking { $exercise_stats = get_all_exercise_results($exercices['id'], $course_info['code'], $session_id); //User attempts we assume the latest item in the loop is the latest attempt if (!empty($exercise_stats)) { - $best_score = 0; - $best_score_array = array(); + //$best_score = 0; $best_score_array = array(); foreach($exercise_stats as $exercise_stat) { if ($exercise_stat['exe_user_id'] == $user_id) { @@ -2240,11 +2245,12 @@ class Tracking { //$score = $score + $exercise_stat['exe_result']; //$weighting = $weighting + $exercise_stat['exe_weighting']; - //Getting the best score + //Getting my best score + /* if ($score > $best_score ) { $best_score = $score; $best_score_array = $exercise_stat; - } + }*/ $attempts++; } } @@ -2259,6 +2265,8 @@ class Tracking { $position = '-'; $best_score = '-'; + $best_score_data = get_best_score($exercices['id'], $course_info['code'], $session_id); + $best_score = show_score($best_score_data['exe_result'], $best_score_data['exe_weighting']); if ($attempts > 0) { $latest_attempt_url .= ' '.Display::return_icon('quiz.gif', get_lang('Quiz')).' '; $percentage_score_result = show_score($score, $weighting).' '.$latest_attempt_url; @@ -2266,12 +2274,7 @@ class Tracking { if (!empty($weighting)) { $my_score = $score/$weighting; } - $position = get_exercise_result_ranking($my_score, $exe_id, $exercices['id'], $course_info['code'], $session_id); - if (!empty($best_score_array)) { - $best_attempt_url .= ' '.Display::return_icon('quiz.gif', get_lang('Quiz')).' '; - $best_score = show_score($best_score_array['exe_result'], $best_score_array['exe_weighting']).' '.$best_attempt_url; - } - + $position = get_exercise_result_ranking($my_score, $exe_id, $exercices['id'], $course_info['code'], $session_id); } $html .= Display::tag('td', $attempts, array('align'=>'center')); $html .= Display::tag('td', $percentage_score_result, array('align'=>'center')); @@ -2290,7 +2293,7 @@ class Tracking { $html .= ''; } } else { - $html .= ''; + $html .= ''; } $html .= '
'.get_lang('Exercices').' '.get_lang('Attempts').' '.get_lang('LatestAttempt').' '.get_lang('Position').''.get_lang('MyBestAttempt').''.get_lang('BestResultInCourse').'
'.get_lang('NoEx').'
'.get_lang('NoEx').'
'; } diff --git a/main/newscorm/lp_stats.php b/main/newscorm/lp_stats.php index 0f5280d60b..309934ce2f 100755 --- a/main/newscorm/lp_stats.php +++ b/main/newscorm/lp_stats.php @@ -287,8 +287,7 @@ if (is_array($list) && count($list) > 0) { $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting')); } else { //$view_score = ($score == 0 ? '/' : ($maxscore === 0 ? $score : $score . '/' . float_format($maxscore, 1))); - $view_score = show_score($score,$maxscore, false); - + $view_score = show_score($score, $maxscore, false); } $output .= "\n" . "\n" . "$extend_attempt_link\n" . '' . get_lang('Attempt') . ' ' . $row['iv_view_count'] . "\n" . '
' . $my_lesson_status . "
\n" . '
' . $view_score . "
\n" . '
'.$time.'
'; @@ -308,7 +307,6 @@ if (is_array($list) && count($list) > 0) { } else { $temp[] = ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1))); } - $temp[] = $time; $csv_content[] = $temp; } @@ -638,18 +636,18 @@ if (is_array($list) && count($list) > 0) { $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting')); } else { // Show only float when need it. - $my_score = float_format( $my_score, 1); - $my_maxscore =float_format($my_maxscore, 1); + //$my_score = float_format( $my_score, 1); + //$my_maxscore =float_format($my_maxscore, 1); if ($my_score == 0 ) { - $view_score = '0/'.$my_maxscore; + //$view_score = '0/'.$my_maxscore; + $view_score = show_score(0, $my_maxscore, false); } else { if ($my_maxscore == 0) { $view_score = $my_score; } else { //$view_score = $my_score . '/' . $my_maxscore; $view_score = show_score($my_score, $my_maxscore, false); - } - + } } //$view_score = ($my_score == 0 ? '0.00/'.$my_maxscore : ($my_maxscore == 0 ? $my_score : $my_score . '/' . $my_maxscore)); } @@ -676,7 +674,7 @@ if (is_array($list) && count($list) > 0) { $output .= ''.get_lang('ShowAndQualifyAttempt').''; } } - $output .= ''; + $output .= ''; $n++; } } diff --git a/main/session/index.php b/main/session/index.php index 69038587fe..153d267d72 100644 --- a/main/session/index.php +++ b/main/session/index.php @@ -225,12 +225,12 @@ $column_week_model = array ( $extra_params_week['grouping'] = 'true'; $extra_params_week['groupingView'] = array('groupField'=>array('week'), - 'groupColumnShow'=>'false', - 'groupText' => array(''.get_lang('PeriodWeek').' {0}')); + 'groupColumnShow'=>'false', + 'groupText' => array(''.get_lang('PeriodWeek').' {0}')); //$extra_params_week['autowidth'] = 'true'; //use the width of the parent //MyQCM grid -$column_exercise = array(get_lang('PublicationDate'), get_lang('Course'), get_lang('Exercise'),get_lang('Attempts'), get_lang('Result'), get_lang('BestResult'), get_lang('Position')); +$column_exercise = array(get_lang('PublicationDate'), get_lang('Course'), get_lang('Exercise'),get_lang('Attempts'), get_lang('Result'), get_lang('BestResultInCourse'), get_lang('Position')); $column_exercise_model = array( array('name'=>'date', 'index'=>'date', 'width'=>'130','align'=>'left', 'sortable'=>'true'), array('name'=>'course', 'index'=>'course', 'width'=>'200','align'=>'left', 'sortable'=>'true'), @@ -275,7 +275,7 @@ $my_reporting = Tracking::show_user_progress(api_get_user_id(), $session_id, ' $my_reporting .= '
'.Tracking::show_course_detail(api_get_user_id(), $_GET['course'], $_GET['session_id']); //Main headers -$headers = array(get_lang('LearningPaths'), get_lang('MyQCM'), get_lang('MyResults')); +$headers = array(get_lang('LearningPaths'), get_lang('MyQCM'), get_lang('MyStatistics')); //Subheaders $sub_header = array(get_lang('AllLearningPaths'), get_lang('PerWeek'), get_lang('ByCourse'));