示例#1
0
class HeightCurveMaleMonths(generics.RetrieveAPIView):
    """
    Height-based growth curve for males aged 0 to 36 months view.
    """

    serializer_class = HeightCurveSerializer

    def get_object(self):
        """
        Get the specific curve.
        """

        self.graphic = HeightCurve(gender=Constants.MALE, age=Constants.MONTHS)

        return self.graphic.make()

    def get_serializer_context(self):
        """
        Insert some attribute inside serializer.
        """

        context = super(HeightCurveMaleMonths, self).get_serializer_context()
        context['graphic'] = self.graphic.make_charts()

        return context
示例#2
0
class HeightCurveFemaleYears(generics.RetrieveAPIView):
    """
    Height-based growth curve for females aged 3 to 20 years view.
    """

    serializer_class = HeightCurveSerializer

    def get_object(self):
        """
        Get the specific curve.
        """

        self.graphic = HeightCurve(gender=Constants.FEMALE,
                                   age=Constants.YEARS)

        return self.graphic.make()

    def get_serializer_context(self):
        """
        Insert some attribute inside serializer.
        """

        context = super(HeightCurveFemaleYears, self).get_serializer_context()
        context['graphic'] = self.graphic.make_charts(years=True)

        return context
示例#3
0
    def get_object(self):
        """
        Get the specific curve.
        """

        self.graphic = HeightCurve(gender=Constants.MALE, age=Constants.YEARS)

        return self.graphic.make()
示例#4
0
    def test_height_curve_female_years(self):
        """
        Test to verify if graphic construct is correct with FEMALE and YEARS.
        """

        graphic = HeightCurve(gender=Constants.FEMALE, age=Constants.YEARS)
        self.assertEqual(graphic.make(), self.female_years)
        self.assertEqual(graphic.make(HeightCurve.TITLE),
                         self.female_years['title'])
示例#5
0
    def test_height_curve_male_months(self):
        """
        Test to verify if graphic construct is correct with MALE and MONTHS.
        """

        graphic = HeightCurve(gender=Constants.MALE, age=Constants.MONTHS)
        self.assertEqual(graphic.make(), self.male_months)
        self.assertEqual(graphic.make(HeightCurve.TITLE),
                         self.male_months['title'])
示例#6
0
    def test_result_months_invalid(self):
        """
        Test to check if the result with months is incorrect because age is
        incorrect.
        """

        graphic = HeightCurve(gender=Constants.MALE, age=Constants.MONTHS)

        # percentis_3
        self.assertEqual(graphic.result(42.91, 0), 0)
        self.assertEqual(graphic.result(42.91, -1), "Invalid age")
        self.assertEqual(graphic.result(81.85, 36), 0)
        self.assertEqual(graphic.result(81.85, 37), "Invalid age")
    def get_graphic(self):
        """
        Get the specific graphic.
        """

        graphic = HeightCurve(gender=Constants.MALE, age=Constants.MONTHS)

        return graphic
示例#8
0
    def test_result_years_ok(self):
        """
        Test to check if the result with years is correct.
        """

        graphic = HeightCurve(gender=Constants.MALE, age=Constants.YEARS)

        # percentis_3
        self.assertEqual(graphic.result(83.24, 3), -1)
        self.assertEqual(graphic.result(83.25, 3), 0)
        self.assertEqual(graphic.result(83.26, 3), 0)
        self.assertEqual(graphic.result(118.42, 10), -1)
        self.assertEqual(graphic.result(118.43, 10), 0)
        self.assertEqual(graphic.result(118.44, 10), 0)

        # percentis_97
        self.assertEqual(graphic.result(100.50, 3), 0)
        self.assertEqual(graphic.result(100.51, 3), 0)
        self.assertEqual(graphic.result(100.52, 3), 1)
        self.assertEqual(graphic.result(143.42, 10), 0)
        self.assertEqual(graphic.result(143.43, 10), 0)
        self.assertEqual(graphic.result(143.44, 10), 1)
示例#9
0
    def test_result_months_ok(self):
        """
        Test to check if the result with months is correct.
        """

        graphic = HeightCurve(gender=Constants.MALE, age=Constants.MONTHS)

        # percentis_3
        self.assertEqual(graphic.result(42.90, 0), -1)
        self.assertEqual(graphic.result(42.91, 0), 0)
        self.assertEqual(graphic.result(42.92, 0), 0)
        self.assertEqual(graphic.result(63.74, 10), -1)
        self.assertEqual(graphic.result(63.75, 10), 0)
        self.assertEqual(graphic.result(63.76, 10), 0)

        # percentis_97
        self.assertEqual(graphic.result(53.06, 0), 0)
        self.assertEqual(graphic.result(53.07, 0), 0)
        self.assertEqual(graphic.result(53.08, 0), 1)
        self.assertEqual(graphic.result(76.26, 10), 0)
        self.assertEqual(graphic.result(76.27, 10), 0)
        self.assertEqual(graphic.result(76.28, 10), 1)
示例#10
0
    def get_curve(cls, gender, interval):
        """
        Get the specific curve from gender and interval.
        """

        curve_gender = Constants.MALE
        curve_interval = Constants.YEARS

        if gender == 'F':
            curve_gender = Constants.FEMALE

        if interval == 'months':
            curve_interval = Constants.MONTHS

        graphic = HeightCurve(gender=curve_gender, age=curve_interval)

        return graphic
示例#11
0
    def test_result_years_invalid(self):
        """
        Test to check if the result with years is incorrect because age is
        incorrect.
        """

        graphic = HeightCurve(gender=Constants.MALE, age=Constants.YEARS)

        # percentis_3
        self.assertEqual(graphic.result(83.25, -5), "Invalid age")
        self.assertEqual(graphic.result(83.25, -1), "Invalid age")
        self.assertEqual(graphic.result(83.25, 0), "Invalid age")
        self.assertEqual(graphic.result(83.25, 1), "Invalid age")
        self.assertEqual(graphic.result(83.25, 2), "Invalid age")
        self.assertEqual(graphic.result(83.25, 3), 0)
        self.assertEqual(graphic.result(143.83, 20), 0)
        self.assertEqual(graphic.result(143.83, 21), "Invalid age")