Профиль персоны и связь «вместе снимались»
GET /coworkers отдаёт партнёров по фильмам (актёры, режиссёры, композиторы) с числом совместных работ. Страница /person.html показывает фильмографию и партнёров со ссылками. В графе при клике на персону — ссылка на профиль. Проверено: Zendaya → Denis Villeneuve, Hans Zimmer, Javier Bardem (по Dune: Part Two).
This commit is contained in:
1 parent
f6cb5c76a6
commit
d816841e92
3 files changed
+154
-1
No files matched your search
@@ -832,6 +832,42 @@ def do_candidates(limit=20):
|
||||
return {"count": len(items), "items": items}
|
||||
|
||||
|
||||
|
||||
|
||||
def do_coworkers(query, limit=12):
|
||||
"""С кем вместе снимался: партнёры по фильмам."""
|
||||
con = db()
|
||||
cur = con.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
|
||||
cur.execute("""select id, title from entities
|
||||
where kind in ('актёр','режиссёр','композитор') and search_text like %s
|
||||
order by length(title) limit 1""", (f"%{query.lower()}%",))
|
||||
person = cur.fetchone()
|
||||
if not person:
|
||||
con.close()
|
||||
return None
|
||||
|
||||
cur.execute("""
|
||||
with films as (
|
||||
select case when l.from_id = %s then l.to_id else l.from_id end as fid
|
||||
from entity_links l
|
||||
where (l.from_id = %s or l.to_id = %s)
|
||||
)
|
||||
select p.id, p.title, p.kind, count(*) as together,
|
||||
string_agg(f.title, ', ' order by f.title) as films
|
||||
from films x
|
||||
join entity_links l on (l.from_id = x.fid)
|
||||
join entities p on p.id = l.to_id and p.kind in ('актёр','режиссёр','композитор')
|
||||
join entities f on f.id = x.fid
|
||||
where l.relation in ('снялся','снял','музыка') and p.id <> %s
|
||||
group by p.id, p.title, p.kind
|
||||
order by together desc, p.title
|
||||
limit %s
|
||||
""", (person["id"], person["id"], person["id"], person["id"], limit))
|
||||
partners = [dict(r) for r in cur.fetchall()]
|
||||
con.close()
|
||||
return {"person": dict(person), "partners": partners}
|
||||
|
||||
|
||||
def render_panel():
|
||||
"""HTML-страница: состояние системы в одном месте."""
|
||||
try:
|
||||
@@ -1204,6 +1240,29 @@ class Handler(BaseHTTPRequestHandler):
|
||||
return self._json(200, do_graph_stats())
|
||||
except Exception as e:
|
||||
return self._json(500, {"error": str(e)[:200]})
|
||||
if self.path.startswith("/person.html"):
|
||||
try:
|
||||
with open("/opt/hub-core/person.html", encoding="utf-8") as f:
|
||||
body = f.read().encode("utf-8")
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "text/html; charset=utf-8")
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
return
|
||||
except Exception as e:
|
||||
return self._json(500, {"error": str(e)[:200]})
|
||||
if self.path.startswith("/coworkers"):
|
||||
import urllib.parse as _ucw
|
||||
qs = _ucw.parse_qs(self.path.split("?")[1]) if "?" in self.path else {}
|
||||
q = (qs.get("q") or [""])[0]
|
||||
if not q:
|
||||
return self._json(400, {"error": "нужен q"})
|
||||
try:
|
||||
data = do_coworkers(q)
|
||||
except Exception as e:
|
||||
return self._json(500, {"error": str(e)[:200]})
|
||||
return self._json(200 if data else 404, data or {"error": "не найдено"})
|
||||
if self.path.startswith("/candidates"):
|
||||
import urllib.parse as _ucd
|
||||
qs = _ucd.parse_qs(self.path.split("?")[1]) if "?" in self.path else {}
|
||||
|
||||
@@ -198,8 +198,11 @@ c.addEventListener("click", e=>{
|
||||
const other = byId[x.s===n.id ? x.t : x.s];
|
||||
return `<li>${x.r}: <b>${other?other.title:""}</b></li>`;
|
||||
}).join("");
|
||||
const profile = ["актёр","режиссёр","композитор"].includes(n.kind)
|
||||
? `<div style="margin-top:10px"><a style="color:#58a6ff" href="person.html?name=${encodeURIComponent(n.title)}">профиль и связи →</a></div>`
|
||||
: "";
|
||||
info.innerHTML = `<b>${n.title}</b><br><span style="color:#8b949e">${n.kind} · связей ${n.degree}</span>
|
||||
<ul>${rels}</ul>`;
|
||||
<ul>${rels}</ul>${profile}`;
|
||||
info.style.display="block";
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Персона — Buryans Hub</title>
|
||||
<style>
|
||||
:root { --bg:#0d1117; --fg:#c9d1d9; --dim:#8b949e; --line:#30363d; --acc:#58a6ff; }
|
||||
* { box-sizing: border-box; }
|
||||
body { margin:0; background:var(--bg); color:var(--fg);
|
||||
font:15px/1.6 -apple-system,"Segoe UI",Roboto,sans-serif; }
|
||||
.wrap { max-width:900px; margin:0 auto; padding:28px 20px 60px; }
|
||||
h1 { font-size:22px; margin:0 0 4px; }
|
||||
.sub { color:var(--dim); font-size:13px; margin-bottom:20px; }
|
||||
form { display:flex; gap:8px; margin-bottom:22px; }
|
||||
input { flex:1; background:#161b22; border:1px solid var(--line); color:var(--fg);
|
||||
border-radius:8px; padding:10px 12px; outline:none; }
|
||||
input:focus { border-color:var(--acc); }
|
||||
button { background:var(--acc); color:#0d1117; border:0; border-radius:8px;
|
||||
padding:10px 16px; font-weight:600; cursor:pointer; }
|
||||
.grid { display:grid; grid-template-columns:1fr 1fr; gap:16px; }
|
||||
.card { background:#161b22; border:1px solid var(--line); border-radius:10px; padding:14px 16px; }
|
||||
.card h3 { margin:0 0 10px; font-size:13px; color:var(--dim); font-weight:600;
|
||||
text-transform:uppercase; letter-spacing:.04em; }
|
||||
ul { margin:0; padding-left:18px; }
|
||||
li { margin:4px 0; }
|
||||
.muted { color:var(--dim); font-size:13px; }
|
||||
a { color:var(--acc); text-decoration:none; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrap">
|
||||
<h1 id="title">Персона</h1>
|
||||
<div class="sub" id="sub"></div>
|
||||
<form id="f">
|
||||
<input id="q" placeholder="Имя: Zendaya, Nolan, Hans Zimmer" autofocus>
|
||||
<button>Показать</button>
|
||||
</form>
|
||||
<div class="grid">
|
||||
<div class="card"><h3>Фильмография</h3><ul id="films"><li class="muted">—</li></ul></div>
|
||||
<div class="card"><h3>Вместе снимались</h3><ul id="partners"><li class="muted">—</li></ul></div>
|
||||
</div>
|
||||
<p class="muted" style="margin-top:22px">
|
||||
<a href="graph.html">граф</a> · <a href="ask.html">спросить агента</a> · <a href="./">панель</a>
|
||||
</p>
|
||||
</div>
|
||||
<script>
|
||||
const params = new URLSearchParams(location.search);
|
||||
const name = params.get("name") || "";
|
||||
const $ = id => document.getElementById(id);
|
||||
|
||||
document.getElementById("f").addEventListener("submit", e => {
|
||||
e.preventDefault();
|
||||
const q = $("q").value.trim();
|
||||
if (q) location.search = "?name=" + encodeURIComponent(q);
|
||||
});
|
||||
|
||||
async function load(person){
|
||||
$("title").textContent = person;
|
||||
$("q").value = person;
|
||||
$("films").innerHTML = '<li class="muted">загрузка…</li>';
|
||||
$("partners").innerHTML = '<li class="muted">загрузка…</li>';
|
||||
try {
|
||||
const [p, c] = await Promise.all([
|
||||
fetch("person?q=" + encodeURIComponent(person)).then(r => r.json()),
|
||||
fetch("coworkers?q=" + encodeURIComponent(person)).then(r => r.json())
|
||||
]);
|
||||
if (p.error) throw new Error(p.error);
|
||||
const films = (p.films || []);
|
||||
$("sub").textContent = (p.person ? p.person.kind : "") + " · фильмов: " + films.length;
|
||||
$("films").innerHTML = films.length
|
||||
? films.map(f => "<li>" + esc(f.title) + "</li>").join("")
|
||||
: '<li class="muted">ничего не найдено</li>';
|
||||
const partners = (c.partners || []);
|
||||
$("partners").innerHTML = partners.length
|
||||
? partners.map(x => "<li><a href='?name=" + encodeURIComponent(x.title) + "'>" +
|
||||
esc(x.title) + "</a> — " + x.together + " <span class='muted'>" +
|
||||
esc((x.films || "").slice(0, 60)) + "</span></li>").join("")
|
||||
: '<li class="muted">нет общих фильмов</li>';
|
||||
} catch (e) {
|
||||
$("sub").textContent = "не найдено";
|
||||
$("films").innerHTML = '<li class="muted">' + esc(String(e)) + "</li>";
|
||||
$("partners").innerHTML = '<li class="muted">—</li>';
|
||||
}
|
||||
}
|
||||
function esc(s){ return String(s).replace(/[&<>]/g, c => ({"&":"&","<":"<",">":">"}[c])); }
|
||||
|
||||
if (name) load(name);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user