47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
"""Пересчёт score всех записей текущей формулой rank.py (после правок веса).
|
|
|
|
python tools/rescore.py # показать топ-15 без записи
|
|
python tools/rescore.py --apply # обновить items.score
|
|
"""
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
|
|
from omni import config, rank, sources, store # noqa: E402
|
|
|
|
CAT = {s.name: (s.category or "") for s in sources.SOURCES}
|
|
|
|
|
|
class _It:
|
|
__slots__ = ("provider", "kind", "title", "text", "published", "price", "score", "category")
|
|
|
|
def __init__(self, provider, kind, title, text, published, price, category=""):
|
|
self.provider, self.kind = provider, kind
|
|
self.title, self.text = title or "", text or ""
|
|
self.published, self.price, self.score = published or "", price, 0.0
|
|
self.category = category or ""
|
|
|
|
|
|
def main():
|
|
apply = "--apply" in sys.argv
|
|
c = store.conn()
|
|
rows = c.execute("SELECT id, provider, kind, title, text, published, price, score, source FROM items").fetchall()
|
|
upd, top = [], []
|
|
for iid, prov, kind, title, text, pub, price, old, src in rows:
|
|
it = rank.score(_It(prov, kind, title, text, pub, price, CAT.get(src, "")))
|
|
upd.append((it.score, iid))
|
|
top.append((it.score, old, prov, title or ""))
|
|
top.sort(reverse=True)
|
|
print(f"записей {len(rows)}; топ по новой формуле:")
|
|
for sc, old, prov, title in top[:15]:
|
|
print(f" {sc:6.2f} (было {old:5.2f}) {prov[:10]:10} {title[:72]}")
|
|
if apply:
|
|
c.executemany("UPDATE items SET score=? WHERE id=?", upd)
|
|
c.commit()
|
|
print("обновлено", len(upd))
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |