Forecasting¶
This package contains the simulation and methods for creating forecasts. They are split into statistical forecasts and weather forecast.
Forecasts¶
- class Forecast(initial_time, configurations=None, code=None, forward=None, forecast=True)[source]¶
Bases: threading.Thread
Setup a Forecast Object. A new BaseEnvironment and new Devices will be created. Forecasting can either be ran synchronous or asynchronous (threaded):
foocast = Forecast(time.time(), forward=10*24*3600) barcast = Forecast(time.time(), forward=2*24*3600) #run threaded barcast.start() #wait until foocast is finished, then get result resultfoo = foocast.run().get() # wait until barcast is finished while resultbar == None: resultbar = barcast.get()
Parameters: - initial_time (int) – timestamp of the time, at which the forecast starts
- configurations – cached configurations, if None, retrieve from database
- code – code to be executed
- forward (int) – Time to forecast. Uses DEFAULT_FORECAST_INTERVAL if None
- forecast (boolean) – Passed to BaseEnvironment forecast.
- get()[source]¶
return the result of the forecast. If the mainloop is still forecasting, None is returned.
outputs a dict with:
result = {start: datetime, step: stepsize, end: datetime, sensors: list with values per sensor (see MeasurementStorage)}
- class DemoSimulation(initial_time, configurations=None)[source]¶
Bases: server.forecasting.Forecast
A Forecast, which writes the values to the database. It replaces the real devices and is used to develop and show the capabilities of ecoControl. It uses real electrical and weather values instead of forecasts, the device simulation on the other hand is the same as in Forecast.
After calling start(), the simulation will currently run at 30 steps per second (or 30x speed). This is controlled by the step_size in BaseEnvironment.
The simulation can be forwarded to a certain point by setting the forward variable in seconds > 0. It will then run at maximum speed. The simulation runs until the variable running is set to False.
Note
DemoSimulations should generally be started with start_or_get()
- run()[source]¶
run while running is true, call the parent step() method. This method must be called by start(), otherwise it immediately returns
- classmethod start_or_get(print_visible=False)[source]¶
This method starts a new demo simulation if necessary and it makes sure that only one demo simulation can run at once. This is the preferred way to start the demo simulation.
Returns: DemoSimulation or None if system not in demo mode.
- class ForecastQueue[source]¶
A container, holding the running forecasts. Each forecast gets an id.
Usage:
q = ForecastQueue() f_id = q.schedule_new(initial_time=time.time()) #... do other stuff, then retrieve forecast result = q.get_by_id(f_id)
- get_initialized_scenario(env, configurations)[source]¶
this function returns an initialized scenario. It creates new simulated devices and connects the right devices.
The devices are restored to the latest state of the SensorValue‘s in the db, if there are no Values, a warning will be logged and the standard values are used.
Parameters: - env – BaseEnvironment for all Devices
- configurations (list) – the device configurations, which to set in the devices. These are typically DeviceConfiguration objects.
Returns: a namedtuple of devices, with the acronym (f.e plb), as key