Jaspersoft Studio - Plotting Percentile for a MongoDB Field

Hi Experts

I am new to Jaspersoft so kindly excuse me incase I ask very fundamental question.

Jaspersoft Version: 6.4

MongoDb: 3.4

Objective: I have stored some timeseries data in MongoDB. My target is to plot this data in a line graph. Further, for one of the "columns" I will also like to plot another line which essentially provides the 95% percentile trajectory.


Methodology Planned:
Create a Scriptlet (Custom Java Class) that will collect all the values in the source Column/field and will provide a percentile output.

Done so far:
1. I am successfull in using the Jasper studio to import and plot my timeseries data on a XY Graph.
2. Created following class be extending JRDefaultScriptlet:

package net.sf.jasperreports.engine.mymethods;
import net.sf.jasperreports.engine.JRDefaultScriptlet;
import net.sf.jasperreports.engine.JRScriptletException;
import org.apache.commons.math3.stat.descriptive.rank.*;
 
public class class1 extends JRDefaultScriptlet{
 
    public static double[] u_list = new double [1000];
    public static int counter = 0;
 
        public double percentile(double u_value, double u_percentile) throws JRScriptletException {
            u_list[counter] = u_value;
            org.apache.commons.math3.stat.descriptive.rank.Percentile test = new org.apache.commons.math3.stat.descriptive.rank.Percentile();
            double x = test.evaluate(u_list, u_percentile);
            return x;
        }
}


3. Mapped a new Y Series in the graph with the following paramteres:

$P{Scriptlet_2_SCRIPTLET}.percentile( (double) $F{Pre_Policy_BitRate}, (double) 95 )

Problem:
What I realised at the end of the excersize is that Jaspersoft re-instantiates the scriptlet class for every row of data. This really means that I never have more than one real value in my array. I was hoping that hte scriptlet would only create a single instance per report so that I can generate an array of numbers to feed my percentile method. Is this possible to acheive?

Regards
Deepak

deepakgup's picture
Joined: Aug 2 2017 - 11:31am
Last seen: 3 years 11 months ago

0 Answers:

No answers yet
Feedback