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
Comment | File | Size | Author |
---|---|---|---|
feeds_tamper_math_7.x-1.x-dev.tar_.gz | 1.09 KB | OnkelTem |
Comments
Comment #1
PedroMiguel CreditAttribution: PedroMiguel commentedWorks well for me, thanks.
Suggestion: add a readme file instead this comment on feeds_tamper_math_rpn.inc
Comment #1.0
OnkelTem CreditAttribution: OnkelTem commentedUpdated issue summary.
Comment #2
OnkelTem CreditAttribution: OnkelTem commentedThanks 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.
Comment #2.0
OnkelTem CreditAttribution: OnkelTem commentedUpdated issue summary.
Comment #3
Summit CreditAttribution: Summit commentedHi,
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
Comment #3.0
Summit CreditAttribution: Summit commentedasdasd
Comment #4
twistor CreditAttribution: twistor commentedThis is pretty nifty.
We already have basic math capabilities, and I don't think we should be adding external dependencies to this module.
It's in sandbox, so looks good to me.