@eliceio/cdk-cli 1.4.1 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -16
- package/es/cli.js +1 -1
- package/es/commands/create/index.js +1 -0
- package/es/commands/create/scaffold.d.ts +1 -1
- package/es/commands/create/scaffold.js +1 -1
- package/es/core/config.d.ts +36 -0
- package/es/core/config.js +234 -6
- package/es/core/quiz-check.js +123 -4
- package/es/dev/grading.d.ts +26 -4
- package/es/dev/grading.js +66 -11
- package/es/dev/mock-api.d.ts +6 -1
- package/es/dev/mock-api.js +45 -6
- package/es/rules/answers.d.ts +1 -0
- package/es/rules/answers.js +8 -0
- package/es/rules.json.js +1 -1
- package/package.json +2 -2
- package/rules.json +1 -1
- package/skills/_shared/always.md +1 -1
- package/skills/_shared/references/02-design-the-material.md +8 -7
- package/skills/_shared/references/03-create-the-project.md +10 -9
- package/skills/_shared/references/12-upload-with-the-material-mcp.md +5 -5
- package/skills/_shared/references/16-using-the-survey-template.md +158 -0
- package/skills/elice-content-create/SKILL.md +2 -2
- package/skills/elice-content-edit/SKILL.md +2 -2
- package/skills/elice-content-publish/SKILL.md +1 -1
- package/templates/_shared/lib/cdk-mock.d.ts +22 -3
- package/templates/_shared/lib/cdk-mock.js +78 -11
- package/templates/_shared/lib/elice-content.d.ts +17 -1
- package/templates/_shared/lib/elice-content.js +47 -5
- package/templates/blank/template.json +1 -1
- package/templates/document/template.json +2 -2
- package/templates/quiz/README.md +26 -1
- package/templates/quiz/core/behaviors.d.ts +5 -0
- package/templates/quiz/core/behaviors.js +16 -1
- package/templates/quiz/core/model.d.ts +78 -1
- package/templates/quiz/core/model.js +219 -4
- package/templates/quiz/screens/edit.js +244 -55
- package/templates/quiz/screens/learn.js +137 -27
- package/templates/quiz/styles.css +258 -5
- package/templates/quiz/template.json +1 -1
- package/templates/quiz/ui/templates/edit.d.ts +1 -0
- package/templates/quiz/ui/templates/edit.js +67 -8
- package/templates/quiz/ui/templates/page.js +34 -0
- package/templates/quiz/ui/templates/text.js +15 -2
- package/templates/quiz/ui/texts.js +61 -0
- package/templates/steps/template.json +1 -1
- package/templates/survey/README.md +112 -0
- package/templates/survey/commentary.txt +2 -0
- package/templates/survey/core/behaviors.d.ts +14 -0
- package/templates/survey/core/behaviors.js +115 -0
- package/templates/survey/core/dom.d.ts +13 -0
- package/templates/survey/core/dom.js +83 -0
- package/templates/survey/core/editor.d.ts +80 -0
- package/templates/survey/core/editor.js +720 -0
- package/templates/survey/core/markdown.d.ts +21 -0
- package/templates/survey/core/markdown.js +298 -0
- package/templates/survey/core/model.d.ts +83 -0
- package/templates/survey/core/model.js +209 -0
- package/templates/survey/core/rich-text.d.ts +18 -0
- package/templates/survey/core/rich-text.js +469 -0
- package/templates/survey/edit.html +26 -0
- package/templates/survey/gitignore +4 -0
- package/templates/survey/index.html +26 -0
- package/templates/survey/metadata.json +9 -0
- package/templates/survey/package.json +13 -0
- package/templates/survey/screens/edit.js +345 -0
- package/templates/survey/screens/learn.js +100 -0
- package/templates/survey/styles.css +1264 -0
- package/templates/survey/template.json +12 -0
- package/templates/survey/ui/templates/edit.d.ts +27 -0
- package/templates/survey/ui/templates/edit.js +656 -0
- package/templates/survey/ui/templates/index.d.ts +3 -0
- package/templates/survey/ui/templates/index.js +3 -0
- package/templates/survey/ui/templates/learn.js +147 -0
- package/templates/survey/ui/templates/page.js +19 -0
- package/templates/survey/ui/texts.d.ts +3 -0
- package/templates/survey/ui/texts.js +116 -0
- package/templates/survey/ui/theme.css +42 -0
- package/templates/video/template.json +1 -1
|
@@ -9,12 +9,19 @@
|
|
|
9
9
|
// - 2 (1.10.0부터 편집 화면이 저장): 원문, `%` → `%25` · `;` → `%3B`만 바꿈 "q1=b;q2=a,d;q4=가중치"
|
|
10
10
|
// - 없음 (1.9.x 이하가 저장한 자료): encodeURIComponent "q4=%EA%B0%80%EC%A4%91%EC%B9%98"
|
|
11
11
|
// 어느 쪽이든 decodeURIComponent 하나로 원래 답이 된다. 정답 정규식(grading)도 같은 형식으로 만들어 둘이 늘 짝이 맞는다
|
|
12
|
-
// 주관식 문항의 공개 값 answerMode: 'list'(허용 답 목록, 기본) · 'regex'(작성자 정규식). 다시 열 때 정답 입력 방식을 되살린다
|
|
12
|
+
// 주관식 문항의 공개 값 answerMode: 'list'(허용 답 목록, 기본) · 'regex'(작성자 정규식) · 'rubric'(AI 채점, 1.11.0). 다시 열 때 정답 입력 방식을 되살린다
|
|
13
13
|
// 채점 방식은 둘 중 하나 (작성자가 고름, 완료 정책은 LXP 설정, ADR 0012). 정답(settings.grading)은 편집 화면이 문항마다 고른 답으로 만든다.
|
|
14
14
|
// - pattern (기본, 모두 맞혀야 100점): 정규식 하나 { type: 'pattern', answer_key: '^q1=b;…$' }, 답은 위 문자열 하나
|
|
15
15
|
// - partial_pattern (문항별 부분 점수): 문항마다 정규식 { type: 'partial_pattern', answer_key: ['^q1=b$', …], scores: [50, …] },
|
|
16
16
|
// 답은 문항 순서대로 문자열 배열 ["q1=b", "q2=a,d", …] (한 항목의 모양은 pattern 답 · 정답의 한 조각과 같음).
|
|
17
17
|
// 학생 화면은 grading을 받지 못하므로 settings에 공개 값 gradingType: 'partial_pattern'을 같이 둔다 (없으면 pattern)
|
|
18
|
+
// - per_question (1.11.0, 서버 elice-material #65 · AI 채점 문항이 하나라도 있을 때): 문항마다 배점과 채점기
|
|
19
|
+
// { type: 'per_question', questions: [{ score: 30, grader: { type: 'pattern', answer_key: '^q1=b$' } },
|
|
20
|
+
// { score: 70, grader: { type: 'rubric', rubric: '…', question: '문제 글' } }], pass_score: 60 }.
|
|
21
|
+
// questions 순서 = 답 배열 순서 = 문항 순서. 답은 partial_pattern처럼 문자열 배열이고, AI 채점 문항 자리에는 `문항id=` 없이 그 문항의 답 글만.
|
|
22
|
+
// 서버는 AI 점수(0~100) × 배점 / 100을 내림, 합은 100에서 자르고 100점일 때만 정답, 합이 pass_score 이상이면 완료.
|
|
23
|
+
// 공개 값 gradingType: 'per_question' · passScore(학생 화면의 "통과" 표시) · answerFormat 3 · requires { quiz: '1.11.0' }.
|
|
24
|
+
// AI 채점 문항이 없으면 pattern · partial_pattern을 예전 그대로 저장한다
|
|
18
25
|
|
|
19
26
|
// 화면에 보이는 문구는 여기 두지 않습니다 (ui/texts.js). 문구가 필요한 함수는 화면(screens/)이 문구를 넘겨 줍니다.
|
|
20
27
|
|
|
@@ -31,12 +38,16 @@ export const LIMITS = {
|
|
|
31
38
|
// 편집 화면에서 올린 그림 (지문 · 해설): 퀴즈 전체에 50개까지. 그림은 서버 파일로 올리고 글에는 파일 키(약 90자)만 두어
|
|
32
39
|
// settings(서버 한도 약 64KB)에는 50개를 넣어도 약 5KB
|
|
33
40
|
imagesMax: 50,
|
|
41
|
+
// AI 채점 문항의 채점 기준(rubric) 글자 수 (서버 rubric 한도와 같게, 문항마다)
|
|
42
|
+
rubricMax: 10000,
|
|
34
43
|
};
|
|
35
44
|
|
|
36
45
|
/** 편집 화면에서 문항을 더 넣을 수 있는지. 이미 여러 문항으로 저장된 퀴즈도 그대로 보이고 저장되며, 더 넣는 것만 막는다 */
|
|
37
46
|
export const canAddQuestion = (questions) => (questions?.length ?? 0) < LIMITS.questionsMax;
|
|
38
47
|
|
|
39
48
|
const hasOptions = (type) => type !== 'text';
|
|
49
|
+
/** 주관식 정답 입력 방식 (공개 값 answerMode) */
|
|
50
|
+
const ANSWER_MODES = ['list', 'regex', 'rubric'];
|
|
40
51
|
|
|
41
52
|
/** 보기·그룹 id는 답 문자열에 그대로 들어가므로 영문 소문자·숫자만 (구분자 , | : 를 쓰지 않음) */
|
|
42
53
|
export function nextId(used, prefix = '') {
|
|
@@ -96,7 +107,7 @@ export function convertType(q, type, names) {
|
|
|
96
107
|
if (type === 'text') {
|
|
97
108
|
next.placeholder = q.placeholder ?? '';
|
|
98
109
|
// 정답 입력 방식 (공개 값, ADR 0013): 직접 입력이 기본
|
|
99
|
-
next.answerMode = q.answerMode
|
|
110
|
+
next.answerMode = ANSWER_MODES.includes(q.answerMode) ? q.answerMode : 'list';
|
|
100
111
|
} else {
|
|
101
112
|
delete next.placeholder;
|
|
102
113
|
delete next.answerMode;
|
|
@@ -130,7 +141,7 @@ export function validateQuiz(content, v) {
|
|
|
130
141
|
if (q.explanation?.enabled && !q.explanation.text?.trim()) return at(v.explanation);
|
|
131
142
|
}
|
|
132
143
|
// 부분 채점(문제 2개 이상): 문제별 배점은 0~100 정수, 합은 100 이상 (100보다 작으면 다 맞혀도 완료되지 않음)
|
|
133
|
-
if (content.gradingType === PARTIAL && content.questions.length > 1) {
|
|
144
|
+
if ((content.gradingType === PARTIAL || isPerQuestionType(content.gradingType)) && content.questions.length > 1) {
|
|
134
145
|
const bad = content.questions.findIndex(
|
|
135
146
|
(q) => !Number.isInteger(q.points) || q.points < 0 || q.points > 100,
|
|
136
147
|
);
|
|
@@ -249,6 +260,8 @@ export function joinAnswers(questions, values, format = 1) {
|
|
|
249
260
|
* `;`로 나누고 첫 `=`에서 문항 id와 답을 나눈 뒤, 주관식은 decodeURIComponent (답 형식 1 · 2 모두 이것 하나로 풀림)
|
|
250
261
|
*/
|
|
251
262
|
export function splitAnswers(questions, answer) {
|
|
263
|
+
// per_question 답 (AI 채점 문항이 있음): AI 채점 문항 자리는 `문항id=` 없이 답 글 그대로라 자리(문항 순서)로 푼다
|
|
264
|
+
if (Array.isArray(answer) && questions.some(isRubricMode)) return splitQuestionAnswers(questions, answer);
|
|
252
265
|
// partial_pattern 답: 문항별 문자열 배열 → 한 문자열로 이어 같은 방식으로 푼다
|
|
253
266
|
if (Array.isArray(answer))
|
|
254
267
|
return splitAnswers(questions, answer.filter((a) => typeof a === 'string').join(';'));
|
|
@@ -278,8 +291,10 @@ export function splitAnswers(questions, answer) {
|
|
|
278
291
|
const escapeRegex = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
279
292
|
const unescapeRegex = (text) => text.replace(/\\(.)/g, '$1');
|
|
280
293
|
|
|
281
|
-
/** 주관식 정답 입력 방식: 'list'(허용 답 목록, 기본) · 'regex'(작성자 정규식) */
|
|
294
|
+
/** 주관식 정답 입력 방식: 'list'(허용 답 목록, 기본) · 'regex'(작성자 정규식) · 'rubric'(AI 채점) */
|
|
282
295
|
export const isRegexMode = (q) => q?.type === 'text' && q.answerMode === 'regex';
|
|
296
|
+
/** AI 채점(채점 기준으로 AI가 점수를 매김) 주관식 문항인지 (1.11.0) */
|
|
297
|
+
export const isRubricMode = (q) => q?.type === 'text' && q.answerMode === 'rubric';
|
|
283
298
|
|
|
284
299
|
/** 정답 하나(화면 값) → 문항 정규식 조각. 주관식 목록은 허용 답 여러 개를 (?:…|…)로, 정규식은 바꾼 식을 (?:…)로 */
|
|
285
300
|
function keyPart(q, value, format) {
|
|
@@ -595,7 +610,10 @@ export const PARTIAL = 'partial_pattern';
|
|
|
595
610
|
|
|
596
611
|
/** 채점 방식: 저장된 settings.grading.type, 없으면 학생 화면에도 보이는 settings.gradingType, 둘 다 없으면 pattern */
|
|
597
612
|
export function gradingTypeOf(content, grading) {
|
|
613
|
+
// 옛 제안 items(1.11.0 개발 중 draft)는 per_question으로 읽는다
|
|
614
|
+
if (isPerQuestionType(grading?.type)) return PER_QUESTION;
|
|
598
615
|
if (grading?.type === PARTIAL || grading?.type === 'pattern') return grading.type;
|
|
616
|
+
if (isPerQuestionType(content?.gradingType)) return PER_QUESTION;
|
|
599
617
|
return content?.gradingType === PARTIAL ? PARTIAL : 'pattern';
|
|
600
618
|
}
|
|
601
619
|
|
|
@@ -662,6 +680,197 @@ export function scoresFor(questions, saved, split) {
|
|
|
662
680
|
return { scores: split(questions.length), resplit: had };
|
|
663
681
|
}
|
|
664
682
|
|
|
683
|
+
// ---------- 문항별 채점 (per_question, 1.11.0 · 서버 elice-material #65) ----------
|
|
684
|
+
// 정규식 문항과 AI 채점 문항을 섞은 퀴즈. AI 채점 문항이 하나라도 있으면 이 방식으로 저장한다.
|
|
685
|
+
// 1.11.0 개발 중에 쓴 제안 모양 items({ kind, score } 항목)는 서버가 받지 않는다. 편집 화면은 읽기만 하고 per_question으로 다시 쓴다
|
|
686
|
+
|
|
687
|
+
export const PER_QUESTION = 'per_question';
|
|
688
|
+
/** 옛 제안 (1.11.0 개발 중 저장한 draft). 읽기만 한다 */
|
|
689
|
+
export const ITEMS = 'items';
|
|
690
|
+
/** per_question 채점 설정을 쓰는 settings가 필요한 템플릿 버전 (공개 settings requires). AI 채점 문항이 없으면 REQUIRES 그대로 */
|
|
691
|
+
export const REQUIRES_PER_QUESTION = { quiz: '1.11.0' };
|
|
692
|
+
/**
|
|
693
|
+
* per_question 퀴즈의 답 형식 (공개 settings answerFormat). 주관식 인코딩은 형식 2와 같고(정규식 문항 `문항id=원문`),
|
|
694
|
+
* 답이 문항별 배열이고 AI 채점 문항 자리는 답 글만 간다. 1.10 편집 화면은 answerFormat이 2보다 크면 정답을 저장하지 않으므로
|
|
695
|
+
* 1.10 화면이 이 자료의 채점 설정을 덮어쓰지 못한다
|
|
696
|
+
*/
|
|
697
|
+
export const ANSWER_FORMAT_PER_QUESTION = 3;
|
|
698
|
+
/** 이 판이 읽는 가장 새 답 형식 (편집 화면 · doctor가 "더 새 템플릿이 저장한 자료"를 가르는 기준) */
|
|
699
|
+
export const ANSWER_FORMAT_MAX = ANSWER_FORMAT_PER_QUESTION;
|
|
700
|
+
/** AI 채점 기준(rubric) 최대 글자 수 (서버 RubricGrader.rubric) */
|
|
701
|
+
export const RUBRIC_MAX = LIMITS.rubricMax;
|
|
702
|
+
/** AI에 같이 보내는 문제 글(question) 최대 글자 수 (서버 RubricGrader.question) */
|
|
703
|
+
export const RUBRIC_QUESTION_MAX = 2000;
|
|
704
|
+
/** 문항 수 상한 (서버 GradingPerQuestion.questions) */
|
|
705
|
+
export const PER_QUESTION_MAX = 50;
|
|
706
|
+
/** AI 채점 문항 수 상한 (서버: 루브릭을 제출당 한 번 묶어 채점, 자료당 10개) */
|
|
707
|
+
export const RUBRIC_QUESTIONS_MAX = 10;
|
|
708
|
+
|
|
709
|
+
/** AI 채점 문항이 하나라도 있으면 per_question으로 채점한다 */
|
|
710
|
+
export const usesPerQuestion = (questions) => (questions ?? []).some(isRubricMode);
|
|
711
|
+
|
|
712
|
+
/** per_question으로 읽는 채점 방식 이름 (옛 제안 items 포함) */
|
|
713
|
+
export const isPerQuestionType = (type) => type === PER_QUESTION || type === ITEMS;
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* 문항별 답 → per_question 답 배열 (문항 순서). 정규식 문항은 partial_pattern과 같은 `문항id=답`,
|
|
717
|
+
* AI 채점 문항은 그 문항의 답 글(앞뒤 공백을 자름)만. 예: ["q1=b", "q2=weight", "과적합은 …"]
|
|
718
|
+
*/
|
|
719
|
+
export function joinQuestionAnswers(questions, values, format = 1) {
|
|
720
|
+
return questions.map((q, i) =>
|
|
721
|
+
isRubricMode(q) ? encodeAnswer(q, values[i]) : joinAnswers([q], [values[i]], format),
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/** per_question 답 배열 → 문항 id별 답 문자열 (자리 = 문항 순서). 정규식 문항 조각은 `문항id=`를 떼고 푼다 */
|
|
726
|
+
function splitQuestionAnswers(questions, answer) {
|
|
727
|
+
const out = {};
|
|
728
|
+
questions.forEach((q, i) => {
|
|
729
|
+
const piece = answer[i];
|
|
730
|
+
if (typeof piece !== 'string') return;
|
|
731
|
+
if (isRubricMode(q)) out[q.id] = piece;
|
|
732
|
+
else Object.assign(out, splitAnswers([q], piece));
|
|
733
|
+
});
|
|
734
|
+
return out;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* per_question 답 배열의 자리마다 어느 문항인지 (문항 id 배열). 정규식 문항 조각은 `문항id=`로 맞추고, AI 채점 문항은 자리로 맞춘다.
|
|
739
|
+
* 지금 문항과 맞지 않으면(빠짐 · 더함 · 순서 바뀜) null
|
|
740
|
+
*/
|
|
741
|
+
export function questionAnswerIds(questions, answer) {
|
|
742
|
+
if (!Array.isArray(answer) || answer.length !== questions.length) return null;
|
|
743
|
+
const ids = questions.map((q, i) => {
|
|
744
|
+
const piece = answer[i];
|
|
745
|
+
if (typeof piece !== 'string') return null;
|
|
746
|
+
if (isRubricMode(q)) return q.id;
|
|
747
|
+
return piece.startsWith(`${q.id}=`) ? q.id : null;
|
|
748
|
+
});
|
|
749
|
+
return ids.every(Boolean) ? ids : null;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/** 마크다운(지문) → AI에 보낼 글: 그림은 설명 글만, 링크는 글만, 서식 기호(굵게 · 기울임 · 취소선 · 코드 · 제목 · 코드 블록 울타리)는 뗀다 */
|
|
753
|
+
export function plainText(source) {
|
|
754
|
+
// \로 막은 서식 기호는 잠시 다른 글자(U+E000 + 기호 번호)로 두었다가 마지막에 기호만 되돌린다
|
|
755
|
+
const marks = '\\*`[]#-.~';
|
|
756
|
+
return String(source ?? '')
|
|
757
|
+
.replace(/\\([\\*`[\]#\-.~])/g, (_, c) => String.fromCharCode(0xe000 + marks.indexOf(c)))
|
|
758
|
+
.replace(/^```.*$/gm, '')
|
|
759
|
+
.replace(/!\[([^\]]*)\]\([^)]*\)/g, '$1')
|
|
760
|
+
.replace(/\[([^\]]+)\]\([^)]*\)/g, '$1')
|
|
761
|
+
.replace(/\*\*([^*]+)\*\*/g, '$1')
|
|
762
|
+
.replace(/\*([^*\n]+)\*/g, '$1')
|
|
763
|
+
.replace(/~~([^~]+)~~/g, '$1')
|
|
764
|
+
.replace(/`([^`]+)`/g, '$1')
|
|
765
|
+
.replace(/^#{1,3}\s+/gm, '')
|
|
766
|
+
.replace(/[\ue000-\ue009]/g, (c) => marks[c.charCodeAt(0) - 0xe000])
|
|
767
|
+
.replace(/[ \t]+$/gm, '')
|
|
768
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
769
|
+
.trim();
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* AI 채점 문항의 문제 글 (서버 grader.question, AI가 채점 기준과 같이 읽음): 질문 + 지문을 글로, RUBRIC_QUESTION_MAX자까지
|
|
774
|
+
*/
|
|
775
|
+
export function questionText(q) {
|
|
776
|
+
const text = [String(q?.title ?? '').trim(), plainText(q?.description)].filter(Boolean).join('\n\n');
|
|
777
|
+
return text.length > RUBRIC_QUESTION_MAX ? text.slice(0, RUBRIC_QUESTION_MAX) : text;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* 문항별 정답 · 배점 → per_question 채점 설정 (서버 GradingPerQuestion). 정규식 문항은 buildAnswerKey를 문항 하나씩
|
|
782
|
+
* (partial_pattern과 같은 정규식), AI 채점 문항은 채점 기준 글과 문제 글(questionText). scores: 문항 순서의 배점.
|
|
783
|
+
* passScore: 통과 점수 (편집 화면은 늘 넣는다, 비우면 100)
|
|
784
|
+
*/
|
|
785
|
+
export function buildPerQuestionGrading(questions, key, scores, format = 1, passScore) {
|
|
786
|
+
return {
|
|
787
|
+
type: PER_QUESTION,
|
|
788
|
+
questions: questions.map((q, i) => ({
|
|
789
|
+
score: scores[i],
|
|
790
|
+
grader: isRubricMode(q)
|
|
791
|
+
? { type: 'rubric', rubric: String(key[q.id] ?? ''), question: questionText(q) }
|
|
792
|
+
: { type: 'pattern', answer_key: buildAnswerKey([q], key, format) },
|
|
793
|
+
})),
|
|
794
|
+
...(passScore !== undefined ? { pass_score: passScore } : {}),
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/** 옛 제안 items의 항목 → per_question 문항 모양 (읽을 때만) */
|
|
799
|
+
const fromItem = (item) =>
|
|
800
|
+
item?.kind === 'rubric'
|
|
801
|
+
? { score: item.score, grader: { type: 'rubric', rubric: item.rubric } }
|
|
802
|
+
: item?.kind === 'pattern'
|
|
803
|
+
? { score: item.score, grader: { type: 'pattern', answer_key: item.answer_key } }
|
|
804
|
+
: null;
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* 저장된 per_question(옛 items도) 채점 설정 → { key: 문항별 정답(화면 값), scores: 문항 순서 배점, passScore }.
|
|
808
|
+
* 자리 = 문항 순서이고 정규식 문항은 문항 id가, AI 채점 문항은 그 자리 문항이 AI 채점 문항이어야 한다. 모양이 다르면 null
|
|
809
|
+
*/
|
|
810
|
+
export function parsePerQuestionGrading(questions, grading) {
|
|
811
|
+
const list =
|
|
812
|
+
grading?.type === ITEMS && Array.isArray(grading.items)
|
|
813
|
+
? grading.items.map(fromItem)
|
|
814
|
+
: grading?.questions;
|
|
815
|
+
if (!Array.isArray(list) || list.length !== questions.length) return null;
|
|
816
|
+
const key = {};
|
|
817
|
+
const scores = [];
|
|
818
|
+
for (const [i, entry] of list.entries()) {
|
|
819
|
+
const q = questions[i];
|
|
820
|
+
const grader = entry?.grader;
|
|
821
|
+
if (!grader || typeof grader !== 'object') return null;
|
|
822
|
+
if (grader.type === 'rubric') {
|
|
823
|
+
if (!isRubricMode(q) || typeof grader.rubric !== 'string') return null;
|
|
824
|
+
key[q.id] = grader.rubric;
|
|
825
|
+
} else if (grader.type === 'pattern') {
|
|
826
|
+
if (isRubricMode(q)) return null;
|
|
827
|
+
const parsed = parseAnswerKey([q], grader.answer_key);
|
|
828
|
+
if (!parsed || !(q.id in parsed)) return null;
|
|
829
|
+
key[q.id] = parsed[q.id];
|
|
830
|
+
} else return null;
|
|
831
|
+
scores.push(entry.score);
|
|
832
|
+
}
|
|
833
|
+
const passScore = Number.isInteger(grading.pass_score) ? grading.pass_score : undefined;
|
|
834
|
+
return { key, scores, passScore };
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* per_question 채점 설정 검사 (서버 GradingPerQuestion과 같은 규칙, 그리고 편집 화면 규칙: 채점 기준은 비어 있지 않음):
|
|
839
|
+
* 문항 1~50 · 배점 0~100 정수 · 합 100 이상 · 정규식은 비어 있지 않고 500자 이하 · 채점 기준 10,000자 이하 ·
|
|
840
|
+
* 문제 글 2,000자 이하 · AI 채점 문항 10개 이하 · pass_score(있으면) 1~100 정수.
|
|
841
|
+
* 문제가 없으면 null, 있으면 { index, code } (index는 문항 자리, 전체 문제면 -1. 문구는 화면이 정함)
|
|
842
|
+
* @param {object} grading
|
|
843
|
+
* @param {number} [answerKeyMax] 정규식 길이 상한 (키트 ANSWER_KEY_MAX)
|
|
844
|
+
*/
|
|
845
|
+
export function validatePerQuestionGrading(grading, answerKeyMax = 500) {
|
|
846
|
+
const list = grading?.questions;
|
|
847
|
+
if (!Array.isArray(list) || list.length < 1 || list.length > PER_QUESTION_MAX)
|
|
848
|
+
return { index: -1, code: 'count' };
|
|
849
|
+
for (const [i, entry] of list.entries()) {
|
|
850
|
+
if (!Number.isInteger(entry?.score) || entry.score < 0 || entry.score > 100)
|
|
851
|
+
return { index: i, code: 'score' };
|
|
852
|
+
const grader = entry.grader;
|
|
853
|
+
if (grader?.type === 'pattern') {
|
|
854
|
+
if (typeof grader.answer_key !== 'string' || !grader.answer_key)
|
|
855
|
+
return { index: i, code: 'pattern' };
|
|
856
|
+
if (grader.answer_key.length > answerKeyMax) return { index: i, code: 'patternMax' };
|
|
857
|
+
} else if (grader?.type === 'rubric') {
|
|
858
|
+
if (typeof grader.rubric !== 'string' || !grader.rubric.trim())
|
|
859
|
+
return { index: i, code: 'rubric' };
|
|
860
|
+
if (grader.rubric.length > RUBRIC_MAX) return { index: i, code: 'rubricMax' };
|
|
861
|
+
if (grader.question !== undefined && (typeof grader.question !== 'string' || grader.question.length > RUBRIC_QUESTION_MAX))
|
|
862
|
+
return { index: i, code: 'questionMax' };
|
|
863
|
+
} else return { index: i, code: 'kind' };
|
|
864
|
+
}
|
|
865
|
+
if (list.filter((entry) => entry.grader.type === 'rubric').length > RUBRIC_QUESTIONS_MAX)
|
|
866
|
+
return { index: -1, code: 'rubricCount' };
|
|
867
|
+
if (list.reduce((sum, entry) => sum + entry.score, 0) < 100) return { index: -1, code: 'total' };
|
|
868
|
+
const pass = grading.pass_score;
|
|
869
|
+
if (pass !== undefined && (!Number.isInteger(pass) || pass < 1 || pass > 100))
|
|
870
|
+
return { index: -1, code: 'passScore' };
|
|
871
|
+
return null;
|
|
872
|
+
}
|
|
873
|
+
|
|
665
874
|
/**
|
|
666
875
|
* 정답 검증 1: 모든 문항에 정답이 있고, 정답이 지금 있는 보기 · 그룹을 가리키는지.
|
|
667
876
|
* 문제가 없으면 null, 있으면 { questionIndex, message }
|
|
@@ -672,6 +881,12 @@ export function validateAnswerKey(questions, key, v) {
|
|
|
672
881
|
const at = (message) => ({ questionIndex: i, message: v.at(i + 1, message) });
|
|
673
882
|
const value = key[q.id];
|
|
674
883
|
if (q.type === 'text') {
|
|
884
|
+
if (isRubricMode(q)) {
|
|
885
|
+
const rubric = typeof value === 'string' ? value : '';
|
|
886
|
+
if (!rubric.trim()) return at(v.noRubric);
|
|
887
|
+
if (rubric.length > RUBRIC_MAX) return at(v.rubricMax(rubric.length, RUBRIC_MAX));
|
|
888
|
+
continue;
|
|
889
|
+
}
|
|
675
890
|
if (isRegexMode(q)) {
|
|
676
891
|
const { error, detail } = compileTextRegex(typeof value === 'string' ? value : '');
|
|
677
892
|
if (error === 'empty') return at(v.noAnswer);
|