-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalculator.py
54 lines (39 loc) · 1.53 KB
/
calculator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import detail
class Calculator:
def __init__(self, groupSize, lookback, idx, buffer, threshold):
self.hist = []
self.frameCache = []
self.diff = 0
self.idx = None
self.done = False
self.groupSize = groupSize
self.lookback = lookback
self.idx = idx
self.buffer = buffer # TODO: Should be passing in just the consumer, not buffer. Maybe get rid of consumer model
self.consumer = buffer.getConsumer()
self.threshold = threshold
def Calculate(self):
if self.done:
raise Exception("Calculator already done")
assert self.idx >= len(self.hist) * self.groupSize
self.hist.append(self.idx)
self.frameCache.append(self.consumer.getFrame(self.idx))
while len(self.frameCache) > self.lookback:
del self.frameCache[0]
startIdx = len(self.hist) * self.groupSize
if startIdx + self.groupSize > self.buffer.getFrameCount(): # TODO: Consider ways of handling remainder frames
self.done = True
return True
minDiffIdx = None
minDiff = None
for i in range(self.groupSize):
iidx = startIdx + i
idiff = 0
for f in self.frameCache:
idiff += detail.Diff(self.consumer.getFrame(iidx), f, self.threshold)
if minDiff is None or idiff < minDiff:
minDiffIdx = iidx
minDiff = idiff
self.diff += minDiff
self.idx = minDiffIdx
return False