get measure of correctness for the question
172001
def get_correctness(self, question_id):
        """"""
        response = self.get_response(question_id)
        if response.is_answered():
            item = self._get_item(response.get_item_id())
            return item.get_correctness_for_response(response)
        raise errors.IllegalState()
1203304
def is_answer_valid(self, ans):
        """"""
        return ans in [str(i+1) for i in range(len(self.choices))]
1353062
def get_question_text(constant):
    
    if constant in dir(safe.gui.tools.wizard.wizard_strings):
        return getattr(safe.gui.tools.wizard.wizard_strings, constant)
    else:
        return '<b>MISSING CONSTANT: %s</b>' % constant
1368363
def get_confidence(self):
        """"""
        # if we didn't receive any character in our consideration range,
        # return negative answer
        if self._mTotalChars <= 0 or self._mFreqChars <= MINIMUM_DATA_THRESHOLD:
            return SURE_NO

        if self._mTotalChars != self._mFreqChars:
            r = (self._mFreqChars / ((self._mTotalChars - self._mFreqChars)
                 * self._mTypicalDistributionRatio))
            if r < SURE_YES:
                return r

        # normalize confidence (we don't want to be 100% sure)
        return SURE_YES
621674
protected function get_correct_answers($question) {
        $arrayofchoices = $this->get_array_of_choices($question);
        $arrayofplaceholdeers = $this->get_array_of_placeholders($question);

        $correctplayers = array();
        foreach ($arrayofplaceholdeers as $ph) {
            foreach ($arrayofchoices as $key => $choice) {
                if ($key + 1 == $ph) {
                    $correctplayers[] = $choice;
                }
            }
        }
        return $correctplayers;
    }
167459
def RetryQuestion(question_text, output_re="", default_val=None):
  """"""
  while True:
    if default_val is not None:
      new_text = "%s [%s]: " % (question_text, default_val)
    else:
      new_text = "%s: " % question_text
    # pytype: disable=wrong-arg-count
    output = builtins.input(new_text) or str(default_val)
    # pytype: enable=wrong-arg-count
    output = output.strip()
    if not output_re or re.match(output_re, output):
      break
    else:
      print("Invalid input, must match %s" % output_re)
  return output
915709
def graded_submissions(self):
        '''
            
        '''
        qs = self._valid_submissions().filter(state__in=[Submission.GRADED])
        return qs
862622
def _ask_questionnaire():
    """"""

    answers = {}
    print(info_header)
    pprint(questions.items())

    for question, default in questions.items():
        response = _ask(question, default, str(type(default)), show_hint=True)
        if type(default) == unicode and type(response) != str:
            response = response.decode('utf-8')
        answers[question] = response

    return answers
1225182
def is_correct(self):
        
        state = True

        # Internal checks before executing inherited function...
        if not hasattr(self, 'check_command'):
            msg = "[checkmodulation::%s] do not have any check_command defined" % (
                self.get_name()
            )
            self.add_error(msg)
            state = False
        else:
            if self.check_command is None:
                msg = "[checkmodulation::%s] a check_command is missing" % (self.get_name())
                self.add_error(msg)
                state = False
            if self.check_command and not self.check_command.is_valid():
                msg = "[checkmodulation::%s] a check_command is invalid" % (self.get_name())
                self.add_error(msg)
                state = False

        # Ok just put None as check_period, means 24x7
        if not hasattr(self, 'check_period'):
            self.check_period = None

        return super(CheckModulation, self).is_correct() and state
535427
def confirm(self, question, default=False, true_answer_regex="(?i)^y"):
        
        return self._io.confirm(question, default, true_answer_regex)
836093
def find_best_question(X, y, criterion):
    
    
    measure_impurity = gini_impurity if criterion == "gini" else entropy

    current_impurity = measure_impurity(y)
    best_info_gain = 0
    best_question = None

    for feature_n in range(X.shape[1]):
        for value in set(X[:, feature_n]):
            q = Question(feature_n, value)
            _, _, true_y, false_y = split(X, y, q)

            current_info_gain = info_gain(current_impurity, true_y, false_y, criterion)
            if current_info_gain >= best_info_gain:
                best_info_gain = current_info_gain
                best_question = q

    return best_info_gain, best_question
