Weather

This module handles crawling, storing and retrieving of weather values.

It is split into two Classes.

DemoWeather([env]) Gets Weathervalues from the database.
CurrentWeatherForecast([env, city]) Gets the current Weatherforecast from an online service.
get_temperature(env, date)[source]

General function to retrieve forecasts. Will decide upon the env parameter, if DemoWeather or CurrentWeatherForecast should be used.

Parameters:
  • env (BaseEnvironment) – the current environment
  • date (datetime) – the time of which to retrieve the weather(forecast)
class DemoWeather(env=None)[source]

Gets Weathervalues from the database. The demo_mode operates on stored data from the past. For maximum realism, the past data should contain the real weather values as well as stored weather forecasts.

The data is stored in the database, with server.models.RealWeatherValue for history weather and server.models.WeatherValue for stored forecasts.

get_temperature(date)[source]

Retrieve a temperature at a certain time. The class will cache the values after the first query to speed up subsequent requests.

Parameters:date (datetime) – The time

Raises an Exception if there are no values in the database for the current time.

get_temperature_estimate(target_date)[source]

Retrieve a forecasted temperature at a certain time. The target_date must be between 0 and 10 days away from the creation_date, as weather forecasts only cover 10 days.

The class will cache the values after the first query to speed up subsequent requests.

Parameters:date (datetime) – The timepoint
class CurrentWeatherForecast(env=None, city='Berlin')[source]

Gets the current Weatherforecast from an online service. This is http://api.openweathermap.org/ at the moment, but may change in future versions.

get_temperature_estimate(date)[source]

Get the most accurate forecast for given date that can be derived from 5 days forecast, 14 days forecast or from history data. This is the public getter for forecasts and should be used

Parameters:date (datetime) – the timepoint for which to get the forecast
Returns:temperature (float)
get_forecast_temperature_hourly(date)[source]

Get the hourly forecast for the given date.

get_forecast_temperature_daily(date)[source]

get the forecast for given date. This only has day accuracy, but the forecast span is longer

find_city(name)[source]

returns a dictionary with city id, names and country based on the given search name the first search result is returned as ‘default’ too.

Parameters:name (string) – f.e. “Berlin”
get_weather_forecast(hourly=True)[source]

retrieves an entire forecast. Tries to get forecast from internal list or filesystem cache. If that fails or data is too old, the online service will be queried

get_openweathermapdata()[source]

read from openweathermap. If this fails, use get_average_outside_temperature()

get_average_outside_temperature(date, offset_days=0)[source]

return an average Berlin temperature in 2012/2013 for a given date.

Parameters:offset_days (int) – offset the real days, f.e. to get some randomness