separate picking from add_word
This commit is contained in:
parent
c91ba9f320
commit
e96b1e8199
19
dict_dl.py
19
dict_dl.py
@ -207,6 +207,7 @@ class Queue:
|
|||||||
self.unusual = lambda prefix: not all([c in letters for c in prefix.lower()]) or len(prefix) < self.prefix_length
|
self.unusual = lambda prefix: not all([c in letters for c in prefix.lower()]) or len(prefix) < self.prefix_length
|
||||||
|
|
||||||
def wait(self):
|
def wait(self):
|
||||||
|
self.time_exponent = abs(self.time_exponent)
|
||||||
a = self.time_base**self.time_exponent
|
a = self.time_base**self.time_exponent
|
||||||
b = self.time_base ** (self.time_exponent * 3)
|
b = self.time_base ** (self.time_exponent * 3)
|
||||||
time.sleep(randtime(a, b))
|
time.sleep(randtime(a, b))
|
||||||
@ -216,13 +217,23 @@ class Queue:
|
|||||||
with open(db_file, "r") as f:
|
with open(db_file, "r") as f:
|
||||||
self.words |= set(json.load(f).keys())
|
self.words |= set(json.load(f).keys())
|
||||||
|
|
||||||
def add_word(self):
|
def pick_random(self):
|
||||||
self.redo.load()
|
self.redo.load()
|
||||||
self.queue -= self.words
|
self.queue -= self.words
|
||||||
self.queue -= self.snafus
|
self.queue -= self.snafus
|
||||||
self.queue |= self.redo
|
self.queue |= self.redo
|
||||||
len_queue = len(self.queue) # actual queue
|
if len(self.queue) < 1:
|
||||||
p = random.choice(list(self.queue))
|
p = random.choice(list(self.words))
|
||||||
|
self.time_exponent += 1
|
||||||
|
else:
|
||||||
|
p = random.choice(list(self.queue))
|
||||||
|
self.time_exponent -= 20
|
||||||
|
else:
|
||||||
|
return p
|
||||||
|
|
||||||
|
def add_word(self, p=None):
|
||||||
|
if p == None:
|
||||||
|
p = self.pick_random()
|
||||||
try:
|
try:
|
||||||
start_parsing = time.time()
|
start_parsing = time.time()
|
||||||
w = self.Parser(p) # fetch new word
|
w = self.Parser(p) # fetch new word
|
||||||
@ -231,7 +242,7 @@ class Queue:
|
|||||||
print(
|
print(
|
||||||
f"{p} | "
|
f"{p} | "
|
||||||
f"{len(self.words)} words collected, "
|
f"{len(self.words)} words collected, "
|
||||||
f"{len_queue} words waiting in queue"
|
f"{len(self.queue)} words waiting in queue"
|
||||||
# f", {start_db_stuff-start_parsing:.06f}s"
|
# f", {start_db_stuff-start_parsing:.06f}s"
|
||||||
# f"/{time.time() - start_db_stuff:.06f}s"
|
# f"/{time.time() - start_db_stuff:.06f}s"
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user