prepare formulas for py3
This commit is contained in:
parent
79b8b3c180
commit
16be3e8fc9
@ -146,7 +146,7 @@ def compute_user_formula(
|
|||||||
nbabs, nbabs_just = 0, 0
|
nbabs, nbabs_just = 0, 0
|
||||||
try:
|
try:
|
||||||
moy_val = float(moy)
|
moy_val = float(moy)
|
||||||
except:
|
except ValueError:
|
||||||
moy_val = 0.0 # 0. when no valid value
|
moy_val = 0.0 # 0. when no valid value
|
||||||
variables = {
|
variables = {
|
||||||
"cmask": coefs_mask, # NoteVector(v=coefs_mask),
|
"cmask": coefs_mask, # NoteVector(v=coefs_mask),
|
||||||
@ -162,8 +162,8 @@ def compute_user_formula(
|
|||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
formula = formula.replace("\n", "").replace("\r", "")
|
formula = formula.replace("\n", "").replace("\r", "")
|
||||||
# log('expression : %s\nvariables=%s\n' % (formula, variables)) # XXX debug
|
# log('expression : %s\nvariables=%s\n' % (formula, variables)) # debug
|
||||||
user_moy = sco_formulas.eval_user_expression(context, formula, variables)
|
user_moy = sco_formulas.eval_user_expression(formula, variables)
|
||||||
# log('user_moy=%s' % user_moy)
|
# log('user_moy=%s' % user_moy)
|
||||||
if user_moy != "NA0" and user_moy != "NA":
|
if user_moy != "NA0" and user_moy != "NA":
|
||||||
user_moy = float(user_moy)
|
user_moy = float(user_moy)
|
||||||
|
@ -73,7 +73,7 @@ class NoteVector(object):
|
|||||||
"""Append a value to the vector."""
|
"""Append a value to the vector."""
|
||||||
try:
|
try:
|
||||||
v = float(value)
|
v = float(value)
|
||||||
except:
|
except ValueError:
|
||||||
v = 0.0
|
v = 0.0
|
||||||
self.v.append(v)
|
self.v.append(v)
|
||||||
if name:
|
if name:
|
||||||
@ -99,10 +99,20 @@ class NoteVector(object):
|
|||||||
__rmul__ = __mul__
|
__rmul__ = __mul__
|
||||||
|
|
||||||
def __div__(self, x):
|
def __div__(self, x):
|
||||||
return binary_op(self.v, x, operator.div)
|
return binary_op(self.v, x, operator.truediv)
|
||||||
|
|
||||||
|
__truediv__ = __div__ # for py3
|
||||||
|
|
||||||
|
def __floordiv__(self, x):
|
||||||
|
return binary_op(self.v, x, operator.floordiv)
|
||||||
|
|
||||||
def __rdiv__(self, x):
|
def __rdiv__(self, x):
|
||||||
return binary_op(x, self.v, operator.div)
|
return binary_op(x, self.v, operator.truediv)
|
||||||
|
|
||||||
|
__rtruediv__ = __rdiv__ # for py3
|
||||||
|
|
||||||
|
def __rfloordiv__(self, x):
|
||||||
|
return binary_op(x, self.v, operator.floordiv)
|
||||||
|
|
||||||
|
|
||||||
def isScalar(x):
|
def isScalar(x):
|
||||||
@ -169,7 +179,7 @@ formula_builtins = {
|
|||||||
# eval("max(4,5)", {'__builtins__': formula_builtins, {'x' : 1, 'v' : NoteVector(1,2) }, {})
|
# eval("max(4,5)", {'__builtins__': formula_builtins, {'x' : 1, 'v' : NoteVector(1,2) }, {})
|
||||||
|
|
||||||
|
|
||||||
def eval_user_expression(context, expression, variables):
|
def eval_user_expression(expression, variables):
|
||||||
"""Evalue l'expression (formule utilisateur) avec les variables (dict) données."""
|
"""Evalue l'expression (formule utilisateur) avec les variables (dict) données."""
|
||||||
variables["__builtins__"] = formula_builtins
|
variables["__builtins__"] = formula_builtins
|
||||||
# log('Evaluating %s with %s' % (expression, variables))
|
# log('Evaluating %s with %s' % (expression, variables))
|
||||||
|
Loading…
Reference in New Issue
Block a user