From 2df9e408a0ff74539862c4a4e562a878cc11a329 Mon Sep 17 00:00:00 2001 From: rcoh Date: Wed, 16 Feb 2011 18:20:36 -0500 Subject: Code cleanup. Made Oval behavior (circle with h/w). --- behaviors/Circle.py | 2 +- behaviors/ModifyParam.py | 3 --- behaviors/Oval.py | 36 ++++++++++++++++++++++++++++++++++++ behaviors/VerticalBar.py | 1 - 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 behaviors/Oval.py (limited to 'behaviors') diff --git a/behaviors/Circle.py b/behaviors/Circle.py index f3e103b..24d71f1 100644 --- a/behaviors/Circle.py +++ b/behaviors/Circle.py @@ -15,7 +15,7 @@ class Circle(Behavior): data[self['Id']+'Radius'] = self['Radius'] rad = data[self['Id']+'Radius'] cond = '>=' if self['Outside'] else '<=' - circleStr = 'math.sqrt(({x}-'+str(xLoc)+')**2+(({y}-'+str(yLoc)+')**2)*2)'+cond+str(rad) + circleStr = 'math.sqrt(({x}-'+str(xLoc)+')**2+(({y}-'+str(yLoc)+')**2))'+cond+str(rad) if self['Combine']: data['Location'] += ',' + circleStr else: diff --git a/behaviors/ModifyParam.py b/behaviors/ModifyParam.py index ebcb98f..6f81383 100644 --- a/behaviors/ModifyParam.py +++ b/behaviors/ModifyParam.py @@ -1,6 +1,5 @@ from operationscore.Behavior import * import math -import pdb #Class to perform a given operation on some element of an argDict. Designed to be used a recursive hook, but can serve sensor-based functions as well. Specify ParamType (Sensor or Recurse), ParamName, and ParamOp, (a valid python statement with the old value represented as {val}) class ModifyParam(Behavior): """ModifyParam is a powerful class to perform an action on a specified key in the Argument @@ -30,8 +29,6 @@ class ModifyParam(Behavior): #TODO: move elsewhere paramOp = paramOp.replace('{y}', "behaviorInput['Location'][1]") paramOp = paramOp.replace('{x}', "behaviorInput['Location'][0]") - if eval(paramOp) == None: - import pdb; pdb.set_trace() behaviorInput[paramName] = eval(paramOp) if paramType == 'Sensor': #return accordingly return (searchSet, recursiveInputs) diff --git a/behaviors/Oval.py b/behaviors/Oval.py new file mode 100644 index 0000000..b7486f5 --- /dev/null +++ b/behaviors/Oval.py @@ -0,0 +1,36 @@ +from operationscore.Behavior import * +class Oval(Behavior): + def processResponse(self, sensors, recurs): + ret = [] + for data in sensors: + #import pdb; pdb.set_trace() + height = width = 1 + if 'Height' in self: + height = 1/float(self['Height']) + if 'Width' in self: + width = 1/float(self['Width']) + if 'CenterLoc' in data: + xLoc = data['CenterLoc'][0] + yLoc = data['CenterLoc'][1] + else: + data['CenterLoc'] = tuple(data['Location']) + xLoc = data['Location'][0] + yLoc = data['Location'][1] + if not self['Id']+'Radius' in data: + data[self['Id']+'Radius'] = self['Radius'] + rad = data[self['Id']+'Radius'] + cond = '>=' if self['Outside'] else '<=' + circleStr = \ + 'math.sqrt((({x}-%(xLoc)d))**2*%(width)d+(({y}-%(yLoc)d)**2)*%(height)d)%(cond)s%(rad)d' % \ + locals() + if self['Combine']: + data['Location'] += ',' + circleStr + else: + data['Location'] = circleStr + ret.append(data) + return (ret, []) + def setLastOutput(self, output): + coutput = Behavior.deepCopyPacket(output) + for data in coutput: + data['Location'] = data['CenterLoc'] + return coutput diff --git a/behaviors/VerticalBar.py b/behaviors/VerticalBar.py index 66c8e56..85960cb 100644 --- a/behaviors/VerticalBar.py +++ b/behaviors/VerticalBar.py @@ -5,7 +5,6 @@ class VerticalBar(Behavior): ret = [] inputs = list(inputs) for inputset in inputs: - #import pdb; pdb.set_trace() inputset = dict(inputset) if 'xLoc' not in inputset: inputset['xLoc'] = inputset['Location'][0] -- cgit v1.2.3