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 must 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 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 DemandForecastingDemoProject.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.json 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.json 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.json
{
	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 project DemandForecastingDemoProject.zip file.

Start with Machine Learning Workbench

Follow the steps described in Machine Learning Workbench > Upload a project and upload the DemandForecastingDemoProject.zip project to MLW. This creates a new project named DemandForecastingDemoProject_uuid, which has a total of 5 resources. You will get 2 files in the Data folder and 3 notebooks in the Code folder.

Register a demo device in the platform

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. To do so, follow the steps below: We have added a script RegisterDevice.ipynb which registers a demo device in Cumulocity IoT.

  1. Open it and click the edit icon Edit.
  2. Execute each cell one by one and you will have a registered device in Cumulocity IoT. Upon successful execution, a device named “DemandForecastDemoDevice” is registered in Cumulocity IoT.
  3. 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. The device ID is already updated by the code and is saved in the CONFIG.json file.

Download

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. The CONFIG.json file is already updated by the code with the device ID.

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 SimulateData.ipynb for simulating the measurements for the demo device.

  1. Open it and click the edit icon Edit.
  2. Execute each cell one by one and you have a registered device in Cumulocity IoT. Upon successful execution, c8y_Flow measurements are sent to Cumulocity IoT on behalf of the demo device. The measurements are simulated dynamically for the last 8 days period and for every two hours (that is, 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. This can be confirmed by checking the data points in the Cumulocity IoT Cockpit application.

Download

Download the data for model building exercise

Download

Generate forecasts based on the simulated data

Run all the cells in TrainModelandPredict.ipynb notebook which does the following:

  1. Loads the data for building the Time Series model using the Nyoka microservice.
  2. Forecasts the next day’s (i.e. today) water consumption values along with the timestamps using the generated Time Series model by invoking the Zementis microservice.
Download Download

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.