1 from operationscore.SmootCoreObject import *
2 from logger import main_log
3 import pdb
5 """PixelMapper is the parent class for PixelMappers. Inheriting classes should define
6 mappingFunction which takes an eventLocation and a screen and returns a list of (weight, pixels). PixelMapper
7 handles caching automatically."""
9 self.mem = {}
10 self.totalCalls = 0
11 self.cachehits = 0
12 - def mapEvent(self, eventLocation, screen):
13 self.totalCalls += 1
14 if self.totalCalls % 100 == 0:
15 main_log.info('Cache percentage for :', self['Id'], self.cachehits /\
16 float(self.totalCalls))
17 if eventLocation in self.mem:
18 self.cachehits += 1
19 return self.mem[eventLocation]
20 else:
21 self.mem[eventLocation] = self.mappingFunction(eventLocation, screen)
22 return self.mem[eventLocation]
23
24
26 """Takes a Screen and event location and returns a list of tuples (pixel,weight) with
27 sum(weights)=1"""
28 raise Exception('Mapping function not defined!')
29