Jump to content
  • How to compute the 90° percentile in an Aggregate Operator


    There might be situations where it is necessary to enhance the functionalties of the out-of-the-box StreamBase aggregation operations. In particular, in aviation it's very common to compute the 90th percentile of the velocity. This can be done by adding a StreamBase Custom Java Aggregate Function like the following:

    //
    // Copyright (c) 2009-2014 TIBCO Software Inc. All rights reserved.
    //
    package com.tibco.sb.math;
    
    import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
    import com.streambase.sb.operator.AggregateWindow;
    /**
     * Java custom aggregate that returns the 90° Percentile in a window. 
     * 
     */
    @SuppressWarnings("serial")
    public class Percentile90 extends AggregateWindow {
        // Get a DescriptiveStatistics instance
        DescriptiveStatistics stats = null;
    
        public void init() {
            // Get a DescriptiveStatistics instance
            stats = new DescriptiveStatistics();
        }
    
        public Double calculate() {
            return new Double(stats.getPercentile(90));     
        }
    
        public void accumulate(double val) {
            stats.addValue(val);
        } 
    }
     

    This function is based on the org.apache.commons.math3.stat library. Once compiled, the enhancement can be used in an Aggregate Operator as shown below. 

    screen_shot_2016-11-04_at_21_57_45.thumb.png.e4ba2a8ba73babd3cc725a42a3bd72cc.png


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...