Hi eveyone,
I'm developing an web application which has to interact with "user-
defined formulas" of some financial kpis.
I decided to use sympy to have a more solid math engine.
Basically the input I reiceve is very simple, it might be in the worst
case something like:

kpi -> "(log(sum('production'))*count('sales')/min('spread')" (this
formula is totally made-up)

I defined some functions to interact with the database according to
the official docs and they seem to be working:

For example defining

from sympy.core.function import Function

class SUM(Function):
    nargs = 2
    @classmethod
    def eval(cls, arg):
        map = Code("""function () {
                        emit("sum",{%(field)s:this.%(field)s});
                   }""" % {'field':arg})
        reduce = Code("""
                    function(key, values) {
                      var sum = 0;
                      values.forEach(function(doc) {
                        if (doc.%(field)s != undefined){
                            sum += doc.%(field)s;
                        }
                      });
                      return {%(field)s:sum};
                    };""" % {'field':arg})
        result = db.people.map_reduce(map, reduce, "myresults")
        return result.find_one()['value'][unicode(arg)]

#EOF

Then from the command line I can type:

>>> print SUM("field")
>>> 1923

But when I try to use sympify my function doesn't evaluate..

>>> print sympify("SUM('field')").evalf()
>>> SUM(field)
>>> N("SUM('field')")
>>> SUM(field)

Am I doing anything wrong?
Thanks in advance!

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to