first commit
This commit is contained in:
201
reports/best.php
Normal file
201
reports/best.php
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once('../lib.php');
|
||||
require_once($CFG->dirroot.'/lib/tablelib.php');
|
||||
|
||||
$id = required_param('id', PARAM_INT); // programming ID
|
||||
$page = optional_param('page', 0, PARAM_INT);
|
||||
$perpage = optional_param('perpage', 10, PARAM_INT);
|
||||
$tsort = optional_param('tsort', 'timemodified', PARAM_CLEAN);
|
||||
$language = optional_param('language', '', PARAM_INT);
|
||||
$groupid = optional_param('group', 0, PARAM_INT);
|
||||
|
||||
if (! $cm = get_coursemodule_from_id('programming', $id)) {
|
||||
print_error('invalidcoursemodule');
|
||||
}
|
||||
|
||||
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
|
||||
print_error('coursemisconf');
|
||||
}
|
||||
|
||||
if (! $programming = $DB->get_record('programming', array('id' => $cm->instance))) {
|
||||
print_error('invalidprogrammingid', 'programming');
|
||||
}
|
||||
|
||||
$params = array('id' => $cm->id,
|
||||
'page' => $page,
|
||||
'perpage' => $perpage,
|
||||
'tsort' => $tsort,
|
||||
'language' => $language,
|
||||
'group' => $groupid);
|
||||
|
||||
$PAGE->set_url('/mod/programming/reports/best.php', $params);
|
||||
|
||||
require_login($course->id, true, $cm);
|
||||
$context = context_module::instance($cm->id);
|
||||
|
||||
require_capability('mod/programming:viewreport', $context);
|
||||
$viewotherresult = has_capability('mod/programming:viewotherresult', $context);
|
||||
$viewotherprogram = has_capability('mod/programming:viewotherprogram', $context);
|
||||
|
||||
|
||||
/// Print the page header
|
||||
$PAGE->set_title($programming->name);
|
||||
$PAGE->set_heading(format_string($course->fullname));
|
||||
echo $OUTPUT->header();
|
||||
|
||||
/// Print tabs
|
||||
$renderer = $PAGE->get_renderer('mod_programming');
|
||||
$tabs = programming_navtab('reports', 'reports-best', $course, $programming, $cm);
|
||||
echo $renderer->render_navtab($tabs);
|
||||
|
||||
/// Print the main part of the page
|
||||
$renderer = $PAGE->get_renderer('mod_programming');
|
||||
|
||||
echo html_writer::tag('h2', get_string('allprograms', 'programming'));
|
||||
echo $renderer->render_filters(build_filters(), $PAGE->url, $params);
|
||||
|
||||
print_submit_table();
|
||||
|
||||
/// Finish the page
|
||||
echo $OUTPUT->footer($course);
|
||||
|
||||
function build_filters() {
|
||||
global $OUTPUT, $DB;
|
||||
global $perpage, $page, $cm, $course;
|
||||
|
||||
$filters = array();
|
||||
|
||||
$groups = $DB->get_records('groups', array('courseid' => $course->id));
|
||||
if (is_array($groups)) {
|
||||
$options = array('' => get_string('all'));
|
||||
foreach ($groups as $group) {
|
||||
$options[$group->id] = $group->name;
|
||||
}
|
||||
$filters['group'] = array(
|
||||
'title' => get_string('groups'),
|
||||
'options' => $options);
|
||||
}
|
||||
|
||||
$languages = $DB->get_records('programming_languages');
|
||||
if (is_array($languages)) {
|
||||
$options = array('' => get_string('all'));
|
||||
foreach ($languages as $language) {
|
||||
$options[$language->id] = $language->name;
|
||||
}
|
||||
$filters['language'] = array(
|
||||
'title' => get_string('language', 'programming'),
|
||||
'options' => $options);
|
||||
}
|
||||
|
||||
$options = array(10 => 10, 20 => 20, 30 => 30, 50 => 50, 100 => 100);
|
||||
$filters['perpage'] = array(
|
||||
'title' => get_string('showperpage', 'programming'),
|
||||
'options' => $options);
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
function get_submits($orderby) {
|
||||
global $CFG, $DB, $page, $perpage, $programming, $course, $language, $groupid;
|
||||
|
||||
$gfrom = $gwhere = '';
|
||||
if ($groupid) {
|
||||
$gfrom = ", {$CFG->prefix}groups_members AS gm";
|
||||
$gwhere = " AND gm.groupid = $groupid AND gm.userid = ps.userid";
|
||||
}
|
||||
|
||||
$lwhere = '';
|
||||
if ($language) {
|
||||
$lwhere = " AND ps.language = $language";
|
||||
}
|
||||
|
||||
$submits = 0;
|
||||
$total = 0;
|
||||
$crit = " FROM {$CFG->prefix}programming_submits AS ps,
|
||||
{$CFG->prefix}programming_result AS pr
|
||||
$gfrom
|
||||
WHERE ps.programmingid = {$programming->id}
|
||||
AND pr.programmingid = {$programming->id}
|
||||
AND pr.latestsubmitid = ps.id
|
||||
AND ps.judgeresult = 'AC'
|
||||
$gwhere $lwhere
|
||||
ORDER BY $orderby";
|
||||
$sql = "SELECT ps.* $crit";
|
||||
$submits = $DB->get_records_sql($sql, null, $page * $perpage, $perpage);
|
||||
$sql = "SELECT COUNT(*) $crit";
|
||||
$total = $DB->count_records_sql($sql);
|
||||
|
||||
return array($submits, $total);
|
||||
}
|
||||
|
||||
function print_submit_table() {
|
||||
global $CFG, $DB, $PAGE, $OUTPUT;
|
||||
global $page, $perpage, $programming, $course, $language, $groupid;
|
||||
global $viewotherresult, $viewotherprogram;
|
||||
|
||||
$table = new flexible_table('detail-table');
|
||||
$def = array('rank', 'ps.timemodified', 'user', 'language', 'code', 'ps.timeused', 'ps.memused');
|
||||
$table->define_columns($def);
|
||||
$headers = array(
|
||||
get_string('rank', 'programming'),
|
||||
get_string('submittime', 'programming'),
|
||||
get_string('fullname'),
|
||||
get_string('language', 'programming'),
|
||||
get_string('programcode', 'programming'),
|
||||
get_string('timeused', 'programming'),
|
||||
get_string('memused', 'programming'),
|
||||
);
|
||||
$table->define_headers($headers);
|
||||
|
||||
$table->baseurl = $PAGE->url;
|
||||
$table->set_attribute('cellspacing', '0');
|
||||
$table->set_attribute('id', 'detail-table');
|
||||
$table->set_attribute('class', 'generaltable generalbox');
|
||||
$table->set_attribute('align', 'center');
|
||||
$table->set_attribute('cellpadding', '3');
|
||||
$table->set_attribute('cellspacing', '1');
|
||||
$table->sortable(true, 'ps.timeused');
|
||||
$table->no_sorting('rank');
|
||||
$table->no_sorting('user');
|
||||
$table->no_sorting('language');
|
||||
$table->no_sorting('code');
|
||||
$table->column_class('user', 'fullname');
|
||||
$table->setup();
|
||||
$orderby = $table->get_sql_sort();
|
||||
|
||||
list($submits, $totalcount) = get_submits($orderby);
|
||||
if (is_array($submits)) {
|
||||
$i = 0;
|
||||
$lang = $DB->get_records('programming_languages');
|
||||
foreach ($submits as $submit) {
|
||||
$data = array();
|
||||
$data[] = ++$i;
|
||||
$data[] = userdate($submit->timemodified, '%Y-%m-%d %H:%M:%S');
|
||||
$user = $DB->get_record('user', array('id' => $submit->userid));
|
||||
$data[] = $OUTPUT->user_picture($user)."<a href='{$CFG->wwwroot}/user/view.php?id={$submit->userid}&course={$course->id}'>".fullname($user).'</a>';
|
||||
$data[] = $lang[$submit->language]->name;
|
||||
if ($viewotherprogram) {
|
||||
$data[] = "<a href='{$CFG->wwwroot}/mod/programming/history.php?a={$programming->id}&userid={$submit->userid}&submitid={$submit->id}'>".get_string('sizelines', 'programming', $submit).'</a>';
|
||||
} else {
|
||||
$data[] = get_string('sizelines', 'programming', $submit);
|
||||
}
|
||||
if ($submit->judgeresult) {
|
||||
$data[] = round($submit->timeused, 3);
|
||||
$data[] = get_string('memusednk', 'programming', $submit->memused);
|
||||
} else {
|
||||
$data[] = ''; $data[] = ''; $data[] = '';
|
||||
}
|
||||
$table->add_data($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$table->print_html();
|
||||
|
||||
$pagingbar = new paging_bar($totalcount, $page, $perpage, $PAGE->url, 'page');
|
||||
echo $OUTPUT->render($pagingbar);
|
||||
}
|
||||
|
||||
?>
|
||||
255
reports/detail.php
Normal file
255
reports/detail.php
Normal file
@@ -0,0 +1,255 @@
|
||||
<?php
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once('../lib.php');
|
||||
|
||||
$id = required_param('id', PARAM_INT); // Course Module ID, or
|
||||
$groupid = optional_param('group', 0, PARAM_INT);
|
||||
$page = optional_param('page', 0, PARAM_INT);
|
||||
$perpage = optional_param('perpage', 10, PARAM_INT);
|
||||
$latestonly = optional_param('latestonly', 1, PARAM_INT);
|
||||
$judgeresult = optional_param('judgeresult', '', PARAM_CLEAN);
|
||||
$firstinitial = optional_param('firstinitial', '', PARAM_CLEAN);
|
||||
$lastinitial = optional_param('lastinitial', '', PARAM_CLEAN);
|
||||
|
||||
if (! $cm = get_coursemodule_from_id('programming', $id)) {
|
||||
print_error('Course Module ID was incorrect');
|
||||
}
|
||||
|
||||
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
|
||||
print_error('Course is misconfigured');
|
||||
}
|
||||
|
||||
if (! $programming = $DB->get_record('programming', array('id' => $cm->instance))) {
|
||||
print_error('Course module is incorrect');
|
||||
}
|
||||
|
||||
$params = array('id' => $cm->id,
|
||||
'latestonly' => $latestonly,
|
||||
'lastinitial' => $lastinitial,
|
||||
'firstinitial' => $firstinitial,
|
||||
'group' => $groupid,
|
||||
'judgeresult' => $judgeresult,
|
||||
'page' => $page,
|
||||
'perpage' => $perpage);
|
||||
|
||||
$PAGE->set_url('/mod/programming/reports/detail.php', $params);
|
||||
|
||||
require_login($course->id, true, $cm);
|
||||
$context = context_module::instance($cm->id);
|
||||
|
||||
require_capability('mod/programming:viewreport', $context);
|
||||
|
||||
$rejudge = has_capability('mod/programming:rejudge', $context);
|
||||
$deleteothersubmit = has_capability('mod/programming:deleteothersubmit', $context);
|
||||
$viewotherresult = has_capability('mod/programming:viewotherresult', $context);
|
||||
$viewotherprogram = has_capability('mod/programming:viewotherprogram', $context);
|
||||
|
||||
|
||||
list($submits, $totalcount) = get_submits();
|
||||
|
||||
/// Print the page header
|
||||
$PAGE->set_title($programming->name);
|
||||
$PAGE->set_heading(format_string($course->fullname));
|
||||
echo $OUTPUT->header();
|
||||
|
||||
/// Print tabs
|
||||
$renderer = $PAGE->get_renderer('mod_programming');
|
||||
$tabs = programming_navtab('reports', 'reports-detail', $course, $programming, $cm);
|
||||
echo $renderer->render_navtab($tabs);
|
||||
|
||||
/// Print the main part of the page
|
||||
echo html_writer::tag('h2', get_string('allprograms', 'programming'));
|
||||
|
||||
$renderer = $PAGE->get_renderer('mod_programming');
|
||||
echo $renderer->render_filters(build_filters(), $PAGE->url, $params);
|
||||
|
||||
if (is_array($submits)) {
|
||||
$table = build_result_table($submits, $totalcount);
|
||||
$strrejudge = get_string('rejudge', 'programming');
|
||||
$strdelete = get_string('delete');
|
||||
echo html_writer::start_tag('form', array('id' => 'submitaction', 'method' => 'post'));
|
||||
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'id', 'value' => $cm->id));
|
||||
echo html_writer::table($table);
|
||||
$pagingbar = new paging_bar($totalcount, $page, $perpage, $PAGE->url, 'page');
|
||||
echo $OUTPUT->render($pagingbar);
|
||||
echo html_writer::start_tag('div', array('id' => 'submitbuttons', 'style' => 'display: none'));
|
||||
echo html_writer::empty_tag('input', array('id' => 'rejudge', 'type' => 'button', 'value' => $strrejudge));
|
||||
echo html_writer::empty_tag('input', array('id' => 'delete', 'type' => 'button', 'value' => $strdelete));
|
||||
echo html_writer::end_tag('div');
|
||||
echo html_writer::end_tag('form');
|
||||
$PAGE->requires->js_init_call('M.mod_programming.init_reports_detail');
|
||||
}
|
||||
|
||||
/// Finish the page
|
||||
echo $OUTPUT->footer($course);
|
||||
|
||||
function get_submits() {
|
||||
global $CFG, $DB, $page, $perpage, $programming, $course;
|
||||
global $firstinitial, $lastinitial, $latestonly, $groupid, $language;
|
||||
global $judgeresult;
|
||||
|
||||
$submits = 0;
|
||||
$total = 0;
|
||||
if ($latestonly) {
|
||||
$rfrom = ", {programming_result} AS pr";
|
||||
$rwhere = " AND pr.programmingid = {$programming->id}
|
||||
AND pr.latestsubmitid = ps.id";
|
||||
} else {
|
||||
$rfrom = $rwhere = '';
|
||||
}
|
||||
if ($firstinitial || $lastinitial) {
|
||||
$ufrom = ", {user} AS u";
|
||||
$uwhere = " AND u.firstnameletter LIKE '{$firstinitial}%'
|
||||
AND u.lastnameletter LIKE '{$lastinitial}%'
|
||||
AND u.id = ps.userid";
|
||||
} else {
|
||||
$ufrom = $uwhere = '';
|
||||
}
|
||||
if ($groupid) {
|
||||
$gfrom = ", {groups_members} AS gm";
|
||||
$gwhere = " AND gm.groupid = $groupid AND gm.userid = ps.userid";
|
||||
} else {
|
||||
$gfrom = $gwhere = '';
|
||||
}
|
||||
if ($judgeresult) {
|
||||
if ($judgeresult == 'NULL') {
|
||||
$jrwhere = " AND (ps.judgeresult IS NULL OR ps.judgeresult = '')";
|
||||
} else {
|
||||
$jrwhere = " AND ps.judgeresult = '$judgeresult'";
|
||||
}
|
||||
} else {
|
||||
$jrwhere = '';
|
||||
}
|
||||
|
||||
$crit = " FROM {programming_submits} AS ps
|
||||
$ufrom $rfrom $gfrom
|
||||
WHERE ps.programmingid = {$programming->id}
|
||||
$uwhere $rwhere $gwhere $jrwhere
|
||||
ORDER BY ps.timemodified DESC";
|
||||
$sql = "SELECT ps.* $crit";
|
||||
$submits = $DB->get_records_sql($sql, null, $page * $perpage, $perpage);
|
||||
$sql = "SELECT COUNT(*) $crit";
|
||||
$total = $DB->count_records_sql($sql);
|
||||
|
||||
return array($submits, $total);
|
||||
}
|
||||
|
||||
function build_result_table($submits, $total) {
|
||||
global $CFG, $DB, $PAGE, $OUTPUT, $page, $perpage, $programming, $course, $cm;
|
||||
global $viewotherresult, $viewotherprogram, $deleteothersubmit, $rejudge;
|
||||
|
||||
$table = new html_table();
|
||||
$headers = array(
|
||||
get_string('ID', 'programming'),
|
||||
get_string('submittime', 'programming'),
|
||||
get_string('fullname'),
|
||||
get_string('language', 'programming'),
|
||||
get_string('programcode', 'programming'),
|
||||
get_string('result', 'programming'),
|
||||
get_string('timeused', 'programming'),
|
||||
get_string('memused', 'programming'),
|
||||
);
|
||||
if ($deleteothersubmit || $rejudge) $headers[] = get_string('select');
|
||||
$table->head = $headers;
|
||||
$table->colclasses[2] = 'fullname';
|
||||
|
||||
$table->attributes = array('id' => 'detail-table', 'class' => 'generaltable');
|
||||
$table->tablealign = 'center';
|
||||
$table->cellpadding = 3;
|
||||
$table->cellspacing = 1;
|
||||
|
||||
$lang = $DB->get_records('programming_languages');
|
||||
foreach ($submits as $submit) {
|
||||
$data = array();
|
||||
$data[] = $submit->id;
|
||||
$data[] = userdate($submit->timemodified, '%Y-%m-%d %H:%M:%S');
|
||||
$user = $DB->get_record('user', array('id' => $submit->userid));
|
||||
$data[] = $OUTPUT->user_picture($user)."<a href='{$CFG->wwwroot}/user/view.php?id={$submit->userid}&course={$course->id}'>".fullname($user).'</a>';
|
||||
$data[] = $lang[$submit->language]->name;
|
||||
if ($viewotherprogram) {
|
||||
$url = new moodle_url('../history.php', array('id' => $cm->id, 'userid' => $submit->userid, 'submitid' => $submit->id));
|
||||
$data[] = $OUTPUT->action_link($url, get_string('sizelines', 'programming', $submit));
|
||||
} else {
|
||||
$data[] = get_string('sizelines', 'programming', $submit);
|
||||
}
|
||||
if ($submit->judgeresult) {
|
||||
$strresult = get_string($submit->judgeresult, 'programming');
|
||||
if ($viewotherresult) {
|
||||
$url = new moodle_url('../result.php', array('id' => $cm->id, 'submitid' => $submit->id));
|
||||
$data[] = $OUTPUT->action_link($url, $strresult);
|
||||
} else {
|
||||
$data[] = $strresult;
|
||||
}
|
||||
} else {
|
||||
$data[] = '';
|
||||
}
|
||||
if ($submit->timeused != null) {
|
||||
$data[] = round($submit->timeused, 3);
|
||||
} else {
|
||||
$data[] = '';
|
||||
}
|
||||
if ($submit->memused != null) {
|
||||
$data[] = get_string('memusednk', 'programming', $submit->memused);
|
||||
} else {
|
||||
$data[] = '';
|
||||
}
|
||||
if ($deleteothersubmit || $rejudge) {
|
||||
$data[] = html_writer::empty_tag('input', array('class' => 'selectsubmit', 'type' => 'checkbox', 'name' => 'submitid[]', 'value' => $submit->id));
|
||||
}
|
||||
$table->data[] = $data;
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
function build_filters() {
|
||||
global $OUTPUT, $DB;
|
||||
global $perpage, $page, $cm, $course;
|
||||
|
||||
$filters = array();
|
||||
|
||||
// select range
|
||||
$filters['latestonly'] = array(
|
||||
'title' => get_string('range', 'programming'),
|
||||
'options' => array('0' => get_string('showall', 'programming'),
|
||||
'1' => get_string('showlatestonly', 'programming')));
|
||||
|
||||
$options = programming_judgeresult_options(true);
|
||||
$options['NULL'] = get_string('statusshortnew', 'programming');
|
||||
$filters['judgeresult'] = array(
|
||||
'title' => get_string('judgeresult', 'programming'),
|
||||
'options' => $options);
|
||||
|
||||
$groups = $DB->get_records('groups', array('courseid' => $course->id));
|
||||
if (is_array($groups)) {
|
||||
$options = array('' => get_string('all'));
|
||||
foreach ($groups as $group) {
|
||||
$options[$group->id] = $group->name;
|
||||
}
|
||||
$filters['group'] = array(
|
||||
'title' => get_string('groups'),
|
||||
'options' => $options);
|
||||
}
|
||||
|
||||
$alphabet = explode(',', get_string('alphabet', 'langconfig'));
|
||||
$options = array('' => get_string('all'));
|
||||
foreach ($alphabet as $a) {
|
||||
$options[$a] = $a;
|
||||
}
|
||||
$filters['firstinitial'] = array(
|
||||
'title' => get_string('firstname'),
|
||||
'options' => $options);
|
||||
$filters['lastinitial'] = array(
|
||||
'title' => get_string('lastname'),
|
||||
'options' => $options);
|
||||
|
||||
$options = array(10 => 10, 20 => 20, 30 => 30, 50 => 50, 100 => 100);
|
||||
$filters['perpage'] = array(
|
||||
'title' => get_string('showperpage', 'programming'),
|
||||
'options' => $options);
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
?>
|
||||
137
reports/judgeresultchart.php
Normal file
137
reports/judgeresultchart.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?PHP
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once('../lib.php');
|
||||
|
||||
$id = required_param('id', PARAM_INT); // programming ID
|
||||
$range = optional_param('range', 0, PARAM_INT); // 0 for show all
|
||||
$groupid = optional_param('group', 0, PARAM_INT); // 0 for show all
|
||||
|
||||
if (! $cm = get_coursemodule_from_id('programming', $id)) {
|
||||
print_error('invalidcoursemodule');
|
||||
}
|
||||
|
||||
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
|
||||
print_error('coursemisconf');
|
||||
}
|
||||
|
||||
if (! $programming = $DB->get_record('programming', array('id' => $cm->instance))) {
|
||||
print_error('invalidprogrammingid', 'programming');
|
||||
}
|
||||
|
||||
$params = array('id' => $cm->id,
|
||||
'range' => $range,
|
||||
'group' => $groupid);
|
||||
$PAGE->set_url('/mod/programming/reports/judgeresultchart.php', $params);
|
||||
|
||||
require_login($course->id, true, $cm);
|
||||
$context = context_module::instance($cm->id);
|
||||
|
||||
require_capability('mod/programming:viewreport', $context);
|
||||
|
||||
|
||||
/// Print the page header
|
||||
$PAGE->set_title($programming->name);
|
||||
$PAGE->set_heading(format_string($course->fullname));
|
||||
echo $OUTPUT->header();
|
||||
|
||||
/// Print tabs
|
||||
$renderer = $PAGE->get_renderer('mod_programming');
|
||||
$tabs = programming_navtab('reports', 'reports-judgeresultchart', $course, $programming, $cm);
|
||||
echo $renderer->render_navtab($tabs);
|
||||
|
||||
/// Print the main part of the page
|
||||
$renderer = $PAGE->get_renderer('mod_programming');
|
||||
echo $renderer->render_filters(build_filters(), $PAGE->url, $params);
|
||||
print_judgeresult_chart();
|
||||
|
||||
/// Finish the page
|
||||
echo $OUTPUT->footer($course);
|
||||
|
||||
function count_judgeresult() {
|
||||
global $DB, $programming, $range, $groupid;
|
||||
|
||||
$rfrom = $rwhere = '';
|
||||
if ($range == 1) {
|
||||
$rfrom = ", {programming_result} AS pr";
|
||||
$rwhere = " AND pr.programmingid = {$programming->id}
|
||||
AND pr.latestsubmitid = ps.id";
|
||||
}
|
||||
$gfrom = $gwhere = '';
|
||||
if ($groupid) {
|
||||
$gfrom = ", {groups_members} AS gm";
|
||||
$gwhere = " AND gm.groupid = $groupid AND gm.userid = ps.userid";
|
||||
}
|
||||
|
||||
$sql = "SELECT ps.judgeresult AS judgeresult,
|
||||
COUNT(*) AS count
|
||||
FROM {programming_submits} AS ps
|
||||
$rfrom $gfrom
|
||||
WHERE ps.programmingid = {$programming->id}
|
||||
$rwhere $gwhere
|
||||
GROUP BY ps.judgeresult";
|
||||
$rst = $DB->get_recordset_sql($sql);
|
||||
$ret = array();
|
||||
foreach ($rst as $row) {
|
||||
$ret[$row->judgeresult] = $row->count;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function print_judgeresult_chart() {
|
||||
global $PAGE;
|
||||
|
||||
$values = array();
|
||||
|
||||
$c = count_judgeresult();
|
||||
$keys = array('AC', 'PE', 'WA', 'RE', 'FPE', 'KS', 'TLE', 'MLE', 'OLE', 'CE');
|
||||
foreach ($keys as $key) {
|
||||
$name = get_string($key, 'programming');
|
||||
if (!array_key_exists($key, $c)) $c[$key] = 0;
|
||||
$values[] = array('result' => $name, 'count' => $c[$key]);
|
||||
$c[$key] = 0;
|
||||
}
|
||||
|
||||
$others = 0; foreach ($c as $key => $value) $others += $value;
|
||||
$name = get_string('others', 'programming');
|
||||
$values[] = array('result' => $name, 'count' => $others);
|
||||
|
||||
$strjudgeresultchart = get_string('judgeresultcountchart', 'programming');
|
||||
$strvisitgoogleneeded = get_string('visitgoogleneeded', 'programming');
|
||||
|
||||
$jsmodule = array(
|
||||
'name' => 'mod_programming',
|
||||
'fullpath' => '/mod/programming/module.js',
|
||||
'requires' => array('base', 'io', 'node', 'json', 'charts'),
|
||||
'strings' => array()
|
||||
);
|
||||
|
||||
echo html_writer::tag('div', '', array('id' => 'judgeresult-chart', 'class' => 'chart'));
|
||||
$PAGE->requires->js_init_call('M.mod_programming.draw_judgeresult_chart', array(json_encode($values)), false, $jsmodule);
|
||||
}
|
||||
|
||||
function build_filters() {
|
||||
global $OUTPUT, $DB;
|
||||
global $perpage, $page, $cm, $course;
|
||||
|
||||
$filters = array();
|
||||
|
||||
// select range
|
||||
$filters['range'] = array(
|
||||
'title' => get_string('range', 'programming'),
|
||||
'options' => array('0' => get_string('showall', 'programming'),
|
||||
'1' => get_string('showlatestonly', 'programming')));
|
||||
|
||||
$groups = $DB->get_records('groups', array('courseid' => $course->id));
|
||||
if (is_array($groups)) {
|
||||
$options = array('' => get_string('all'));
|
||||
foreach ($groups as $group) {
|
||||
$options[$group->id] = $group->name;
|
||||
}
|
||||
$filters['group'] = array(
|
||||
'title' => get_string('groups'),
|
||||
'options' => $options);
|
||||
}
|
||||
|
||||
return $filters;
|
||||
}
|
||||
287
reports/summary.php
Normal file
287
reports/summary.php
Normal file
@@ -0,0 +1,287 @@
|
||||
<?PHP
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once('../lib.php');
|
||||
require_once($CFG->dirroot.'/lib/tablelib.php');
|
||||
|
||||
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
|
||||
|
||||
$params = array();
|
||||
if ($id) {
|
||||
$params['id'] = $id;
|
||||
}
|
||||
$PAGE->set_url('/mod/programming/reports/summary.php', $params);
|
||||
|
||||
if ($id) {
|
||||
if (! $cm = get_coursemodule_from_id('programming', $id)) {
|
||||
print_error('Course Module ID was incorrect');
|
||||
}
|
||||
|
||||
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
|
||||
print_error('Course is misconfigured');
|
||||
}
|
||||
|
||||
if (! $programming = $DB->get_record('programming', array('id' => $cm->instance))) {
|
||||
print_error('Course module is incorrect');
|
||||
}
|
||||
}
|
||||
|
||||
require_login($course->id, true, $cm);
|
||||
$context = context_module::instance($cm->id);
|
||||
|
||||
require_capability('mod/programming:viewreport', $context);
|
||||
|
||||
// results is stored in a array
|
||||
$stat_results = array();
|
||||
$groupnum = $DB->count_records('groups', array('courseid' => $course->id));
|
||||
$groups = $DB->get_records('groups', array('courseid' => $course->id));
|
||||
if (is_array($groups)) {
|
||||
foreach($groups as $group) {
|
||||
summary_stat($stat_results, $group);
|
||||
}
|
||||
}
|
||||
summary_stat($stat_results);
|
||||
|
||||
/// Print the page header
|
||||
$PAGE->set_title($programming->name);
|
||||
$PAGE->set_heading(format_string($course->fullname));
|
||||
echo $OUTPUT->header();
|
||||
|
||||
/// Print tabs
|
||||
$renderer = $PAGE->get_renderer('mod_programming');
|
||||
$tabs = programming_navtab('reports', 'reports-summary', $course, $programming, $cm);
|
||||
echo $renderer->render_navtab($tabs);
|
||||
|
||||
/// Print the main part of the page
|
||||
echo html_writer::tag('h2', get_string('summary', 'programming'));
|
||||
print_summary_table($stat_results);
|
||||
print_action_table();
|
||||
print_summary_chart($stat_results);
|
||||
|
||||
/// Finish the page
|
||||
echo $OUTPUT->footer($course);
|
||||
|
||||
function print_summary_table($stat_results) {
|
||||
global $CFG, $DB, $course, $params;
|
||||
|
||||
$student_role = $DB->get_record('role', array('archetype' => 'student'));
|
||||
|
||||
$table = new flexible_table('summary-stat-table');
|
||||
$def = array('range', 'studentcount', 'submitcount', 'submitpercent', 'compilecount', 'compilepercent', 'passedcount', 'passedpercent', 'intimepassedcount', 'intimepassedpercent', 'codelines');
|
||||
$table->define_columns($def);
|
||||
$headers = array(
|
||||
get_string('statrange', 'programming'),
|
||||
get_string('statstudentcount', 'programming', $student_role->name),
|
||||
get_string('statsubmitcount', 'programming'),
|
||||
'%',
|
||||
get_string('statcompiledcount', 'programming'),
|
||||
'%',
|
||||
get_string('statpassedcount', 'programming'),
|
||||
'%',
|
||||
get_string('statintimepassedcount', 'programming'),
|
||||
'%',
|
||||
get_string('stataveragelines', 'programming'));
|
||||
$table->define_headers($headers);
|
||||
|
||||
$table->set_attribute('id', 'summary-stat-table');
|
||||
$table->set_attribute('class', 'generaltable generalbox');
|
||||
$table->set_attribute('cellspacing', '1');
|
||||
$table->define_baseurl('/mod/programming/view.php', $params);
|
||||
$table->setup();
|
||||
|
||||
foreach ($stat_results as $row) {
|
||||
$data = array();
|
||||
$data[] = $row['name'];
|
||||
$data[] = $row['studentcount'];
|
||||
$data[] = $row['submitcount'];
|
||||
$data[] = ($row['studentcount'] > 0 ? round($row['submitcount'] / $row['studentcount'] * 100, 0) : 0).'%';
|
||||
$data[] = $row['compiledcount'];
|
||||
$data[] = ($row['studentcount'] > 0 ? round($row['compiledcount'] / $row['studentcount'] * 100, 0) : 0).'%';
|
||||
$data[] = $row['passedcount'];
|
||||
$data[] = ($row['studentcount'] > 0 ? round($row['passedcount'] / $row['studentcount'] * 100, 0) : 0).'%';
|
||||
$data[] = $row['intimepassedcount'];
|
||||
$data[] = ($row['studentcount'] > 0 ? round($row['intimepassedcount'] / $row['studentcount'] * 100, 0) : 0).'%';
|
||||
$data[] = $row['submitcount'] > 0 ? round($row['averagelines']) : 0;
|
||||
$table->add_data($data);
|
||||
}
|
||||
|
||||
$table->print_html();
|
||||
}
|
||||
|
||||
function print_summary_chart($stat_results) {
|
||||
global $PAGE;
|
||||
|
||||
$summary = array_pop($stat_results);
|
||||
$acintime = $summary['intimepassedcount'];
|
||||
$ac = $summary['passedcount'] - $summary['intimepassedcount'];
|
||||
$se = $summary['compiledcount'] - $summary['passedcount'];
|
||||
$ce = $summary['submitcount'] - $summary['compiledcount'];
|
||||
$ns = $summary['studentcount'] - $summary['submitcount'];
|
||||
$strresultcount = get_string('resultcountchart', 'programming');
|
||||
$stracintime = get_string('resultchartacintime', 'programming');
|
||||
$strac = get_string('resultchartacdiscount', 'programming');
|
||||
$strse = get_string('resultchartsomethingwrong', 'programming');
|
||||
$strce = get_string('resultchartcompileerror', 'programming');
|
||||
$strns = get_string('resultchartnosubmition', 'programming');
|
||||
$strgroupresultcount = get_string('resultgroupcountchart', 'programming');
|
||||
|
||||
$jsmodule = array(
|
||||
'name' => 'mod_programming',
|
||||
'fullpath' => '/mod/programming/module.js',
|
||||
'requires' => array('base', 'io', 'node', 'json', 'charts'),
|
||||
'strings' => array()
|
||||
);
|
||||
|
||||
$groupcount = count($stat_results);
|
||||
if ($groupcount) {
|
||||
$data = array();
|
||||
foreach ($stat_results as $group) {
|
||||
$data[] = array(
|
||||
'category' => $group['name'],
|
||||
'acintime' => $group['intimepassedcount'],
|
||||
'ac' => $group['passedcount'] - $group['intimepassedcount'],
|
||||
'se' => $group['compiledcount'] - $group['passedcount'],
|
||||
'ce' => $group['submitcount'] - $group['compiledcount'],
|
||||
);
|
||||
}
|
||||
|
||||
echo html_writer::tag('div', '', array('id' => 'summary-group-count-chart', 'class' => 'chart'));
|
||||
$PAGE->requires->js_init_call('M.mod_programming.draw_summary_group_count_chart', array(json_encode($data)), false, $jsmodule);
|
||||
}
|
||||
|
||||
$percent_chart_data = array(
|
||||
array('result' => $stracintime, 'count' => $acintime),
|
||||
array('result' => $strac, 'count' => $ac),
|
||||
array('result' => $strse, 'count' => $se),
|
||||
array('result' => $strce, 'count' => $ce),
|
||||
array('result' => $strns, 'count' => $ns)
|
||||
);
|
||||
echo html_writer::tag('div', '', array('id' => 'summary-percent-chart', 'class' => 'chart'));
|
||||
$PAGE->requires->js_init_call('M.mod_programming.draw_summary_percent_chart', array(json_encode($percent_chart_data)), false, $jsmodule);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计各个小组完成题目的情况。
|
||||
*
|
||||
* 目前此函数只处理 roleid 为 5 即学生的情况。
|
||||
*
|
||||
* @param $state_results 存储统计结果
|
||||
* @param $group 要统计的小组,如果为 null 则统计全部人员的情况
|
||||
*/
|
||||
function summary_stat(&$stat_results, $group = null) {
|
||||
global $USER, $CFG, $DB, $course, $programming;
|
||||
|
||||
$context = $DB->get_record('context', array('contextlevel' => CONTEXT_COURSE, 'instanceid' => $course->id));
|
||||
$roleid = 5;
|
||||
|
||||
$student_role = $DB->get_record('role', array('archetype' => 'student'));
|
||||
|
||||
if ($group) {
|
||||
$gfrom = ", {groups_members} AS gm";
|
||||
$gwhere = " AND gm.groupid = $group->id AND ra.userid = gm.userid ";
|
||||
$name = $group->name;
|
||||
} else {
|
||||
$gfrom = $gwhere = '';
|
||||
$name = get_string('allstudents', 'programming', $student_role->name);
|
||||
}
|
||||
|
||||
$studentcount = $DB->count_records_sql("
|
||||
SELECT COUNT(*)
|
||||
FROM {role_assignments} AS ra
|
||||
$gfrom
|
||||
WHERE ra.roleid = $roleid
|
||||
AND ra.contextid = $context->id
|
||||
$gwhere");
|
||||
$submitcount = $DB->count_records_sql("
|
||||
SELECT COUNT(*)
|
||||
FROM {role_assignments} AS ra,
|
||||
{programming_result} AS pr
|
||||
$gfrom
|
||||
WHERE ra.roleid = $roleid
|
||||
AND ra.contextid = $context->id
|
||||
AND pr.programmingid = $programming->id
|
||||
AND ra.userid = pr.userid
|
||||
$gwhere");
|
||||
$compiledcount = $DB->count_records_sql("
|
||||
SELECT COUNT(*)
|
||||
FROM {role_assignments} AS ra,
|
||||
{programming_result} AS pr,
|
||||
{programming_submits} AS ps
|
||||
$gfrom
|
||||
WHERE ps.programmingid = $programming->id
|
||||
AND pr.programmingid = $programming->id
|
||||
AND ra.roleid = $roleid
|
||||
AND ra.contextid = $context->id
|
||||
AND ps.id = pr.latestsubmitid
|
||||
AND pr.userid = ra.userid
|
||||
AND ps.judgeresult != 'CE' AND ps.judgeresult != ''
|
||||
$gwhere");
|
||||
$passedcount = $DB->count_records_sql("
|
||||
SELECT COUNT(*)
|
||||
FROM {role_assignments} AS ra,
|
||||
{programming_submits} AS ps,
|
||||
{programming_result} AS pr
|
||||
$gfrom
|
||||
WHERE ps.programmingid = {$programming->id}
|
||||
AND pr.programmingid = {$programming->id}
|
||||
AND ra.roleid = $roleid
|
||||
AND ra.contextid = $context->id
|
||||
AND pr.userid = ra.userid
|
||||
AND pr.latestsubmitid = ps.id
|
||||
AND ps.passed = 1
|
||||
$gwhere");
|
||||
$intimepassedcount = $DB->count_records_sql("
|
||||
SELECT COUNT(*)
|
||||
FROM {role_assignments} AS ra,
|
||||
{programming_submits} AS ps,
|
||||
{programming_result} AS pr
|
||||
$gfrom
|
||||
WHERE ps.programmingid = {$programming->id}
|
||||
AND pr.programmingid = {$programming->id}
|
||||
AND ra.roleid = $roleid
|
||||
AND ra.contextid = $context->id
|
||||
AND pr.userid = ra.userid
|
||||
AND pr.latestsubmitid = ps.id
|
||||
AND ps.timemodified <= {$programming->timediscount}
|
||||
AND ps.passed = 1
|
||||
$gwhere");
|
||||
$codeavg = $DB->get_record_sql("
|
||||
SELECT AVG(codelines) as codelines
|
||||
FROM {role_assignments} AS ra,
|
||||
{programming_submits} AS ps,
|
||||
{programming_result} AS pr
|
||||
$gfrom
|
||||
WHERE ps.programmingid = {$programming->id}
|
||||
AND pr.programmingid = {$programming->id}
|
||||
AND pr.latestsubmitid = ps.id
|
||||
AND ra.roleid = $roleid
|
||||
AND ra.contextid = $context->id
|
||||
AND pr.userid = ra.userid
|
||||
$gwhere");
|
||||
$codeavg = intval($codeavg->codelines);
|
||||
array_push($stat_results,
|
||||
array('name' => $name,
|
||||
'studentcount' => $studentcount,
|
||||
'submitcount' => $submitcount,
|
||||
'compiledcount' => $compiledcount,
|
||||
'passedcount' => $passedcount,
|
||||
'intimepassedcount' => $intimepassedcount,
|
||||
'averagelines' => $codeavg));
|
||||
return;
|
||||
}
|
||||
|
||||
function print_action_table() {
|
||||
global $CFG, $OUTPUT, $cm, $context;
|
||||
|
||||
echo '<table><tr><td>';
|
||||
if (has_capability('mod/programming:viewotherprogram', $context)) {
|
||||
echo $OUTPUT->single_button(new moodle_url('/mod/programming/package.php', array('id' => $cm->id)), get_string('package', 'programming'), 'get');
|
||||
}
|
||||
echo '</td><td>';
|
||||
if (has_capability('mod/programming:edittestcase', $context)) {
|
||||
echo $OUTPUT->single_button(new moodle_url('/mod/programming/rejudge.php', array('id' => $cm->id)), get_string('rejudge', 'programming'), 'get');
|
||||
}
|
||||
echo '</td></tr></table>';
|
||||
}
|
||||
|
||||
?>
|
||||
106
reports/testcase.php
Normal file
106
reports/testcase.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?PHP
|
||||
|
||||
require_once('../../../config.php');
|
||||
require_once('../lib.php');
|
||||
require_once($CFG->dirroot.'/lib/tablelib.php');
|
||||
|
||||
$a = optional_param('a', 0, PARAM_INT); // programming ID
|
||||
|
||||
if (! $programming = get_record('programming', 'id', $a)) {
|
||||
error('Course module is incorrect');
|
||||
}
|
||||
if (! $course = get_record('course', 'id', $programming->course)) {
|
||||
error('Course is misconfigured');
|
||||
}
|
||||
if (! $cm = get_coursemodule_from_instance('programming', $programming->id, $course->id)) {
|
||||
error('Course Module ID was incorrect');
|
||||
}
|
||||
$context = context_module::instance($cm->id);
|
||||
|
||||
require_login($course->id);
|
||||
require_capability('mod/programming:viewreport', $context);
|
||||
|
||||
|
||||
/// Print the page header
|
||||
$pagename = get_string('reports', 'programming');
|
||||
$CFG->scripts[] = 'http://www.google.com/jsapi';
|
||||
include_once('../pageheader.php');
|
||||
|
||||
/// Print tabs
|
||||
$currenttab = 'reports';
|
||||
$currenttab2 = 'summary';
|
||||
include_once('../tabs.php');
|
||||
|
||||
/// Print the main part of the page
|
||||
echo '<div class="maincontent generalbox">';
|
||||
print_testcase_chart($programming->id);
|
||||
echo '</div>';
|
||||
|
||||
/// Finish the page
|
||||
$OUTPUT->footer($course);
|
||||
|
||||
function print_testcase_chart($programmingid) {
|
||||
global $CFG;
|
||||
|
||||
$j = array('AC', 'WA', 'RE');
|
||||
$sql = "SELECT * FROM (
|
||||
SELECT id AS testid, seq, weight, pub
|
||||
FROM {$CFG->prefix}programming_tests
|
||||
WHERE programmingid = {$programmingid}
|
||||
) AS pt";
|
||||
foreach ($j as $r) {
|
||||
$sql .= " LEFT JOIN \n";
|
||||
$sql .= "(SELECT testid, COUNT(*) AS $r
|
||||
FROM {$CFG->prefix}programming_result AS pr,
|
||||
{$CFG->prefix}programming_test_results AS ptr
|
||||
WHERE pr.programmingid = {$programmingid}
|
||||
AND ptr.submitid = pr.latestsubmitid
|
||||
AND ptr.judgeresult='$r'
|
||||
GROUP BY testid) AS SE{$r}";
|
||||
$sql .= " USING (testid)\n";
|
||||
}
|
||||
$sql .= "ORDER BY seq";
|
||||
|
||||
#print "<pre>$sql</pre";
|
||||
|
||||
|
||||
$table = new flexible_table('testcase-table');
|
||||
$table->define_columns(array('seq', 'weight', 'pub', 'ac', 'wa', 're'));
|
||||
$headers = array(
|
||||
get_string('testcase', 'programming'),
|
||||
get_string('weight', 'programming'),
|
||||
get_string('public', 'programming'),
|
||||
get_string('AC', 'programming'),
|
||||
get_string('WA', 'programming'),
|
||||
get_string('RE', 'programming'),
|
||||
);
|
||||
$table->define_headers($headers);
|
||||
|
||||
#$table->pagesize($perpage, $total);
|
||||
$table->set_attribute('cellspacing', '0');
|
||||
$table->set_attribute('id', 'detail-table');
|
||||
$table->set_attribute('class', 'generaltable generalbox');
|
||||
$table->set_attribute('align', 'center');
|
||||
$table->set_attribute('cellpadding', '3');
|
||||
$table->set_attribute('cellspacing', '1');
|
||||
$table->setup();
|
||||
|
||||
$rst = get_recordset_sql($sql);
|
||||
while ($row = $rst->FetchNextObject(false)) {
|
||||
$data = array();
|
||||
$data[] = $row->seq;
|
||||
$data[] = $row->weight;
|
||||
$data[] = programming_testcase_pub_getstring($row->pub);
|
||||
$data[] = $row->AC;
|
||||
$data[] = $row->WA;
|
||||
$data[] = $row->RE;
|
||||
$table->add_data($data);
|
||||
}
|
||||
$rst->Close();
|
||||
|
||||
$table->print_html();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user