update test for more buttons!
parent
1c41c2a717
commit
bdb874cd5e
|
|
@ -25,13 +25,18 @@ def with_(P, D, M):
|
|||
|
||||
window = Window(D, M)
|
||||
|
||||
previous = {}
|
||||
while True:
|
||||
got = readline()
|
||||
if got:
|
||||
window.push(got)
|
||||
else:
|
||||
window.pop()
|
||||
print(window.report())
|
||||
report = window.report()
|
||||
#print(report)
|
||||
for k in [k for k in report if not k in previous]:
|
||||
cb.cb(k)(State(True, report[k]))
|
||||
for k in [k for k in previous if not k in report]:
|
||||
cb.cb(k)(State(False, 0))
|
||||
previous = report
|
||||
|
||||
def readline():
|
||||
def __input(*args):
|
||||
|
|
@ -61,6 +66,7 @@ class Window():
|
|||
self.n = 1024
|
||||
|
||||
def report(self):
|
||||
self.__pop()
|
||||
scaled_rates = self.report_scaled_rates()
|
||||
ttl = sum([scaled_rates[k] for k in scaled_rates])
|
||||
results = {}
|
||||
|
|
@ -69,7 +75,6 @@ class Window():
|
|||
return {k:results[k] for k in results if results[k] > self.M}
|
||||
|
||||
def report_scaled_rates(self):
|
||||
self.__pop()
|
||||
cnt = len(self.w)
|
||||
keys = list(set([i[0] for i in self.w]))
|
||||
scaled_rates = {}
|
||||
|
|
@ -101,27 +106,7 @@ class Window():
|
|||
def __now(self):
|
||||
return time.time()*1000
|
||||
|
||||
class Bucket():
|
||||
def __init__(self, N, M, R, T, CB):
|
||||
self.q = 0.0
|
||||
self.N = N
|
||||
self.M = M
|
||||
self.R = R
|
||||
self.T = T
|
||||
self.CB = CB
|
||||
self.__last_pop = 0
|
||||
self.__last_state = False
|
||||
|
||||
def push(self):
|
||||
result = self.__push_c(1)
|
||||
self.__cb()
|
||||
return result
|
||||
|
||||
def pop(self):
|
||||
result = self.__pop()
|
||||
self.__cb()
|
||||
return result
|
||||
|
||||
'''
|
||||
def __cb(self):
|
||||
new_state = self.q > self.T
|
||||
if new_state == self.__last_state:
|
||||
|
|
@ -139,27 +124,7 @@ class Bucket():
|
|||
if filledness > 1.0:
|
||||
filledness = 1.0
|
||||
self.CB(State(new_state, filledness))
|
||||
|
||||
def state(self):
|
||||
return self.__last_state
|
||||
|
||||
def __push_c(self, c):
|
||||
self.__pop()
|
||||
if self.q+c > self.N:
|
||||
return False
|
||||
self.q += c
|
||||
return True
|
||||
|
||||
def __pop(self):
|
||||
now = self.__now()
|
||||
remove_up_to = (now - self.__last_pop) / self.R
|
||||
if remove_up_to > self.q:
|
||||
remove_up_to = self.q
|
||||
self.q -= remove_up_to
|
||||
self.__last_pop = now
|
||||
|
||||
def __now(self):
|
||||
return time.time()
|
||||
'''
|
||||
|
||||
class CBAppend():
|
||||
def __init__(self, path):
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ set -o pipefail
|
|||
peek() {
|
||||
while read -r line; do
|
||||
echo $line
|
||||
echo $line >&2
|
||||
#echo $line >&2
|
||||
done
|
||||
}
|
||||
cleanup() {
|
||||
|
|
@ -16,16 +16,19 @@ trap cleanup EXIT
|
|||
|
||||
python3 ./state_to_buttons.py &
|
||||
|
||||
python3 ./testdata/rand_0_n_stream.py \
|
||||
python3 ./testdata/rand_0_n_weighted_stream.py \
|
||||
-n 6 \
|
||||
-b-min 1 \
|
||||
-b-max 10 \
|
||||
-d-min 100 \
|
||||
-d-max 3000 \
|
||||
-between 100 \
|
||||
-b-min 10 \
|
||||
-b-max 100 \
|
||||
-d-min 100 \
|
||||
-d-max 3000 \
|
||||
-between 10 \
|
||||
| peek \
|
||||
| python3 ./stream_to_state.py \
|
||||
-n 20 \
|
||||
-m 15 \
|
||||
-r 15 \
|
||||
-t 15
|
||||
-d 10000 \
|
||||
-m .2
|
||||
|
|
|
|||
Loading…
Reference in New Issue