fix(assessment): add the missing result summary and format imports
This commit is contained in:
1 parent
5c52fd8b91
commit
6bfd7098c3
3 files changed
+144
-1
No files matched your search
@@ -1,8 +1,8 @@
|
|||||||
package assessment
|
package assessment
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/hmac"
|
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/hmac"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import type { AssessmentResult } from "../../../shared/api/schemas";
|
||||||
|
import { assessmentResultSummary } from "./result-summary";
|
||||||
|
|
||||||
|
const base = {
|
||||||
|
attempt_id: "0199b4f2-7c1e-7d3a-9f00-aabbccddeeff",
|
||||||
|
specialization: "backend",
|
||||||
|
target_grade: "middle",
|
||||||
|
root_attempt_id: null,
|
||||||
|
chain_deadline: null,
|
||||||
|
task_language: "go",
|
||||||
|
kind: "root",
|
||||||
|
mode: "demo_basic",
|
||||||
|
not_determined_reason: null,
|
||||||
|
confirmed_grade: null,
|
||||||
|
previous_confirmed_grade: null,
|
||||||
|
strength: null,
|
||||||
|
calibration_status: "uncalibrated",
|
||||||
|
limitations: [],
|
||||||
|
uncertainty: null,
|
||||||
|
basic_score: null,
|
||||||
|
practices: [],
|
||||||
|
gaps: [],
|
||||||
|
durations: { items_seconds: 60, practice_seconds: null },
|
||||||
|
next_steps: [],
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
function result(patch: Record<string, unknown>): AssessmentResult {
|
||||||
|
return { ...base, ...patch } as unknown as AssessmentResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("assessmentResultSummary", () => {
|
||||||
|
it("restates a confirmed grade without deriving one", () => {
|
||||||
|
const summary = assessmentResultSummary(
|
||||||
|
result({ outcome: "confirmed", confirmed_grade: "middle" }),
|
||||||
|
);
|
||||||
|
expect(summary.text).toBe("Уровень подтвержден: Backend, Middle.");
|
||||||
|
expect(summary.reason).toBeNull();
|
||||||
|
expect(summary.isDemonstration).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps the previous grade when nothing was confirmed", () => {
|
||||||
|
const summary = assessmentResultSummary(
|
||||||
|
result({ outcome: "not_confirmed", previous_confirmed_grade: "junior" }),
|
||||||
|
);
|
||||||
|
expect(summary.text).toBe("Уровень пока не подтвержден: Backend, Middle.");
|
||||||
|
expect(summary.reason).toBe("Прежний подтвержденный уровень Junior сохраняется.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("explains why no decision was made", () => {
|
||||||
|
const summary = assessmentResultSummary(
|
||||||
|
result({ outcome: "not_determined", not_determined_reason: "expired" }),
|
||||||
|
);
|
||||||
|
expect(summary.text).toBe("Результат не определен: Backend, Middle.");
|
||||||
|
expect(summary.reason).toBe("Время попытки истекло до завершения заданий.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("marks express training as a demonstration", () => {
|
||||||
|
const summary = assessmentResultSummary(
|
||||||
|
result({
|
||||||
|
kind: "demo_express",
|
||||||
|
mode: "demo_express",
|
||||||
|
specialization: null,
|
||||||
|
target_grade: null,
|
||||||
|
task_language: null,
|
||||||
|
outcome: "demonstration",
|
||||||
|
limitations: ["demonstration_only"],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(summary.isDemonstration).toBe(true);
|
||||||
|
expect(summary.reason).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
import type { AssessmentResult } from "../../../shared/api/schemas";
|
||||||
|
import { gradeLabels, outcomeLabels, specializationLabels } from "./labels";
|
||||||
|
|
||||||
|
export type AssessmentResultSummary = {
|
||||||
|
/** One sentence with the decision of the attempt as the server recorded it. */
|
||||||
|
readonly text: string;
|
||||||
|
/** Why no decision was made, or what stays in force; null when nothing to add. */
|
||||||
|
readonly reason: string | null;
|
||||||
|
/** True for training results that never confirm a grade. */
|
||||||
|
readonly isDemonstration: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
type NotDeterminedReason = NonNullable<
|
||||||
|
Exclude<AssessmentResult, { kind: "demo_express" }>["not_determined_reason"]
|
||||||
|
>;
|
||||||
|
|
||||||
|
const notDeterminedReasons: Readonly<Record<NotDeterminedReason, string>> = {
|
||||||
|
expired: "Время попытки истекло до завершения заданий.",
|
||||||
|
practice_incomplete: "Практическое задание не было отправлено до окончания срока.",
|
||||||
|
insufficient_bank: "Банк заданий не смог обеспечить нужное покрытие.",
|
||||||
|
sandbox_unavailable: "Проверка практического решения была недоступна по технической причине.",
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the text shown for a finished attempt. It only restates fields of
|
||||||
|
* the server result and never derives a grade on its own.
|
||||||
|
*/
|
||||||
|
export function assessmentResultSummary(result: AssessmentResult): AssessmentResultSummary {
|
||||||
|
if (result.kind === "demo_express") {
|
||||||
|
return {
|
||||||
|
text: "Демонстрационный экспресс-запуск завершен.",
|
||||||
|
reason: null,
|
||||||
|
isDemonstration: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const isDemonstration = false;
|
||||||
|
|
||||||
|
const specialization = specializationLabels[result.specialization];
|
||||||
|
const keptGrade = result.previous_confirmed_grade
|
||||||
|
? `Прежний подтвержденный уровень ${gradeLabels[result.previous_confirmed_grade]} сохраняется.`
|
||||||
|
: null;
|
||||||
|
|
||||||
|
switch (result.outcome) {
|
||||||
|
case "confirmed": {
|
||||||
|
const grade = result.confirmed_grade ?? result.target_grade;
|
||||||
|
return {
|
||||||
|
text: `${outcomeLabels.confirmed}: ${specialization}, ${gradeLabels[grade]}.`,
|
||||||
|
reason: null,
|
||||||
|
isDemonstration,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
case "not_confirmed":
|
||||||
|
return {
|
||||||
|
text: `${outcomeLabels.not_confirmed}: ${specialization}, ${gradeLabels[result.target_grade]}.`,
|
||||||
|
reason: keptGrade,
|
||||||
|
isDemonstration,
|
||||||
|
};
|
||||||
|
case "not_determined": {
|
||||||
|
const why = result.not_determined_reason
|
||||||
|
? notDeterminedReasons[result.not_determined_reason]
|
||||||
|
: null;
|
||||||
|
return {
|
||||||
|
text: `${outcomeLabels.not_determined}: ${specialization}, ${gradeLabels[result.target_grade]}.`,
|
||||||
|
reason: [why, keptGrade].filter(Boolean).join(" ") || null,
|
||||||
|
isDemonstration,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user