Exemple #1
0
  def test_parse_zscore_and_percentile(self):
    xml = TestVisitStatistics.XML1

    doc = minidom.parseString(xml)

    zandp = models.VisitStatistics._parse_zscore_and_percentile(
              u'weight_for_length_or_height', doc)
    self.assertTrue(util.isNaN(zandp.percentile))
    self.assertTrue(math.fabs(zandp.zscore - -3.49) < 0.01)

    visit_stats = models.VisitStatistics._parse_visit_statistics(xml)
    self.assertTrue(util.isNaN(visit_stats.weight_for_length_or_height.percentile))
    self.assertTrue(math.fabs(
                visit_stats.weight_for_length_or_height.zscore - -3.49) < 0.01)

    self.assertEquals(1461, visit_stats.age_in_days)
    self.assertTrue(math.fabs(12.5 - visit_stats.body_mass_index) < 0.01)

    # Try datastore code
    visit_stats.put()
    id = visit_stats.id
    self.assertTrue(id is not None)

    # Try str()
    foo = str(visit_stats)
    self.assertTrue(foo is not None)
Exemple #2
0
 def testBmiNan(self):
   # Height is too small, return NaN
   self.assertTrue(util.isNaN(
                       growthcalc.growthcalc.heightAndWeightToBmi(37.99, 24)))
   # Weight is too small, return NaN
   self.assertTrue(util.isNaN(
                         growthcalc.growthcalc.heightAndWeightToBmi(50, 0.8)))
Exemple #3
0
 def test2(self):
   visit_stats = VisitStatistics.get_stats(
                                           datetime.date(2005,03,21),
                                           datetime.date(2007,03,25),
                                           Sex.FEMALE, 
                                           8.2, 45, 74,
                                           Measured.RECUMBENT, None)
   
   # BMI
   util.assertNear(self, 15.3, visit_stats.body_mass_index, 0.1)
   
   # Weight-for-length-or-height
   zandp = visit_stats.get_zandp('weight_for_length_or_height')
   util.assertNear(self, -1.00, zandp.zscore, 0.01)
   util.assertNear(self, 15.9, zandp.percentile, 0.1)
   
   # Weight-for-age
   zandp = visit_stats.get_zandp('weight_for_age')
   util.assertNear(self, -2.87, zandp.zscore, 0.01)
   util.assertNear(self, 0.2, zandp.percentile, 0.1)
   
   # Length-or-height for age
   zandp = visit_stats.get_zandp('length_or_height_for_age')
   util.assertNear(self, -3.87, zandp.zscore, 0.01)
   self.assertTrue(util.isNaN(zandp.percentile))
   
   # BMI-for-age
   zandp = visit_stats.get_zandp('body_mass_index_for_age')
   util.assertNear(self, -0.33, zandp.zscore, 0.01)
   util.assertNear(self, 37.2, zandp.percentile, 0.1)
   
   # HC-for-age
   zandp = visit_stats.get_zandp('head_circumference_for_age')
   util.assertNear(self, -1.58, zandp.zscore, 0.01)
   util.assertNear(self, 5.8, zandp.percentile, 0.1)
Exemple #4
0
 def testHCforAgeNaN(self):
   # Head circumference is calculated slightly differently from other
   # stats in a way that should make it come out NaN.
   # This is "computeFinalZScore" from zscoreOtherRestricted.
   # Equivalent to AA8 in the anthrotest.csv.
   visit_stats = VisitStatistics.get_stats(
                                           datetime.date(2007,12,14),
                                           datetime.date(2008,02,29),
                                           Sex.FEMALE,
                                           8, 24.99, 63,
                                           Measured.STANDING, None)
   
   # HC-for-age
   zandp = visit_stats.get_zandp('head_circumference_for_age')
   self.assertTrue(util.isNaN(zandp.zscore))
   self.assertTrue(util.isNaN(zandp.percentile))
