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
|
self.__last_state = False
|
||||||
|
|
||||||
def push(self):
|
def push(self):
|
||||||
return self.__push_c(1)
|
result = self.__push_c(1)
|
||||||
|
self.__cb()
|
||||||
|
return result
|
||||||
|
|
||||||
def pop(self):
|
def pop(self):
|
||||||
return self.__pop()
|
result = self.__pop()
|
||||||
|
|
||||||
def __mod(self, foo):
|
|
||||||
result = foo()
|
|
||||||
self.__cb()
|
self.__cb()
|
||||||
|
return result
|
||||||
|
|
||||||
def __cb(self):
|
def __cb(self):
|
||||||
new_state = self.q > self.T
|
new_state = self.q > self.T
|
||||||
|
|
@ -28,11 +28,15 @@ class Bucket:
|
||||||
self.__last_state = new_state
|
self.__last_state = new_state
|
||||||
self.CB(new_state)
|
self.CB(new_state)
|
||||||
|
|
||||||
|
def state(self):
|
||||||
|
return self.__last_state
|
||||||
|
|
||||||
def __push_c(self, c):
|
def __push_c(self, c):
|
||||||
self.__pop()
|
self.__pop()
|
||||||
if self.q+c > self.N:
|
if self.q+c > self.N:
|
||||||
return False
|
return False
|
||||||
self.q += c
|
self.q += c
|
||||||
|
print(f"{int(self.q)} = + {int(c+.5)}")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __pop(self):
|
def __pop(self):
|
||||||
|
|
@ -41,17 +45,21 @@ class Bucket:
|
||||||
if remove_up_to > self.q:
|
if remove_up_to > self.q:
|
||||||
remove_up_to = self.q
|
remove_up_to = self.q
|
||||||
self.q -= remove_up_to
|
self.q -= remove_up_to
|
||||||
|
print(f"{int(self.q)} = - {int(remove_up_to+.5)}")
|
||||||
self.__last_pop = now
|
self.__last_pop = now
|
||||||
|
|
||||||
def __now(self):
|
def __now(self):
|
||||||
return time.time()
|
return time.time()
|
||||||
|
|
||||||
def main(stream):
|
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():
|
while readline():
|
||||||
print(bucket.push(), file=stdout)
|
bucket.push()
|
||||||
#print(f'q={bucket.q}, N={bucket.N}, R={bucket.R}', file=stdout)
|
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
|
|
||||||
def readline():
|
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