Пример #1
0
 def processResponse(self, sensor, recurs):
     ret = []
     for sensory in sensor:
         opsensory = dict(sensory)
         isNew = self.insertStepIfMissing(opsensory) 
         #TODO: update 19 to be a configurable variable
         if opsensory['isNew'] <= 0:
             results = bqs.query([
                 bqs.getBehaviorIdLambda(self['Id']),\
                 bqs.getDifferentUIDLambda(opsensory['UniqueResponseIdentifier']),\
                 bqs.getDistLambda(opsensory['Location'], 19)
             ])
             if results:
                 opsensory['XStep'] = -opsensory['XStep']
                 opsensory['Location'] = Geo.addLocations((opsensory['XStep'], opsensory['YStep']), opsensory['Location']) 
         else:
             opsensory['isNew'] -= 1
         if isNew:
             if opsensory['Direction'] != 0:
                 opsensory['Location'] = Geo.addLocations((2*opsensory['XStep'], opsensory['YStep']), opsensory['Location']) 
                 ret.append(opsensory)
                 opsensory2 = dict(opsensory)
                 opsensory2['XStep'] = -opsensory2['XStep']
                 opsensory2['Location'] = Geo.addLocations((2*opsensory2['XStep'], opsensory2['YStep']), opsensory['Location']) 
                 ret.append(opsensory2)
         else:
             opsensory['Location'] = Geo.addLocations((opsensory['XStep'], opsensory['YStep']), opsensory['Location']) 
             ret.append(opsensory)
     return (ret, []) 
Пример #2
0
 def processResponse(self, sensor, recurs):
     ret = []
     for sensory in sensor:
         opsensory = dict(sensory)
         isNew = self.insertStepIfMissing(opsensory) 
         #TODO: update 19 to be a configurable variable
         if opsensory['isNew'] <= 0:
             results = bqs.query([
                 bqs.getBehaviorIdLambda(self['Id']),\
                 bqs.getDifferentUIDLambda(opsensory['UniqueResponseIdentifier']),\
                 bqs.getDistLambda(opsensory['Location'], 19)
             ])
             if results:
                 opsensory['XStep'] = -opsensory['XStep']
                 opsensory['Location'] = Geo.addLocations((opsensory['XStep'], opsensory['YStep']), opsensory['Location']) 
         else:
             opsensory['isNew'] -= 1
         if isNew:
             opsensory['Location'] = Geo.addLocations((2*opsensory['XStep'], opsensory['YStep']), opsensory['Location']) 
             ret.append(opsensory)
             opsensory2 = dict(opsensory)
             opsensory2['XStep'] = -opsensory2['XStep']
             opsensory2['Location'] = Geo.addLocations((2*opsensory2['XStep'], opsensory2['YStep']), opsensory['Location']) 
             ret.append(opsensory2)
         else:
             opsensory['Location'] = Geo.addLocations((opsensory['XStep'], opsensory['YStep']), opsensory['Location']) 
             ret.append(opsensory)
     return (ret, []) 
Пример #3
0
 def test_complex_queries(self):
     validQuery = lambda args:args['Color']==(255,0,0)
     doubleDist = lambda args:geo.dist(args['Location'], (0,0)) <= 20
     
     twoPartPredicate = lambda args:doubleDist(args) and validQuery(args)
     assert bqs.query(twoPartPredicate) == [{'Color':(255,0,0), 'Location':(3,4)}] 
     assert bqs.query([validQuery, doubleDist]) == [{'Color':(255,0,0), 'Location':(3,4)}] 
Пример #4
0
    def test_dist_query(self):
        validDist = lambda args:geo.dist(args['Location'], (0,0)) <= 5
        invalidDist = lambda args:geo.dist(args['Location'], (0,0)) <= 2
        doubleDist = lambda args:geo.dist(args['Location'], (0,0)) <= 20

        assert bqs.query(validDist) == [{'Color':(255,0,0), 'Location':(3,4)}] 
        assert bqs.query(invalidDist) == [] 
        assert bqs.query(doubleDist) == [{'Color':(255,0,0), 'Location':(3,4)}, {'Color':(0,0,255),\
                                         'Location':(5,12)}] 
Пример #5
0
 def test_simple_query(self):
     validQuery = lambda args: args['Color'] == (255, 0, 0)
     invalidQuery = lambda args: args['Color'] == (254, 0, 0)
     import pdb
     pdb.set_trace()
     assert bqs.query(validQuery) == [{
         'Color': (255, 0, 0),
         'Location': (3, 4),
         'BehaviorId': 'color'
     }]
     assert bqs.query(invalidQuery) == []
