aboutsummaryrefslogtreecommitdiff
path: root/operationscore/PixelMapper.py
blob: 1f94fa538cc4351d63e9325c14ac0c1336ee6ed6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from operationscore.SmootCoreObject import *
import pdb
class PixelMapper(SmootCoreObject):
    def init(self):
        self.mem = {} #Dictionary of all seen events
        self.totalCalls = 0
        self.cachehits = 0
    def mapEvent(self, eventLocation, screen):
        self.totalCalls += 1
        if self.totalCalls % 100 == 0:
            print self['Id'], self.cachehits / float(self.totalCalls)
        if eventLocation in self.mem:
            self.cachehits += 1
            return self.mem[eventLocation]
        else:
            self.mem[eventLocation] = self.mappingFunction(eventLocation, screen)
            return self.mem[eventLocation]
    #Takes a Screen and returns a list of tuples
    #(pixel, weight), with the sum of weights = 1
    #TODO: consider abstracting away from pixels
    def mappingFunction(self,eventLocation, screen):
        pass