PPF Expressions & Functions

Pass report metrics to custom JavaScript functions for flexible report output.

Overview

PPF expressions and functions increase the flexibility of reports by allowing report metrics to be passed to custom JavaScript functions. Create a JavaScript function within your PPF or HTML page, then use expression syntax within your report to pass metrics to it.

Defining an Expression or Function

Take the example JavaScript function below:

function testfunc(download, upload) {
    console.log(download);
    console.log(upload);
}

This function can be called within other widgets. For example, if the following syntax was included in a text widget, the download and upload speed results would be passed to the testfunc function. If the function returns a value, that value appears in the text:

$$exp.testfunc(||speed.dspeed||,||speed.uspeed||)$$

Full Example

Below is a complete example using an expression as part of a text widget:

var ppf_datasets = {
    data: {
        speeddata: {
            plugins: ['speed'],
            last: '1',
            unit: 'hour',
            by: 10
        }
    }
}

var ppf_widgets = {
    example_text: {
        ele: ['text_ele_id'],
        data: 'speeddata',
        type: 4,
        text: 'The overall result of this test was <b>$$exp.testfunc(||speed.dspeed||,||speed.uspeed||)$$</b>',
        thrdep: [[]],
        caldep: [[]]
    }
}

function testfunc(download, upload) {
    console.log(download);
    console.log(upload);
}

Global Functions

Global functions are processed once and can be referenced throughout the PPF. They are defined in the reserved ppf_funcs object.

Note: When using metrics, a data set must be specified (c24 in the example below).

var ppf_funcs = {
    cCalls: 'calcCalls(||c24.capacity.dpackets||,||c24.capacity.upackets||)'
}

The function result is referenced using ppf_funcs followed by the function name. The example below shows this used in a box widget — the expression calls a function that returns a color for the text based on the threshold result:

tl_pktc: {
    inc: 'tl_capd',
    ele: ['grid2'],
    top: {
        text: "Concurrent Calls Supported"
    },
    middle: {
        text: "$$ppf_funcs.cCalls$$ calls",
        txtcol: "$$exp.getTxtCol('capacity.ccalls', ||ppf_funcs.cCalls||)$$"
    }
}