Пример #6
0
    def test_complex_queries(self):
        validQuery = lambda args: args['Color'] == (255, 0, 0)
        doubleDist = lambda args: geo.dist(args['Location'], (0, 0)) <= 20

        twoPartPredicate = lambda args: doubleDist(args) and validQuery(args)
        assert bqs.query(twoPartPredicate) == [{
            'Color': (255, 0, 0),
            'Location': (3, 4)
        }]
        assert bqs.query([validQuery, doubleDist]) == [{
            'Color': (255, 0, 0),
            'Location': (3, 4)
        }]
Пример #7
0
    def test_dist_query(self):
        validDist = lambda args: geo.dist(args['Location'], (0, 0)) <= 5
        invalidDist = lambda args: geo.dist(args['Location'], (0, 0)) <= 2
        doubleDist = lambda args: geo.dist(args['Location'], (0, 0)) <= 20

        assert bqs.query(validDist) == [{
            'Color': (255, 0, 0),
            'Location': (3, 4),
            'BehaviorId': 'color'
        }]
        assert bqs.query(invalidDist) == []
        assert bqs.query(doubleDist) == [{'Color':(255,0,0), 'Location':(3,4), 'BehaviorId':'color'}, {'Color':(0,0,255),\
                                         'Location':(5,12), 'BehaviorId':'color'}]
Пример #8
0
    def __init__(self, configFileName):
        main_log.info("System Initialization began based on: " + str(configFileName))
        self.timer = clock.Stopwatch()
        self.timer.start()
        self.inputs = {}  # dict of inputs and their bound behaviors, keyed by InputId
        self.behaviors = {}
        self.lock = thread.allocate_lock()
        self.behaviorOutputs = {}  # key: [list of output destinations]
        self.behaviorInputs = {}
        self.componentDict = {}
        self.inputBehaviorRegistry = {}  # inputid -> behaviors listening to that
        self.dieNow = False
        # input
        self.screen = Screen()
        compReg.initRegistry()
        compReg.registerComponent(self.screen, "Screen")  # TODO: move to constants file

        bqs.initBQS()  # initialize the behavior query system
        # read configs from xml
        config = configGetter.loadConfigFile(configFileName)

        rendererConfig = config.find("RendererConfiguration")
        self.initializeRenderers(rendererConfig)

        pixelConfig = config.find("PixelConfiguration")
        self.initializeScreen(pixelConfig)

        inputConfig = config.find("InputConfiguration")
        self.initializeInputs(inputConfig)

        behaviorConfig = config.find("BehaviorConfiguration")
        self.initializeBehaviors(behaviorConfig)

        mapperConfig = config.find("PixelMapperConfiguration")
        self.initializeMapper(mapperConfig)

        # inits
        main_log.info("All components initialized")
        #
        self.registerAllComponents()

        installationConfig = config.find("InstallationConfiguration")
        self.configureInstallation(installationConfig)
        # Done initializing.  Lets start this thing!
        self.timer.stop()
        # main_log.info('Initialization done.  Time: ', self.timer.elapsed(), 'ms')
        self.mainLoop()
Пример #9
0
    def __init__(self, configFileName):
        main_log.info("System Initialization began based on: " + str(configFileName))
        self.timer = clock.Stopwatch()
        self.timer.start()
        self.inputs = {} #dict of inputs and their bound behaviors, keyed by InputId
        self.behaviors = {}
        self.lock = thread.allocate_lock()
        self.behaviorOutputs = {} #key: [list of output destinations]
        self.behaviorInputs = {}
        self.componentDict = {}
        self.inputBehaviorRegistry = {} #inputid -> behaviors listening to that
        self.dieNow = False
        #input
        self.screen = Screen()
        compReg.initRegistry()
        compReg.registerComponent(self.screen, 'Screen') #TODO: move to constants file
       
        bqs.initBQS()   #initialize the behavior query system
        #read configs from xml
        config = configGetter.loadConfigFile(configFileName)
        
        rendererConfig = config.find('RendererConfiguration')
        self.initializeRenderers(rendererConfig)
        
        pixelConfig = config.find('PixelConfiguration')
        self.initializeScreen(pixelConfig)
        
        inputConfig = config.find('InputConfiguration')
        self.initializeInputs(inputConfig)
        
        behaviorConfig = config.find('BehaviorConfiguration')
        self.initializeBehaviors(behaviorConfig)
        
        mapperConfig = config.find('PixelMapperConfiguration')
        self.initializeMapper(mapperConfig)

        #inits
        main_log.info('All components initialized')
        #
        self.registerAllComponents()
        
        installationConfig = config.find('InstallationConfiguration')
        self.configureInstallation(installationConfig)
        #Done initializing.  Lets start this thing!
        self.timer.stop()
        #main_log.info('Initialization done.  Time: ', self.timer.elapsed(), 'ms')
        self.mainLoop()
