Experimental project

This is a sandbox project, which contains experimental code for developer use only.

This is a plugin for making arithmetical calculations when tampering imported data with Feeds Tamper.

Original issue: http://drupal.org/node/1439280

About

It allows you to execute simple mathematical operations against numeric data being imported. I personally needed this to multiply prices by 100, to get them in cents, following Drupal Commerce reqs.

How it works

It uses PEAR's Math_RPN package which is pretty fast calculator. So you must install it first.

How it looks

It is similar to Rewrite plugin (and in fact - almost full copy-paste of it), which simply takes rewrited output and feeds it to Math_RPN as the expression. NOTE: your expressions must be in RPN-format, not like a usual math expression. In short, instead of doing:

[price] * 0.9 + 100

you do:

[price] 0.9 * 100 +

Why RPN? Because I found no another standard PHP calculator with pretty fast parser. If you interested, you are welcome to review results of a simple performance test I created to compare different approaches:

Running 1000 times
Using PHP native: 0.00071191787719727s
Using PHP eval: 0.0074231624603271s
Using PEAR RPN true-rpn: 0.16375494003296s
Using PEAR RPN generic: 0.78050303459167s

RESULTS
PHP eval is slower then PHP native in 10 times
PEAR RPN true-rpn is slower then PHP native in 230 times
PEAR RPN generic is slower then PHP native in 1096 times
PEAR RPN true-rpn is slower then PHP eval in 22 times
PEAR RPN generic is slower then PHP eval in 105 times
PEAR RPN generic is slower then PEAR RPN true-rpn in 5 times

As you see, this Math_RPN thing in native RPN-mode is 22 times slower then PHP's eval() but 5 times faster itself, launched in generic (human native) mode.

Project information

  • caution Minimally maintained
    Maintainers monitor issues, but fast responses are not guaranteed.
  • Module categories: Import and Export
  • Created by OnkelTem on , updated