class IMCCurveMale(generics.RetrieveAPIView): """ IMC based growth curve for males aged 2 to 18 years view. """ serializer_class = IMCCurveSerializer def get_object(self): """ Get the specific curve. """ self.graphic = IMCCurve(gender=Constants.MALE) return self.graphic.make() def get_serializer_context(self): """ Insert some attribute inside serializer. """ context = super(IMCCurveMale, self).get_serializer_context() context['graphic'] = self.graphic.make_charts() return context
def get_object(self): """ Get the specific curve. """ self.graphic = IMCCurve(gender=Constants.FEMALE) return self.graphic.make()
def test_imc_curve_female(self): """ Test to verify if graphic construct is correct with FEMALE gender. """ graphic = IMCCurve(gender=Constants.FEMALE) self.assertEqual(graphic.make(), self.female) self.assertEqual(graphic.make(IMCCurve.TITLE), self.female['title'])
def get_graphic(self): """ Get the specific graphic. """ graphic = IMCCurve(gender=Constants.FEMALE) return graphic
def get_curve(cls, gender='M'): """ Get the specific curve from gender and interval. """ curve_gender = Constants.MALE if gender == 'F': curve_gender = Constants.FEMALE graphic = IMCCurve(gender=curve_gender) return graphic
def test_result_ok(self): """ Test to check if the result with age is correct. """ graphic = IMCCurve(gender=Constants.MALE) # percentis_3 self.assertEqual(graphic.result(13.82, 2), -1) self.assertEqual(graphic.result(13.83, 2), 0) self.assertEqual(graphic.result(13.84, 2), 0) self.assertEqual(graphic.result(15.36, 10), -1) self.assertEqual(graphic.result(15.37, 10), 0) self.assertEqual(graphic.result(15.38, 10), 0) # percentis_97 self.assertEqual(graphic.result(19.70, 2), 0) self.assertEqual(graphic.result(19.71, 2), 0) self.assertEqual(graphic.result(19.72, 2), 1) self.assertEqual(graphic.result(28.26, 10), 0) self.assertEqual(graphic.result(28.27, 10), 0) self.assertEqual(graphic.result(28.28, 10), 1)
def test_result_invalid(self): """ Test to check if the result with age is incorrect. """ graphic = IMCCurve(gender=Constants.MALE) # percentis_3 self.assertEqual(graphic.result(13.83, -2), "Invalid age") self.assertEqual(graphic.result(13.83, 0), "Invalid age") self.assertEqual(graphic.result(13.83, 1), "Invalid age") self.assertEqual(graphic.result(13.83, 2), 0) self.assertEqual(graphic.result(19.48, 18), 0) self.assertEqual(graphic.result(19.48, 19), "Invalid age")