Пример #10
0
 def processResponse(self, sensor, recurs):
     ret = []
     for sensory in sensor:
         opsensory = dict(sensory)
         self.insertStepIfMissing(opsensory) 
         #TODO: update 19 to be a configurable variable
         results = bqs.query([
             bqs.getBehaviorIdLambda(self['Id']),\
             bqs.getDifferentUIDLambda(opsensory['UniqueResponseIdentifier']),\
             bqs.getDistLambda(opsensory['Location'], 19)
         ])
         if results:
             print len(results)
             opsensory['XStep'] = -opsensory['XStep']
             opsensory['Location'] = Geo.addLocations((opsensory['XStep'], opsensory['YStep']), opsensory['Location']) 
         opsensory['Location'] = Geo.addLocations((opsensory['XStep'], opsensory['YStep']), opsensory['Location']) 
         ret.append(opsensory)
     return (ret, []) 
Пример #11
0
 def processResponse(self, sensor, recurs):
     ret = []
     for sensory in sensor:
         opsensory = dict(sensory)
         #TODO: update 19 to be a configurable variable
         self.insertVelIfMissing(opsensory)
         results = bqs.query([
             bqs.getBehaviorIdLambda('accelerate'),\
             bqs.getDirectionLambda('+'),\
             bqs.getDistLambda(opsensory['Location'], 38)
         ])
         if results:
             opsensory['XVel'] = opsensory['XVel'] + 10 
         opsensory['XVel'] = min(max(-1, opsensory['XVel'] - 1), 10)
         opsensory['Location'] = Geo.addLocations((-opsensory['XVel'], 0), opsensory['Location'])
         if opsensory['Location'][0] >= 800: #TODO: Make this dynamic
             opsensory['Location'] = tuple([799, 25])
         ret.append(opsensory)
     return (ret, []) 
Пример #12
0
 def processResponse(self, sensor, recurs):
     ret = []
     for sensory in sensor:
         opsensory = dict(sensory)
         #TODO: update 19 to be a configurable variable
         self.insertVelIfMissing(opsensory)
         results = bqs.query([
             bqs.getBehaviorIdLambda('accelerate'),\
             bqs.getDirectionLambda('+'),\
             bqs.getDistLambda(opsensory['Location'], 38)
         ])
         if results:
             opsensory['XVel'] = opsensory['XVel'] + 10
         opsensory['XVel'] = min(max(-1, opsensory['XVel'] - 1), 10)
         opsensory['Location'] = Geo.addLocations((-opsensory['XVel'], 0),
                                                  opsensory['Location'])
         if opsensory['Location'][0] >= 800:  #TODO: Make this dynamic
             opsensory['Location'] = tuple([799, 25])
         ret.append(opsensory)
     return (ret, [])
Пример #13
0
    def processResponse(self, sensor, recurs):
        ret = []

        if self['NoBounceTime'] != None:
            noBounceTime = self['NoBounceTime']
        else:
            noBounceTime = 1000
        if self['BQSDistance'] != None:
            BQSDistance = self['BQSDistance']
        else:
            BQSDistance = 19


        for sensory in sensor:
            opsensory = dict(sensory)

            isNew = self.insertVelIfMissing(opsensory) 
            if not 'NoBounceTime' in opsensory:
                opsensory['NoBounceTime'] = noBounceTime 

            if opsensory['NoBounceTime'] <= 0:
                results = bqs.query([
                    bqs.getBehaviorIdLambda(self['Id']),\
                    bqs.getDifferentUIDLambda(opsensory['UniqueResponseIdentifier']),\
                    bqs.getDistLambda(opsensory['Location'], BQSDistance)
                ])
                if results:
                    opsensory['XVel'] = -opsensory['XVel']
                    opsensory['Location'] = Geo.addLocations((opsensory['XVel'], opsensory['YVel']), opsensory['Location']) 
            else:
                opsensory['NoBounceTime'] -= 1
            if isNew:
                if opsensory['Direction'] < 0:
                    opsensory['XVel'] = -opsensory['XVel']
                if opsensory['Direction'] != 0:
                    opsensory['Location'] = Geo.addLocations((2*opsensory['XVel'], opsensory['YVel']), opsensory['Location']) 
                    ret.append(opsensory)
            else:
                opsensory['Location'] = Geo.addLocations((opsensory['XVel'], opsensory['YVel']), opsensory['Location']) 
                ret.append(opsensory)
        return (ret, []) 
