PEATDB/TableFormula.py
def doFormula(cls, cellformula, data):
        """Evaluate the formula for a cell and return the result
           takes a formula dict or just the string as input"""        
        if type(cellformula) is DictType:
            cellformula = cellformula['formula']

        vals = []        
        cells, ops = cls.readExpression(cellformula)
        
        #get cell records into their values
        for i in cells:
            if type(i) is ListType:
                recname, col= i
                if data.has_key(recname):
                    if data[recname].has_key(col):                        
                        v = data[recname][col]
                        if cls.isFormula(v):
                            #recursive
                            v = cls.doFormula(cls.getFormula(v),data)
                        vals.append(v)
                    else:
                        return ''                   
                else:
                    return ''
            elif i== '' or type(i) is IntType or type(i) is FloatType:
                vals.append(i)
            else:
                return ''
        if vals == '':
            return ''
        #print vals, ops
        expr = cls.doExpression(vals, ops)
        #print 'expr', expr                    
        result = eval(expr)
        return str(round(result,3))
Evaluate the formula for a cell and return the result
           takes a formula dict or just the string as input
Evaluate the formula for a cell and return the result
takes a formula dict or just the string as input
Evaluate the formula for a cell and return the result takes a formula dict or just the string as input
def doFormula(cls, cellformula, data):
        if type(cellformula) is DictType:
            cellformula = cellformula['formula']
        vals = []        
        cells, ops = cls.readExpression(cellformula)
        for i in cells:
            if type(i) is ListType:
                recname, col= i
                if data.has_key(recname):
                    if data[recname].has_key(col):                        
                        v = data[recname][col]
                        if cls.isFormula(v):
                            v = cls.doFormula(cls.getFormula(v),data)
                        vals.append(v)
                    else:
                        return ''                   
                else:
                    return ''
            elif i== '' or type(i) is IntType or type(i) is FloatType:
                vals.append(i)
            else:
                return ''
        if vals == '':
            return ''
        expr = cls.doExpression(vals, ops)
        result = eval(expr)
        return str(round(result,3))
def doFormula ( cls , cellformula , data ) : if type ( cellformula ) is DictType : cellformula = cellformula [ 'formula' ] vals = [ ] cells , ops = cls . readExpression ( cellformula ) for i in cells : if type ( i ) is ListType : recname , col = i if data . has_key ( recname ) : if data [ recname ] . has_key ( col ) : v = data [ recname ] [ col ] if cls . isFormula ( v ) : v = cls . doFormula ( cls . getFormula ( v ) , data ) vals . append ( v ) else : return '' else : return '' elif i == '' or type ( i ) is IntType or type ( i ) is FloatType : vals . append ( i ) else : return '' if vals == '' : return '' expr = cls . doExpression ( vals , ops ) result = eval ( expr ) return str ( round ( result , 3 ) )
Evaluate the formula for a cell and return the result
takes a formula dict or just the string as input
Evaluate the formula for a cell and return the result takes a formula dict or just the string as input
"""Evaluate the formula for a cell and return the result
           takes a formula dict or just the string as input""" #get cell records into their values #recursive #print vals, ops #print 'expr', expr                    
cls
cellformula
data