Exemple #5
0
  def test1(self):    
    # Bernadette
    sex = Sex.FEMALE
    dateOfBirth = datetime.date(2005,03,21)
    dateOfVisit = datetime.date(2007,03,25)
    ageInDays = (dateOfVisit - dateOfBirth).days
    weight = 8.2 # kg
    length = 74.0 # cm
    headCircumference = 45.0 # cm
    measured = Measured.RECUMBENT
    
    loh = growthcalc.growthcalc.NormalizedLengthOrHeight(
                                                   ageInDays, length, measured)  
    bmi = growthcalc.growthcalc.heightAndWeightToBmi(loh.lengthOrHeight, weight)
    util.assertNear(self, 15.3, bmi, 0.1)
    
    anthro = growthcalc.growthcalc.Anthro()
    
    # Weight-for-length-or-height
    zscore = anthro.getWeightZscoreConfigForLengthOrHeight(
                                          Sex.map[sex], loh, weight, ageInDays)
    percentile = growthcalc.growthcalc.zscoreToPercentile(zscore)
    util.assertNear(self, -1.00, zscore, 0.01)
    util.assertNear(self, 15.9, percentile, 0.1)

    # Weight-for-age
    zscore = anthro.getWeightZscoreConfigForAge(Sex.map[sex], ageInDays, weight)
    percentile = growthcalc.growthcalc.zscoreToPercentile(zscore)
    util.assertNear(self, -2.87, zscore, 0.01)
    util.assertNear(self, 0.2, percentile, 0.1)
    
    # Length-or-height for age
    zscore = anthro.getLengthOrHeightZscoreConfigForAge(
                          Sex.map[sex], ageInDays, loh.lengthOrHeight, measured)
    percentile = growthcalc.growthcalc.zscoreToPercentile(zscore)
    util.assertNear(self, -3.87, zscore, 0.01)
    self.assertTrue(util.isNaN(percentile))
    
    # BMI-for-age
    zscore = anthro.getBodyMassIndexZscoreConfigForAge(
                       Sex.map[sex], ageInDays, bmi, weight, loh.lengthOrHeight)
    percentile = growthcalc.growthcalc.zscoreToPercentile(zscore)
    util.assertNear(self, -0.33, zscore, 0.01)
    util.assertNear(self, 37.2, percentile, 0.1)
    
    # HC-for-age
    zscore = anthro.getHeadCircumferenceZscoreConfigForAge(
                                     Sex.map[sex], ageInDays, headCircumference)
    percentile = growthcalc.growthcalc.zscoreToPercentile(zscore)
    util.assertNear(self, -1.58, zscore, 0.01)
    util.assertNear(self, 5.8, percentile, 0.1)
Exemple #6
0
 def testLengthOrHeightForAgeNotNan(self):
   # Age is right on the border, but still valid.
   # Equivalent to AA2 in the anthrotest.csv.
   visit_stats = VisitStatistics.get_stats(
                                           datetime.date(2002,03,15),
                                           datetime.date(2007,04,14),
                                           Sex.MALE,
                                           10, 50, 65.6,
                                           Measured.RECUMBENT, None)
    
   # Length-or-height for age
   zandp = visit_stats.get_zandp('length_or_height_for_age')
   util.assertNear(self, -9.76, zandp.zscore, 0.01)
   self.assertTrue(util.isNaN(zandp.percentile))
Exemple #7
0
  def test_nans(self):
    '''This was a bug in bucket_zscore: all zscores are NaNs'''

    xml= """
      <growthserver_response date_generated="2011-02-08 21:35:49 +0000">
        <input_data name="" sex="MALE" birth_date="2011-02-10"
         visit_date="2011-02-08"
         weight="30.0" height="40.0" height_position="STANDING"/>
        <results age_in_days="-1" body_mass_index="181.1058322114833"
         weight_for_length_or_height_percentile="NaN"
         weight_for_length_or_height_zscore="NaN"
         weight_for_age_percentile="NaN" weight_for_age_zscore="NaN"
         length_or_height_for_age_percentile="NaN"
         length_or_height_for_age_zscore="NaN"
         body_mass_index_for_age_percentile="NaN"
         body_mass_index_for_age_zscore="NaN"
         head_circumference_for_age_percentile="NaN"
         head_circumference_for_age_zscore="NaN"/>
      </growthserver_response>"""
    visit_stats = models.VisitStatistics._parse_visit_statistics(xml)
    self.assertTrue(util.isNaN(util.bucket_zscore(
          visit_stats.get_worst_zscore())))
Exemple #8
0
 def testIsNaN(self):
   self.assertFalse(util.isNaN(3.5))
   # String NaN is not float NaN.
   self.assertFalse(util.isNaN("NaN"))
   self.assertFalse(util.isNaN(u"NaN"))
   self.assertTrue(util.isNaN(util.NaN))