Пример #14
0
 def processResponse(self, sensor, recurs):
     ret = []
     for sensory in sensor:
         opsensory = dict(sensory)
         self.insertStepIfMissing(opsensory)
         #TODO: update 19 to be a configurable variable
         results = bqs.query([
             bqs.getBehaviorIdLambda(self['Id']),\
             bqs.getDifferentUIDLambda(opsensory['UniqueResponseIdentifier']),\
             bqs.getDistLambda(opsensory['Location'], 19)
         ])
         if results:
             for result in results:
                 new = opsensory['XStep'] + result['XStep']
                 if new >= 0:
                     opsensory['XStep'] = min(20, new)
                 if new < 0:
                     opsensory['XStep'] = max(-20, new)
         opsensory['Location'] = Geo.addLocations(
             (opsensory['XStep'], opsensory['YStep']),
             opsensory['Location'])
         ret.append(opsensory)
     return (ret, [])
Пример #15
0
 def setUp(self):
     bqs.initBQS()
     b = ColorChangerBehavior({'Id': 'color', 'ColorList': [(255, 0, 0)]})
     c = ColorChangerBehavior({'Id': 'color2', 'ColorList': [(0, 0, 255)]})
     bqs.addBehavior(b)
     bqs.addBehavior(c)
     b.addInput({'Location': (3, 4)})
     c.addInput({'Location': (5, 12)})
     b.timeStep()
     c.timeStep()
Пример #16
0
 def setUp(self):
     bqs.initBQS()
     b = ColorChangerBehavior({'Id': 'color','ColorList':[(255,0,0)]})
     c = ColorChangerBehavior({'Id': 'color2', 'ColorList':[(0,0,255)]})
     bqs.addBehavior(b)
     bqs.addBehavior(c)
     b.addInput({'Location':(3,4)})
     c.addInput({'Location':(5,12)})
     b.timeStep()
     c.timeStep()
Пример #17
0
 def test_uri_query(self):
     mydict = {'UniqueResponseIdentifier': 'abc'}
     goodict = {'UniqueResponseIdentifier': 'cde'}
     urichecker = bqs.getDifferentUIDLambda('abc')
     assert urichecker(mydict) == False
     assert urichecker(goodict) == True
Пример #18
0
 def test_simple_query(self):
     validQuery = lambda args:args['Color']==(255,0,0)
     invalidQuery = lambda args:args['Color']==(254,0,0)
     assert bqs.query(validQuery) == [{'Color':(255,0,0), 'Location':(3,4)}]
     assert bqs.query(invalidQuery) == []
Пример #19
0
    def processResponse(self, sensor, recurs):
        ret = []

        if self['GrowthDirection'] != None:
            growthDirection = self['GrowthDirection']
        else:
            growthDirection = 'right'
        if self['HitSensitivity'] != None:
            hitSensitivity = self['HitSensitivity']
        else:
            hitSensitivity = 4
        if self['MaxVelocity'] != None:
            maxVelocity = self['MaxVelocity']
        else:
            maxVelocity = 10
        if self['MinVelocity'] != None:
            minVelocity = self['MinVelocity']
        else:
            minVelocity = -1
        if self['MinLength'] != None:
            minLength = self['MinLength']
        else:
            minLength = 30

        for sensory in sensor:
            opsensory = dict(sensory)

            if not 'XVel' in opsensory:
                opsensory['XVel'] = -1
            if not 'SpeedupTimer' in opsensory:
                opsensory['SpeedupTimer'] = 0

            if growthDirection == 'right':
                results = bqs.query([
                    bqs.getBehaviorIdLambda('accelerate'),\
                    bqs.getDirectionLambda('-'),\
                    bqs.getLeftLambda(0)
                ])
            else:
                compReg.getLock().acquire()
                self.minX, self.minY, self.maxX, self.maxY = compReg.getComponent(
                    'Screen').size
                compReg.getLock().release()

                results = bqs.query([
                    bqs.getBehaviorIdLambda('accelerate'),\
                    bqs.getDirectionLambda('+'),\
                    bqs.getRightLambda(self.maxX)
                ])

            if results:
                opsensory['SpeedupTimer'] = hitSensitivity

            if opsensory['SpeedupTimer'] > 0:
                opsensory['XVel'] = min(opsensory['XVel'] + 1, maxVelocity)
                opsensory['SpeedupTimer'] = opsensory['SpeedupTimer'] - 1
            else:
                opsensory['XVel'] = max(minVelocity, opsensory['XVel'] - 1)

            opsensory['Location'] = (opsensory['Location'][0],
                                     opsensory['Location'][1] +
                                     opsensory['XVel'])

            #Set min length
            if opsensory['Location'][1] <= minLength:
                opsensory['Location'] = (opsensory['Location'][0], minLength)

            ret.append(opsensory)
        return (ret, [])
