61 lines
3.4 KiB
TypeScript
61 lines
3.4 KiB
TypeScript
import { BLOCK_TITLES, QUESTIONS, WEIGHTS, type BlockId, type Position, type Question } from "./questions.ts";
|
||
|
||
export const BLOCKS: readonly BlockId[] = ["numerals", "literacy", "stress"];
|
||
export const ATTENTION_BELOW = 40;
|
||
export const BANDS = [
|
||
{ min: 75, code: "recommended", label: "Рекомендуется к следующему этапу" },
|
||
{ min: 50, code: "consider", label: "Рассмотреть: нужно интервью" },
|
||
{ min: 0, code: "more_assessment", label: "Нужна дополнительная оценка" },
|
||
] as const;
|
||
export type Recommendation = (typeof BANDS)[number]["code"];
|
||
|
||
export interface HrResult {
|
||
blocks: Record<BlockId, number>;
|
||
total: number;
|
||
recommendation: Recommendation;
|
||
attention: BlockId[];
|
||
/** Баллы по каждому вопросу и выбранный вариант — для разбора в отчёте. */
|
||
items: { id: string; chosen: string; points: number; max: number }[];
|
||
}
|
||
|
||
const maxPoints = (q: Question) => Math.max(...q.options.map((o) => o.points));
|
||
|
||
/** answers: id вопроса → текст выбранного варианта. null — ответы не покрывают вопросы или содержат лишнее. */
|
||
export function score(position: Position, answers: unknown): HrResult | null {
|
||
if (typeof answers !== "object" || answers === null || Array.isArray(answers)) return null;
|
||
const a = answers as Record<string, unknown>;
|
||
if (Object.keys(a).length !== QUESTIONS.length) return null;
|
||
const got: Record<BlockId, number> = { numerals: 0, literacy: 0, stress: 0 };
|
||
const max: Record<BlockId, number> = { numerals: 0, literacy: 0, stress: 0 };
|
||
const items: HrResult["items"] = [];
|
||
for (const q of QUESTIONS) {
|
||
const chosen = a[q.id];
|
||
const opt = typeof chosen === "string" ? q.options.find((o) => o.text === chosen) : undefined;
|
||
if (!opt) return null;
|
||
got[q.block] += opt.points;
|
||
max[q.block] += maxPoints(q);
|
||
items.push({ id: q.id, chosen: opt.text, points: opt.points, max: maxPoints(q) });
|
||
}
|
||
const blocks = { numerals: 0, literacy: 0, stress: 0 } as Record<BlockId, number>;
|
||
let total = 0;
|
||
for (const b of BLOCKS) {
|
||
blocks[b] = Math.round((got[b] / max[b]) * 100);
|
||
total += (got[b] / max[b]) * 100 * WEIGHTS[position][b];
|
||
}
|
||
total = Math.round(total);
|
||
const recommendation = (BANDS.find((b) => total >= b.min) ?? BANDS[2]).code;
|
||
return { blocks, total, recommendation, attention: BLOCKS.filter((b) => blocks[b] < ATTENTION_BELOW), items };
|
||
}
|
||
|
||
export function methodology() {
|
||
return {
|
||
note: "Результат — рекомендация для специалиста по подбору, а не решение об отказе. Решение всегда принимает человек.",
|
||
scoring: "Каждый вопрос — выбор одного варианта, у каждого варианта фиксированные баллы. Балл блока = набранные баллы / максимум × 100. Итог = взвешенная сумма блоков. LLM не используется, оценка воспроизводима.",
|
||
blocks: BLOCKS.map((id) => ({ id, title: BLOCK_TITLES[id], questions: QUESTIONS.filter((q) => q.block === id).length })),
|
||
weights: WEIGHTS,
|
||
bands: BANDS.map((b) => ({ from: b.min, code: b.code, label: b.label })),
|
||
attentionBelow: ATTENTION_BELOW,
|
||
timeLimitMinutes: 30,
|
||
};
|
||
}
|