Exemple #1
0
 def create_unit_hint(cls, from_unit, to_unit):
     converted_value = convert(from_unit, 1, to_unit).magnitude
     if converted_value < 1:
         converted_value = convert(to_unit, 1, from_unit).magnitude
         return ScaleHint(top_unit=from_unit, top_min=0, top_max=converted_value, bottom_unit=to_unit, bottom_min=0, bottom_max=1)
     else:
         return ScaleHint(top_unit=from_unit, top_min=0, top_max=1, bottom_unit=to_unit, bottom_min=0, bottom_max=converted_value)
Exemple #2
0
 def create_unit_hint(cls, from_unit, to_unit):
     converted_value = convert(from_unit, 1, to_unit)
     if converted_value.magnitude > 0.001:
         value = format_quantity(converted_value)
         return TextHint(text='{} is {}'.format(format_value(from_unit, 1), value))
     else:
         converted_value = convert(to_unit, 1, from_unit)
         value = format_quantity(converted_value)
         return TextHint(text='{} is {}'.format(format_value(to_unit, 1), value))
    def explanation(self):
        correct_question = [x for x in self.question.answers if x.correct and x.unit != self.unit]
        if len(correct_question) == 1:
            converted_value = convert.convert(self.unit, self.value, correct_question[0].unit)

            if converted_value.magnitude > 0.001:
                return convert.format_quantity(converted_value)
            else:
                # the value is below the required precision so we cannot use it
                return None
        else:
            return None
    def explanation(self):
        min_unit = None
        for question in self.question.answers:
            normalized = convert.to_normalized(question.unit, 1)
            if min_unit is None or convert.to_normalized(min_unit, 1) > normalized:
                min_unit = question.unit

        if min_unit and min_unit != self.unit:
            converted_value = convert.convert(self.unit, self.value, min_unit)
            if converted_value.magnitude > 0.001:
                return convert.format_quantity(converted_value)
            else:
                # the value is below the required precision so we cannot use it
                return None
        else:
            return None
 def to_value(self):
     return convert.convert(self.from_unit, self.from_value, self.to_unit).magnitude