Files
full-parse-kit/imba/rank.py
T

69 lines
2.1 KiB
Python

"""Скоринг: что показывать первым. Ценность = тип + цена + объём + свежесть + надёжность источника."""
import re
from datetime import datetime, timezone
KIND_WEIGHT = {
"combo": 30, "accounts": 26, "ai_credits": 24, "carding": 22, "proxy": 20,
"spammer": 18, "inviter": 16, "traffic": 14, "tool": 12, "freebie": 10,
"crypto": 8, "leak": 6, "other": 0,
}
VOL_RX = re.compile(r"(\d+(?:[.,]\d+)?)\s?([KkMm])")
def _volume_score(volume: str) -> float:
m = VOL_RX.search(volume or "")
if not m:
return 0.0
try:
n = float(m.group(1).replace(",", "."))
except ValueError:
return 0.0
if m.group(2).lower() == "m":
n *= 1000
# 50K = 10 очков, 500K = 20, логарифмически
return min(20.0, max(0.0, (n / 50000.0) ** 0.5 * 10))
def _fresh_score(ts: str) -> float:
if not ts:
return 0.0
s = ts.strip().replace("Z", "+00:00")
for fmt in ("%Y-%m-%dT%H:%M:%S%z", "%Y-%m-%dT%H:%M:%S", "%Y-%m-%d %H:%M:%S", "%Y-%m-%d",
"%a, %d %b %Y %H:%M:%S %z", "%d.%m.%Y"):
try:
dt = datetime.strptime(s[:len(datetime.now().strftime(fmt)) + 6], fmt)
if dt.tzinfo is None:
dt = dt.replace(tzinfo=timezone.utc)
days = (datetime.now(timezone.utc) - dt).days
if days <= 1:
return 25.0
if days <= 3:
return 18.0
if days <= 7:
return 12.0
if days <= 30:
return 6.0
return 0.0
except Exception:
continue
return 0.0
def score(f, source_ok: int = 0) -> float:
s = float(KIND_WEIGHT.get(f.kind, 0))
if f.price:
s += 12
s += _volume_score(f.volume)
s += _fresh_score(f.ts)
if "bulk_emails" in (f.flags or []):
s += 8
if f.snippet and len(f.snippet) > 60:
s += 2
s += min(10.0, source_ok * 1.5)
return round(s, 2)
def rank_all(findings, source_ok: int = 0):
for f in findings:
f.score = score(f, source_ok)
return findings