Use productivity.
This commit is contained in:
parent
7650a1b784
commit
e8abbbd16e
84
words.py
84
words.py
|
@ -3,6 +3,12 @@ import httpx
|
|||
import random
|
||||
import sqlite3
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
|
||||
@dataclass
|
||||
class Scores:
|
||||
productivity : int
|
||||
rank : int
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -23,22 +29,50 @@ r = db.execute('''
|
|||
where c.x = x.word and c.y = y.word
|
||||
)
|
||||
''')
|
||||
Q: set[tuple[tuple[str, int], tuple[str, int]]] = {
|
||||
((x, xr), (y, yr)) for x, xr, y, yr in r.fetchall()
|
||||
}
|
||||
|
||||
productivity : dict[str, int] = {}
|
||||
while True:
|
||||
r = db.execute('''
|
||||
select
|
||||
w.word,
|
||||
w.rank,
|
||||
count(distinct c.z) as productivity
|
||||
from combos c
|
||||
join words w on w.word = c.x
|
||||
where w.word != 'Nothing'
|
||||
group by w.word
|
||||
''')
|
||||
scores = {
|
||||
w: Scores(productivity=p, rank=r)
|
||||
for w, r, p in r.fetchall()
|
||||
}
|
||||
|
||||
while Q:
|
||||
log.info('%d items queued', len(Q))
|
||||
# (x, x_rank), (y, y_rank) = random.choice(list(Q))
|
||||
((x, x_rank), (y, y_rank)), = random.sample(
|
||||
population=list(Q),
|
||||
k=1,
|
||||
#counts=[max(xr, yr) for (x, xr), (y, yr) in Q],
|
||||
counts=[productivity.get(x, 1)*productivity.get(y, 1) for (x, xr), (y, yr) in Q],
|
||||
)
|
||||
Q.remove(((x, x_rank), (y, y_rank)))
|
||||
while True:
|
||||
(x, y), = random.sample(
|
||||
k=1,
|
||||
population=[
|
||||
(x,y)
|
||||
for x in scores.keys()
|
||||
for y in scores.keys()
|
||||
],
|
||||
counts=[
|
||||
xs.productivity*ys.productivity
|
||||
for xs in scores.values()
|
||||
for ys in scores.values()
|
||||
],
|
||||
)
|
||||
|
||||
r = db.execute('''
|
||||
select exists (
|
||||
select *
|
||||
from combos
|
||||
where x = ? and y = ?
|
||||
)
|
||||
''', (x, y))
|
||||
if r.fetchall()[0][0]:
|
||||
# we already know the answer
|
||||
continue
|
||||
else:
|
||||
break
|
||||
|
||||
resp = http.get(
|
||||
'https://neal.fun/api/infinite-craft/pair',
|
||||
|
@ -53,12 +87,12 @@ while Q:
|
|||
z = response['result']
|
||||
is_new = response['isNew']
|
||||
log.info(
|
||||
'%s (%d/%d) + %s (%d/%d) -> %s%s',
|
||||
x, x_rank, productivity.get(x, 0), y, y_rank, productivity.get(y, 0), z,
|
||||
'%s (%s) + %s (%s) -> %s%s',
|
||||
x, scores[x], y, scores[y], z,
|
||||
' [NEW!]' if is_new else ''
|
||||
)
|
||||
|
||||
z_rank = 1+max(x_rank, y_rank)
|
||||
z_rank = 1+max(scores[x].rank, scores[y].rank)
|
||||
db.execute('''
|
||||
insert into words (word, rank, is_new) values (?, ?, ?)
|
||||
on conflict(word) do update set rank = ? where rank > ?
|
||||
|
@ -70,20 +104,4 @@ while Q:
|
|||
)
|
||||
db.commit()
|
||||
|
||||
if z != 'Nothing':
|
||||
r = db.execute('''
|
||||
select q.word, q.rank, z.rank
|
||||
from words q, words z
|
||||
where not exists (
|
||||
select *
|
||||
from combos c
|
||||
where c.x = q.word and c.y = ?
|
||||
) and z.word = ? and q.word != 'Nothing'
|
||||
''', (z, z))
|
||||
for q, q_rank, z_rank in r.fetchall():
|
||||
Q.add(((z, z_rank), (q, q_rank)))
|
||||
|
||||
r = db.execute('select x, count(distinct z) as cnt from combos group by x')
|
||||
productivity = {w: score for w, score in r.fetchall()}
|
||||
|
||||
time.sleep(5)
|
||||
|
|
Loading…
Reference in New Issue