public function add($order_id) { import('system/share/network/redirect'); AuthPlugins::required($this, array('销售经理', '销售顾问')); $order_id = abs(intval($order_id)); if (!$this->is_post() || !$order_id) { return false; } /* * 上传方案附件 */ import('system/share/io/filesystem'); FileSystem::init(); $file_path = FileSystem::Upload($_FILES['attachment'], false); if (!$file_path) { HTTPRedirect::flash_to('order/detail/' . $order_id, '文件上传失败:' . FileSystem::$message, $this->smarty); } /* * 写入方案表 */ parent::load('model', 'order'); $solution = new Solution(); $solution->order_id = $order_id; $solution->solution_code = trim(strip_tags($_POST['solution_code'])); $solution->name = trim(strip_tags($_POST['name'])); $solution->attachment = $file_path; $solution->price = abs(intval($_POST['price'])); $solution->save(); HTTPRedirect::flash_to('order/detail/' . $order_id, '添加方案成功', $this->smarty); }
function list_import_prepare() { $CI =& get_instance(); $periods = new Period(); $periods->truncate(); echo 'LIST periods table truncated ...' . "\n"; $courses = new Course(); $courses->truncate(); echo 'LIST courses table truncated ...' . "\n"; $groups = new Group(); $groups->truncate(); echo 'LIST groups table truncated ...' . "\n"; $rooms = new Room(); $rooms->truncate(); echo 'LIST rooms table truncated ...' . "\n"; $participants = new Participant(); $participants->truncate(); echo 'LIST participants table truncated ...' . "\n"; $CI->db->simple_query('TRUNCATE TABLE `course_task_set_type_rel`'); echo 'LIST course_task_set_type_rel table truncated ...' . "\n"; $categories = new Category(); $categories->truncate(); echo 'LIST categories table truncated ...' . "\n"; $tasks = new Task(); $tasks->truncate(); $CI->lang->delete_overlays('tasks'); unlink_recursive('private/uploads/task_files/', FALSE); unlink_recursive('private/uploads/unit_tests/', FALSE); echo 'LIST tasks table truncated ...' . "\n"; $CI->db->simple_query('TRUNCATE TABLE `task_category_rel`'); echo 'LIST task_category_rel table truncated ...' . "\n"; $task_set_types = new Task_set_type(); $task_set_types->truncate(); echo 'LIST task_set_types table truncated ...' . "\n"; $task_sets = new Task_set(); $task_sets->truncate(); $CI->lang->delete_overlays('task_sets'); echo 'LIST task_sets table truncated ...' . "\n"; $comments = new Comment(); $comments->truncate(); echo 'LIST comments table truncated ...' . "\n"; $solutions = new Solution(); $solutions->truncate(); unlink_recursive('private/uploads/solutions/', FALSE); echo 'LIST solutions table truncated ...' . "\n"; $CI->db->simple_query('TRUNCATE TABLE `task_task_set_rel`'); echo 'LIST task_task_set_rel table truncated ...' . "\n"; }
public function render() { $course = new Course(); $course->include_related('period'); $course->get_by_id((int) @$this->config['course_id']); $this->parser->assign('course', $course); if ($course->exists()) { $solutions = new Solution(); $solutions->select_func('COUNT', '@id', 'count'); $solutions->where('revalidate', 1); $solutions->where_related('task_set', 'id', '${parent}.id'); $solutions->where_related('student/participant/course', 'id', $course->id); $solutions->where_related('student/participant', 'allowed', 1); $task_sets = new Task_set(); $task_sets->select('*'); $task_sets->select_subquery($solutions, 'solutions_count'); $task_sets->where_related($course); $task_sets->where_related('solution', 'revalidate', 1); $task_sets->where_related('solution/student/participant/course', 'id', $course->id); $task_sets->where_related('solution/student/participant', 'allowed', 1); $task_sets->group_by('id'); $task_sets->order_by_with_overlay('name', 'ASC'); $task_sets->get_iterated(); $this->parser->assign('task_sets', $task_sets); } $this->parser->parse('widgets/admin/unevaluated_solutions/main.tpl'); }
/** * 编辑解决方案 * */ function actionEdit() { //创建表单 $form = new QForm('solution', url('solutions/edit')); $form->add(QForm::ELEMENT, 'id', array('_ui' => 'hidden'))->add(QForm::ELEMENT, 'name', array('_ui' => 'textbox', '_label' => '解决方案名'))->add(QForm::ELEMENT, 'content', array('_ui' => 'fckeditor', '_label' => '内容', 'class' => "txt", 'height' => '500px', 'width' => '60%')); $form->addValidations(Solution::meta()); $solu_id = (int) $this->_context->id; $data = Solution::find($solu_id)->query(); //导入数据 $form->import($data); if ($this->_context->isPOST() && $form->invalidate($_POST)) { try { $data->changeProps($form->values()); $data->save(); return $this->_redirectMessage('修改成功', '修改改页面成功', url('solutions/index')); } catch (QValidator_ValidateFailedException $ex) { $form->invalidate($ex); } } $this->_view['form'] = $form; }
<?php class Solution { public $m = ['a' => ['top' => ' __ ', 'mid' => '|__|', 'bot' => '| |'], 'b' => ['top' => ' __ ', 'mid' => '|__\\', 'bot' => '|__/'], 'c' => ['top' => ' __', 'mid' => '| ', 'bot' => '|__'], 'd' => ['top' => ' __ ', 'mid' => '| \\', 'bot' => '|__/'], 'e' => ['top' => ' __', 'mid' => '|_ ', 'bot' => '|__'], 'f' => ['top' => ' __ ', 'mid' => '|_ ', 'bot' => '| '], 'g' => ['top' => ' __ ', 'mid' => '| _ ', 'bot' => '|__|'], 'h' => ['top' => ' ', 'mid' => '|__|', 'bot' => '| |'], 'i' => ['top' => ' ', 'mid' => '|', 'bot' => '|'], 'j' => ['top' => ' - ', 'mid' => ' | ', 'bot' => ' _| '], 'k' => ['top' => ' ', 'mid' => '|_/', 'bot' => '| \\'], 'l' => ['top' => ' ', 'mid' => '| ', 'bot' => '|__'], 'm' => ['top' => ' ', 'mid' => '|\\/|', 'bot' => '| |'], 'n' => ['top' => ' ', 'mid' => '|\\ |', 'bot' => '| \\|'], 'o' => ['top' => ' __ ', 'mid' => '| |', 'bot' => '|__|'], 'p' => ['top' => ' __ ', 'mid' => '|__|', 'bot' => '| '], 'r' => ['top' => ' __ ', 'mid' => '| _|', 'bot' => '| \\'], 's' => ['top' => ' -- ', 'mid' => '|__ ', 'bot' => ' __|'], 't' => ['top' => '___', 'mid' => ' | ', 'bot' => ' | '], 'u' => ['top' => ' ', 'mid' => '| |', 'bot' => '|__|'], 'w' => ['top' => ' ', 'mid' => '| |', 'bot' => '|/\\|'], 'y' => ['top' => ' ', 'mid' => '\\_/', 'bot' => ' | '], 'z' => ['top' => ' __ ', 'mid' => ' / ', 'bot' => ' /_ ']]; public $ip, $arr; function run($ip) { $this->ip = $ip; $this->arr = explode(" ", strtolower($this->ip)); $this->printSeg('top'); $this->printSeg('mid'); $this->printSeg('bot'); } function printSeg($seg) { foreach ($this->arr as $k => $w) { $chArr = str_split($w); foreach ($chArr as $c) { echo $this->m[$c][$seg]; echo " "; } echo $k == count($this->arr) - 1 ? "\n" : " "; } } } $i = new Solution(); $i->run('how are you');
} else { if ($head->next == null) { $head->next = $p; } else { $start = $head; while ($start->next != null) { $start = $start->next; } $start->next = $p; } } return $head; } function display($head) { $start = $head; while ($start) { echo $start->data, ' '; $start = $start->next; } } } $T = intval(fgets(STDIN)); $head = null; $mylist = new Solution(); while ($T-- > 0) { $data = intval(fgets(STDIN)); $head = $mylist->insert($head, $data); } $head = $mylist->removeDuplicates($head); $mylist->display($head);
public $headNode = NULL; public $lastInsertedNode = NULL; function insert($head, $data) { if ($this->headNode === NULL) { $this->headNode = new Node($data); $this->lastInsertedNode = $this->headNode; } else { $LLNode = new Node($data); $this->lastInsertedNode->next = $LLNode; $this->lastInsertedNode = $LLNode; } return $this->headNode; } function display($head) { $start = $head; while ($start != null) { echo $start->data, ' '; $start = $start->next; } } } $T = intval(fgets(STDIN)); $head = null; $mylist = new Solution(); while ($T-- > 0) { $data = intval(fgets(STDIN)); $head = $mylist->insert($head, $data); } $mylist->display($head);
private function get_valuation_table_data($course_id, $group_id = NULL, $condensed = FALSE) { $table_data = array('header' => array(), 'content' => array()); $course = new Course(); $course->get_by_id(intval($course_id)); $group = new Group(); $group->get_by_id((int) $group_id); if ($course->exists()) { $students = new Student(); $students->select('id, fullname, email'); $students->include_related('participant/group', array('id', 'name')); $students->where_related('participant/course', 'id', $course->id); $students->where_related('participant', 'allowed', 1); $students->order_by_as_fullname('fullname'); if ($group->exists()) { $students->where_related('participant/group', 'id', (int) $group_id); } $students->get_iterated(); $task_sets_out_of_group_ids = array(0); $task_sets_data = array(); $task_sets_ids = array(); $projects_ids = array(); if ($group->exists()) { $students_filter = new Student(); $students_filter->select('id'); $students_filter->where_related('participant/course', 'id', $course->id); $students_filter->where_related('participant', 'allowed', 1); $students_filter->where_related('participant/group', 'id', (int) $group->id); $solutions_filter = new Solution(); $solutions_filter->select('id'); $solutions_filter->where_in_subquery('student_id', $students_filter); $task_sets_out_of_group = new Task_set(); $task_sets_out_of_group->select('id'); $task_sets_out_of_group->where_in_subquery('id', $solutions_filter); $task_sets_out_of_group->where('published', 1); $task_sets_out_of_group->get(); $task_sets_out_of_group_ids = $task_sets_out_of_group->all_to_single_array('id'); $task_sets_out_of_group_ids[] = 0; } $content_type_task_set = new Task_set(); $content_type_task_set->select('id, name, content_type, group_id, task_set_type_id'); $content_type_task_set->include_related('task_set_type', 'name'); $content_type_task_set->include_related('group', 'name'); $content_type_task_set->where('content_type', 'task_set'); $content_type_task_set->where('published', 1); $content_type_task_set->where_related_course($course); $content_type_task_set->order_by_related_with_constant('task_set_type', 'name', 'asc'); $content_type_task_set->order_by('task_set_type_id', 'asc'); $content_type_task_set->order_by('publish_start_time', 'asc'); if ($group->exists()) { $content_type_task_set->group_start(); $content_type_task_set->group_start('', 'OR '); $content_type_task_set->group_start(); $content_type_task_set->or_where('group_id', NULL); $content_type_task_set->or_where('group_id', (int) $group_id); $content_type_task_set->group_end(); $content_type_task_set->where_subquery(0, '(SELECT COUNT(`tsp`.`id`) AS `count` FROM `task_set_permissions` tsp WHERE `tsp`.`task_set_id` = `task_sets`.`id` AND `tsp`.`enabled` = 1)'); $content_type_task_set->group_end(); $content_type_task_set->group_start('', 'OR '); $content_type_task_set->where_related('task_set_permission', 'group_id', (int) $group_id); $content_type_task_set->where_related('task_set_permission', 'enabled', 1); $content_type_task_set->group_end(); $content_type_task_set->or_where_in('id', $task_sets_out_of_group_ids); $content_type_task_set->group_end(); } $content_type_task_set->get(); $header_items = array(); if ($content_type_task_set->result_count() > 0) { $last_task_set_type_id = NULL; foreach ($content_type_task_set->all as $task_set) { $permissions = new Task_set_permission(); $permissions->select('id, group_id'); $permissions->include_related('group', 'name'); $permissions->where_related_task_set($task_set); $permissions->where('enabled', 1); $permissions->get_iterated(); if ($permissions->result_count() > 0) { $group_ids = array(); $group_names = array(); foreach ($permissions as $permission) { $group_ids[] = $permission->group_id; $group_names[] = $this->lang->text($permission->group_name); } $task_sets_data[$task_set->id] = array('group_id' => $group_ids, 'group_name' => $group_names); } else { $task_sets_data[$task_set->id] = array('group_id' => array($task_set->group_id), 'group_name' => $this->lang->text($task_set->group_name)); } if ($task_set->task_set_type_id !== $last_task_set_type_id) { $last_task_set_type_id = $task_set->task_set_type_id; $header_items[] = array('type' => 'task_set_type', 'id' => $task_set->task_set_type_id, 'name' => $this->lang->text($task_set->task_set_type_name), 'title' => ''); } if (!$condensed) { $header_items[] = array('type' => 'task_set', 'id' => $task_set->id, 'name' => $this->lang->get_overlay_with_default('task_sets', $task_set->id, 'name', $task_set->name), 'title' => is_array($task_sets_data[$task_set->id]['group_name']) ? implode(', ', $task_sets_data[$task_set->id]['group_name']) : $task_sets_data[$task_set->id]['group_name']); } $task_sets_ids[] = $task_set->id; } } $table_data['header']['content_type_task_set'] = array('content_type_name' => $this->lang->line('admin_solutions_valuation_tables_header_content_type_task_sets'), 'items' => $header_items); $content_type_project = new Task_set(); $content_type_project->where('content_type', 'project'); $content_type_project->where('published', 1); $content_type_project->where_related_course($course); $content_type_project->order_by_related_with_constant('task_set_type', 'name', 'asc'); $content_type_project->order_by('publish_start_time', 'asc'); $content_type_project->get(); $header_items = array(); if ($content_type_project->result_count() > 0) { foreach ($content_type_project->all as $project) { if (!$condensed) { $header_items[] = array('type' => 'task_set', 'id' => $project->id, 'name' => $this->lang->get_overlay_with_default('task_sets', $project->id, 'name', $project->name), 'title' => ''); } $projects_ids[] = $project->id; } } $table_data['header']['content_type_project'] = array('content_type_name' => $this->lang->line('admin_solutions_valuation_tables_header_content_type_project'), 'items' => $header_items); foreach ($students as $student) { $student_line = array('fullname' => $student->fullname, 'email' => $student->email, 'id' => $student->id, 'total_points' => 0, 'task_sets_points' => array(), 'task_sets_points_total' => 0, 'projects_points' => array(), 'projects_points_total' => 0); $solutions_data = array(); if ($content_type_task_set->result_count() > 0 || $content_type_project->result_count() > 0) { $solutions = new Solution(); $solutions->select('task_set_id, points, tests_points, not_considered, revalidate'); $solutions->where_related_student($student); $solutions->group_start(); if (count($task_sets_ids) > 0) { $solutions->or_where_in('task_set_id', $task_sets_ids); } if (count($projects_ids) > 0) { $solutions->or_where_in('task_set_id', $projects_ids); } $solutions->group_end(); $solutions->get_iterated(); foreach ($solutions as $solution) { $solutions_data[$solution->task_set_id] = array('points' => is_null($solution->points) && is_null($solution->tests_points) ? NULL : $solution->points + $solution->tests_points, 'not_considered' => $solution->not_considered, 'revalidate' => $solution->revalidate); } } $task_sets_points_array = array(); if ($content_type_task_set->result_count() > 0) { $task_sets_points = 0; $last_task_set_type_id = NULL; $last_task_set_type_key = NULL; foreach ($content_type_task_set->all as $task_set) { if ($last_task_set_type_id !== $task_set->task_set_type_id) { $last_task_set_type_id = $task_set->task_set_type_id; $task_sets_points_array[] = array('type' => 'task_set_type', 'points' => 0, 'flag' => 'ok'); $last_task_set_type_key = count($task_sets_points_array) - 1; } $points = 0; if (isset($solutions_data[$task_set->id])) { if ($solutions_data[$task_set->id]['not_considered']) { if (!$condensed) { $task_sets_points_array[] = array('type' => 'task_set', 'points' => '*', 'flag' => 'notConsidered'); } } else { if (is_null($solutions_data[$task_set->id]['points'])) { if (!$condensed) { $task_sets_points_array[] = array('type' => 'task_set', 'points' => '!', 'flag' => 'revalidate'); } } elseif ($solutions_data[$task_set->id]['revalidate']) { if (!$condensed) { $task_sets_points_array[] = array('type' => 'task_set', 'points' => $solutions_data[$task_set->id]['points'], 'flag' => 'revalidate'); } $points = floatval($solutions_data[$task_set->id]['points']); } else { if (!$condensed) { $task_sets_points_array[] = array('type' => 'task_set', 'points' => $solutions_data[$task_set->id]['points'], 'flag' => 'ok'); } $points = floatval($solutions_data[$task_set->id]['points']); } } } else { if (!$condensed) { if (!is_null($task_sets_data[$task_set->id]['group_id'][0]) && !in_array($student->participant_group_id, $task_sets_data[$task_set->id]['group_id'])) { $task_sets_points_array[] = array('type' => 'task_set', 'points' => '-', 'flag' => 'notInGroup'); } else { $task_sets_points_array[] = array('type' => 'task_set', 'points' => 'x', 'flag' => 'notSubmitted'); } } } $task_sets_points += $points; $task_sets_points_array[$last_task_set_type_key]['points'] += $points; $student_line['total_points'] += $points; $student_line['task_sets_points_total'] = $task_sets_points; } } $student_line['task_sets_points'] = $task_sets_points_array; $task_sets_points_array = array(); if ($content_type_project->result_count() > 0) { $task_sets_points = 0; foreach ($content_type_project as $task_set) { $points = 0; if (isset($solutions_data[$task_set->id])) { if ($solutions_data[$task_set->id]['not_considered']) { if (!$condensed) { $task_sets_points_array[] = array('type' => 'task_set', 'points' => '*', 'flag' => 'notConsidered'); } } else { if (is_null($solutions_data[$task_set->id]['points'])) { if (!$condensed) { $task_sets_points_array[] = array('type' => 'task_set', 'points' => '!', 'flag' => 'revalidate'); } } elseif ($solutions_data[$task_set->id]['revalidate']) { if (!$condensed) { $task_sets_points_array[] = array('type' => 'task_set', 'points' => $solutions_data[$task_set->id]['points'], 'flag' => 'revalidate'); } $points = floatval($solutions_data[$task_set->id]['points']); } else { if (!$condensed) { $task_sets_points_array[] = array('type' => 'task_set', 'points' => $solutions_data[$task_set->id]['points'], 'flag' => 'ok'); } $points = floatval($solutions_data[$task_set->id]['points']); } } } else { if (!$condensed) { $task_sets_points_array[] = array('type' => 'task_set', 'points' => 'x', 'flag' => 'notSubmitted'); } } $task_sets_points += $points; $student_line['total_points'] += $points; $student_line['projects_points_total'] = $task_sets_points; } } $student_line['projects_points'] = $task_sets_points_array; $table_data['content'][] = $student_line; } } return $table_data; }
public function index($worker_id = 0) { $test_queue = new Test_queue(); $execute_tests = FALSE; try { $this->db->query('SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;'); $this->db->trans_begin(); $test_queue->where('worker', NULL); $test_queue->where('status', 0); $test_queue->where('version >', 0); $test_queue->group_start(' NOT '); $test_queue->where('task_set_id', NULL); $test_queue->group_end(); $test_queue->group_start(' NOT '); $test_queue->where('student_id', NULL); $test_queue->group_end(); $test_queue->order_by('priority', 'asc'); $test_queue->order_by('start', 'asc'); $test_queue->limit(1); $sql_query = $test_queue->get_sql(); $sql_query = rtrim($sql_query, '; ' . "\n\r") . ' FOR UPDATE;'; $test_queue->query($sql_query); if ($test_queue->exists()) { $test_queue->worker = (int) $worker_id; $test_queue->status = 1; $test_queue->exec_start = date('Y-m-d H:i:s'); $test_queue->where('worker', NULL); $test_queue->where('status', 0); if ($test_queue->save()) { $this->db->trans_commit(); $execute_tests = TRUE; } else { $this->db->trans_rollback(); } } else { $this->db->trans_rollback(); } } catch (Exception $e) { } if ($test_queue->exists() && $execute_tests) { //$this->db->query('SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;'); //$this->db->trans_begin(); $this->lang->reinitialize_for_idiom($test_queue->system_language); $this->lang->load('admin/tests'); $task_set = new Task_set(); $task_set->include_related('course', 'test_scoring_deadline'); $task_set->get_by_id($test_queue->task_set_id); $student = new Student(); $student->get_by_id($test_queue->student_id); $tests = new Test(); $tests->where_related($test_queue); $tests->get_iterated(); try { if ($task_set->exists() && $student->exists() && $tests->exists()) { $version = $test_queue->version; $run_evaluation = $task_set->enable_tests_scoring > 0 && $task_set->course_test_scoring_deadline >= date('Y-m-d H:i:s') ? TRUE : FALSE; $score_percent = array(); $score_points = array(); $bonus_percent = array(); $bonus_points = array(); $total_tests_count = $tests->result_count(); foreach ($tests as $test) { $test_queue->single_test_exec_start = date('Y-m-d H:i:s'); $test_queue->save(); $files = $task_set->get_student_files($student->id, (int) $version); if (isset($files[(int) $version]['filepath']) && file_exists($files[(int) $version]['filepath'])) { $test_object = $this->load->test($test->type); $test_object->initialize($test); $token = ''; //echo 'Test queue ' . $test_queue->id . ' is running test ' . $test->id . ' ... ' . PHP_EOL; try { $test_output = $test_object->run($files[(int) $version]['filepath'], $run_evaluation && $test->enable_scoring > 0, $student->id, $token); $test_score = $test_object->get_last_test_score(); } catch (Exception $e) { $test_output = $e->getMessage(); $test_score = 0; } $test_queue->set_join_field($test, 'result_text', $test_output); $test_queue->set_join_field($test, 'evaluation_table', $test_object->get_last_test_scoring()); $test_queue->set_join_field($test, 'result', $test_object->get_last_exit_code()); //echo 'Test queue ' . $test_queue->id . ' is done with test ' . $test->id . ' ... ' . PHP_EOL; if ($run_evaluation && $test->enable_scoring > 0) { $this->db->select('*'); $task_id = $test->task_id; $this->db->where('task_set_id', $task_set->id); $this->db->where('task_id', (int) $task_id); $query = $this->db->get('task_task_set_rel'); if ($query->num_rows() > 0) { $task_rel = $query->row_object(); $min = (double) $task_rel->test_min_points; $max = (double) $task_rel->test_max_points; $percent = (double) $test_score / 100.0; $points = (1.0 - $percent) * $min + $percent * $max; if ($task_rel->bonus_task == 0) { $test_queue->set_join_field($test, 'percent_points', $test_score); $test_queue->set_join_field($test, 'points', $points); $score_percent[$task_id] = isset($score_percent[$task_id]) ? $score_percent[$task_id] + $percent : $percent; $percent = (double) $score_percent[$task_id]; $points = (1.0 - $percent) * $min + $percent * $max; $score_points[$task_id] = $points; } else { $test_queue->set_join_field($test, 'percent_bonus', $test_score); $test_queue->set_join_field($test, 'bonus', $points); $bonus_percent[$task_id] = isset($bonus_percent[$task_id]) ? $bonus_percent[$task_id] + $percent : $percent; $percent = (double) $bonus_percent[$task_id]; $points = (1.0 - $percent) * $min + $percent * $max; $bonus_points[$task_id] = $points; } } $query->free_result(); } } else { //$this->db->trans_rollback(); $test_queue->worker = NULL; $test_queue->status = 3; $test_queue->finish = date('Y-m-d H:i:s'); $test_queue->save(); die; } } $tests = new Test(); $tests->where_related('task/task_set', 'id', $task_set->id); $tests->where('type', $test_queue->test_type); $tests->where('enable_scoring >', 0); $tests->group_by('task_id'); $tests->where('task_task_task_set_rel.bonus_task', 0); $tests->get_iterated(); $test_count = $tests->result_count(); $min_results = $task_set->test_min_needed > $test_count ? $test_count : $task_set->test_min_needed; $course = new Course(); $course->where_related_task_set('id', $task_set->id); $course->get(); $min_points_limit = -$course->default_points_to_remove; if ($test_count > 0 && $run_evaluation) { $max_results = $task_set->test_max_allowed < count($score_points) ? $task_set->test_max_allowed : count($score_points); arsort($score_points, SORT_NUMERIC); $i = 0; $total_score = 0; foreach ($score_points as $task_id => $points) { if ($i < $max_results) { $total_score += $points; $i++; } else { break; } } $total_score = $total_score < $min_points_limit ? $min_points_limit : $total_score; $total_bonus = array_sum($bonus_points); $total_score += $total_bonus; if (count($score_points) >= $min_results) { $solution = new Solution(); $solution->where('task_set_id', $task_set->id); $solution->where('student_id', $student->id); $solution->get(); $save_solution = FALSE; $solution_not_considered = FALSE; $solution_disable_evaluation = FALSE; $best_old_score = $min_points_limit; if ($solution->exists()) { if ($solution->not_considered == 0) { if ($solution->disable_evaluation_by_tests == 0) { if ($solution->tests_points < $total_score || is_null($solution->tests_points)) { $solution->tests_points = $total_score; $solution->teacher_id = NULL; $solution->best_version = (int) $version; $solution->revalidate = 0; $save_solution = TRUE; } else { $best_old_score = $solution->tests_points; } } else { $solution_disable_evaluation = TRUE; } } else { $solution_not_considered = TRUE; } } else { $solution->tests_points = $total_score; $solution->comment = ''; $solution->teacher_id = NULL; $solution->best_version = (int) $version; $solution->task_set_id = $task_set->id; $solution->student_id = $student->id; $solution->revalidate = 0; $save_solution = TRUE; } if ($save_solution) { $solution->save(); $this->parser->clearCache('frontend/tasks/index.tpl'); $test_queue->result_message = $this->lang->line('admin_tests_test_result_new_points_added'); } else { if (!$solution_disable_evaluation) { if (!$solution_not_considered) { $test_queue->result_message = sprintf($this->lang->line('admin_tests_test_result_nothing_to_update'), $total_score, $best_old_score); } else { $test_queue->result_message = $this->lang->line('admin_tests_test_result_solution_not_considered'); } } else { $test_queue->result_message = $this->lang->line('admin_tests_test_result_solution_disable_evaluation'); } } $test_queue->points = $total_score - $total_bonus; $test_queue->bonus = $total_bonus; } else { $test_queue->result_message = sprintf($this->lang->line('admin_tests_test_result_minimum_number_of_test_not_selected'), $min_results); } $result_table_tasks = new Task(); $result_table_tasks->where_related_task_set('id', $task_set->id); $result_table_tasks->order_by('`task_task_set_rel`.`sorting`', 'asc'); $result_table_tasks->get_iterated(); $test_queue->result_html = $this->parser->parse('backend/tests/evaluation_table.tpl', array('tasks' => $result_table_tasks, 'real_points' => $score_points, 'bonus_points' => $bonus_points, 'real_percentage' => $score_percent, 'bonus_percentage' => $bonus_percent, 'max_results' => $max_results), TRUE); $test_queue->worker = NULL; $test_queue->status = 2; $test_queue->finish = date('Y-m-d H:i:s'); $test_queue->save(); //$this->db->trans_commit(); } else { if ($total_tests_count && !$run_evaluation) { $test_queue->worker = NULL; $test_queue->status = 2; $test_queue->finish = date('Y-m-d H:i:s'); $test_queue->result_message = $this->lang->line('admin_tests_test_result_testing_finished'); $test_queue->save(); //$this->db->trans_commit(); } else { //$this->db->trans_rollback(); $test_queue->worker = NULL; $test_queue->status = 3; $test_queue->finish = date('Y-m-d H:i:s'); $test_queue->result_message = $this->lang->line('admin_tests_test_result_no_test_selected'); $test_queue->save(); } } } else { //$this->db->trans_rollback(); $test_queue->worker = NULL; $test_queue->status = 3; $test_queue->finish = date('Y-m-d H:i:s'); $test_queue->result_message = $this->lang->line('admin_tests_test_result_configuration_error'); $test_queue->save(); } } catch (Exception $e) { //$this->db->trans_rollback(); $test_queue->worker = NULL; $test_queue->status = 3; $test_queue->finish = date('Y-m-d H:i:s'); $test_queue->result_message = $this->lang->line('admin_tests_test_result_execution_error'); $test_queue->result_html = '<pre>' . $e->getMessage() . '</pre>'; $test_queue->save(); } } //@unlink($test_locks_path . 'worker_' . (int)$worker_id . '_lock.txt'); }
public function run_comparation() { $task_sets_setup_data = $this->input->post('task_sets_setup'); $solutions_data = $this->input->post('solutions'); $moss_setup_data = $this->input->post('moss_setup'); $moss_base_files_data = $this->input->post('moss_base_files'); $course = new Course(); $course->get_by_id((int) $task_sets_setup_data['course']); $task_set = new Task_set(); $task_set->where_related($course); $task_set->get_by_id(isset($task_sets_setup_data['task_set']) ? (int) $task_sets_setup_data['task_set'] : 0); $this->config->load('moss'); $languages = $this->config->item('moss_langs_for_list'); asort($languages); $this->parser->assign(array('course' => $course, 'task_set' => $task_set, 'languages' => $languages)); $this->parser->assign('moss_enabled', $this->is_moss_user_id_set()); if ($course->exists() && $task_set->exists()) { $this->load->library('form_validation'); $this->form_validation->set_rules('solutions', 'lang:admin_moss_list_solutions_form_field_solution_selection', 'callback__selected_solutions'); $this->form_validation->set_rules('moss_setup[l]', 'lang:admin_moss_list_solutions_form_field_language', 'required'); $this->form_validation->set_rules('moss_setup[m]', 'lang:admin_moss_list_solutions_form_field_sensitivity', 'required|integer|greater_than[1]'); $this->form_validation->set_rules('moss_setup[n]', 'lang:admin_moss_list_solutions_form_field_matching_files', 'required|integer|greater_than[1]'); $this->form_validation->set_message('_selected_solutions', $this->lang->line('admin_moss_list_solutions_validation_callback_selected_solutions')); if ($this->form_validation->run() && $this->is_moss_user_id_set()) { $solutions = new Solution(); $solutions->include_related('student'); $solutions->where_related($task_set); $solutions->order_by_related_as_fullname('student', 'fullname', 'asc'); $solutions->get_iterated(); $this->parser->assign('solutions', $solutions); $tasks = new Task(); $tasks->where_related($task_set); $tasks->get_iterated(); $base_files_list = array(); foreach ($tasks as $task) { $base_files_list[$task->id] = array('task_id' => $task->id, 'task_name' => $this->lang->get_overlay_with_default('tasks', $task->id, 'name', $task->name), 'files' => $this->construct_base_files_for_task($task->id)); } $this->parser->assign('base_files_list', $base_files_list); $path = $this->get_random_hash_folder($course->id, $task_set->id); $path_source = $path . '/source'; $path_base = $path . '/base'; @mkdir($path_source, DIR_WRITE_MODE, TRUE); @mkdir($path_base, DIR_WRITE_MODE, TRUE); $all_extracted = TRUE; $moss_langs_extensions = $this->config->item('moss_langs_file_extensions'); if (isset($moss_langs_extensions[$moss_setup_data['l']])) { $file_extensions = $moss_langs_extensions[$moss_setup_data['l']]; } else { $all_extracted = FALSE; } foreach ($solutions_data as $id => $config) { if (!$all_extracted) { break; } if (isset($config['selected']) && $config['selected'] == 1) { set_time_limit(120); $version = isset($config['version']) ? $config['version'] : 0; $student = isset($config['student']) ? $config['student'] : 0; $file = $task_set->get_student_files($student, $version); if (count($file) == 1) { $file = $file[$version]; $subdir = '/' . normalize($file['file_name']) . '_sid-' . $file['student_id'] . '_ver-' . $file['version']; $extract_path = $path_source . $subdir; @mkdir($extract_path, DIR_WRITE_MODE, TRUE); $status = $task_set->extract_student_zip_to_folder($file['file'], $extract_path, $file_extensions); $all_extracted = $all_extracted && $status; } } } if (is_array($moss_base_files_data) && count($moss_base_files_data)) { foreach ($moss_base_files_data as $task_id => $path_array) { if (!$all_extracted) { break; } if (is_array($path_array) && count($path_array)) { foreach ($path_array as $path_hash => $file_path) { if (!$all_extracted) { break; } if (preg_match('/\\.zip(?P<indexNumberBox>\\[(?P<zipIndexNumber>[0-9]+)\\])$/', $file_path, $matches)) { $zipfile = mb_substr($file_path, 0, mb_strlen($file_path) - mb_strlen($matches['indexNumberBox'])); $zipindex = (int) $matches['zipIndexNumber']; $zip = new ZipArchive(); if ($zip->open($zipfile)) { set_time_limit(120); @mkdir($path_base . '/' . $task_id . '/' . $path_hash, DIR_WRITE_MODE, TRUE); if (!$zip->extractTo($path_base . '/' . $task_id . '/' . $path_hash, $zip->getNameIndex($zipindex))) { $all_extracted = FALSE; } $zip->close(); } else { $all_extracted = FALSE; } } else { set_time_limit(120); @mkdir($path_base . '/' . $task_id . '/' . $path_hash, DIR_WRITE_MODE, TRUE); $path_info = pathinfo($file_path); if (!copy($file_path, $path_base . '/' . $task_id . '/' . $path_hash . '/' . $path_info['basename'])) { $all_extracted = FALSE; } } } } } } if (!$all_extracted) { unlink_recursive($path, TRUE); } $this->parser->assign('all_extracted', $all_extracted); $this->parser->assign('path', $path); $this->parser->assign('moss_config', $moss_setup_data); $this->parser->parse('backend/moss/run_comparation.tpl'); } else { $this->list_solutions(); } } }
public function upload_solution($task_set_id_url, $task_id_url) { $task_set_id = url_get_id($task_set_id_url); $task_id = url_get_id($task_id_url); $this->_transaction_isolation(); $this->db->trans_begin(); $date = date('Y-m-d H:i:s'); $student = new Student(); $student->get_by_id($this->usermanager->get_student_id()); $course = new Course(); $course->where_related('active_for_student', 'id', $student->id); $course->where_related('participant', 'student_id', $student->id); $course->where_related('participant', 'allowed', 1); $course->include_related('period', 'name'); $course->get(); $task_set = new Task_set(); $task_set->where_related($course); $task_set->where('published', 1); $task_set->group_start(); $task_set->where('publish_start_time <=', $date); $task_set->or_where('publish_start_time', NULL); $task_set->group_end(); $task_set->get_by_id($task_set_id); $task = $task_set->task->include_join_fields()->get_by_id($task_id); $project_selection = new Project_selection(); $project_selection->where_related($student); $project_selection->where_related($task_set); $project_selection->where_related($task); $project_selection->get(); if ($student->exists() && $course->exists() && $task_set->exists() && $task->exists() && $project_selection->exists()) { if ($date <= $task_set->upload_end_time) { $config['upload_path'] = 'private/uploads/solutions/task_set_' . intval($task_set_id) . '/'; $config['allowed_types'] = 'zip'; $config['max_size'] = intval($this->config->item('maximum_solition_filesize')); $current_version = $task_set->get_student_file_next_version($student->id); $config['file_name'] = $student->id . '_' . $this->normalize_student_name($student) . '_' . substr(md5(time() . rand(-500000, 500000)), 0, 4) . '_' . $current_version . '.zip'; @mkdir($config['upload_path'], DIR_READ_MODE); $this->load->library('upload', $config); if ($this->upload->do_upload('file')) { $solution = new Solution(); $solution->where('task_set_id', $task_set->id); $solution->where('student_id', $student->id); $solution->get(); $revalidate = 1; if ($solution->exists()) { $solution->ip_address = $_SERVER["REMOTE_ADDR"]; $solution->revalidate = $revalidate; $solution->save(); } else { $solution = new Solution(); $solution->ip_address = $_SERVER["REMOTE_ADDR"]; $solution->revalidate = $revalidate; $solution->save(array('student' => $student, 'task_set' => $task_set)); } $solution_version = new Solution_version(); $solution_version->ip_address = $_SERVER["REMOTE_ADDR"]; $solution_version->version = $current_version; $solution_version->save($solution); if ($this->db->trans_status()) { $log = new Log(); $log->add_student_solution_upload_log(sprintf($this->lang->line('projects_task_solution_upload_log_message'), $config['file_name']), $student, $solution->id); $this->db->trans_commit(); $this->messages->add_message('lang:projects_task_solution_uploaded', Messages::MESSAGE_TYPE_SUCCESS); $this->_action_success(); $this->output->set_internal_value('task_set_id', $solution->task_set_id); $this->output->set_internal_value('task_id', $task->id); } else { $this->db->trans_rollback(); @unlink($config['upload_path'] . $config['file_name']); $this->messages->add_message('lang:projects_task_solution_canceled_due_db_error', Messages::MESSAGE_TYPE_ERROR); } redirect(create_internal_url('projects/task/' . $task_set_id_url . '/' . $task_id_url)); } else { $this->db->trans_rollback(); $this->parser->assign('file_error_message', $this->upload->display_errors('', '')); $this->task($task_set_id_url, $task_id_url); } } else { $this->db->trans_rollback(); $this->messages->add_message('lang:projects_task_solution_upload_time_error', Messages::MESSAGE_TYPE_ERROR); redirect(create_internal_url('projects/task/' . $task_set_id_url . '/' . $task_id_url)); } } else { $this->db->trans_rollback(); $this->messages->add_message('lang:projects_task_solution_database_data_wrong_error', Messages::MESSAGE_TYPE_ERROR); redirect(create_internal_url('projects/task/' . $task_set_id_url . '/' . $task_id_url)); } }
<?php global $user; if (isset($mo_request[1]) && is_numeric($mo_request[1])) { $solution = new Solution($mo_request[1]); $solution->load(); if (!$solution->getSID() || $solution->getInfo('uid') != $user->getUID()) { require_once $mo_theme_floder . '404.php'; } echo '<h2>提交:#' . $solution->getInfo('id') . '</h2>'; echo '用户:#' . $solution->getInfo('uid') . '<br>'; echo '问题:#<a href="/?r=problem/' . $solution->getInfo('pid') . '">' . $solution->getInfo('pid') . '</a><br>'; echo '语言:#' . $solution->getInfo('language') . '<br>'; echo '评测机:#' . $solution->getInfo('client') . '<br><br>'; if ($solution->getInfo('state') <= 0) { echo '评测中,当前状态:' . $solution->getInfo('state') . '<br>'; } else { echo '总耗时:' . $solution->getInfo('used_time') . 'MS 最大使用内存:' . $solution->getInfo('used_memory') . 'KB<br>'; echo '<table width="100%" border="1"> <tbody> <tr> <td width="20%"><strong>测试数据</strong></td> <td width="30%"><strong>耗时(MS)</strong></td> <td width="30%"><strong>内存(KB)</strong></td> <td width="20%"><strong>结果</strong></td> </tr>'; $detail_time = explode(' ', $solution->getInfo('detail_time')); $detail_memory = explode(' ', $solution->getInfo('detail_memory')); $detail_result = explode(' ', $solution->getInfo('detail_result')); $turn = count($detail_result); for ($i = 0; $i < $turn && $detail_result[$i]; ++$i) {
public function runQuery($s) { $qc = new QueryCompiler($this); $this->reset(); $this->p->deleteFrom("query\$"); $s = trim($s); $query = $qc->compile($s); if ($query == null) { // query could not be compiled $this->writeLn("Illegal query."); return true; } else { if ($this->debugOn > 1) { // if in debug mode, display query WAM code $this->writeLn("----- BEGIN QUERYCODE -----"); $this->writeLn($query->__toString()); $this->writeLn("------ END QUERYCODE ------"); } $this->p->addProgram($query); // add query to program in memory and $this->p->updateLabels(); // update the labels for jumping hin und her } // reset the WAM's registers and jump to label "query$" (the current query, of course) $this->programCounter = $this->p->getLabelIndex("query\$"); $stackResult = array(); $getOut = false; do { $result = new Solution(); $this->stringBuffer = $result; $ms = microtime(true); $this->run(); $result->elapsedTime = microtime(true) - $ms; $result->opCount = $this->opCount; $result->backtrackCount = $this->backtrackCount; $this->writeLn(""); if ($this->failed) { // if execution failed, just tell that $result->succeed = false; $this->writeLn("Failed."); $getOut = true; } else { $result->succeed = true; // if there are any query variables (e.g. in "start(X, Y)", X and Y would be such variables), // display their current values and ask the user if he/she wants to see more possible solutions if ($this->displayQCount > 0) { $this->write("Success: "); $cnt = 0; for ($i = 0; $i < 100; $i++) { // yes, we do not allow more than 100 query variables! if ($this->displayQValue[$i]) { $key = $this->queryVariables[$i]->name; $value = $this->queryVariables[$i]; $result->setQueryVar($key, $value->toArrayValue()); $cnt++; // if Q[i] is to be displayed, just do that $this->write($key . " = " . $value); if ($cnt < $this->displayQCount) { $this->write(", "); } else { $this->writeLn("."); } } } } else { $this->writeLn("Success."); } // we see other choice while there is any if ($this->choicePoint !== null) { $this->backtrack(); } else { $getOut = true; } } $stackResult[] = $result; } while (!$getOut); $this->reset(); return $stackResult; }
$connection->name = ''; $connection->last_ping = 0; $connection->deadline = Timer::add(5, function () use($connection) { Timer::del($connection->deadline); $connection->deadline = 0; sendMsg($connection, array('action' => 'refuse')); $connection->close(); p("A client timeout logging in. ( IP = {$connection->IP} )"); }); p("A new client has joined. ( IP = {$connection->IP} )"); }; $worker_tasker->onMessage = function ($connection, $data) { $data = json_decode($data, True); if ($connection->IP == '127.0.0.1' && isset($data['pass'], $data['task']) && $data['pass'] == sha1(DB_PASS)) { if (!isset($data['task']['action'])) { $solution = new Solution($data['task']); $solution->push(); return; } else { switch ($data['task']['action']) { case 'kill': kill_client($data['task']['cid']); break; } } } if ($data == NULL || !isset($data['action'])) { p("Json decoding failed or in bad format. ( cid = {$connection->cid}, IP = {$connection->IP} )"); return; } switch ($data['action']) {
public function details($log_id) { $log = new Log(); $log->include_related('student'); $log->include_related('teacher'); $log->get_by_id($log_id); if ($log->exists()) { if ($log->log_type == Log::LOG_TYPE_STUDENT_SOLUTION_UPLOAD || $log->log_type == Log::LOG_TYPE_TEACHER_SOLUTION_UPLOAD) { $solution = new Solution(); $solution->include_related('student'); $solution->include_related('task_set'); $solution->include_related('task_set/course'); $solution->include_related('task_set/course/period'); $solution->get_by_id((int) $log->affected_row_primary_id); $this->parser->assign('solution', $solution); } elseif ($log->log_type == Log::LOG_TYPE_STUDENT_SOLUTION_DOWNLOAD) { $additional_data = unserialize($log->additional_data); $task_set = new Task_set(); $task_set->include_related('course'); $task_set->include_related('course/period'); $task_set->get_by_id(@$additional_data['task_set_id']); $this->parser->assign(array('task_set' => $task_set, 'filename' => @$additional_data['solution_file'])); } } $this->parser->add_css_file('admin_logs.css'); $this->parser->parse('backend/logs/details.tpl', array('log' => $log)); }
public function create_one($params = []) { global $_PST; Render::json(Solution::create($_PST)); }
public function upload_solution($task_set_id = 0) { $this->usermanager->student_login_protected_redirect(); $task_set = $this->get_task_set_by_id($course, $group, $student, $task_set_id); $task_sets = $this->filter_valid_task_sets($task_set); $filtered_task_set = count($task_sets) == 1 ? $task_sets[0] : new Task_set(); if ($filtered_task_set->id == intval($task_set_id) && $this->can_upload_file($filtered_task_set, $course)) { $allowed_file_types_array = trim($filtered_task_set->allowed_file_types) != '' ? array_map('trim', explode(',', $filtered_task_set->allowed_file_types)) : array(); $config['upload_path'] = 'private/uploads/solutions/task_set_' . intval($task_set_id) . '/'; $config['allowed_types'] = 'zip' . (count($allowed_file_types_array) ? '|' . implode('|', $allowed_file_types_array) : ''); $config['max_size'] = intval($this->config->item('maximum_solition_filesize')); $current_version = $filtered_task_set->get_student_file_next_version($student->id); $config['file_name'] = $student->id . '_' . $this->normalize_student_name($student) . '_' . substr(md5(time() . rand(-500000, 500000)), 0, 4) . '_' . $current_version . '.zip'; @mkdir($config['upload_path'], DIR_READ_MODE, TRUE); $this->load->library('upload', $config); if ($this->upload->do_upload('file')) { $upload_data = $this->upload->data(); $mimes = $this->upload->mimes_types('zip'); if (is_array($mimes) && !in_array($upload_data['file_type'], $mimes) || is_string($mimes) && $upload_data['file_type'] != $mimes) { if (!$this->zip_plain_file_to_archive($upload_data['full_path'], $upload_data['client_name'], $upload_data['file_path'])) { $this->messages->add_message('lang:tasks_task_error_cant_zip_file', Messages::MESSAGE_TYPE_ERROR); redirect(create_internal_url('tasks/task/' . intval($task_set_id))); die; } } $this->_transaction_isolation(); $this->db->trans_begin(); $solution = new Solution(); $solution->where('task_set_id', $filtered_task_set->id); $solution->where('student_id', $student->id); $solution->get(); $revalidate = 1; if ($course->test_scoring_deadline >= date('Y-m-d H:i:s') && $filtered_task_set->enable_tests_scoring == 1 && $filtered_task_set->allowed_test_types != '') { $test_types = explode(',', $filtered_task_set->allowed_test_types); $tests = new Test(); $tests->where_related('task/task_set', 'id', $filtered_task_set->id); $tests->where('enabled', 1); $tests->where('enable_scoring', 1); $tests->where_in('type', $test_types); $revalidate = $tests->count() > 0 ? 0 : 1; } if ($solution->exists()) { $solution->ip_address = $_SERVER["REMOTE_ADDR"]; $solution->revalidate = $revalidate; $solution->save(); } else { $solution = new Solution(); $solution->ip_address = $_SERVER["REMOTE_ADDR"]; $solution->revalidate = $revalidate; $solution->save(array('student' => $student, 'task_set' => $filtered_task_set)); } $solution_version = new Solution_version(); $solution_version->ip_address = $_SERVER["REMOTE_ADDR"]; $solution_version->version = $current_version; $solution_version->save($solution); if ($this->db->trans_status()) { $log = new Log(); $log->add_student_solution_upload_log(sprintf($this->lang->line('tasks_task_solution_upload_log_message'), $config['file_name']), $student, $solution->id); $this->db->trans_commit(); $this->messages->add_message('lang:tasks_task_solution_uploaded', Messages::MESSAGE_TYPE_SUCCESS); $this->_action_success(); $this->output->set_internal_value('task_set_id', $solution->task_set_id); } else { $this->db->trans_rollback(); @unlink($config['upload_path'] . $config['file_name']); $this->messages->add_message('lang:tasks_task_solution_canceled_due_db_error', Messages::MESSAGE_TYPE_ERROR); } redirect(create_internal_url('tasks/task/' . intval($task_set_id))); } else { $this->parser->assign('file_error_message', $this->upload->display_errors('', '')); $this->task($task_set_id); } } else { $this->messages->add_message('lang:tasks_task_error_cant_upload_solution', Messages::MESSAGE_TYPE_ERROR); redirect(create_internal_url('tasks/task/' . intval($task_set_id))); } }
} if (!isset($_SESSION["loggedUser"]) || $_SESSION["loggedUser"] == null) { dieWithError("err-not-logged-in"); } if (get_class($_SESSION["loggedUser"]) != "Team") { dieWithError("err-add-solution-rights"); } $sql_get_solution = "SELECT c.context_id as 'context_id' FROM solutions s, contexts c WHERE s.context_id = c.context_id AND s.assignment_id = " . $_SESSION["assignment"]->getId() . " AND c.user_id = " . $_SESSION["loggedUser"]->getId(); $conn = db_connect(); $solution = mysqli_query($conn, $sql_get_solution); if (mysqli_num_rows($solution) == 0) { $cid = new_solution($conn, $_SESSION["loggedUser"]->getId(), $_SESSION["assignment"]->getId()); } else { $cid = mysqli_fetch_array($solution)['context_id']; } $solution = new Solution($conn, $cid, $_SESSION["loggedUser"], $_SESSION["assignment"]); if (isset($_POST['checkbox'])) { $solution->deleteAttachments($conn, $_POST['checkbox']); } if (isset($_POST['textPopis']) && $_POST['textPopis'] != $solution->getTxt()) { $solution->setTxt($conn, $_POST['textPopis']); } if (isset($_POST['textVideo']) && $_POST['textVideo'] != "") { $solution->uploadVideo($conn, $_POST['textVideo']); } if (isset($_FILES['uploadedFiles'])) { $fileCount = count($_FILES['uploadedFiles']["name"]); if ($fileCount != 0 && $_FILES['uploadedFiles']["name"][0] != "") { $solution->uploadFiles($conn, $_FILES['uploadedFiles']); } }
public function evaluate_test_result($task_set_id, $student_id, $version, $test_type, $token) { $task_set = new Task_set(); $task_set->include_related('course', 'test_scoring_deadline'); $task_set->get_by_id((int) $task_set_id); $student = new Student(); $student->get_by_id((int) $student_id); $output = new stdClass(); $output->result = FALSE; $output->message = ''; $output->points_new = 0; $output->points_before = 0; $this->load->model('test_score'); if ($task_set->exists() && $student->exists()) { if ($task_set->course_test_scoring_deadline >= date('Y-m-d H:i:s') && $task_set->enable_tests_scoring > 0) { $results = $this->test_score->get_data_for_student($student->id, $token, $test_type); $this->_transaction_isolation(); $this->db->trans_start(); $tests = new Test(); $tests->where_related('task/task_set', 'id', $task_set->id); $tests->where('type', $test_type); $tests->where('enable_scoring >', 0); $tests->group_by('task_id'); $tests->where('task_task_task_set_rel.bonus_task', 0); $tests->get_iterated(); //$output->debug = $tests->check_last_query(array('', ''), TRUE); $test_count = $tests->result_count(); $min_results = $task_set->test_min_needed > $test_count ? $test_count : $task_set->test_min_needed; $course = new Course(); $course->where_related_task_set('id', $task_set->id); $course->get(); $min_points_limit = -$course->default_points_to_remove; if ($test_count > 0) { $total_score = 0; $score_array = array(); $bonus_tasks_array = array(); $score_percentage = array(); $bonus_tasks_percentage = array(); if (count($results)) { foreach ($results as $task_id => $score) { $this->db->select('*'); $this->db->where('task_set_id', $task_set->id); $this->db->where('task_id', (int) $task_id); $query = $this->db->get('task_task_set_rel'); if ($query->num_rows() > 0) { $task_rel = $query->row_object(); $min = $task_rel->test_min_points; $max = $task_rel->test_max_points; $diff = abs($max - $min); $score_percent = (double) $score / 100; $sub_score = round(10 * ($min + $diff * $score_percent)) / 10; if ($task_rel->bonus_task == 0) { $score_array[$task_id] = $sub_score; $score_percentage[$task_id] = $score; } else { $bonus_tasks_array[$task_id] = $sub_score; $bonus_tasks_percentage[$task_id] = $score; } } $query->free_result(); } } $max_results = $task_set->test_max_allowed < count($score_array) ? $task_set->test_max_allowed : count($score_array); arsort($score_array, SORT_NUMERIC); $i = 0; foreach ($score_array as $task_id => $points) { if ($i < $max_results) { $total_score += $points; $i++; } else { break; } } $total_score = $total_score < $min_points_limit ? $min_points_limit : $total_score; arsort($bonus_tasks_array, SORT_NUMERIC); $total_score += array_sum($bonus_tasks_array); if (count($score_array) >= $min_results) { $tasks = new Task(); $tasks->where_related_task_set('id', $task_set_id); $tasks->order_by('`task_task_set_rel`.`sorting`', 'asc'); $tasks->get_iterated(); //$output->debug = $tasks->check_last_query(array('', ''), TRUE); $output->evaluation = $this->parser->parse('backend/tests/evaluation_table.tpl', array('tasks' => $tasks, 'real_points' => $score_array, 'bonus_points' => $bonus_tasks_array, 'real_percentage' => $score_percentage, 'bonus_percentage' => $bonus_tasks_percentage, 'max_results' => $max_results), TRUE); $solution = new Solution(); $solution->where('task_set_id', $task_set->id); $solution->where('student_id', $student->id); $solution->get(); $save_solution = FALSE; $solution_not_considered = FALSE; $output->points_new = $total_score; if ($solution->exists()) { if ($solution->not_considered == 0) { $output->points_before = $solution->points; if ($solution->points < $total_score || is_null($solution->points)) { $solution->points = $total_score; $solution->comment = ''; $solution->teacher_id = NULL; $solution->best_version = (int) $version; $solution->revalidate = 0; $save_solution = TRUE; } } else { $solution_not_considered = TRUE; } } else { $solution->points = $total_score; $solution->comment = ''; $solution->teacher_id = NULL; $solution->best_version = (int) $version; $solution->task_set_id = $task_set->id; $solution->student_id = $student->id; $solution->revalidate = 0; $save_solution = TRUE; } if ($save_solution) { $solution->save(); $output->result = TRUE; $this->_action_success(); } else { if (!$solution_not_considered) { $output->message = sprintf($this->lang->line('admin_tests_test_result_nothing_to_update'), $output->points_new, $output->points_before); } else { $output->message = $this->lang->line('admin_tests_test_result_solution_not_considered'); } } } else { $output->message = sprintf($this->lang->line('admin_tests_test_result_minimum_number_of_test_not_selected'), $min_results); } } else { $output->message = $this->lang->line('admin_tests_test_result_no_evaluationg_tests'); } $this->db->trans_complete(); } else { $output->message = $this->lang->line('admin_tests_test_result_disabled'); } } else { $output->message = $this->lang->line('admin_tests_test_result_input_error'); } $this->test_score->delete_token($token); $this->output->set_content_type('application/json'); $this->output->set_output(json_encode($output)); }
public function contract($order_id, $step = null) { AuthPlugins::required($this, array('销售经理', '销售顾问')); $order_id = abs(intval($order_id)); $order = Order::get_by_id($order_id); if (!$step) { $step = 'solution'; } $smarty = parent::load('smarty'); $smarty->assign('order', $order); switch ($step) { case 'solution': $solution_id = abs(intval($_GET['id'])); if ($solution_id) { /* * 全部设为非选定方案 */ Solution::set_unchecked(); /* * 选定某个方案 */ Solution::select($solution_id); HttpRedirect::to('order/contract/' . $order_id . '/paper'); } else { $solutions = Solution::get_by_order($order_id); if (!$solutions) { $message = '您还没有为此订单添加方案, 请返回添加'; HTTPRedirect::flash_to('order/detail/' . $order_id, $message, $smarty); } $smarty->assign('page_title', '签约订单 - 选定方案 Step 1'); $smarty->display('contract/solution'); } break; case 'paper': if (!Solution::get_checked($order_id)) { $message = '您还没有选择方案, 请返回选择'; HTTPRedirect::flash_to('order/contract/' . $order_id . '/solution', $message, $smarty); } if ($this->is_post() || $_FILES) { import('system/share/io/filesystem'); FileSystem::init(); $http_path = FileSystem::Upload($_FILES['paper_attachment'], false); if (!FileSystem::$local_path) { $message = '不支持的附件类型, 请检查'; HTTPRedirect::flash_to('order/detail/' . $order_id, $message, $smarty); } $order->paper_attachment = $http_path; $order->save(); HTTPRedirect::flash_to('order/contract/' . $order_id . '/payment', '上传合同成功', $this->smarty); } else { $smarty->assign('page_title', '签约订单 - 上传合同附件 Step 2'); $smarty->display('contract/paper'); } break; case 'payment': if ($this->is_post()) { /* * 获取选定的订单方案 */ $solution = Solution::get_checked($order_id); /*首付款*/ $first_pay = new Payment(); $first_pay->order_id = $order_id; $first_pay->type = 'first'; $first_pay->price = abs(intval($_POST['deposit'])); $first_pay->invoice = abs(intval($_POST['invoice'])); $first_pay->public = abs(intval($_POST['pub'])); $first_pay->bank = trim(strip_tags($_POST['bank'])); $first_pay->is_payed = abs(intval($_POST['is_deposit'])); $first_pay->save(); /*二期款*/ $second_pay = new Payment(); $second_pay->order_id = $order_id; $second_pay->type = 'second'; $second_pay->price = abs(intval($_POST['payment'])); $second_pay->invoice = abs(intval($_POST['invoice'])); $second_pay->public = abs(intval($_POST['pub'])); $second_pay->bank = trim(strip_tags($_POST['bank'])); $second_pay->is_payed = abs(intval($_POST['is_payment'])); $second_pay->save(); /*尾款*/ $last_pay = new Payment(); $last_pay->order_id = $order_id; $last_pay->type = 'last'; $last_pay->price = abs(intval($_POST['last_pay'])); $last_pay->invoice = abs(intval($_POST['invoice'])); $last_pay->public = abs(intval($_POST['pub'])); $last_pay->bank = trim(strip_tags($_POST['bank'])); $last_pay->is_payed = abs(intval($_POST['is_last_pay'])); $last_pay->save(); $old_workflow = $order->Workflow->action; $workflow = Workflow::get_by_alias('新增财务订单'); $order->Workflow = $workflow; $order->save(); /* * 在用户表中写入客户的登录信息 * 登录名为客户填写的名字加订单ID * 密码为'MG-客服ID-订单号' */ $user = new User(); $user->username = $order->Customer->name . $order->id; $user->password = User::generate_password(sprintf('MG-%s-%s', $order->customer_service_id, $order->id)); $user->Role[0] = Role::get_by_alias('客户'); $user->save(); $order->Customer->CustomerUser = $user; $order->Customer->save(); $message = '恭喜您签约订单成功, 目前订单已转入财务管理页面'; HTTPRedirect::flash_to('order/list/6', $message, $smarty); } else { $smarty->assign('page_title', '签约订单 - 付款信息 Step 3'); $smarty->display('contract/payment'); } break; } }
<?php require_once dirname(__FILE__) . "/includes/functions.php"; page_head("Letná liga FLL"); page_nav(); if (!isset($_SESSION['loggedUser'])) { get_login_form(); } else { get_logout_button(); } $id = (int) $_GET["id"]; if ($link = db_connect()) { $_SESSION['solution'] = Solution::getFromDatabaseByID($link, $id); } if (isset($_SESSION['solution'])) { if (isset($_GET['comment'])) { $comment = $_SESSION['solution']->getComments()[$_GET['comment']]; if ($_SESSION['loggedUser']->getId() == $comment->getAuthor()->getId()) { if (isset($_POST['commentText']) && $_POST['commentText'] != $comment->getTxt()) { $comment->setTxt($link, $_POST['commentText']); } if (isset($_POST['commentPoints']) && $_POST['commentPoints'] != $comment->getPoints()) { $comment->setPoints($link, $_POST['commentPoints']); } } } ?> <div id="content"> <?php $_SESSION['solution']->getPreviewHtml(); ?>
<?php include 'Solution.php'; ini_set('display_errors', 1); $sln = new Solution(5, 10); $initialRandomArray = $sln->getArray(); $duplicatesArray = $sln->getDuplicates(); $uniqueElementsArray = $sln->getUnique(); $mostFrequentDuplicatedElement = $sln->getMostFrequentDuplicatedElement(); echo "Initial array: [ " . Solution::concatArray($initialRandomArray) . " ] <br />"; echo "Unique values: [ " . Solution::concatArray($uniqueElementsArray) . " ] <br />"; echo "Duplicated values: [ " . Solution::concatArray($duplicatesArray) . " ] <br />"; echo "Most frequent duplicated value: " . $mostFrequentDuplicatedElement;
function check_forgotten() { global $db, $task; $sql = 'SELECT `id`, `pid`, `uid`, `code`, `state`, `language` FROM `mo_judge_solution` WHERE `state` = 0'; $mark = $db->prepare($sql); $result = $db->execute($mark); if (!count($result)) { return 0; } foreach ($result as $solution) { if (!isset($task[(int) $solution['id']])) { $data = array('sid' => $solution['id'], 'pid' => $solution['pid'], 'uid' => $solution['uid'], 'lang' => $solution['language'], 'code' => $solution['code']); $new_solution = new Solution($data); $new_solution->push(); } } return True; }
<?php /* Три метода возвращают минимальное из двух переданных в него чисел Написать public static методы: int min(int, int), long min(long, long), double min(double, double). Каждый метод должен возвращать минимальное из двух переданных в него чисел. */ class Solution { public static function min($x, $y) { if ($x > $y) { return $y; } elseif ($x < $y) { return $x; } else { return 'Equals'; } } } echo Solution::min(332, 3);
public function run_comparation() { $task_sets_setup_data = $this->input->post('task_sets_setup'); $solutions_data = $this->input->post('solutions'); $comparator_setup_data = $this->input->post('comparator_setup'); $course = new Course(); $course->get_by_id((int) $task_sets_setup_data['course']); $task_set = new Task_set(); $task_set->where_related($course); $task_set->get_by_id(isset($task_sets_setup_data['task_set']) ? (int) $task_sets_setup_data['task_set'] : 0); $this->parser->assign(array('course' => $course, 'task_set' => $task_set)); if ($course->exists() && $task_set->exists()) { $this->load->library('form_validation'); $this->form_validation->set_rules('solutions', 'lang:admin_comparator_list_solutions_form_field_solution_selection', 'callback__selected_solutions'); $this->form_validation->set_rules('comparator_setup[threshold]', 'lang:admin_comparator_list_solutions_form_field_threshold', 'required|numeric|greater_than_equal[0]|less_than_equal[1]'); $this->form_validation->set_rules('comparator_setup[min_tree_size]', 'lang:admin_comparator_list_solutions_form_field_min_tree_size', 'required|integer|greater_than_equal[1]'); $this->form_validation->set_rules('comparator_setup[max_cutted_tree_size]', 'lang:admin_comparator_list_solutions_form_field_max_cutted_tree_size', 'required|integer|greater_than_field_or_equal[comparator_setup[min_tree_size]]'); $this->form_validation->set_rules('comparator_setup[branching_factor]', 'lang:admin_comparator_list_solutions_form_field_branching_factor', 'required|integer|greater_than_equal[1]'); $this->form_validation->set_rules('comparator_setup[min_similarity]', 'lang:admin_comparator_list_solutions_form_field_minimum_similarity', 'required|numeric|greater_than_equal[0]|less_than_equal[1]'); $this->form_validation->set_rules('comparator_setup[timeout]', 'lang:admin_comparator_list_solutions_form_field_timeout', 'required|integer|greater_than_equal[1]'); $this->form_validation->set_message('_selected_solutions', $this->lang->line('admin_comparator_list_solutions_validation_callback_selected_solutions')); if ($this->form_validation->run()) { $solutions = new Solution(); $solutions->include_related('student'); $solutions->where_related($task_set); $solutions->order_by_related_as_fullname('student', 'fullname', 'asc'); $solutions->get_iterated(); $this->parser->assign('solutions', $solutions); $path = $this->get_random_hash_folder($course->id, $task_set->id); $path_source = $path . '/source'; $path_output = $path . '/output'; @mkdir($path_source, DIR_WRITE_MODE, TRUE); @mkdir($path_output, DIR_WRITE_MODE, TRUE); $all_extracted = TRUE; foreach ($solutions_data as $id => $config) { if (isset($config['selected']) && $config['selected'] == 1) { set_time_limit(120); $version = isset($config['version']) ? $config['version'] : 0; $student = isset($config['student']) ? $config['student'] : 0; $file = $task_set->get_student_files($student, $version); if (count($file) == 1) { $file = $file[$version]; $subdir = '/' . normalize($file['file_name']) . '_sid-' . $file['student_id'] . '_ver-' . $file['version']; $extract_path = $path_source . $subdir; @mkdir($extract_path, DIR_WRITE_MODE, TRUE); $status = $task_set->extract_student_zip_to_folder($file['file'], $extract_path, array('java')); $all_extracted = $all_extracted && $status; } } } if (!$all_extracted) { unlink_recursive($path, TRUE); } $this->parser->assign('all_extracted', $all_extracted); $this->parser->assign('path', $path); $this->parser->assign('comparator_config', array('t' => $comparator_setup_data['threshold'], 'm' => $comparator_setup_data['min_tree_size'], 'cut' => $comparator_setup_data['max_cutted_tree_size'], 'bf' => $comparator_setup_data['branching_factor'], 'mp' => $comparator_setup_data['min_similarity'], 'timeout' => $comparator_setup_data['timeout'] * 60000)); $this->parser->parse('backend/comparator/run_comparation.tpl'); } else { $this->list_solutions(); } } else { $this->list_solutions(); } }
/** * Deletes relations (if parameters are set) or this object from database. * All solutions related to this task set will be deleted as well. * @param DataMapper|string $object related object to delete from relation. * @param string $related_field relation internal name. */ public function delete($object = '', $related_field = '') { $this_id = $this->id; if (empty($object) && !is_array($object) && !empty($this_id)) { $solutions = new Solution(); $solutions->get_by_related('task_set', 'id', $this_id); foreach ($solutions as $solution) { set_time_limit(ini_get('max_execution_time')); $solution->delete(); } } parent::delete($object, $related_field); }
class Bird { } class Lamp { } class Pig { } class Solution { public function getObjectType($obj) { if ($obj instanceof Cat) { echo "Cat"; } elseif ($obj instanceof Dog) { echo "dog"; } elseif ($obj instanceof Bird) { echo "Bird"; } elseif ($obj instanceof Lamp) { echo "lamp"; } else { echo "Unknown animal"; } } } $s = new Solution(); $s->getObjectType(new Cat()); $s->getObjectType(new Dog()); $s->getObjectType(new Lamp()); $s->getObjectType(new Pig());