students: modal for student face refs and found/similar photos

Кнопка "Лица" в строке ученика открывает #studentFacesModal: эталонные
фото, фото, где лицо ученика уже найдено, и похожие непривязанные лица.
Эталоны переехали из #profileDataModal — id элементов должны быть в
документе ровно один раз.

Поиск похожих личностей переведён с перебора эмбеддингов на хранение
кандидата в БД: photo_faces.best_student_id + best_score заполняются при
скане и при пересчёте, у привязанных лиц обнуляются. Частичный индекс
WHERE student_id IS NULL - без него запрос поднимал бы все эмбеддинги.

Также:
- пересчёт по всем фото теперь запускается и при удалении эталона,
  иначе кандидаты устаревают
- иконки в панели действий карточки фото и в бейдже лиц - lucide
- бейдж лиц прижат вправо, панель действий прижата к низу карточки
This commit is contained in:
dev
2026-10-10 12:50:29 +03:00
parent 0356fd4e02
commit 60e701d1d3
9 changed files with 238 additions and 77 deletions
+15 -13
View File
@@ -1,4 +1,7 @@
const DAYS = ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'];
const FACE_CANDIDATE_MIN = 0.5;
const facePct = v => Math.round((Number(v) || 0) * 100) + '%';
const faceCandidateMin = () => (Number(faceViewer.candidateMin) > 0 ? Number(faceViewer.candidateMin) : FACE_CANDIDATE_MIN);
let branchesCache = [];
let tutorsCache = [];
let allGroups = [];
@@ -163,6 +166,7 @@ async function loadGroupPhotos() {
document.getElementById('photoGrid').innerHTML = photos.length
? photos.map(photoHTML).join('')
: '<div class="empty" style="grid-column:1/-1">Фото пока нет. Загрузите первое фото.</div>';
renderIcons();
renderPager(document.getElementById('photosPager'), photoPage, Math.max(1, Math.ceil(totalPhotos / PHOTO_PAGE_SIZE)), goPhotoPage);
}
@@ -170,7 +174,7 @@ function goPhotoPage(p) { photoPage = p; loadGroupPhotos(); }
let allStudents = [];
let allStudentsLoaded = false;
let faceViewer = { photoId: null, faces: [], sourceType: 'group', layout: null };
let faceViewer = { photoId: null, faces: [], sourceType: 'group', layout: null, candidateMin: FACE_CANDIDATE_MIN };
let faceAssignFaceId = null;
async function loadAllStudents() {
@@ -222,15 +226,13 @@ async function openFaceViewer(photoId) {
}
const data = await res.json();
faceViewer.faces = data.faces || [];
faceViewer.candidateMin = Number(data.candidate_min) > 0 ? Number(data.candidate_min) : FACE_CANDIDATE_MIN;
renderFaceViewer(photo.photo_path);
} catch {
body.innerHTML = '<div class="empty">Не удалось загрузить лица</div>';
}
}
const FACE_CANDIDATE_MIN = 0.5;
const facePct = v => Math.round((Number(v) || 0) * 100) + '%';
function faceBoxesHTML(nw, nh) {
if (!nw || !nh) return '';
return faceViewer.faces.map(f => {
@@ -241,7 +243,7 @@ function faceBoxesHTML(nw, nh) {
cls = 'face-box face-box--matched';
const name = f.student_name || 'Ученик';
label = f.manual ? name + ' · вручную' : name + ' · ' + facePct(f.confidence);
} else if (f.best_student_id && f.best_score >= FACE_CANDIDATE_MIN) {
} else if (f.best_student_id && f.best_score >= faceCandidateMin()) {
cls = 'face-box face-box--candidate';
label = 'Похож: ' + (f.best_student_name || 'ученик') + ' · ' + facePct(f.best_score);
}
@@ -284,7 +286,7 @@ function renderFaceViewer(photoPath) {
function closeFaceViewer() {
if (faceViewer.layout) window.removeEventListener('resize', faceViewer.layout);
document.getElementById('faceViewerModal').classList.remove('open');
faceViewer = { photoId: null, faces: [], sourceType: 'group', layout: null };
faceViewer = { photoId: null, faces: [], sourceType: 'group', layout: null, candidateMin: FACE_CANDIDATE_MIN };
}
async function openFaceAssign(faceId) {
@@ -292,7 +294,7 @@ async function openFaceAssign(faceId) {
faceAssignFaceId = faceId;
const face = faceViewer.faces.find(f => String(f.id) === String(faceId));
const inp = document.getElementById('faceAssignSearch');
inp.value = face && !face.student_id && face.best_student_id && face.best_score >= FACE_CANDIDATE_MIN
inp.value = face && !face.student_id && face.best_student_id && face.best_score >= faceCandidateMin()
? (face.best_student_name || '')
: '';
renderFaceAssignList(inp.value);
@@ -388,7 +390,7 @@ function photoHTML(p) {
const faces = p.face_count || 0;
const unassigned = p.face_unassigned || 0;
const faceBadge = faces
? `<span class="p-faces${unassigned ? ' unassigned' : ''}" data-faces-photo="${p.id}" title="Распознанных лиц: ${faces}${unassigned ? `, не опознано: ${unassigned}` : ''}">👤 ${faces}${unassigned ? ` (${unassigned})` : ''}</span>`
? `<span class="p-faces${unassigned ? ' unassigned' : ''}" data-faces-photo="${p.id}" title="Распознанных лиц: ${faces}${unassigned ? `, не опознано: ${unassigned}` : ''}"><i data-lucide="scan-face"></i> ${faces}${unassigned ? ` (${unassigned})` : ''}</span>`
: '';
return `
<div class="photo-item" data-photo-id="${p.id}" data-photo-path="${esc(p.photo_path)}" draggable="true">
@@ -398,11 +400,11 @@ function photoHTML(p) {
<div class="p-cap">${esc(p.caption || '')}</div>
<div class="p-date">${taken ? taken + ' · ' : ''}${uploaded}</div>
<div class="p-actions">
<button class="p-cover${isCover ? ' active' : ''}" data-photo-id="${p.id}" data-photo-path="${esc(p.photo_path)}" title="${isCover ? 'Текущая обложка' : 'Сделать обложкой'}" ${isCover ? 'disabled' : ''}>🖼️</button>
<button class="p-edit" data-edit-photo="${p.id}" title="Редактировать">✎</button>
<button class="p-faces-btn" data-faces-photo="${p.id}" title="Лица на фото">👤</button>
<button class="p-enhance" data-enhance-photo="${p.id}" title="Улучшить фото">✨</button>
<button class="p-del" data-del-photo="${p.id}" title="Удалить">&times;</button>
<button class="p-cover${isCover ? ' active' : ''}" data-photo-id="${p.id}" data-photo-path="${esc(p.photo_path)}" title="${isCover ? 'Текущая обложка' : 'Сделать обложкой'}" ${isCover ? 'disabled' : ''}><i data-lucide="image"></i></button>
<button class="p-edit" data-edit-photo="${p.id}" title="Редактировать"><i data-lucide="pencil"></i></button>
<button class="p-faces-btn" data-faces-photo="${p.id}" title="Лица на фото"><i data-lucide="scan-face"></i></button>
<button class="p-enhance" data-enhance-photo="${p.id}" title="Улучшить фото"><i data-lucide="sparkles"></i></button>
<button class="p-del" data-del-photo="${p.id}" title="Удалить"><i data-lucide="trash-2"></i></button>
</div>
</div>
`;