Hi,

I've created a plugin which brings arithmetical calculations to Feeds Tamper.
This is very first version, w/o documentation etc - have no time atm to make it shine.

What's it for

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.

UPDATE: Sandboxed: http://drupal.org/sandbox/onkeltem/1647750

Files: 
CommentFileSizeAuthor
feeds_tamper_math_7.x-1.x-dev.tar_.gz1.09 KBOnkelTem

Comments

Works well for me, thanks.

Suggestion: add a readme file instead this comment on feeds_tamper_math_rpn.inc

/*
* Requires REAR RPN library.
*
* Get it first http://pear.php.net/package/Math_RPN/download
*
*  or simply do:
*
*    `pear install Math_RPN-1.1.2`
*
*/

Issue summary:View changes

Updated issue summary.

Thanks for your interest and feedback.
I moved it to where it should be - in a sandbox: http://drupal.org/sandbox/onkeltem/1647750
Proposed addition of README.txt is done.

Issue summary:View changes

Updated issue summary.

Hi,
Can with your plugin I also filter on a price range?
I have put issue in sandbox: http://drupal.org/node/1947634

Thanks a lot for building this!
Greetings, Martijn

Issue summary:View changes

asdasd