示例#1
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)
示例#2
0
 def testBmiNotNan(self):
   #tombomist is too old for most calculations, but BMI should be calculated
   visit_stats = VisitStatistics.get_stats(
                                           datetime.date(1995,03,21),
                                           datetime.date(2007,03,25),
                                           Sex.MALE,
                                           30, 49.5, 140,
                                           Measured.STANDING, None)
   util.assertNear(self, 15.3, visit_stats.body_mass_index, 0.1)
示例#3
0
 def testZeroDayStats(self):
   # Age is 0 days, whcih is still valid.
   # Equivalent to AA2 in the anthrotest.csv
   visit_stats = VisitStatistics.get_stats(
                                           datetime.date(2009,11,27),
                                           datetime.date(2009,11,27),
                                           Sex.FEMALE,
                                           4, 35, 49,
                                           Measured.RECUMBENT, None)
   
   # Length-or-height for age
   zandp = visit_stats.get_zandp('length_or_height_for_age')
   util.assertNear(self, -0.08, zandp.zscore, 0.01)
   util.assertNear(self, 46.8, zandp.percentile, 0.1)
示例#4
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))
示例#5
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))
示例#6
0
  def testFile(self):
    lineNum = 0
    for row in csv.DictReader(open('growthcalc/anthrotest.csv')):
      lineNum += 1
      # The first fields are the visit
      name = row['name']
      sex = row['sex']
      
      try:
        dateOfBirth = datetime.datetime.strptime(row['dateOfBirth'], "%m/%d/%Y")   
      except:
        dateOfBirth = None
      
      try:
        dateOfVisit = datetime.datetime.strptime(row['dateOfVisit'], "%m/%d/%Y")
      except:
        dateOfVisit = None
        
      weight = float(row['weight'])
      height = float(row['lengthOrHeight'])
      headCircumference = float(row['headCircumference'])
      measured = row['measured']
      if row['oedema'] == "TRUE":
        oedema = True
      elif row['oedema'] == "FALSE":
        oedema = False

      visit_stats = VisitStatistics.get_stats(dateOfBirth,
                                              dateOfVisit,
                                              sex,
                                              weight,
                                              headCircumference,
                                              height,
                                              measured,
                                              oedema,
                                              None)
      
      testScore = float(row['bmi'])
      eps = float(row['bmi-eps'])
      self.assertTrue(util.isNanOrNear(
                                   testScore, visit_stats.body_mass_index, eps))
          
      testScore = float(row['weight-for-length-or-height'])
      eps = float(row['weight-for-length-or-height-eps'])
      zandp = visit_stats.get_zandp('weight_for_length_or_height')
      util.assertIsNanOrNear(self, testScore, zandp.zscore, eps)        
      testScore = float(row['weight-for-length-or-height-%'])
      eps = float(row['weight-for-length-or-height-%-eps'])
      util.assertIsNanOrNear(self, testScore, zandp.percentile, eps)        
      
      testScore = float(row['weight-for-age'])
      eps = float(row['weight-for-age-eps'])
      zandp = visit_stats.get_zandp('weight_for_age')
      util.assertIsNanOrNear(self, testScore, zandp.zscore, eps)
      testScore = float(row['weight-for-age-%'])
      eps = float(row['weight-for-age-%-eps'])        
      util.assertIsNanOrNear(self, testScore, zandp.percentile, eps)        
      
      testScore = float(row['length-or-height-for-age'])
      eps = float(row['length-or-height-for-age-eps'])
      zandp = visit_stats.get_zandp('length_or_height_for_age')
      self.assertTrue(util.isNanOrNear(testScore, zandp.zscore, eps))
      testScore = float(row['length-or-height-for-age-%'])
      eps = float(row['length-or-height-for-age-%-eps'])
      self.assertTrue(util.isNanOrNear(testScore, zandp.percentile, eps))
      
      testScore = float(row['bmi-for-age'])
      eps = float(row['bmi-for-age-eps'])
      zandp = visit_stats.get_zandp('body_mass_index_for_age')
      self.assertTrue(util.isNanOrNear(testScore, zandp.zscore, eps))
      testScore = float(row['bmi-for-age-%'])
      eps = float(row['bmi-for-age-%-eps'])
      self.assertTrue(util.isNanOrNear(testScore, zandp.percentile, eps))
     
      testScore = float(row['head-circumference-for-age'])
      eps = float(row['head-circumference-for-age-eps'])
      zandp = visit_stats.get_zandp('head_circumference_for_age')
      self.assertTrue(util.isNanOrNear(testScore, zandp.zscore, eps))
      testScore = float(row['head-circumference-for-age-%'])
      eps = float(row['head-circumference-for-age-%-eps'])
      self.assertTrue(util.isNanOrNear(testScore, zandp.percentile, eps))
    self.assertEquals(lineNum, 23)