How to inject Forecast values

Context

I want to inject Forecast values from Data Integration or WebService.

In the following examples we will implement a use case in which we would like to absorb a Forecast for an observed value having a rhythm of 10 minutes. We will forecast this value for the next hour and want to compute only 3 projections so as to not overload the chart. In order to do so, we choose a forecast with a rhythm of 20 minutes.

Observed attribute configuration

Go to the Model Entities panel and add a new Observed attribute then select on of the following type: Forecast (Decimal), Forecast (Duration) or Forecast (Integer).

The rhythm is mandatory. For the current use case we choose 20 minutes.

Mapping configuration

Go to the Mapping panel and create a mapping configuration with the following settings:

  • Name: addForecastInteger
  • A Forecast (Integer) parameter named myForecastValue to pass the data to absorb
  • An Instant parameter named updateTime to provide the time at which the data must be absorbed
  • An Instance operation on entity Process
    • Operation begin uses the updateTime parameter
    • Operation end is set to UNTIL_CHANGED
  •  Change value(s) of attribute operation on myForecast attribute

Route configuration

Go to the Routes panel and create a routing context with the following definition:

<?xml version="1.0" encoding="UTF-8"?>
<routes xmlns="http://camel.apache.org/schema/spring" xmlns:u="http://www.systar.com/aluminium/camel-util">
    <route>
        <from uri="timer://foo?repeatCount=1"/>
        <setBody>
            <u:map-create>
                <u:map-entry key="myForecastValue">
                    <u:map-create>
						 <u:map-entry key="forecasts">
                            <u:list-create>
                                <u:map-create>
                                    <u:map-entry key="validTime">
	                                    <u:date-parse pattern="yyyy-MM-dd HH:mm:ss">
		                                    <simple>2016-01-21 12:20:00</simple>
	                                    </u:date-parse>
                                    </u:map-entry>
                                    <u:map-entry key="value">
	                                    <simple>42</simple>
                                    </u:map-entry>
                                </u:map-create>
                                <u:map-create>
                                    <u:map-entry key="validTime">
	                                    <u:date-parse pattern="yyyy-MM-dd HH:mm:ss">
		                                    <simple>2016-01-21 12:40:00</simple>
	                                    </u:date-parse>
                                    </u:map-entry>
                                    <u:map-entry key="value">
	                                    <simple>43</simple>
                                    </u:map-entry>
                                </u:map-create>
                                <u:map-create>
                                    <u:map-entry key="validTime">
	                                    <u:date-parse pattern="yyyy-MM-dd HH:mm:ss">
		                                    <simple>2016-01-21 13:00:00</simple>
	                                    </u:date-parse>
                                    </u:map-entry>
                                    <u:map-entry key="value">
	                                    <simple>44</simple>
                                    </u:map-entry>
                                </u:map-create>
                            </u:list-create>
                        </u:map-entry>
                    </u:map-create>
                </u:map-entry>
                <u:map-entry key="updateTime">
                    <u:date-parse pattern="yyyy-MM-dd HH:mm:ss">
                        <simple>2016-01-21 12:00:00</simple>
                    </u:date-parse>
                </u:map-entry>
            </u:map-create>
        </setBody>
        <to uri="tnd-absorption:addForecastInteger"/>
        <log message="Forecasts created ${body}."/>
    </route>
</routes>

WebService configuration

When invoked from a WebService, use the following query parameter:

{
  "myForecastValue": {
	"forecasts": [
      {
        "validTime": "2016-01-21T12:20:00",
        "value": 42
      },
      {
        "validTime": "2016-01-27T12:40:00",
        "value": 43
      },
      {
        "validTime": "2016-01-27T13:00:00",
        "value": 44
      }
    ]
  },
  "updateTime": "2016-01-21T12:00:00"
}

As you can see at the first level of the JSON above there is two properties

  1. myForecastValue: which corresponds to the forecast value that will be absorbed.
  2. updateTime which is the time at which the forecast will be absorbed.

Both of these two properties corresponds to the parameters that are defined in the mapping.

Related Links