[svn r19906] Logic change - Added average exercises score in reporting trainings list - partial FS#3909

skala
Cristian Fasanando 16 years ago
parent 66ba25592d
commit da47f5eaeb
  1. 64
      main/inc/lib/tracking.lib.php
  2. 15
      main/mySpace/index.php

@ -241,6 +241,70 @@ class Tracking {
return $nb_courses;
}
/**
* This function gets the score average from all tests in a course by student
* @param int $student_id - User id
* @param string $course_code - Course id
* @return string value (number %) Which represents a round integer about the score average.
*/
function get_avg_student_exercise_score($student_id, $course_code) {
// protect datas
$student_id = Database::escape_string($student_id);
$course_code = Database::escape_string($course_code);
// get the informations of the course
$a_course = CourseManager :: get_course_information($course_code);
if(!empty($a_course['db_name']))
{
// table definition
$tbl_course_quiz = Database::get_course_table(TABLE_QUIZ_TEST,$a_course['db_name']);
$tbl_stats_exercise = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
//get the list of exercises
$sql = "SELECT id, title FROM $tbl_course_quiz WHERE active <> -1";
$rs = api_sql_query($sql, __FILE__, __LINE__);
$count_exe = Database::num_rows($rs);
if ($count_exe > 0) {
$quiz_avg_score = 0;
while($quiz = Database::fetch_array($rs)) {
// get the score and max score from track_e_exercise
$sql = 'SELECT exe_result , exe_weighting
FROM '.$tbl_stats_exercise.'
WHERE exe_exo_id = '.(int)$quiz['id'].'
AND exe_user_id = '.(int)$student_id.'
AND orig_lp_id = 0
AND orig_lp_item_id = 0
ORDER BY exe_date DESC';
$rsAttempt = api_sql_query($sql, __FILE__, __LINE__);
$nb_attempts = 0;
while ($attempt = Database::fetch_array($rsAttempt)) {
$nb_attempts++;
$exe_weight=$attempt['exe_weighting'];
if ($exe_weight>0) {
$quiz_avg_score = $attempt['exe_result']/$exe_weight*100;
}
}
if($nb_attempts>0) {
$quiz_avg_score = $quiz_avg_score / $nb_attempts;
}
}
return $quiz_avg_score/$count_exe;
}
}
else
{
return null;
}
}
function get_avg_student_progress($student_id, $course_code) {
require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php');

@ -543,9 +543,7 @@ if(api_is_allowed_to_create_course() && $view=='teacher')
{
$course_code = $course['course_code'];
//var_dump(Tracking ::get_avg_student_exercise($student_id,$course_code));
//var_dump($course_code);
$avg_assignments_in_course = $avg_messages_in_course = $nb_students_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = 0;
$avg_assignments_in_course = $avg_messages_in_course = $nb_students_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = $avg_score_in_exercise = 0;
// students directly subscribed to the course
$sql = "SELECT user_id FROM $tbl_course_user as course_rel_user WHERE course_rel_user.status='5' AND course_rel_user.course_code='$course_code'";
@ -557,6 +555,7 @@ if(api_is_allowed_to_create_course() && $view=='teacher')
// tracking datas
$avg_progress_in_course += Tracking :: get_avg_student_progress ($row['user_id'], $course_code);
$avg_score_in_course += Tracking :: get_avg_student_score ($row['user_id'], $course_code);
$avg_score_in_exercise += Tracking :: get_avg_student_exercise_score ($row['user_id'], $course_code);
$avg_time_spent_in_course += Tracking :: get_time_spent_on_the_course ($row['user_id'], $course_code);
$avg_messages_in_course += Tracking :: count_student_messages ($row['user_id'], $course_code);
$avg_assignments_in_course += Tracking :: count_student_assignments ($row['user_id'], $course_code);
@ -578,21 +577,22 @@ if(api_is_allowed_to_create_course() && $view=='teacher')
// tracking datas
$avg_progress_in_course += Tracking :: get_avg_student_progress ($row['user_id'], $course_code);
$avg_score_in_course += Tracking :: get_avg_student_score ($row['user_id'], $course_code);
$avg_score_in_course += Tracking :: get_avg_student_score ($row['user_id'], $course_code);
$avg_score_in_exercise += Tracking :: get_avg_student_exercise_score ($row['user_id'], $course_code);
$avg_time_spent_in_course += Tracking :: get_time_spent_on_the_course ($row['user_id'], $course_code);
$avg_messages_in_course += Tracking :: count_student_messages ($row['user_id'], $course_code);
$avg_assignments_in_course += Tracking :: count_student_assignments ($row['user_id'], $course_code);
$a_course_students[] = $row['user_id'];
}
}
}
}
if($nb_students_in_course>0)
{
$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).' %';
$avg_score_in_exercise = round($avg_score_in_exercise / $nb_students_in_course,2).' %';
$avg_messages_in_course = round($avg_messages_in_course / $nb_students_in_course,2);
$avg_assignments_in_course = round($avg_assignments_in_course / $nb_students_in_course,2);
}
@ -614,6 +614,7 @@ if(api_is_allowed_to_create_course() && $view=='teacher')
$avg_time_spent_in_course,
$avg_progress_in_course,
$avg_score_in_course,
$avg_score_in_exercise,
$avg_messages_in_course,
$avg_assignments_in_course,
);

Loading…
Cancel
Save