from orangescape.model.engine.execution.MathandTrig import POWER
from orangescape.model.engine.execution.exFunctions import getNumber,getString

""" Operator functions here """
def addOper(argList):
    return argList[0]+argList[1]

def subOper(argList):
    return argList[0]-argList[1]

def mulOper(argList):
    return argList[0]*argList[1]

def divOper(argList):
    return argList[0]/argList[1]

def powerOper(argList):
    return argList[0]**argList[1]

def concatOper(argList):
    return argList[0]+argList[1]

def ltOper(argList):
    value1,value2 = getOperands(argList)
    if value1 < value2:
        return 1.0
    return 0.0

def gtOper(argList):
    value1,value2 = getOperands(argList)
    if value1 > value2:
        return 1.0
    return 0.0

def gtEqOper(argList):
    value1,value2 = getOperands(argList)
    if value1 >= value2:
        return 1.0
    return 0.0

def ltEqOper(argList):
    value1,value2 = getOperands(argList)
    if value1 <= value2:
        return 1.0
    return 0.0

def eqOper(argList):
    # Checking [None Vs ""] and [None Vs 0] combinations.
    if (argList[0]==None and argList[1]=="") or (argList[0]=="" and argList[1]==None) or (argList[0]==None and argList[1]==0.0) or (argList[0]==0.0 and argList[1]==None):
        return 1.0
    value1,value2 = getOperands(argList)
    if value1 == value2:
        return 1.0
    return 0.0

def notEqOper(argList):
    value1,value2 = getOperands(argList)
    if value1 != value2:
        return 1.0
    return 0.0

def percentageOper(argList):
    return argList[0]/100

def ampersandOper(argList):
    return str(argList[0])+str(argList[1]);

""" Supporting functions here """
def getOperands(argList):
    value1=argList[0]
    value2=argList[1]
    if type(value1) in (str,unicode) and type(value2) in (str,unicode):
        value1 = value1.lower()
        value2 = value2.lower()
    elif type(value1)==type(value2):
        value1 = getNumber(value1)
        value2 = getNumber(value2)
    elif (value1==None or value2==None):
        if type(value1) in (str,unicode) or type(value2) in (str,unicode):
            value1 = getString(value1)
            value2 = getString(value2)
        else:
            value1 = getNumber(value1)
            value2 = getNumber(value2)
    return (value1,value2)
