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). --- LightInstallation.py | 1 - behaviors/Circle.py | 2 +- behaviors/ModifyParam.py | 3 --- behaviors/Oval.py | 36 ++++++++++++++++++++++++++++++++++++ behaviors/VerticalBar.py | 1 - config/C5Sign.xml | 6 +++--- operationscore/PixelAssembler.py | 4 ++-- pixelmappers/SimpleMapper.py | 4 ++-- util/ComponentRegistry.py | 3 +-- 9 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 behaviors/Oval.py diff --git a/LightInstallation.py b/LightInstallation.py index 91be752..19d6c54 100755 --- a/LightInstallation.py +++ b/LightInstallation.py @@ -181,7 +181,6 @@ class LightInstallation(object): def processResponse(self,inputDict, responseDict): inputId = inputDict['Id'] - #coming from. boundBehaviorIds = self.inputBehaviorRegistry[inputId] try: [compReg.getComponent(b).addInput(responseDict) for b in boundBehaviorIds] 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] diff --git a/config/C5Sign.xml b/config/C5Sign.xml index a05cb1e..024f0d8 100644 --- a/config/C5Sign.xml +++ b/config/C5Sign.xml @@ -208,7 +208,7 @@ centerleft center - {'scanningbars':10,'runcolordecay':10,'expandingcircles':10} + {'scanningbars':0,'runcolordecay':10,'expandingcircles':10} {'scanningbars':'centerleft', 'runcolordecay':'center',\ 'expandingcircles':'center'} True @@ -266,7 +266,7 @@ - behaviors.Circle + behaviors.Oval innercircle 0 @@ -274,7 +274,7 @@ - behaviors.Circle + behaviors.Oval outercircle 3 diff --git a/operationscore/PixelAssembler.py b/operationscore/PixelAssembler.py index 582b59d..8ae27c9 100644 --- a/operationscore/PixelAssembler.py +++ b/operationscore/PixelAssembler.py @@ -19,10 +19,10 @@ class PixelAssembler(SmootCoreObject): defined or improperly defined.') if Geo.dist(newLocation, locations[-1]) > \ self['pixelToPixelSpacing']: - import pdb; pdb.set_trace() raise Exception('Illegal pixel location. Distance \ between adjacent pixels must be less than \ - pixelToPixelSpacing.') + pixelToPixelSpacing. Illegal distance is between '+str(pixelIndex) + ' and'\ + + str(pixelIndex+1)) locations.append(newLocation) if self['Reverse']: locations.reverse() diff --git a/pixelmappers/SimpleMapper.py b/pixelmappers/SimpleMapper.py index 6603c98..1decdd1 100644 --- a/pixelmappers/SimpleMapper.py +++ b/pixelmappers/SimpleMapper.py @@ -44,7 +44,7 @@ class SimpleMapper(PixelMapper): if pixelValid: ret.append((pixel, 1)) except Exception as exp: - import pdb; pdb.set_trace() - raise Exception('Bad event condition') + exp.message += 'Bad Event Condition' + raise exp return ret diff --git a/util/ComponentRegistry.py b/util/ComponentRegistry.py index 3036138..1db5135 100644 --- a/util/ComponentRegistry.py +++ b/util/ComponentRegistry.py @@ -1,4 +1,3 @@ -import pdb import hashlib from logger import main_log import thread @@ -41,7 +40,7 @@ def registerComponent(component, cid=None): component['Id'] = cid main_log.debug(cid + 'automatically assigned') if cid in Registry: - import pdb; pdb.set_trace() + main_log.warn(cid + 'overwritten.') Registry[cid] = component return cid -- cgit v1.2.3