Search in sources :

Example 6 with AbstractDoubleCalc

use of mondrian.calc.impl.AbstractDoubleCalc in project mondrian by pentaho.

the class CovarianceFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final ListCalc listCalc = compiler.compileList(call.getArg(0));
    final Calc calc1 = compiler.compileScalar(call.getArg(1), true);
    final Calc calc2 = call.getArgCount() > 2 ? compiler.compileScalar(call.getArg(2), true) : new ValueCalc(call);
    return new AbstractDoubleCalc(call, new Calc[] { listCalc, calc1, calc2 }) {

        public double evaluateDouble(Evaluator evaluator) {
            TupleList memberList = listCalc.evaluateList(evaluator);
            final int savepoint = evaluator.savepoint();
            try {
                evaluator.setNonEmpty(false);
                final double covariance = (Double) covariance(evaluator, memberList, calc1, calc2, biased);
                return covariance;
            } finally {
                evaluator.restore(savepoint);
            }
        }

        public boolean dependsOn(Hierarchy hierarchy) {
            return anyDependsButFirst(getCalcs(), hierarchy);
        }
    };
}
Also used : ValueCalc(mondrian.calc.impl.ValueCalc) AbstractDoubleCalc(mondrian.calc.impl.AbstractDoubleCalc) ValueCalc(mondrian.calc.impl.ValueCalc) AbstractDoubleCalc(mondrian.calc.impl.AbstractDoubleCalc)

Example 7 with AbstractDoubleCalc

use of mondrian.calc.impl.AbstractDoubleCalc in project mondrian by pentaho.

the class PercentileFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final ListCalc listCalc = compiler.compileList(call.getArg(0));
    final Calc calc = compiler.compileScalar(call.getArg(1), true);
    final DoubleCalc percentCalc = compiler.compileDouble(call.getArg(2));
    return new AbstractDoubleCalc(call, new Calc[] { listCalc, calc, percentCalc }) {

        public double evaluateDouble(Evaluator evaluator) {
            TupleList list = evaluateCurrentList(listCalc, evaluator);
            double percent = percentCalc.evaluateDouble(evaluator) * 0.01;
            final int savepoint = evaluator.savepoint();
            try {
                evaluator.setNonEmpty(false);
                final double percentile = percentile(evaluator, list, calc, percent);
                return percentile;
            } finally {
                evaluator.restore(savepoint);
            }
        }

        public boolean dependsOn(Hierarchy hierarchy) {
            return anyDependsButFirst(getCalcs(), hierarchy);
        }
    };
}
Also used : AbstractDoubleCalc(mondrian.calc.impl.AbstractDoubleCalc) AbstractDoubleCalc(mondrian.calc.impl.AbstractDoubleCalc) AbstractDoubleCalc(mondrian.calc.impl.AbstractDoubleCalc)

Example 8 with AbstractDoubleCalc

use of mondrian.calc.impl.AbstractDoubleCalc in project mondrian by pentaho.

the class StdevPFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final ListCalc listCalc = compiler.compileList(call.getArg(0));
    final Calc calc = call.getArgCount() > 1 ? compiler.compileScalar(call.getArg(1), true) : new ValueCalc(call);
    return new AbstractDoubleCalc(call, new Calc[] { listCalc, calc }) {

        public double evaluateDouble(Evaluator evaluator) {
            final int savepoint = evaluator.savepoint();
            try {
                evaluator.setNonEmpty(false);
                TupleList list = evaluateCurrentList(listCalc, evaluator);
                final double stdev = (Double) stdev(evaluator, list, calc, true);
                return stdev;
            } finally {
                evaluator.restore(savepoint);
            }
        }

        public boolean dependsOn(Hierarchy hierarchy) {
            return anyDependsButFirst(getCalcs(), hierarchy);
        }
    };
}
Also used : ValueCalc(mondrian.calc.impl.ValueCalc) AbstractDoubleCalc(mondrian.calc.impl.AbstractDoubleCalc) ValueCalc(mondrian.calc.impl.ValueCalc) AbstractDoubleCalc(mondrian.calc.impl.AbstractDoubleCalc)

