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.
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.
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 } }
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 } }
Need help? Contact PubNub Support.
Copyright (c) 2018 PubNub
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.