Pakker includes a full featured calculation engine which let you add automatically calculated values based on the data stored in the card. As an example, if you can define an order card with different items including the related prices and calculated total fields, VAT value and a net total sum.
Input fields, date/time pickers, toggles and rating fields components have a formula option in their respective settings where you can enter formulas. See the syntax section below on how to define formulas.
Pakker uses a special $() function to retrieve the values of the fields. To retrieve the value of a card component, simply pass its identifier between double quotes to the $() function. Example: $("input-1").
Template View with Formulas
The price if each item row is automatically calculated as the multiplication of the unit price and the quantity. In this example, for item row 1, the unit price field has the identifier "up01" and the quantity field the identifier "q01". The item price is then automatically calculated as $("up01") * $("q01").
In the database designer, formulas are displayed on each component. This helps you see which input are automatically calculated.
Card View with Calculated Fields
Components with calculated value are always read-only. All calculated fields are automatically updated when the user updates a dependent input. In this example, changing the quantity or the unit price of any item will immediately update the totals and the VAT field.
The syntax of Pakker formulas is similar to most calculators and mathematical applications. Parts of a formula are:
12 / (2.3 + 0.7)
sin( $("var-a") )
textConcat("Hi ", "there!")
Numbers can be expressed as simple decimal numbers or in scientific notation. Example of valid numbers:
Text values are always expressed between double quotes ("). If you need to insert a double quote in a value, use the backslash escaped double quote (\"). Example of valid texts:
Boolean values represent On/Off, True/False, Yes/No values. Boolean values are used for example in comparison operators or as value of toggle components. Valid values are:
Pakker formulas contain all required operators to build easy to complex operators. The table below lists all available operators:
Precedence rules are used to determine the order how apply the operators when chained. For example, 2 + 3 * 4 may be interpreted as (2 + 3) * 4 = 20 or 2 + (3 * 4) = 14. The operators have the following precedence, from highest to lowest:
Functions are called by entering their name, followed by zero or more arguments enclosed by parentheses. The number of arguments depends on the function definition as described below in the functions reference. Function calls can be nested, meaning that a function call can be inserted as a function argument. Example of valid function calls:
log(1000, 3 + 7)
sin(pi / 4)
textConcat("Hi ", "there!")
Formulas on multiple lines
Formulas can be expressed in several statements. An expression can contain multiple lines, and expressions can be spread over multiple lines. Lines can be separated by a newline character
\n or by a semicolon
;. Empty lines are simply ignored. The result of the formula will always be the result of the last statement. Example of valid formulas made of several statements:
Comments can be added to explain or describe calculations in the formula. A comment starts with a sharp sign character
#, and ends at the end of the line. A line can contain a comment only, or can contain an expression followed by a comment. Example of valid comments:
# define some variables
width = 3height = 4 width * height # calculate the area
Pakker provides following variables that you can use in your formulas. Example of usage: sin(pi / 4)
Getting Values from Components
The $() function let you retrieve the value of any component of the card. The $() function accepts one parameter which is the identifier of the component as defined in the component options enclosed by double quotes (example: to retrieve the value from the input field with the identifier input-1, use $("input-1"). The returned value depends on the component as defined in the following list:
x * x * x.
x / y.
xis calculated. Default value of base is the constant e.
x * y.
x ^ y.
x * x.
x - y.
x & y.
x | y.
x ^ y.
x << y.
x >> y.
x >>> y.
kunordered outcomes from
kelements from a set of
nelements. Permutations only takes integer arguments. The following condition must be enforced: k <= n.
minand smaller than
maxusing a uniform distribution. The optional min and max parameters are the respectively minimum and maximum boundary for the random value.
Please note that relational function cannot be used to compare values smaller than approximately 2.22e-16.
std(a, b, c, ...) = sqrt(var(a, b, c, ...)).
acosh(x) = ln(sqrt(x^2 - 1) + x).
acot(x) = atan(1/x).
acoth(x) = atanh(1/x) = (ln((x+1)/x) + ln(x/(x-1))) / 2.
acsc(x) = asin(1/x).
acsch(x) = asinh(1/x) = ln(1/x + sqrt(1/x^2 + 1)).
asech(x) = acosh(1/x) = ln(sqrt(1/x^2 - 1) + 1/x).
asinh(x) = ln(x + sqrt(x^2 + 1)).
atanh(x) = ln((1 + x)/(1 - x)) / 2.
cosh(x) = 1/2 * (exp(x) + exp(-x)).
coth(x) = 1 / tanh(x).
csc(x) = 1/sin(x).
csch(x) = 1 / sinh(x).
sec(x) = 1/cos(x).
sech(x) = 1 / cosh(x).
sinh(x) = 1/2 * (exp(x) - exp(-x)).
tanh(x) = (exp(2 * x) - 1) / (exp(2 * x) + 1).