PubNub Integration

Plot Outliers on Graph

IoT Device Control

IoT Device Control

Data Streaming & Dashboards

Data Streaming & Dashboards

Last Updated:

2016/08/03

Author:

Ian Jennings

Detects outliers and highlights them on a realtime graph.

Detects outliers so we can highlight them on a graph. This is a common pattern found in analytics services, where one would highlight traffic spikes and even email the user when it happens. This block uses the open source Project EON format and library.

Walkthrough

This block assumes messages are being published in the EON format.

{
    eon: {
        data: Math.floor(Math.random() * 99)
    }
}

It stores values sent to it into the blocks database. Then, using the historical data it calculates the mean, median, and median absolute deviation using stats.js. Those values are added to the message payload.

// use stats.js to calculate mean, meadian, and mean absolute deviation
request.message.eon.mean = mean(history).toFixed(2) * 1
request.message.eon.median = median(history);
request.message.eon.mad = medianAbsoluteDeviation(history);

Finally, the indexes of historial values that appear to be outliers are added to the payload, along with a handy function that indicates if the last published message that triggered the event script is an outlier.

// use the mean absolute deviation to find index of outliers
request.message.outliers = indexOfOutliers(history);

// if the new value is an outlier, mark it as such
request.message.is_outlier = (Math.max.apply(Math, request.message.outliers) == history.length - 1)

This data can be plugged right into our open source charting library, eon charts.

Input

This block is configured to work with EON charts, so the published data should match best practices. Input Channel: eon-stats-channel

{
    "eon": {
        "data": 1
    }
}

Output

The extra data from stats.js is added as properties to the EON object. Output Channel: eon-stats-channel

{
    "eon": {
        "data": 1,
        "mean": 1,
        "median": 1,
        "mad": 1
    }
}

Feedback & Support

Need help? Contact PubNub Support.


Talk to an expert

Contact Sales