97857
def measure(self, text, escape = True, max_width = None):
        """"""

        if escape:
            text = text.replace ("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")

        if (max_width, text) in self._measures:
            return self._measures[(max_width, text)]

        width, height = None, None

        context = self._test_context

        layout = self._test_layout
        layout.set_font_description(self.font_desc)
        layout.set_markup(text)
        layout.set_single_paragraph_mode(self.single_paragraph)

        if self.alignment:
            layout.set_alignment(self.alignment)

        if self.wrap is not None:
            layout.set_wrap(self.wrap)
            layout.set_ellipsize(pango.EllipsizeMode.NONE)
        else:
            layout.set_ellipsize(self.ellipsize or pango.EllipsizeMode.END)

        if max_width is not None:
            layout.set_width(max_width * pango.SCALE)
        else:
            if self.max_width:
                max_width = self.max_width * pango.SCALE

            layout.set_width(int(self._bounds_width or max_width or -1))

        width, height = layout.get_pixel_size()

        self._measures[(max_width, text)] = width, height
        return self._measures[(max_width, text)]
727760
def _check_success(self):
        
        t, d, cos = self._compute_orientation()

        return d < 0.06 and t >= -0.12 and t <= 0.14 and cos > 0.95
1328801
def _is_match(self, response, answer):
        """"""
        # TODO: this varies depending on question type
        if self._only_generic_right_feedback():
            return str(answer.genus_type) == str(RIGHT_ANSWER_GENUS)
        elif self._is_multiple_choice():
            return MultiChoiceItemRecord._is_match(self, response, answer)
        elif self._is_image_sequence() or self._is_mw_sentence():
            return OrderedChoiceItemRecord._is_match(self, response, answer)
        elif self._is_numeric_response():
            return CalculationInteractionItemRecord._is_match(self, response, answer)
        elif self._is_fitb():
            return MagicRandomizedInlineChoiceItemRecord._is_match(self, response, answer)
        return False
566235
def ask(question):
    '''
    
    '''
    while True:
        ans = input(question)
        al = ans.lower()
        if match('^y(es)?$', al):
            return True
        elif match('^n(o)?$', al):
            return False
        elif match('^q(uit)?$', al):
            stdout.write(CYAN)
            print("\nGoodbye.\n")
            stdout.write(RESET)
            quit()
        else:
            stdout.write(RED)
            print("%s is invalid. Enter (y)es, (n)o or (q)uit." % ans)
            stdout.write(RESET)
597987
public function getStatistics(Item $question, Exercise $exercise = null, $finishedPapersOnly = false)
    {
        $questionStats = [];

        // We load all the answers for the question (we need to get the entities as the response in DB are not processable as is)
        $answers = $this->answerRepository->findByQuestion($question, $exercise, $finishedPapersOnly);

        // Number of Users that have seen the question
        $questionStats['seen'] = count($answers);

        // Grab answer data to pass it decoded to the question type
        // it doesn't need to know the whole Answer object
        $answersData = [];

        // get corrected answers for the Item in order to compute question success percentage
        $correctedAnswers = [];

        // Number of Users that have answered the question (no blank answer)
        $questionStats['answered'] = 0;

        if (!empty($answers)) {
            // Let the handler of the question type parse and compile the data
            $definition = $this->itemDefinitions->get($question->getMimeType());

            for ($i = 0; $i < $questionStats['seen']; ++$i) {
                $answer = $answers[$i];
                if (!empty($answer->getData())) {
                    ++$questionStats['answered'];
                    $answersData[] = json_decode($answer->getData(), true);
                }

                // for each answer get corresponding correction
                if ($definition instanceof AnswerableItemDefinitionInterface && isset($answersData[$i])) {
                    $corrected = $definition->correctAnswer($question->getInteraction(), $answersData[$i]);
                    $correctedAnswers[] = $corrected;
                }
            }

            // Let the handler of the question type parse and compile the data
            if ($definition instanceof AnswerableItemDefinitionInterface) {
                $questionStats['solutions'] = $definition->getStatistics($question->getInteraction(), $answersData, $questionStats['seen']);
            }
        }

        // get the number of good answers among all
        $nbGoodAnswers = 0;

        foreach ($correctedAnswers as $corrected) {
            if ($corrected instanceof CorrectedAnswer && 0 === count($corrected->getMissing()) && 0 === count($corrected->getUnexpected())) {
                ++$nbGoodAnswers;
            }
        }
        // compute question success percentage
        $questionStats['successPercent'] = $questionStats['answered'] > 0 ? (100 * $nbGoodAnswers) / $questionStats['answered'] : 0;

        return $questionStats;
    }
992592
def is_correctness_available(self, question_id):
        """"""
        response = self.get_response(question_id)
        if response.is_answered():
            item = self._get_item(response.get_item_id())
            return item.is_correctness_available_for_response(response)
        return False