Esempio n. 1
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)}] 
Esempio n. 2
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'}]
Esempio n. 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)}] 
Esempio n. 4
0
 def mappingFunction(self, eventLocation, screen):
     if type(eventLocation) == type(tuple()):
         bestDist = sys.maxint 
         bestPixel = None
         [x,y] = eventLocation
         for (x,pixel) in screen.pixelsInRange(x-self['CutoffDist'], \
                 x+self['CutoffDist']):
             pixelDist = Geo.dist(pixel.location, eventLocation)
             if pixelDist < bestDist:
                 bestPixel = pixel
                 bestDist = pixelDist
         if bestPixel != None:
             return [(bestPixel,1)]
         else:
             return [] 
     else:
         #{x}>5,{y}<k
         ret = []
         eventLocation = eventLocation.replace('{x}', 'pixel.location[0]')
         eventLocation = eventLocation.replace('{y}', 'pixel.location[1]')
         conditions = eventLocation.split(',')
         conditionLambdas = [eval('lambda pixel:'+condition) for condition in conditions]
         for pixel in screen:
             try:
                 pixelValid = True
                 for p in conditionLambdas:
                     if p(pixel) == False:
                         pixelValid = False
                         continue
                 if pixelValid:
                     ret.append((pixel, 1))
             except Exception as exp:
                 raise Exception('Bad event condition')
         return ret
Esempio n. 5
0
 def getPixelLocations(self): #returns a complete list of locations of Pixels
     locations = self.layoutFunc()
     for pixel1, pixel2 in zip(locations[:-1], locations[1:]):
         if (Geo.dist(pixel1, pixel2) > self['pixelToPixelSpacing']):
             raise Exception('Illegal pixel location.  Distance between adjacent ' 
                             + 'pixels must be less than pixelToPixelSpacing.'
                             + 'Illegal distance is between {0} and {1}'
                             .format(pixel1, pixel2))
     return locations[::-1] if self['Reverse'] else locations
Esempio n. 6
0
 def mappingFunction(self, eventLocation, screen):
     returnPixels = [] 
     [x,y] = eventLocation
     potentialPixels = screen.pixelsInRange(x-self.CutoffDist, \
             x+self.CutoffDist)
     for (x,pixel) in screen.pixelsInRange(x-self.CutoffDist, \
             x+self.CutoffDist):
         pixelDist = Geo.dist(pixel.location, eventLocation)
         if pixelDist < self.CutoffDist:
             w = Geo.gaussian(pixelDist, self.Height, 0, self.Width)
             if w > self.MinWeight:
                 returnPixels.append((pixel, w))
     return returnPixels
Esempio n. 7
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)
        }]
Esempio n. 8
0
 def getPixelLocations(self): #returns a complete list of locations of Pixels
     #for a strip
     locations = [self.argDict['originLocation']]
     for pixelIndex in range(self['numPixels']-1): #-1 because origin
         #already exists
         newLocation = self.layoutFunc(locations[-1]) 
         if newLocation == None:
             raise Exception('Location cannot be null.  layoutFunc not \
             defined or improperly defined.')
         if Geo.dist(newLocation, locations[-1]) > \
                 self['pixelToPixelSpacing']:
                     raise Exception('Illegal pixel location.  Distance \
                     between adjacent pixels must be less than \
                     pixelToPixelSpacing.')
         locations.append(newLocation)
     if self['Reverse']:
         locations.reverse()
     return locations
Esempio n. 9
0
 def getPixelLocations(self):  # returns a complete list of locations of Pixels
     # for a strip
     locations = [self.argDict["originLocation"]]
     for pixelIndex in range(self["numPixels"] - 1):  # -1 because origin
         # already exists
         newLocation = self.layoutFunc(locations[-1])
         if newLocation == None:
             raise Exception(
                 "Location cannot be null.  layoutFunc not \
             defined or improperly defined."
             )
         if Geo.dist(newLocation, locations[-1]) > self["pixelToPixelSpacing"]:
             raise Exception(
                 "Illegal pixel location.  Distance \
                     between adjacent pixels must be less than \
                     pixelToPixelSpacing.  Illegal distance is between "
                 + str(pixelIndex)
                 + " and"
                 + str(pixelIndex + 1)
             )
         locations.append(newLocation)
     if self["Reverse"]:
         locations.reverse()
     return locations
Esempio n. 10
0
def getDistLambda(loc, maxDist):
    """Returns a lambda function that checks if for behaviors within maxDist of loc.  Can be passed
    in as an arg to query."""
    return lambda args: Geo.dist(args['Location'], loc) <= maxDist
Esempio n. 11
0
def getDistLambda(loc, maxDist):
    """Returns a lambda function that checks if for behaviors within maxDist of loc.  Can be passed
    in as an arg to query."""
    return lambda args: Geo.dist(args["Location"], loc) <= maxDist