def test_precipitation_intensity(self): """Testing getting string description from precipitation intensity""" self.assertEqual(utils.precipitation_intensity(0.00, 'in/h'), 'none') self.assertEqual(utils.precipitation_intensity(0.002, 'in/h'), 'very-light') self.assertEqual(utils.precipitation_intensity(0.017, 'in/h'), 'light') self.assertEqual(utils.precipitation_intensity(0.1, 'in/h'), 'moderate') self.assertEqual(utils.precipitation_intensity(0.4, 'in/h'), 'heavy') self.assertEqual(utils.precipitation_intensity(0.00, 'mm/h'), 'none') self.assertEqual(utils.precipitation_intensity(0.051, 'mm/h'), 'very-light') self.assertEqual(utils.precipitation_intensity(0.432, 'mm/h'), 'light') self.assertEqual(utils.precipitation_intensity(2.540, 'mm/h'), 'moderate') self.assertEqual(utils.precipitation_intensity(5.08, 'mm/h'), 'heavy')
def precipitation(self, weather_data): """ :return: Condition namedtuple with type and random text field names """ intensity = utils.precipitation_intensity(weather_data.precipIntensity, weather_data.units['precipIntensity']) probability = weather_data.precipProbability precip_type = weather_data.precipType # Consider 80% chance and above as fact if probability >= 0.80 and precip_type != 'none' and intensity != 'none': detailed_type = intensity + '-' + precip_type text = random.choice(self.precipitations[precip_type][intensity]) return Condition(type=detailed_type, text=text) return Condition(type='none', text='')
def precipitation(self): """ :return: Condition namedtuple with type and random text field names """ intensity = utils.precipitation_intensity(self.weather_data.precipIntensity, self.weather_data.units['precipIntensity']) probability = self.weather_data.precipProbability precip_type = self.weather_data.precipType # Consider 80% chance and above as fact if probability >= 0.80 and precip_type != 'none' and intensity != 'none': detailed_type = intensity + '-' + precip_type text = random.choice(self.precipitations[precip_type][intensity]) return Condition(type=detailed_type, text=text) return Condition(type='none', text='')