Changing the get_best_score funcionality in order to find the best result based in the current user list see BT#2093

skala
Julio Montoya 15 years ago
parent 93a6a78bbf
commit 527d406d68
  1. 109
      main/exercice/exercise.lib.php
  2. 8
      main/inc/lib/events.lib.inc.php
  3. 6
      main/inc/lib/javascript/jquery-ui/default.css
  4. 14
      main/inc/lib/tracking.lib.php
  5. 2
      main/session/index.php

@ -1233,9 +1233,9 @@ function get_all_exercises($course_info = null, $session_id = 0, $check_dates =
}
/**
* 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 based in the user list
* (NO Exercises in LPs )
* @param float user score to be compared attention => score/weight
* @param float user score to be compared *attention* $my_score = score/weight and not just the score
* @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
* @param string course code
@ -1243,7 +1243,79 @@ function get_all_exercises($course_info = null, $session_id = 0, $check_dates =
* @return int the position of the user between his friends in a course (or course within a session)
*/
function get_exercise_result_ranking($my_score, $my_exe_id, $exercise_id, $course_code, $session_id = 0, $return_string = true) {
//Getting all exercise results
if (empty($session_id)) {
$session_id = 0;
require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
$user_list = UserManager::get_user_list();
} else {
require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
$user_list = SessionManager::get_users_by_session($session_id);
}
//No score given we return
if (is_null($my_score)) {
return '-';
}
$best_attempts = array();
foreach($user_list as $user_data) {
$user_id = $user_data['user_id'];
$best_attempts[$user_id]= get_best_attempt_score_by_user($user_id,$exercise_id,$course_code,$session_id);
}
$position_data = array();
if (empty($best_attempts)) {
return 1;
} else {
$position = 1;
$my_ranking = array();
foreach($best_attempts as $user_id => $result) {
if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) {
$my_ranking[$user_id] = $result['exe_result']/$result['exe_weighting'];
} else {
$my_ranking[$user_id] = 0;
}
}
//if (!empty($my_ranking)) {
asort($my_ranking);
$position = count($my_ranking);
if (!empty($my_ranking)) {
foreach($my_ranking as $user_id => $ranking) {
if ($my_score >= $ranking) {
if ($my_score == $ranking) {
$exe_id = $best_attempts[$user_id]['exe_id'];
if ($my_exe_id < $exe_id) {
$position--;
}
} else {
$position--;
}
}
}
}
//}
$return_value = array('position'=>$position, 'count'=>count($my_ranking));
//var_dump($my_score, $my_ranking);
if ($return_string) {
if (!empty($position) && !empty($my_ranking)) {
return $position.'/'.count($my_ranking);
}
}
return $return_value;
}
}
/**
* Gets the position of the score based in a given score (result/weight) and the exe_id based in all attempts
* (NO Exercises in LPs ) old funcionality
* @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
* @param string course code
* @param int session id
* @return int the position of the user between his friends in a course (or course within a session)
*/
function get_exercise_result_ranking_by_attempt($my_score, $my_exe_id, $exercise_id, $course_code, $session_id = 0, $return_string = true) {
if (empty($session_id)) {
$session_id = 0;
}
@ -1287,14 +1359,16 @@ function get_exercise_result_ranking($my_score, $my_exe_id, $exercise_id, $cours
return $position.'/'.count($my_ranking);
}
}
return $return_string;
return $return_value;
}
}
/*
* Get the best score in a exercise (NO Exercises in LPs )
*/
function get_best_score($exercise_id, $course_code, $session_id) {
function get_best_attempt_score($exercise_id, $course_code, $session_id) {
$user_results = get_all_exercise_results($exercise_id, $course_code, $session_id);
$best_score_data = array();
$best_score = 0;
@ -1312,6 +1386,31 @@ function get_best_score($exercise_id, $course_code, $session_id) {
return $best_score_data;
}
/*
* Get the best score in a exercise (NO Exercises in LPs )
*/
function get_best_attempt_score_by_user($user_id, $exercise_id, $course_code, $session_id) {
$user_results = get_all_exercise_results($exercise_id, $course_code, $session_id);
$best_score_data = array();
$best_score = 0;
if (!empty($user_results)) {
foreach($user_results as $result) {
if ($result['exe_user_id'] != $user_id) continue;
if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) {
$score = $result['exe_result']/$result['exe_weighting'];
if ($score > $best_score) {
$best_score = $score;
$best_score_data = $result;
}
}
}
}
return $best_score_data;
}
/**
* Get average score (NO Exercises in LPs )
* @param int exercise id

@ -671,8 +671,8 @@ function get_all_exercise_results($exercise_id, $course_code, $session_id = 0) {
$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);
$exercise_id = intval($exercise_id);
$session_id = intval($session_id);
$exercise_id = intval($exercise_id);
$session_id = intval($session_id);
$sql = "SELECT * FROM $TABLETRACK_EXERCICES WHERE status = '' AND exe_cours_id = '$course_code' AND exe_exo_id = '$exercise_id' AND session_id = $session_id AND orig_lp_id =0 AND orig_lp_item_id = 0 ORDER BY exe_id";
@ -691,7 +691,7 @@ function get_all_exercise_results($exercise_id, $course_code, $session_id = 0) {
}
/**
* Gets all exercise results (NO Exercises in LPs ) from a given exercise id, course, session
* Gets all exercise BEST results attempts (NO Exercises in LPs ) from a given exercise id, course, session per user
* @param int exercise id
* @param string course code
* @param int session id
@ -739,6 +739,8 @@ function get_all_best_exercise_results_by_user($exercise_id, $course_code, $sess
}
/**
* Gets all exercise results (NO Exercises in LPs ) from a given exercise id, course, session
* @param int exercise id

@ -41,6 +41,12 @@
background: #FFF;
}
/* anchor size */
.ui-widget {
font-size:100%;
}
/* cupertino */

@ -2185,8 +2185,7 @@ class Tracking {
}
$html .='</table><br />
<table class="data_table" width="100%">';
<table class="data_table" width="100%">';
// This code was commented on purpose see BT#924
@ -2253,8 +2252,6 @@ class Tracking {
$exercices['title'] = Display::url($exercices['title'], $url, array('target'=>'_blank'));
$html .= Display::tag('td', $exercices['title']);
//Exercise configuration show results show results or show only score
if ($exercices['results_disabled'] == 0 || $exercices['results_disabled'] == 2) {
$latest_attempt_url = '';
@ -2262,12 +2259,13 @@ class Tracking {
$graph = $normal_graph = null;
//Getting best results
$best_score_data = get_best_score($exercices['id'], $course_info['code'], $session_id);
$best_score_data = get_best_attempt_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 .= '<a href="../exercice/exercise_show.php?origin=myprogress&id='.$exe_id.'&cidReq='.$course_info['code'].'&id_session='.$session_id.'"> '.Display::return_icon('quiz.gif', get_lang('Quiz')).' </a>';
$percentage_score_result = show_score($score, $weighting).' '.$latest_attempt_url;
//$latest_attempt_url .= '<a href="../exercice/exercise_show.php?origin=myprogress&id='.$exe_id.'&cidReq='.$course_info['code'].'&id_session='.$session_id.'"> '.Display::return_icon('quiz.gif', get_lang('Quiz')).' </a>';
$latest_attempt_url .= '../exercice/exercise_show.php?origin=myprogress&id='.$exe_id.'&cidReq='.$course_info['code'].'&id_session='.$session_id;
$percentage_score_result = Display::url(show_score($score, $weighting), $latest_attempt_url);
$my_score = 0;
if (!empty($weighting)) {
$my_score = $score/$weighting;
@ -2300,7 +2298,7 @@ class Tracking {
$html .= Display::tag('td', '-', array('align'=>'center'));
$html .= Display::tag('td', '-', array('align'=>'center'));
$html .= Display::tag('td', '-', array('align'=>'center'));
$html .= Display::tag('td', '-', array('align'=>'center'));
$html .= Display::tag('td', '-', array('align'=>'center'));
}
$html .= '</tr>';
}

@ -155,7 +155,7 @@ foreach($final_array as $session_data) {
if (!empty($course_data['exercises'])) {
//Exercises
foreach ($course_data['exercises'] as $my_exercise_id => $exercise_data) {
$best_score_data = get_best_score($my_exercise_id, $my_course_code, $session_id);
$best_score_data = get_best_attempt_score($my_exercise_id, $my_course_code, $session_id);
$best_score = show_score($best_score_data['exe_result'], $best_score_data['exe_weighting']);
//Exercise results
$counter = 1;

Loading…
Cancel
Save