Fixing query of the exercise live stats in fact this view could be used for other purposes ...

skala
Julio Montoya 14 years ago
parent b2240f255b
commit 177f794f80
  1. 6
      main/exercice/exercise.class.php
  2. 74
      main/exercice/live_stats.php
  3. 36
      main/inc/ajax/exercise.ajax.php

@ -1551,13 +1551,9 @@ class Exercise {
array_map('intval', $questionList); array_map('intval', $questionList);
$weight = Database::escape_string($weight); $weight = Database::escape_string($weight);
//if ($this->type == ONE_PER_PAGE) {
$sql = "INSERT INTO $track_exercises ($sql_fields exe_exo_id, exe_user_id, exe_cours_id, status,session_id, data_tracking, start_date, orig_lp_id, orig_lp_item_id, exe_weighting) $sql = "INSERT INTO $track_exercises ($sql_fields exe_exo_id, exe_user_id, exe_cours_id, status,session_id, data_tracking, start_date, orig_lp_id, orig_lp_item_id, exe_weighting)
VALUES($sql_fields_values '".$this->id."','" . api_get_user_id() . "','" . api_get_course_id() . "','incomplete','" . api_get_session_id() . "','" . implode(',', $questionList) . "', '" . api_get_utc_datetime() . "', '$safe_lp_id', '$safe_lp_item_id', '$weight' )"; VALUES($sql_fields_values '".$this->id."','" . api_get_user_id() . "','" . api_get_course_id() . "','incomplete','" . api_get_session_id() . "','" . implode(',', $questionList) . "', '" . api_get_utc_datetime() . "', '$safe_lp_id', '$safe_lp_item_id', '$weight' )";
/*} else {
$sql = "INSERT INTO $track_exercises ($sql_fields exe_exo_id, exe_user_id, exe_cours_id, status, session_id, start_date, orig_lp_id, orig_lp_item_id)
VALUES($sql_fields_values '".$this->id."','".api_get_user_id()."','".api_get_course_id()."','incomplete','".api_get_session_id()."','".api_get_utc_datetime()."', '$safe_lp_id', '$safe_lp_item_id')";
}*/
Database::query($sql); Database::query($sql);
$id = Database::insert_id(); $id = Database::insert_id();
return $id; return $id;

@ -17,67 +17,6 @@ if (!$result) {
api_not_allowed(true); api_not_allowed(true);
} }
$students = CourseManager :: get_student_list_from_course_code(api_get_course_id(), false);
$question_list = $objExercise->get_validated_question_list();
$data = array();
//Question title # of students who tool it Lowest score Average Highest score Maximum score
$headers = array(
get_lang('Question'),
get_lang('NumberOfStudentWhoTryTheExercise'),
get_lang('LowestScore'),
get_lang('Average'),
get_lang('HighestScore'),
get_lang('MaximumScore')
);
if (!empty($question_list)) {
foreach($question_list as $question_id) {
$question_obj = Question::read($question_id);
$exercise_stats = get_student_stats_by_question($question_id, $exercise_id, api_get_course_id(), api_get_session_id());
$data[$question_id]['name'] = cut($question_obj->question, 100);
$data[$question_id]['students_who_try_exercise'] = $exercise_stats['users'];
$data[$question_id]['lowest_score'] = $exercise_stats['min'];
$data[$question_id]['average_score'] = $exercise_stats['average'];
$data[$question_id]['highest_score'] = $exercise_stats['max'];
$data[$question_id]['max_score'] = $question_obj->weighting;
}
}
//Format A table
$table = new HTML_Table(array('class' => 'data_table'));
$row = 0;
$column = 0;
foreach ($headers as $header) {
$table->setHeaderContents($row, $column, $header);
$column++;
}
$row++;
foreach ($data as $row_table) {
$column = 0;
foreach ($row_table as $cell) {
$table->setCellContents($row, $column, $cell);
$table->updateCellAttributes($row, $column, 'align="center"');
$column++;
}
$table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
$row++;
}
$content = $table->toHtml();
//Format B
$headers = array(
get_lang('Question'),
get_lang('Answer'),
get_lang('Correct'),
get_lang('NumberStudentWhoSelect'),
get_lang('HighestScore'),
get_lang('MaximumScore')
);
$interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices')); $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices'));
$interbreadcrumb[] = array ("url" => "admin.php?exerciseId=$exercise_id","name" => $objExercise->name); $interbreadcrumb[] = array ("url" => "admin.php?exerciseId=$exercise_id","name" => $objExercise->name);
@ -90,16 +29,19 @@ Display::display_header($tool_name);
//jqgrid will use this URL to do the selects //jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=get_live_stats&exercise_id='.$objExercise->id; $minutes = 60;
$url = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=get_live_stats&exercise_id='.$objExercise->id.'&minutes='.$minutes;
//The order is important you need to check the the $column variable in the model.ajax.php file //The order is important you need to check the the $column variable in the model.ajax.php file
$columns = array(get_lang('Firstname'), get_lang('Lastname'), get_lang('Question'), get_lang('Score')); $columns = array(get_lang('Firstname'), get_lang('Lastname'), get_lang('Date'), get_lang('QuestionsDone'), get_lang('Score'));
//Column config //Column config
$column_model = array( $column_model = array(
array('name'=>'firstname', 'index'=>'firstname', 'width'=>'100', 'align'=>'left'), array('name'=>'firstname', 'index'=>'firstname', 'width'=>'100', 'align'=>'left'),
array('name'=>'lastname', 'index'=>'lastname', 'width'=>'100', 'align'=>'left','sortable'=>'false'), array('name'=>'lastname', 'index'=>'lastname', 'width'=>'100', 'align'=>'left'),
array('name'=>'question', 'index'=>'question', 'width'=>'100', 'align'=>'left','sortable'=>'false'), array('name'=>'start_date', 'index'=>'start_date', 'width'=>'100', 'align'=>'left'),
array('name'=>'question', 'index'=>'count_questions', 'width'=>'100', 'align'=>'left'),
array('name'=>'score', 'index'=>'score', 'width'=>'100', 'align'=>'left','sortable'=>'false'), array('name'=>'score', 'index'=>'score', 'width'=>'100', 'align'=>'left','sortable'=>'false'),
); );
//Autowidth //Autowidth
@ -125,6 +67,8 @@ $(function() {
</script> </script>
<?php <?php
echo '<h2>'.$objExercise->name.'</h2>';
echo Display::grid_html('live_stats'); echo Display::grid_html('live_stats');
Display::display_footer(); Display::display_footer();

@ -30,13 +30,15 @@ switch ($action) {
if (!$sidx) $sidx = 1; if (!$sidx) $sidx = 1;
$track_exercise = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $track_exercise = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $track_attempt = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$now = time() - 60*30; $minutes = intval($_REQUEST['minutes']);
$now = time() - 60*$minutes; //1 hour
$now = api_get_utc_datetime($now); $now = api_get_utc_datetime($now);
$where_condition = "WHERE status = 'incomplete' AND exe_exo_id = $exercise_id AND start_date > '$now' "; $where_condition = " orig_lp_id = 0 AND exe_exo_id = $exercise_id AND start_date > '$now' ";
$sql = "SELECT COUNT(DISTINCT exe_id) FROM $track_exercise $where_condition "; $sql = "SELECT COUNT(DISTINCT exe_id) FROM $track_exercise WHERE $where_condition ";
$result = Database::query($sql); $result = Database::query($sql);
$count = Database::fetch_row($result); $count = Database::fetch_row($result);
@ -59,26 +61,44 @@ switch ($action) {
$start = 0; $start = 0;
} }
$sql = "SELECT * FROM $track_exercise $where_condition ";
$sql = "SELECT count_questions, exe_user_id, firstname, lastname, aa.status, start_date, exe_result, exe_weighting, exe_result/exe_weighting as score, exe_duration, questions_to_check, orig_lp_id
FROM $user_table u INNER JOIN (
SELECT t.exe_user_id, count(question_id) as count_questions, status,
start_date, exe_result, exe_weighting, exe_result/exe_weighting as score, exe_duration, questions_to_check, orig_lp_id
FROM $track_attempt a INNER JOIN $track_exercise t
WHERE a.exe_id = t.exe_id AND exe_user_id = a.user_id AND $where_condition
group by exe_user_id
) as aa
ON aa.exe_user_id = user_id
ORDER BY $sidx $sord LIMIT $start , $limit
";
$result = Database::query($sql); $result = Database::query($sql);
$results = array(); $results = array();
while ($row = Database::fetch_array($result,'ASSOC')){ while ($row = Database::fetch_array($result,'ASSOC')){
$results[] = $row; $results[] = $row;
} }
$response = new stdClass(); $response = new stdClass();
$response->page = $page; $response->page = $page;
$response->total = $total_pages; $response->total = $total_pages;
$response->records = $count; $response->records = $count;
$i=0; $i=0;
if (!empty($results)) { if (!empty($results)) {
foreach($results as $row) { foreach($results as $row) {
//$user_info = api_get_user_info($row['exe_user_id']);
//print_r($row); //print_r($row);
$response->rows[$i]['id'] = $row['exe_id']; $response->rows[$i]['id'] = $row['exe_id'];
$array = array(); $array = array( $row['firstname'],
$array['firstname'] = 'fff'; $row['lastname'],
$array['lastname'] = 'fff'; api_format_date($row['start_date'], DATE_TIME_FORMAT_LONG),
$row['count_questions'],
round($row['score']*100).'%'
);
$response->rows[$i]['cell'] = $array; $response->rows[$i]['cell'] = $array;
$i++; $i++;
} }

Loading…
Cancel
Save