Пример #20
0
 def tearDown(self):
     bqs.initBQS()
Пример #21
0
 def initializeBehaviors(self, behaviorConfig):
     self.behaviors = self.initializeComponent(behaviorConfig)
     for behavior in self.behaviors:
         self.addBehavior(behavior)
         bqs.addBehavior(behavior)
Пример #22
0
    def processResponse(self, sensor, recurs):
        ret = []

        if self['GrowthDirection'] != None:
            growthDirection = self['GrowthDirection']
        else:
            growthDirection = 'right'
        if self['HitSensitivity'] != None:
            hitSensitivity = self['HitSensitivity']
        else:
            hitSensitivity = 4
        if self['MaxVelocity'] != None:
            maxVelocity = self['MaxVelocity']
        else:
            maxVelocity = 10
        if self['MinVelocity'] != None:
            minVelocity = self['MinVelocity']
        else:
            minVelocity = -1
        if self['MinLength'] != None:
            minLength = self['MinLength']
        else:
            minLength = 30

        for sensory in sensor:
            opsensory = dict(sensory)

            if not 'XVel' in opsensory:
                opsensory['XVel'] = -1
            if not 'SpeedupTimer' in opsensory:
                opsensory['SpeedupTimer'] = 0
 
            if growthDirection == 'right':
                results = bqs.query([
                    bqs.getBehaviorIdLambda('accelerate'),\
                    bqs.getDirectionLambda('-'),\
                    bqs.getLeftLambda(0)
                ])
            else:
                compReg.getLock().acquire()
                self.minX, self.minY, self.maxX, self.maxY = compReg.getComponent('Screen').size
                compReg.getLock().release()

                results = bqs.query([
                    bqs.getBehaviorIdLambda('accelerate'),\
                    bqs.getDirectionLambda('+'),\
                    bqs.getRightLambda(self.maxX)
                ])


            if results:
                opsensory['SpeedupTimer'] = hitSensitivity 

            if opsensory['SpeedupTimer'] > 0:
                opsensory['XVel'] = min(opsensory['XVel'] + 1, maxVelocity)
                opsensory['SpeedupTimer'] = opsensory['SpeedupTimer'] - 1
            else:
                opsensory['XVel'] = max(minVelocity, opsensory['XVel'] - 1)

            opsensory['Location'] = (opsensory['Location'][0], opsensory['Location'][1] + opsensory['XVel'])

            #Set min length
            if opsensory['Location'][1] <= minLength:
                opsensory['Location'] = (opsensory['Location'][0], minLength)

            ret.append(opsensory)
        return (ret, []) 
Пример #23
0
 def initializeBehaviors(self, behaviorConfig):
     self.behaviors = self.initializeComponent(behaviorConfig)
     for behavior in self.behaviors:
         self.addBehavior(behavior)
         bqs.addBehavior(behavior)
Пример #24
0
 def test_uri_query(self):
     mydict = {'UniqueResponseIdentifier':'abc'}
     goodict = {'UniqueResponseIdentifier':'cde'}
     urichecker = bqs.getDifferentUIDLambda('abc')
     assert urichecker(mydict) == False
     assert urichecker(goodict) == True
Пример #25
0
 def test_simple_query(self):
     validQuery = lambda args:args['Color']==(255,0,0)
     invalidQuery = lambda args:args['Color']==(254,0,0)
     import pdb; pdb.set_trace()
     assert bqs.query(validQuery) == [{'Color':(255,0,0), 'Location':(3,4), 'BehaviorId':'color'}]
     assert bqs.query(invalidQuery) == []
Пример #26
0
 def tearDown(self):
     bqs.initBQS()