本文整理汇总了PHP中question_state::graded_state_for_fraction方法的典型用法代码示例。如果您正苦于以下问题:PHP question_state::graded_state_for_fraction方法的具体用法?PHP question_state::graded_state_for_fraction怎么用?PHP question_state::graded_state_for_fraction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类question_state
的用法示例。
在下文中一共展示了question_state::graded_state_for_fraction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: feedback
public function feedback(question_attempt $qa, question_display_options $options)
{
// Try to find the last graded step.
$gradedstep = $this->get_graded_step($qa);
if (is_null($gradedstep) || $qa->get_max_mark() == 0 || $options->marks < question_display_options::MARK_AND_MAX) {
return '';
}
// Display the grading details from the last graded state
$mark = new stdClass();
$mark->max = $qa->format_max_mark($options->markdp);
$actualmark = $gradedstep->get_fraction() * $qa->get_max_mark();
$mark->cur = format_float($actualmark, $options->markdp);
$rawmark = $gradedstep->get_behaviour_var('_rawfraction') * $qa->get_max_mark();
$mark->raw = format_float($rawmark, $options->markdp);
// let student know wether the answer was correct
if ($qa->get_state()->is_commented()) {
$class = $qa->get_state()->get_feedback_class();
} else {
$class = question_state::graded_state_for_fraction($gradedstep->get_behaviour_var('_rawfraction'))->get_feedback_class();
}
$gradingdetails = get_string('gradingdetails', 'qbehaviour_adaptive', $mark);
$gradingdetails .= $this->penalty_info($qa, $mark, $options);
$output = '';
$output .= html_writer::tag('div', get_string($class, 'question'), array('class' => 'correctness ' . $class));
$output .= html_writer::tag('div', $gradingdetails, array('class' => 'gradingdetails'));
return $output;
}
示例2: grade_response
public function grade_response(array $response)
{
$fraction = 0;
list($numright, $total) = $this->get_num_parts_right($response);
$numwrong = $this->get_num_selected_choices($response) - $numright;
$numcorrect = $this->get_num_correct_choices();
if ($numwrong == 0 && $numcorrect == $numright) {
$fraction = 1;
}
$state = question_state::graded_state_for_fraction($fraction);
return array($fraction, $state);
}
示例3: correct_response
public function correct_response(question_attempt $qa)
{
$result = "";
$question = $qa->get_question();
if ($question->shownumcorrect) {
foreach ($question->get_order($qa) as $ans_number => $ans_id) {
$answer = $question->answers[$ans_id];
if (question_state::graded_state_for_fraction($answer->fraction) == question_state::$gradedright) {
$result = get_string('correctansweris', 'qtype_multichoice', qtype_omeromultichoice_base_renderer::number_answer($ans_number, $question->answernumbering));
}
}
}
return $result;
}
示例4: get_state_string
public function get_state_string($showcorrectness)
{
$laststep = $this->qa->get_last_step();
if ($laststep->has_behaviour_var('_try')) {
$state = question_state::graded_state_for_fraction($laststep->get_behaviour_var('_rawfraction'));
return $state->default_string(true);
}
$state = $this->qa->get_state();
if ($state == question_state::$todo) {
return get_string('notcomplete', 'qbehaviour_adaptive');
} else {
return parent::get_state_string($showcorrectness);
}
}
示例5: find_right_answer
/**
* Find the corresponding choice id of the first correct answer of a shortanswer question.
* choice is added to the randomsamatch question if it doesn't already exist.
* @param object $wrappedquestion short answer question.
* @return int correct choice id.
*/
public function find_right_answer($wrappedquestion)
{
// We only take into account *one* (the first) correct answer.
while ($answer = array_shift($wrappedquestion->answers)) {
if (!question_state::graded_state_for_fraction($answer->fraction)->is_incorrect()) {
// Store this answer as a choice, only if this is a new one.
$key = array_search($answer->answer, $this->choices);
if ($key === false) {
$key = $answer->id;
$this->choices[$key] = $answer->answer;
}
return $key;
}
}
// We should never get there.
throw new coding_exception('shortanswerquestionwithoutrightanswer', $wrappedquestion->id);
}
示例6: get_num_correct_choices
protected function get_num_correct_choices($questiondata)
{
$numright = 0;
foreach ($questiondata->options->answers as $answer) {
if (!question_state::graded_state_for_fraction($answer->fraction)->is_incorrect()) {
$numright += 1;
}
}
return $numright;
}
示例7: get_num_correct_choices
/**
* @return int the number of choices that are correct.
*/
public function get_num_correct_choices()
{
$numcorrect = 0;
foreach ($this->answers as $ans) {
if (!question_state::graded_state_for_fraction($ans->fraction)->is_incorrect()) {
if ($ans->answer != "none" && $ans->fraction > 0) {
$numcorrect += count(explode(",", $ans->answer));
}
}
}
return $numcorrect;
}
示例8: correct_response
public function correct_response(question_attempt $qa)
{
$question = $qa->get_question();
foreach ($question->answers as $ansid => $ans) {
if (question_state::graded_state_for_fraction($ans->fraction) == question_state::$gradedright) {
return get_string('correctansweris', 'qtype_multichoice', $question->format_text($ans->answer, $ans->answerformat, $qa, 'question', 'answer', $ansid));
}
}
return '';
}
示例9: grade_response
public function grade_response(array $response)
{
$this->update_current_response($response);
$countcorrect = 0;
$countanswers = 0;
$correctresponse = $this->correctresponse;
$currentresponse = $this->currentresponse;
foreach ($currentresponse as $position => $answerid) {
if ($correctresponse[$position] == $answerid) {
$countcorrect++;
}
$countanswers++;
}
if ($countanswers == 0) {
$fraction = 0;
} else {
$fraction = $countcorrect / $countanswers;
}
return array($fraction, question_state::graded_state_for_fraction($fraction));
}
示例10: get_adaptive_marks
/**
* @return qbehaviour_adaptive_mark_details the information about the current state-of-play, scoring-wise,
* for this adaptive attempt.
*/
public function get_adaptive_marks() {
// Try to find the last graded step.
$gradedstep = $this->get_graded_step();
if (is_null($gradedstep) || $this->qa->get_max_mark() == 0) {
// No score yet.
return new qbehaviour_adaptive_mark_details(question_state::$todo);
}
// Work out the applicable state.
if ($this->qa->get_state()->is_commented()) {
$state = $this->qa->get_state();
} else {
$state = question_state::graded_state_for_fraction(
$gradedstep->get_behaviour_var('_rawfraction'));
}
// Prepare the grading details.
$details = $this->adaptive_mark_details_from_step($gradedstep, $state, $this->qa->get_max_mark(), $this->question->penalty);
$details->improvable = $this->is_state_improvable($this->qa->get_state());
return $details;
}
示例11: icon_for_fraction
/**
* Return an appropriate icon (green tick, red cross, etc.) for a grade.
* @param float $fraction grade on a scale 0..1.
* @return string html fragment.
*/
protected function icon_for_fraction($fraction) {
global $OUTPUT;
$state = question_state::graded_state_for_fraction($fraction);
if ($state == question_state::$gradedright) {
$icon = 'i/tick_green_big';
} else if ($state == question_state::$gradedpartial) {
$icon = 'i/tick_amber_big';
} else {
$icon = 'i/cross_red_big';
}
return $OUTPUT->pix_icon($icon, get_string($state->get_feedback_class(), 'question'),
'moodle', array('class' => 'icon'));
}
示例12: grade_response
public function grade_response(array $response)
{
$response = $this->discard_duplicates($response);
list($right, $total) = $this->get_num_parts_right($response);
$this->fraction = $right / $total;
$grade = array($this->fraction, question_state::graded_state_for_fraction($this->fraction));
return $grade;
}
示例13: grade_response
//.........这里部分代码省略.........
#$feedback .= 'dirroot=' . $CFG->dirroot . '<br/>';
#$feedback .= 'wwwroot=' . $CFG->wwwroot . '<br/>';
$feedback .= '<div style="border:1px solid #000;">';
$feedback .= '<b><font color="blue">Results of Code Audit</font></b>';
$feedback .= '</div><br/>';
$feedback .= '<font color="#0000A0">Value of Code Audit in question grade: <b>' . $weight_style * 100 . '%</b></font><br/>';
$feedback .= '<font color="#0000A0">The first <b>' . $max_errors_style . '</b> errors give bad points</font><br/>';
$feedback .= '<font color="#0000A0">Number of errors made by the student: <b>' . $num_errors_style . '</b></font><br/>';
$feedback .= '<font color="#0000A0">Grade for section Code Audit: <b>' . $fraction_style * $weight_style * 100 . '% / ' . $weight_style * 100 . '%</b></font><br/><br/>';
$feedback .= '<font color="#0000A0"><b>Details of audit hereafter:</b></font><br/>';
$feedback .= '<pre>' . $output_audit . '</pre>';
$feedback .= '<br/>';
$feedback .= '<div style="border:1px solid #000;">';
$feedback .= '<b><font color="blue">Results of Unit Tests</font></b>';
$feedback .= '</div><br/>';
$feedback .= '<font color="#0000A0">Number of evaluated tests: <b>' . $numtests . '</b></font><br/>';
$feedback .= '<font color="#0000A0">Number of observed failures: <b>' . $numfailures . ' / ' . $numtests . '</b></font><br/>';
$feedback .= '<font color="#0000A0">Number of observed errors: <b>' . $numerrors . ' / ' . $numtests . '</b></font><br/>';
$feedback .= '<font color="#0000A0">Grade for section Unit Tests: <b>' . $fraction_code * $weight_unittests * 100 . '% / ' . $weight_unittests * 100 . '%</b></font><br/><br/>';
$feedback .= '<font color="#0000A0"><b>Details of unit tests hereafter:</b></font><br/>';
$feedback .= '<pre>' . $outtext . '</pre>';
$feedback .= "<br>\n";
}
// search for common throwables, by package, by alphabet
if (strpos($output, 'java.io.IOException') !== false) {
$feedback .= get_string('ioexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.io.FileNotFoundException') !== false) {
$feedback .= get_string('filenotfoundexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.ArrayIndexOutOfBoundsException') !== false) {
$feedback .= get_string('arrayindexoutofboundexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.ClassCastException') !== false) {
$feedback .= get_string('classcastexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.NegativeArraySizeException') !== false) {
$feedback .= get_string('negativearraysizeexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.NullPointerException') !== false) {
$feedback .= get_string('nullpointerexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.OutOfMemoryError') !== false) {
$feedback .= get_string('outofmemoryerror', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.StackOverflowError') !== false) {
$feedback .= get_string('stackoverflowerror', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.lang.StringIndexOutOfBoundsException') !== false) {
$feedback .= get_string('stringindexoutofboundexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.nio.BufferOverflowException') !== false) {
$feedback .= get_string('bufferoverflowexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.nio.BufferUnderflowException') !== false) {
$feedback .= get_string('bufferunderflowexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
if (strpos($output, 'java.security.AccessControlException') !== false) {
$feedback .= get_string('accesscontrolexception', 'qtype_javaunittest');
$feedback .= "<br>\n<br>\n";
}
// append feedback phrase (wrong / [partially] corrent answer phrase)
if ($numtests > 0 && $totalerrors == 0 && $num_errors_style == 0) {
$feedback .= get_string('CA', 'qtype_javaunittest');
} else {
if ($numtests > 0 && ($totalerrors != 0 || $num_errors_style != 0)) {
$feedback .= get_string('PCA', 'qtype_javaunittest');
} else {
if ($numtest > 0 && ($numtests >= $totalerrors && $num_errors_style >= $max_errors_style)) {
$feedback .= get_string('WA', 'qtype_javaunittest');
}
}
}
$feedback .= "<br>\n";
}
}
// save feedback
$cur_feedback = $DB->get_record('qtype_javaunittest_feedback', array('questionattemptid' => $this->questionattemptid));
$db_feedback = new stdClass();
$db_feedback->questionattemptid = $this->questionattemptid;
$db_feedback->feedback = $feedback;
if ($cur_feedback) {
$db_feedback->id = $cur_feedback->id;
$DB->update_record('qtype_javaunittest_feedback', $db_feedback);
} else {
$DB->insert_record('qtype_javaunittest_feedback', $db_feedback);
}
return array($fraction, question_state::graded_state_for_fraction($fraction));
}
示例14: test_graded_state_for_fraction
public function test_graded_state_for_fraction()
{
$this->assertEquals(question_state::$gradedwrong, question_state::graded_state_for_fraction(-1));
$this->assertEquals(question_state::$gradedwrong, question_state::graded_state_for_fraction(0));
$this->assertEquals(question_state::$gradedpartial, question_state::graded_state_for_fraction(1.0E-6));
$this->assertEquals(question_state::$gradedpartial, question_state::graded_state_for_fraction(0.999999));
$this->assertEquals(question_state::$gradedright, question_state::graded_state_for_fraction(1));
}
示例15: subquestion
//.........这里部分代码省略.........
// Extract the responses that related to this question + strip off the prefix.
$fieldprefixlen = strlen($fieldprefix);
$response = [];
foreach ($qa->get_last_qt_data() as $name => $val) {
if (substr($name, 0, $fieldprefixlen) == $fieldprefix) {
$name = substr($name, $fieldprefixlen);
$response[$name] = $val;
}
}
$basename = $qa->get_qt_field_name($fieldname);
$inputattributes = array(
'type' => 'checkbox',
'value' => 1,
);
if ($options->readonly) {
$inputattributes['disabled'] = 'disabled';
}
$result = $this->all_choices_wrapper_start();
// Calculate the total score (as we need to know if choices should be marked as 'correct' or 'partial').
$fraction = 0;
foreach ($subq->get_order($qa) as $value => $ansid) {
$ans = $subq->answers[$ansid];
if ($subq->is_choice_selected($response, $value)) {
$fraction += $ans->fraction;
}
}
// Display 'correct' answers as correct, if we are at 100%, otherwise mark them as 'partial'.
$answerfraction = ($fraction > 0.999) ? 1.0 : 0.5;
foreach ($subq->get_order($qa) as $value => $ansid) {
$ans = $subq->answers[$ansid];
$name = $basename.$value;
$inputattributes['name'] = $name;
$inputattributes['id'] = $name;
$isselected = $subq->is_choice_selected($response, $value);
if ($isselected) {
$inputattributes['checked'] = 'checked';
} else {
unset($inputattributes['checked']);
}
$class = 'r' . ($value % 2);
if ($options->correctness && $isselected) {
$thisfrac = ($ans->fraction > 0) ? $answerfraction : 0;
$feedbackimg = $this->feedback_image($thisfrac);
$class .= ' ' . $this->feedback_class($thisfrac);
} else {
$feedbackimg = '';
}
$result .= $this->choice_wrapper_start($class);
$result .= html_writer::empty_tag('input', $inputattributes);
$result .= html_writer::tag('label', $subq->format_text($ans->answer,
$ans->answerformat, $qa, 'question', 'answer', $ansid),
array('for' => $inputattributes['id']));
$result .= $feedbackimg;
if ($options->feedback && $isselected && trim($ans->feedback)) {
$result .= html_writer::tag('div',
$subq->format_text($ans->feedback, $ans->feedbackformat,
$qa, 'question', 'answerfeedback', $ansid),
array('class' => 'specificfeedback'));
}
$result .= $this->choice_wrapper_end();
}
$result .= $this->all_choices_wrapper_end();
$feedback = array();
if ($options->feedback && $options->marks >= question_display_options::MARK_AND_MAX &&
$subq->maxmark > 0) {
$a = new stdClass();
$a->mark = format_float($fraction * $subq->maxmark, $options->markdp);
$a->max = format_float($subq->maxmark, $options->markdp);
$feedback[] = html_writer::tag('div', get_string('markoutofmax', 'question', $a));
}
if ($options->rightanswer) {
$correct = [];
foreach ($subq->answers as $ans) {
if (question_state::graded_state_for_fraction($ans->fraction) != question_state::$gradedwrong) {
$correct[] = $subq->format_text($ans->answer, $ans->answerformat, $qa, 'question', 'answer', $ans->id);
}
}
$correct = '<ul><li>'.implode('</li><li>', $correct).'</li></ul>';
$feedback[] = get_string('correctansweris', 'qtype_multichoice', $correct);
}
$result .= html_writer::nonempty_tag('div', implode('<br />', $feedback), array('class' => 'outcome'));
return $result;
}