Ejemplo n.º 1
0
 def get_random_param_set(self):
     """Returns a list of parameter values. This is a parameter set that is
     chosen at random from the dataset."""
     if not self.param_sets:
         return None
     param_set_key = utils.get_random_choice(self.param_sets)
     return ParamSet.get_by_id(param_set_key.id())
Ejemplo n.º 2
0
    def transition(self, answer, params, handler_name):
        """Handle feedback interactions with readers."""

        recorded_answer = answer
        # TODO(sll): This is a special case for multiple-choice input
        # which should really be handled generically.
        if self.widget.widget_id == 'interactive-MultipleChoiceInput':
            recorded_answer = self.widget.params['choices'][int(answer)]

        handlers = [h for h in self.widget.handlers if h.name == handler_name]
        if not handlers:
            raise Exception('No handlers found for %s' % handler_name)
        handler = handlers[0]

        if handler.classifier is None:
            selected_rule = handler.rules[0]
        else:
            # Import the relevant classifier module.
            classifier_module = '.'.join([
                feconf.SAMPLE_CLASSIFIERS_DIR.replace('/', '.'),
                handler.classifier, handler.classifier])
            Classifier = importlib.import_module(classifier_module)

            norm_answer = Classifier.DEFAULT_NORMALIZER().normalize(answer)
            if norm_answer is None:
                raise Exception('Could not normalize %s.' % answer)

            selected_rule = self.find_first_match(
                handler, Classifier, norm_answer, params)

        feedback = (utils.get_random_choice(selected_rule.feedback)
                    if selected_rule.feedback else '')
        return selected_rule.dest, feedback, selected_rule, recorded_answer
Ejemplo n.º 3
0
 def value(self):
     if not self.values:
         return None
     return utils.get_random_choice(self.values)