def test_map_data(self): self.assertDictEqual( get_prevalence_of_undernutrition_data_map( 'icds-cas', config={'month': (2017, 5, 1)}, loc_level='state'), { 'rightLegend': { 'info': u'Percentage of children between 0 - 5 years enrolled for ICDS services' u' with weight-for-age less than -2 standard deviations' u' of the WHO Child Growth Standards median.' u' <br/><br/>Children who are moderately or severely underweight' u' have a higher risk of mortality', 'average': 19.8488634036453, 'extended_info': [{ 'indicator': 'Total Children (0 - 5 years) weighed in given month:', 'value': '4,945' }, { 'indicator': '% Unweighed (0 - 5 years):', 'value': '3.44%' }, { 'indicator': '% Severely Underweight (0 - 5 years):', 'value': '2.22%' }, { 'indicator': '% Moderately Underweight (0 - 5 years):', 'value': '17.59%' }, { 'indicator': '% Normal (0 - 5 years):', 'value': '76.74%' }] }, 'fills': OrderedDict([('0%-20%', MapColors.PINK), ('20%-35%', MapColors.ORANGE), ('35%-100%', MapColors.RED), ('defaultFill', MapColors.GREY)]), 'data': { 'st1': { 'total': 2375, 'severely_underweight': 40, 'moderately_underweight': 450, 'fillKey': '20%-35%', 'original_name': ["st1"], 'normal': 1820 }, 'st2': { 'total': 2570, 'severely_underweight': 70, 'moderately_underweight': 420, 'original_name': ["st2"], 'fillKey': '0%-20%', 'normal': 1975 } }, 'slug': 'moderately_underweight', 'label': 'Percent of Children Underweight (0 - 5 years)' })
def test_map_name_two_locations_represent_by_one_topojson(self): data = get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), 'state_id': 'st1', 'district_id': 'd1', 'aggregation_level': 3 }, loc_level='block', ) self.assertDictEqual( data['data'], { 'block_map': { 'severely_underweight': 8, 'moderately_underweight': 64, 'normal': 245, 'weighed': 317, 'total': 475, 'original_name': ['b1', 'b2'], 'fillKey': '20%-35%' } } )
def test_map_data(self): data = get_prevalence_of_undernutrition_data_map('icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state') self.assertDictEqual( data['data'], { 'st1': { 'weighed': 1585, 'severely_underweight': 40, 'moderately_underweight': 320, 'fillKey': '20%-35%', 'original_name': ["st1"], 'normal': 1225, 'total': 2375 }, 'st2': { 'weighed': 1895, 'severely_underweight': 60, 'moderately_underweight': 330, 'original_name': ["st2"], 'fillKey': '20%-35%', 'normal': 1505, 'total': 2570 } })
def test_map_data_right_legend_extended_info(self): data = get_prevalence_of_undernutrition_data_map('icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state') self.assertListEqual( data['rightLegend']['extended_info'], [{ 'indicator': 'Total Children (0 - 5 years) weighed in given month:', 'value': '3,480' }, { 'indicator': 'Number of children unweighed (0 - 5 years):', 'value': '1,465' }, { 'indicator': '% Severely Underweight (0 - 5 years):', 'value': '2.87%' }, { 'indicator': '% Moderately Underweight (0 - 5 years):', 'value': '18.68%' }, { 'indicator': '% Normal (0 - 5 years):', 'value': '78.45%' }])
def test_map_name_is_different_data(self): self.assertDictEqual( get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), 'state_id': 'st1', 'district_id': 'd1', 'aggregation_level': 3 }, loc_level='block', ), { 'rightLegend': { 'info': u'Percentage of children between 0 - 5 years enrolled for ICDS services' u' with weight-for-age less than -2 standard deviations' u' of the WHO Child Growth Standards median.' u' <br/><br/>Children who are moderately or severely underweight' u' have a higher risk of mortality', 'average': 20.63157894736842, 'extended_info': [{ 'indicator': 'Total Children (0 - 5 years) weighed in given month:', 'value': '475' }, { 'indicator': '% Unweighed (0 - 5 years):', 'value': '2.74%' }, { 'indicator': '% Severely Underweight (0 - 5 years):', 'value': '1.68%' }, { 'indicator': '% Moderately Underweight (0 - 5 years):', 'value': '18.95%' }, { 'indicator': '% Normal (0 - 5 years):', 'value': '76.63%' }] }, 'fills': OrderedDict([('0%-20%', MapColors.PINK), ('20%-35%', MapColors.ORANGE), ('35%-100%', MapColors.RED), ('defaultFill', MapColors.GREY)]), 'data': { 'block_map': { 'severely_underweight': 8, 'moderately_underweight': 90, 'normal': 364, 'total': 475, 'original_name': ['b1', 'b2'], 'fillKey': '20%-35%' } }, 'slug': 'moderately_underweight', 'label': 'Percent of Children Underweight (0 - 5 years)' })
def test_map_data_slug(self): data = get_prevalence_of_undernutrition_data_map('icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state') self.assertEquals(data['slug'], 'moderately_underweight')
def test_map_data_right_legend_average(self): data = get_prevalence_of_undernutrition_data_map('icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state') self.assertEquals(data['rightLegend']['average'], 21.64670434399008)
def test_map_data_label(self): data = get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state' ) self.assertEquals(data['label'], 'Percent of Children Underweight (0 - 5 years)')
def test_map_data_slug(self): data = get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state' ) self.assertEquals(data['slug'], 'moderately_underweight')
def test_map_data_label(self): data = get_prevalence_of_undernutrition_data_map('icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state') self.assertEquals(data['label'], 'Percent of Children Underweight (0 - 5 years)')
def test_map_data_right_legend_keys(self): data = get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state')['rightLegend'] self.assertEquals(len(data), 3) self.assertIn('info', data) self.assertIn('average', data) self.assertIn('extended_info', data)
def test_map_data_right_legend_average(self): data = get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state' ) self.assertEquals(data['rightLegend']['average'], '21.55')
def test_map_data_right_legend_info(self): data = get_prevalence_of_undernutrition_data_map('icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state') expected = underweight_children_help_text(age_label="0 - 5 years", html=True) self.assertEquals(data['rightLegend']['info'], expected)
def test_map_data_right_legend_info(self): data = get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state' ) expected = underweight_children_help_text(age_label="0 - 5 years", html=True) self.assertEquals(data['rightLegend']['info'], expected)
def test_map_data_right_legend_average(self): self.maxDiff = None data = get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), 'aggregation_level': 1 }, loc_level='state') self.assertEqual(data['rightLegend']['average'], '21.44')
def test_map_data_right_legend_keys(self): data = get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state' )['rightLegend'] self.assertEquals(len(data), 3) self.assertIn('info', data) self.assertIn('average', data) self.assertIn('extended_info', data)
def test_average_with_two_locations_represent_by_one_topojson(self): data = get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), 'state_id': 'st1', 'district_id': 'd1', 'aggregation_level': 3 }, loc_level='block', ) self.assertEquals(data['rightLegend']['average'], '22.71')
def test_average_with_two_locations_represent_by_one_topojson(self): data = get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), 'state_id': 'st1', 'district_id': 'd1', 'aggregation_level': 3 }, loc_level='block', ) self.assertEquals(data['rightLegend']['average'], 22.743014091234773)
def test_map_data_keys(self): data = get_prevalence_of_undernutrition_data_map('icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state') self.assertEquals(len(data), 5) self.assertIn('rightLegend', data) self.assertIn('fills', data) self.assertIn('data', data) self.assertIn('slug', data) self.assertIn('label', data)
def test_map_data_right_legend_info(self): data = get_prevalence_of_undernutrition_data_map('icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state') expected = ( 'Of the total children enrolled for Anganwadi services and weighed, the percentage of children ' 'between 0 - 5 years years who were moderately/severely underweight in the current month. ' '<br/><br/>' 'Children who are moderately or severely underweight have a higher risk of mortality.' ) self.assertEquals(data['rightLegend']['info'], expected)
def test_map_data_right_legend_info(self): data = get_prevalence_of_undernutrition_data_map('icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state') expected = ( 'Percentage of children between 0 - 5 years enrolled for Anganwadi Services' ' with weight-for-age less than -2 standard deviations' ' of the WHO Child Growth Standards median.' ' <br/><br/>Children who are moderately or severely underweight' ' have a higher risk of mortality') self.assertEquals(data['rightLegend']['info'], expected)
def test_map_data_keys(self): data = get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state' ) self.assertEquals(len(data), 5) self.assertIn('rightLegend', data) self.assertIn('fills', data) self.assertIn('data', data) self.assertIn('slug', data) self.assertIn('label', data)
def test_map_data_fills(self): data = get_prevalence_of_undernutrition_data_map('icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state') self.assertDictEqual( data['fills'], { "0%-20%": MapColors.PINK, "20%-35%": MapColors.ORANGE, "35%-100%": MapColors.RED, "defaultFill": MapColors.GREY })
def test_map_data_fills(self): data = get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state' ) self.assertDictEqual( data['fills'], { "0%-20%": MapColors.PINK, "20%-35%": MapColors.ORANGE, "35%-100%": MapColors.RED, "defaultFill": MapColors.GREY } )
def test_map_data(self): self.assertDictEqual( get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1) }, loc_level='state' )[0], { 'rightLegend': { 'info': u'Percentage of children between 0-5 years enrolled for ICDS services' u' with weight-for-age less than -2 standard deviations' u' of the WHO Child Growth Standards median.' u' <br/><br/>Children who are moderately or severely underweight' u' have a higher risk of mortality', 'average': 17.593528816986854 }, 'fills': OrderedDict( [ ('0%-20%', '#fee0d2'), ('20%-35%', '#fc9272'), ('35%-100%', '#de2d26'), ('defaultFill', '#9D9D9D') ] ), 'data': { u'st1': { 'total': 2375, 'severely_underweight': 40, 'moderately_underweight': 450, 'fillKey': '20%-35%', 'normal': 1820 }, u'st2': { 'total': 2570, 'severely_underweight': 70, 'moderately_underweight': 420, 'fillKey': '0%-20%', 'normal': 1975 } }, 'slug': 'moderately_underweight', 'label': 'Percent of Children Underweight (0-5 years)' } )
def test_map_data_right_legend_extended_info(self): data = get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state' ) self.assertListEqual( data['rightLegend']['extended_info'], [ {'indicator': 'Total Children (0 - 5 years) weighed in given month:', 'value': '3,480'}, {'indicator': 'Number of children unweighed (0 - 5 years):', 'value': '1,480'}, {'indicator': '% Severely Underweight (0 - 5 years):', 'value': '2.87%'}, {'indicator': '% Moderately Underweight (0 - 5 years):', 'value': '18.68%'}, {'indicator': '% Normal (0 - 5 years):', 'value': '78.45%'} ] )
def test_map_data(self): self.maxDiff = None data = get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), 'aggregation_level': 1 }, loc_level='state') self.assertDictEqual( data['data'], { 'st1': { 'moderately_underweight': 64, 'severely_underweight': 8, 'normal': 245, 'weighed': 317, 'total': 475, 'original_name': ['st1'], 'fillKey': '20%-35%' }, 'st2': { 'moderately_underweight': 65, 'severely_underweight': 12, 'normal': 301, 'weighed': 378, 'total': 513, 'original_name': ['st2'], 'fillKey': '20%-35%' }, 'st7': { 'moderately_underweight': 0, 'severely_underweight': 0, 'normal': 0, 'weighed': 0, 'total': 1, 'original_name': ['st7'], 'fillKey': '0%-20%' } })
def test_map_name_two_locations_represent_by_one_topojson(self): data = get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), 'state_id': 'st1', 'district_id': 'd1', 'aggregation_level': 3 }, loc_level='block', ) self.assertDictEqual( data['data'], { 'block_map': { 'severely_underweight': 8, 'moderately_underweight': 64, 'normal': 245, 'total': 317, 'original_name': ['b1', 'b2'], 'fillKey': '20%-35%' } })
def test_map_data(self): data = get_prevalence_of_undernutrition_data_map('icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state') self.assertDictEqual( data['data'], { 'st1': { 'moderately_underweight': 320, 'severely_underweight': 40, 'normal': 1225, 'weighed': 1585, 'total': 2375, 'original_name': ['st1'], 'fillKey': '20%-35%' }, 'st2': { 'moderately_underweight': 325, 'severely_underweight': 60, 'normal': 1505, 'weighed': 1890, 'total': 2565, 'original_name': ['st2'], 'fillKey': '20%-35%' }, 'st3': { 'moderately_underweight': 0, 'severely_underweight': 0, 'normal': 0, 'weighed': 0, 'total': 1, 'original_name': ['st3'], 'fillKey': '0%-20%' }, 'st4': { 'moderately_underweight': 0, 'severely_underweight': 0, 'normal': 0, 'weighed': 0, 'total': 2, 'original_name': ['st4'], 'fillKey': '0%-20%' }, 'st5': { 'moderately_underweight': 0, 'severely_underweight': 0, 'normal': 0, 'weighed': 0, 'total': 3, 'original_name': ['st5'], 'fillKey': '0%-20%' }, 'st6': { 'moderately_underweight': 0, 'severely_underweight': 0, 'normal': 0, 'weighed': 0, 'total': 4, 'original_name': ['st6'], 'fillKey': '0%-20%' }, 'st7': { 'moderately_underweight': 0, 'severely_underweight': 0, 'normal': 0, 'weighed': 0, 'total': 5, 'original_name': ['st7'], 'fillKey': '0%-20%' } })
def test_map_data(self): data = get_prevalence_of_undernutrition_data_map( 'icds-cas', config={ 'month': (2017, 5, 1), }, loc_level='state' ) self.assertDictEqual( data['data'], { 'st4': { 'severely_underweight': 0, 'normal': 0, 'original_name': ['st4'], 'weighed': 0, 'moderately_underweight': 0, 'total': 2, 'fillKey': '0%-20%' }, 'st5': { 'severely_underweight': 0, 'normal': 0, 'original_name': ['st5'], 'weighed': 0, 'moderately_underweight': 0, 'total': 3, 'fillKey': '0%-20%' }, 'st6': { 'severely_underweight': 0, 'normal': 0, 'original_name': ['st6'], 'weighed': 0, 'moderately_underweight': 0, 'total': 4, 'fillKey': '0%-20%' }, 'st7': { 'severely_underweight': 0, 'normal': 0, 'original_name': ['st7'], 'weighed': 0, 'moderately_underweight': 0, 'total': 5, 'fillKey': '0%-20%' }, 'st1': { 'severely_underweight': 40, 'normal': 1225, 'original_name': ['st1'], 'weighed': 1585, 'moderately_underweight': 320, 'total': 2375, 'fillKey': '20%-35%' }, 'st2': { 'severely_underweight': 60, 'normal': 1505, 'original_name': ['st2'], 'weighed': 1895, 'moderately_underweight': 330, 'total': 2570, 'fillKey': '20%-35%' }, 'st3': { 'severely_underweight': 0, 'normal': 0, 'original_name': ['st3'], 'weighed': 0, 'moderately_underweight': 0, 'total': 1, 'fillKey': '0%-20%' } } )