Example 9 with AbstractDoubleCalc

use of mondrian.calc.impl.AbstractDoubleCalc in project mondrian by pentaho.

the class NthQuartileFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final ListCalc listCalc = compiler.compileList(call.getArg(0));
    final DoubleCalc doubleCalc = call.getArgCount() > 1 ? compiler.compileDouble(call.getArg(1)) : new ValueCalc(call);
    return new AbstractDoubleCalc(call, new Calc[] { listCalc, doubleCalc }) {

        public double evaluateDouble(Evaluator evaluator) {
            final int savepoint = evaluator.savepoint();
            try {
                evaluator.setNonEmpty(false);
                TupleList members = evaluateCurrentList(listCalc, evaluator);
                return quartile(evaluator, members, doubleCalc, range);
            } finally {
                evaluator.restore(savepoint);
            }
        }

        public boolean dependsOn(Hierarchy hierarchy) {
            return anyDependsButFirst(getCalcs(), hierarchy);
        }
    };
}
Also used : ValueCalc(mondrian.calc.impl.ValueCalc) AbstractDoubleCalc(mondrian.calc.impl.AbstractDoubleCalc) AbstractDoubleCalc(mondrian.calc.impl.AbstractDoubleCalc)

Example 10 with AbstractDoubleCalc

use of mondrian.calc.impl.AbstractDoubleCalc in project mondrian by pentaho.

the class AvgFunDef method compileCall.

public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
    final ListCalc listCalc = compiler.compileList(call.getArg(0));
    final Calc calc = call.getArgCount() > 1 ? compiler.compileScalar(call.getArg(1), true) : new ValueCalc(call);
    return new AbstractDoubleCalc(call, new Calc[] { listCalc, calc }) {

        public double evaluateDouble(Evaluator evaluator) {
            evaluator.getTiming().markStart(TIMING_NAME);
            final int savepoint = evaluator.savepoint();
            try {
                TupleList memberList = evaluateCurrentList(listCalc, evaluator);
                evaluator.setNonEmpty(false);
                return (Double) avg(evaluator, memberList, calc);
            } finally {
                evaluator.restore(savepoint);
                evaluator.getTiming().markEnd(TIMING_NAME);
            }
        }

        public boolean dependsOn(Hierarchy hierarchy) {
            return anyDependsButFirst(getCalcs(), hierarchy);
        }
    };
}
Also used : ValueCalc(mondrian.calc.impl.ValueCalc) AbstractDoubleCalc(mondrian.calc.impl.AbstractDoubleCalc) ValueCalc(mondrian.calc.impl.ValueCalc) AbstractDoubleCalc(mondrian.calc.impl.AbstractDoubleCalc)

Aggregations

AbstractDoubleCalc (mondrian.calc.impl.AbstractDoubleCalc)12 ValueCalc (mondrian.calc.impl.ValueCalc)11 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 BooleanCalc (mondrian.calc.BooleanCalc)1 Calc (mondrian.calc.Calc)1 DimensionCalc (mondrian.calc.DimensionCalc)1 DoubleCalc (mondrian.calc.DoubleCalc)1 ExpCompiler (mondrian.calc.ExpCompiler)1 HierarchyCalc (mondrian.calc.HierarchyCalc)1 IntegerCalc (mondrian.calc.IntegerCalc)1 LevelCalc (mondrian.calc.LevelCalc)1 ListCalc (mondrian.calc.ListCalc)1 MemberCalc (mondrian.calc.MemberCalc)1 StringCalc (mondrian.calc.StringCalc)1 TupleList (mondrian.calc.TupleList)1 AbstractBooleanCalc (mondrian.calc.impl.AbstractBooleanCalc)1 AbstractIntegerCalc (mondrian.calc.impl.AbstractIntegerCalc)1