Use Case: Demand Forecasting

Overview

Most of the sensor data produced by connected devices in IoT incorporates a temporal aspect and can therefore be considered as time-series data. Time Series Analysis involves analyzing this data to extract meaningful insights and characteristics. Time Series Forecasting involves leveraging these insights on observed data to predict future values. In the context of planning, time-series forecasting has several use cases.

Recently, Water Demand Forecasting has become an essential strategy in effective water resource planning and management. Water demand forecasts are required for the cost-effective and sustainable management and expansion of urban water supply infrastructure. Water demand forecasts can provide valuable information to distribution-system operators for controlling the production, storage and delivery of drinking water.

Consider a water distribution company that supplies water to a community. The distribution company would maintain a reservoir tank for supplying water to the entire community. The tank has to be refilled at times and should always maintain sufficient water level to meet the consumption demand of the community. It is observed that consumption of water is not uniform throughout the day. There is a peak consumption during the morning/evening hours whereas during the day, the consumption is lesser. Also, consumption during the weekends is higher than in the weekdays; same goes for the consumption during summer seasons than the winters.

Technically speaking, the distribution-system operators should adjust the pressure for water flow regularly in order to maintain sufficient water level so as to meet the demand. This process is continuous and needs to be performed at regular intervals throughout the day based on the water consumption. Here, the forecasting of water consumption would help the distribution-system operators to act appropriately . For example, when the demand is less, they can reduce the pressure for water flow which in turn would ascertain longevity of the water pipes. Also, when the demand is low, less water needs to be pumped which in turn would save a lot in terms of electricity consumed in pumping of water.

In this Demand Forecasting use case, we would like to forecast the peak/non-peak hours of water consumption using a Time Series model. For showcasing this, we would follow these steps.

Prerequisites

Download the DemandForecastingDemo.zip file which contains the scripts and sample data set used in this demo.

Running the demo scripts requires

Getting Started

We have added a CONFIG.INI file to the attached ZIP file. This file is meant for capturing the tenant details and credentials which will be used by the demo scripts.

First of all, update the CONFIG.INI with the appropriate values and save it. Replace c_url with your tenant URL, c_user with your tenant username and c_pass with your tenant password. Leave the c_device_source as is for now.

CONFIG.INI
[cumulocity]
c_url=https://yourtenant.cumulocity.com
c_user=user@company.com
c_pass=password
c_device_source=deviceID

Demand forecasting using a demo device

A fully functional demand forecasting demo can be prepared with the help of a demo device. For this, use the artifacts provided as part of the DemandForecastingDemo.zip file.

Register a demo device in Cumulocity IoT

Instead of registering an actual device for the water demand forecasting use case, a demo device can be registered. This device can be used as a replica of an actual device connected to the reservoir tank.

We have added a script DemoDeviceCreator.sh which registers a demo device in Cumulocity IoT.

DemoDeviceCreator.sh
c_url=$(awk -F "=" '/c_url/ {print $2}' ./CONFIG.INI)
c_user=$(awk -F "=" '/c_user/ {print $2}' ./CONFIG.INI)
c_pass=$(awk -F "=" '/c_pass/ {print $2}' ./CONFIG.INI)
echo
echo "#####################################"
echo "#    Registering new demo device    #"
echo "#####################################"
curl --user $c_user:$c_pass -X POST $c_url"/inventory/managedObjects" -H "accept: application/json" -H "Content-Type: application/json" \
--data '{"name": "DemandForecastDemoDevice", "c8y_IsDevice": {}, "myDemoDevice":{}, "c8y_SupportedMeasurements": ["c8y_Flow"]}'
echo
echo
echo "#####################################################################################################"
echo "#  Registered a demo device with the name 'DemandForecastDemoDevice' and its measurement 'c8y_Flow' #"
echo "#####################################################################################################"

Run the script using the following command:

bash DemoDeviceCreator.sh 

Upon successful execution, a device named DemandForecastDemoDevice is registered in Cumulocity IoT. Once registered, try to get the device ID by looking up your device on the All Devices page of your tenant’s Device Management application. Now, update the c_device_source of the CONFIG.INI file with the device ID of this demo device.

This device is capable of simulating readings of water flow to Cumulocity IoT in the form of a measurement named c8y_Flow.
A higher value of c8y_Flow signifies higher water consumption.

Simulate measurements for the demo device

Use simulate_data.sh for simulating the measurements for the demo device.

simulate_data.sh
#!/bin/bash
input="./input_data.csv"
c_url=$(awk -F "=" '/c_url/ {print $2}' ./CONFIG.INI)
c_user=$(awk -F "=" '/c_user/ {print $2}' ./CONFIG.INI)
c_pass=$(awk -F "=" '/c_pass/ {print $2}' ./CONFIG.INI)
c_device_source=$(awk -F "=" '/c_device_source/ {print $2}' ./CONFIG.INI)

tail -n +2 "$input" | while IFS=',' read -r f1 f2
do
    dt=$f1
    val=$f2
    date="${dt}+05:30"
    tm=${date:11}
    dtt=${date:0:10}
    strdt="${dtt}T${tm}"
    curl --user $c_user:$c_pass -X POST $c_url"/measurement/measurements" -H "accept: application/vnd.com.nsn.cumulocity.measurementCollection+json" -H "Content-Type: application/json" --data '{"measurements":[{"time": "'$strdt'","source": {"id": "'$c_device_source'"},"type": "c8y_Flow","c8y_Flow": {"F": {"unit": "psi","value": '$val'}}}]}'
done

Using this simulator, c8y_Flow measurements are sent to Cumulocity IoT on behalf of the demo device. The measurements are simulated for the time period 2019-12-01 to 2019-12-08 and for every two hours (i.e. 12 observations per day). We use this data to generate a time series model and forecast the next day’s c8y_Flow values. Keep in mind that forecast intervals will match the observation intervals.

Run the simulator script using the following command:

bash simulate_data.sh 

Generate forecasts based on the simulated data

Run the attached Demand_Forecast_Demo.ipynb notebook which does the following:

The notebook provides you with an insight of the peak/non-peak values for the next day. To make the use case simpler, we considered only 8 days worth of data but it can be extended to any number of days. Also, the forecasts can be made for any number of time steps in the future.