main test.sh
parent
696b23d18c
commit
8c97034a80
24
poc/main.py
24
poc/main.py
|
|
@ -12,14 +12,14 @@ class Bucket:
|
|||
self.__last_state = False
|
||||
|
||||
def push(self):
|
||||
return self.__push_c(1)
|
||||
result = self.__push_c(1)
|
||||
self.__cb()
|
||||
return result
|
||||
|
||||
def pop(self):
|
||||
return self.__pop()
|
||||
|
||||
def __mod(self, foo):
|
||||
result = foo()
|
||||
result = self.__pop()
|
||||
self.__cb()
|
||||
return result
|
||||
|
||||
def __cb(self):
|
||||
new_state = self.q > self.T
|
||||
|
|
@ -28,11 +28,15 @@ class Bucket:
|
|||
self.__last_state = new_state
|
||||
self.CB(new_state)
|
||||
|
||||
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
|
||||
print(f"{int(self.q)} = + {int(c+.5)}")
|
||||
return True
|
||||
|
||||
def __pop(self):
|
||||
|
|
@ -41,17 +45,21 @@ class Bucket:
|
|||
if remove_up_to > self.q:
|
||||
remove_up_to = self.q
|
||||
self.q -= remove_up_to
|
||||
print(f"{int(self.q)} = - {int(remove_up_to+.5)}")
|
||||
self.__last_pop = now
|
||||
|
||||
def __now(self):
|
||||
return time.time()
|
||||
|
||||
def main(stream):
|
||||
bucket = Bucket(3, 1, 2, lambda state: print("state is now", state))
|
||||
bucket = None
|
||||
N = 3
|
||||
R = 2
|
||||
T = 1
|
||||
bucket = Bucket(N, R, T, lambda state: print(f"state is now {state} ({bucket.state()}), q={bucket.q}"))
|
||||
|
||||
while readline():
|
||||
print(bucket.push(), file=stdout)
|
||||
#print(f'q={bucket.q}, N={bucket.N}, R={bucket.R}', file=stdout)
|
||||
bucket.push()
|
||||
stdout.flush()
|
||||
|
||||
def readline():
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
#! /bin/bash
|
||||
|
||||
(
|
||||
for j in `seq 1 10`; do
|
||||
for i in `seq 1 10`; do
|
||||
echo $i
|
||||
true || printf "$j/$i " >&2
|
||||
if ((i%j==0)); then
|
||||
sleep $j
|
||||
fi
|
||||
done
|
||||
done
|
||||
) | python3 ./main.py
|
||||
Loading…
Reference in New Issue