예제 #1
0
def test_weather_underground_weather_source(consumption_history_one_summer_electricity):
    wunderground_api_key = os.environ.get('WEATHERUNDERGROUND_API_KEY')
    if wunderground_api_key:
        wu_weather_source = WeatherUndergroundWeatherSource('60605',
                                                            datetime(2012,6,1),
                                                            datetime(2012,10,1),
                                                            wunderground_api_key)
        consumptions = consumption_history_one_summer_electricity.get("electricity")

        avg_temps = wu_weather_source.average_temperature(consumptions,"degF")
        assert_allclose(avg_temps, [74.433,82.677,75.451], rtol=RTOL,atol=ATOL)

        hdds = wu_weather_source.hdd(consumptions,"degF",65)
        assert_allclose(hdds, [14.0,0.0,0.0], rtol=RTOL,atol=ATOL)

        cdds = wu_weather_source.cdd(consumptions,"degF",65)
        assert_allclose(cdds, [297.0,548.0,324.0], rtol=RTOL,atol=ATOL)
    else:
        warnings.warn("Skipping WeatherUndergroundWeatherSource tests. "
            "Please set the environment variable "
            "WEATHERUNDERGOUND_API_KEY to run the tests.")