2025-02-07 17:33:38 +09:00
|
|
|
const jsonPath = require('jsonpath');
|
|
|
|
|
const XLSX = require('xlsx');
|
|
|
|
|
const psd = require('psd');
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
const path = require('path');
|
|
|
|
|
const xpath = require('xpath');
|
|
|
|
|
const { DOMParser } = require('xmldom');
|
|
|
|
|
|
2026-03-06 17:43:14 +09:00
|
|
|
const findSimilarString = require('./findSimilarString.js');
|
2025-03-19 17:45:05 +09:00
|
|
|
const getGpdpScore = require('./gpdpScoring.js');
|
2025-02-20 18:30:42 +09:00
|
|
|
const getToday = require('./getToday.js');
|
|
|
|
|
const todayDate = getToday();
|
2025-02-15 17:00:21 +09:00
|
|
|
|
2026-03-06 17:43:14 +09:00
|
|
|
// 시험 회차
|
2026-04-27 17:54:29 +09:00
|
|
|
const examRound = '2604';
|
2025-07-30 17:40:02 +09:00
|
|
|
|
2025-08-27 18:00:29 +09:00
|
|
|
const codeTypes = [
|
2026-03-06 17:43:14 +09:00
|
|
|
'DIC',
|
2025-08-27 18:00:29 +09:00
|
|
|
'DPI',
|
|
|
|
|
];
|
2025-09-15 17:07:06 +09:00
|
|
|
|
2025-04-11 15:14:28 +09:00
|
|
|
const examTypes = [
|
2026-04-02 15:25:28 +09:00
|
|
|
'A',
|
2026-03-06 17:43:14 +09:00
|
|
|
'B',
|
2026-04-27 17:54:29 +09:00
|
|
|
'C',
|
2025-07-30 17:40:02 +09:00
|
|
|
// 'D'
|
2025-04-08 16:11:38 +09:00
|
|
|
];
|
|
|
|
|
|
2026-04-02 15:25:28 +09:00
|
|
|
// testMode가 true일 경우 TEST 폴더에 있는답안 파일을 읽어옴
|
|
|
|
|
const testMode = false;
|
2026-03-06 17:43:14 +09:00
|
|
|
// const testMode = true;
|
2025-04-08 16:11:38 +09:00
|
|
|
|
|
|
|
|
const outputExcelFiles = [];
|
2025-08-27 18:00:29 +09:00
|
|
|
codeTypes.forEach(codeType => {
|
|
|
|
|
examTypes.forEach(type => {
|
2026-02-12 16:26:20 +09:00
|
|
|
const jsonPath = `./JSON/${examRound}/${codeType}_${examRound}${type}.json`
|
2025-11-28 17:22:13 +09:00
|
|
|
if (!fs.existsSync(jsonPath)) return
|
2025-08-27 18:00:29 +09:00
|
|
|
const scoringJson = require(jsonPath);
|
|
|
|
|
const answerFilesDir = `./output/${examRound}/${type}/${testMode ? 'TEST' : codeType}`;
|
2026-02-19 16:35:49 +09:00
|
|
|
let outputExcelFile =
|
2026-03-06 17:43:14 +09:00
|
|
|
`./${todayDate}_${codeType}_${examRound}${type}_채점결과.xlsx`;
|
2026-02-19 16:35:49 +09:00
|
|
|
|
2025-08-27 18:00:29 +09:00
|
|
|
if (testMode) {
|
2026-03-06 17:43:14 +09:00
|
|
|
outputExcelFile = `./${codeType}_${examRound}${type}_TEST.xlsx`;
|
2025-08-27 18:00:29 +09:00
|
|
|
}
|
2025-04-08 16:11:38 +09:00
|
|
|
|
2025-08-27 18:00:29 +09:00
|
|
|
// 답안 폴더 내부에 디렉토리가 아닌 일반 파일이 있을 경우 디렉토리만 필터링 해서 불러옴
|
|
|
|
|
const studentDirs = fs.readdirSync(answerFilesDir).filter(file => {
|
|
|
|
|
const filePath = path.join(answerFilesDir, file);
|
|
|
|
|
return fs.statSync(filePath).isDirectory();
|
2025-03-20 15:35:04 +09:00
|
|
|
});
|
2025-04-03 17:40:52 +09:00
|
|
|
|
2025-08-27 18:00:29 +09:00
|
|
|
// 채점 결과 리스트
|
|
|
|
|
const scoringResultList = [];
|
|
|
|
|
const psdData = [];
|
|
|
|
|
|
|
|
|
|
studentDirs.forEach(student => {
|
|
|
|
|
// 맥에서 한글 디렉토리 이름을 읽어서 엑셀에 저장 할 시 자소 분리가 되어 저장되는 문제 노말라이즈해서 해결
|
|
|
|
|
const name = student.normalize('NFC');
|
|
|
|
|
const studentDir = path.join(answerFilesDir, student);
|
|
|
|
|
// const psdFiles = fs.readdirSync(studentDir).filter(file => file.endsWith('.psd'));
|
|
|
|
|
const psdFiles = fs.readdirSync(studentDir).filter(file => file.toLowerCase().endsWith('.psd'));
|
|
|
|
|
|
|
|
|
|
// DIAT시험 프로젝트로 생성시 gmep확장자로
|
|
|
|
|
// 교육용 프로젝프로 생성시 gmdp확장자로 생성됨
|
|
|
|
|
const gmepFile = fs.readdirSync(studentDir).filter(
|
|
|
|
|
file => file.toLowerCase().endsWith('.gmep')
|
|
|
|
|
// || file.toLowerCase().endsWith('.gmdp')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 곰픽 파일 gpdp 파일 이거나 xml 파일
|
|
|
|
|
const gpdpFiles = fs.readdirSync(studentDir).filter(
|
|
|
|
|
file => file.toLowerCase().endsWith('.xml')
|
|
|
|
|
|| (file === null && (name + '.xml'))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 학생 이름을 key로 하는 객체 생성
|
|
|
|
|
// 채점결과
|
|
|
|
|
const scoringResult = {
|
|
|
|
|
0: name
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
psdFiles.forEach((psdFile, index) => {
|
|
|
|
|
const psdPath = path.join('./', studentDir, psdFile);
|
2025-05-30 18:05:46 +09:00
|
|
|
|
|
|
|
|
console.log('');
|
2025-08-27 18:00:29 +09:00
|
|
|
console.log(`➡️ Reading ${psdPath}...`);
|
|
|
|
|
try {
|
|
|
|
|
const psdFileData = psd.fromFile(psdPath);
|
|
|
|
|
psdFileData.parse();
|
|
|
|
|
psdData[index] = psdFileData;
|
|
|
|
|
scoringResult[index + 1] = getScore(psdData, scoringJson, index);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(`Error reading PSD file: ${psdPath}`, error);
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-03-06 17:43:14 +09:00
|
|
|
|
|
|
|
|
// ========== 🔴 여기부터 수정 필요 ==========
|
2025-08-27 18:00:29 +09:00
|
|
|
gpdpFiles.forEach((gpdpFile, index) => {
|
|
|
|
|
const gpdpPath = path.join('./', studentDir, gpdpFile);
|
|
|
|
|
console.log(`Reading ${gpdpPath}...`);
|
2025-05-08 18:11:21 +09:00
|
|
|
|
2026-03-06 17:43:14 +09:00
|
|
|
// 🔴 try-catch 추가 필요
|
|
|
|
|
try {
|
|
|
|
|
const xmlString = fs.readFileSync(gpdpPath, 'utf8');
|
|
|
|
|
|
|
|
|
|
if (!xmlString.trim().startsWith("<")) {
|
|
|
|
|
console.warn(`XML 형태 아님 → 스킵: ${gpdpFile}`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const xmlDocument = new DOMParser().parseFromString(xmlString, 'application/xml');
|
|
|
|
|
|
|
|
|
|
// 🔴 파싱 에러 확인 추가 필요
|
|
|
|
|
const parseError = xmlDocument.getElementsByTagName("parsererror");
|
|
|
|
|
if (parseError.length > 0) {
|
|
|
|
|
console.error(`❌ XML 파싱 오류 발생 → 스킵: ${gpdpFile}`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-05-08 18:11:21 +09:00
|
|
|
|
2026-03-06 17:43:14 +09:00
|
|
|
// 260219 - 파일명에서 번호 추출하여 점수 계산에 활용
|
|
|
|
|
// 파일명에서 번호 추출 (dpi_01_, dpi_02_ )
|
|
|
|
|
const fileNumberMatch = gpdpFile.match(/dpi_(\d+)_/);
|
|
|
|
|
const fileNumber = fileNumberMatch ? parseInt(fileNumberMatch[1], 10) : index + 1;
|
|
|
|
|
|
|
|
|
|
// 추출한 번호를 사용하여 scoringResult에 저장
|
|
|
|
|
scoringResult[fileNumber] = getGpdpScore(xmlDocument, scoringJson, fileNumber + 3);
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(`❌ 파일 읽기 또는 파싱 중 오류 발생: ${gpdpPath}`, error.message);
|
2026-02-19 16:35:49 +09:00
|
|
|
}
|
2025-05-08 18:11:21 +09:00
|
|
|
});
|
2026-03-06 17:43:14 +09:00
|
|
|
// ========== 🔴 여기까지 수정 필요 ==========
|
|
|
|
|
|
|
|
|
|
// ========== 🔴 여기부터 수정 필요 ==========
|
2025-08-27 18:00:29 +09:00
|
|
|
if (gmepFile.length === 0) {
|
|
|
|
|
// 곰믹스 채점 항목 갯수
|
|
|
|
|
const gmepItemCount = Object.keys(scoringJson[2]).length;
|
|
|
|
|
|
|
|
|
|
scoringResult[3] = {};
|
|
|
|
|
for (let i = 1; i <= gmepItemCount; i++) {
|
|
|
|
|
scoringResult[3][i] = 0;
|
|
|
|
|
}
|
|
|
|
|
scoringResult[3]['총점'] = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
gmepFile.forEach((gmep, index) => {
|
|
|
|
|
const gmepPath = path.join('./', studentDir, gmep);
|
2025-04-03 17:40:52 +09:00
|
|
|
|
2025-08-27 18:00:29 +09:00
|
|
|
console.log('');
|
|
|
|
|
console.log(`➡️ Reading ${gmepPath}...`);
|
|
|
|
|
|
2026-03-06 17:43:14 +09:00
|
|
|
// 🔴 try-catch 추가 필요
|
|
|
|
|
try {
|
|
|
|
|
const xmlString = fs.readFileSync(gmepPath, 'utf8');
|
|
|
|
|
|
|
|
|
|
// 🔴 XML 형식 사전 확인 추가
|
|
|
|
|
if (!xmlString.trim().startsWith("<?xml") && !xmlString.trim().startsWith("<")) {
|
|
|
|
|
console.warn(`⚠️ XML 형태 아님 → 스킵: ${gmep}`);
|
|
|
|
|
// 0점 처리
|
|
|
|
|
const gmepItemCount = Object.keys(scoringJson[2]).length;
|
|
|
|
|
scoringResult[3] = {};
|
|
|
|
|
for (let i = 1; i <= gmepItemCount; i++) {
|
|
|
|
|
scoringResult[3][i] = 0;
|
|
|
|
|
}
|
|
|
|
|
scoringResult[3]['총점'] = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// XML 문자열을 파싱하여 XML 문서 객체로 변환
|
|
|
|
|
const xmlDocument = new DOMParser().parseFromString(xmlString, 'application/xml');
|
|
|
|
|
|
|
|
|
|
// 🔴 파싱 에러 확인 추가 필요
|
|
|
|
|
const parseError = xmlDocument.getElementsByTagName("parsererror");
|
|
|
|
|
|
|
|
|
|
if (parseError.length > 0) {
|
|
|
|
|
console.error(`❌ XML 파싱 오류 발생 → 스킵: ${gmep}`);
|
|
|
|
|
// 0점 처리
|
|
|
|
|
const gmepItemCount = Object.keys(scoringJson[2]).length;
|
|
|
|
|
scoringResult[3] = {};
|
|
|
|
|
for (let i = 1; i <= gmepItemCount; i++) {
|
|
|
|
|
scoringResult[3][i] = 0;
|
|
|
|
|
}
|
|
|
|
|
scoringResult[3]['총점'] = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-08-27 18:00:29 +09:00
|
|
|
|
2026-03-06 17:43:14 +09:00
|
|
|
scoringResult[3] = getGmepScore(xmlDocument, scoringJson, 2);
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(`❌ 파일 읽기 또는 파싱 중 오류 발생: ${gmepPath}`, error.message);
|
|
|
|
|
// 0점 처리
|
|
|
|
|
const gmepItemCount = Object.keys(scoringJson[2]).length;
|
|
|
|
|
scoringResult[3] = {};
|
|
|
|
|
for (let i = 1; i <= gmepItemCount; i++) {
|
|
|
|
|
scoringResult[3][i] = 0;
|
|
|
|
|
}
|
|
|
|
|
scoringResult[3]['총점'] = 0;
|
|
|
|
|
}
|
2025-08-27 18:00:29 +09:00
|
|
|
});
|
|
|
|
|
}
|
2026-03-06 17:43:14 +09:00
|
|
|
// ========== 🔴 여기까지 수정 필요 ==========
|
|
|
|
|
|
2025-08-27 18:00:29 +09:00
|
|
|
scoringResultList.push(scoringResult);
|
|
|
|
|
});
|
2025-02-07 17:33:38 +09:00
|
|
|
|
2025-08-27 18:00:29 +09:00
|
|
|
const flattenedData = prepareExcelData(scoringResultList);
|
|
|
|
|
const transposedData = transposeData(flattenedData);
|
|
|
|
|
|
|
|
|
|
// 엑셀 파일 생성
|
|
|
|
|
const worksheet = XLSX.utils.json_to_sheet(transposedData, { skipHeader: true });
|
|
|
|
|
const workbook = XLSX.utils.book_new();
|
|
|
|
|
|
|
|
|
|
// 열 너비 계산
|
2026-02-19 16:35:49 +09:00
|
|
|
if (!Array.isArray(transposedData) || transposedData.length === 0) {
|
|
|
|
|
console.warn("transposedData 비어 있음 → 엑셀 컬럼 생성 스킵");
|
|
|
|
|
return; // 또는 continue / break (문맥에 따라)
|
|
|
|
|
}
|
2025-08-27 18:00:29 +09:00
|
|
|
const columnWidths = Object.keys(transposedData[0]).map(key => {
|
|
|
|
|
// 각 열의 최대 길이를 계산
|
|
|
|
|
const maxLength = Math.max(
|
|
|
|
|
// key.length, // 열 제목의 길이
|
|
|
|
|
// ...transposedData.map(row => (row[key] ? row[key].toString().length : 0)) // 각 셀의 데이터 길이
|
|
|
|
|
4 // 고정 너비
|
|
|
|
|
);
|
|
|
|
|
return { wch: maxLength + 1 }; // 여유 공간 추가
|
|
|
|
|
});
|
2025-03-21 17:26:51 +09:00
|
|
|
|
2025-08-27 18:00:29 +09:00
|
|
|
// 열 너비 설정
|
|
|
|
|
worksheet['!cols'] = columnWidths;
|
|
|
|
|
// Add the worksheet to the workbook
|
|
|
|
|
XLSX.utils.book_append_sheet(workbook, worksheet, '채점 결과');
|
|
|
|
|
|
|
|
|
|
// 엑셀 파일 저장
|
|
|
|
|
XLSX.writeFile(workbook, outputExcelFile);
|
|
|
|
|
outputExcelFiles.push(outputExcelFile);
|
|
|
|
|
});
|
2025-04-08 16:11:38 +09:00
|
|
|
});
|
2025-04-15 17:44:45 +09:00
|
|
|
|
|
|
|
|
console.log('채점 결과');
|
2025-05-08 18:11:21 +09:00
|
|
|
outputExcelFiles.forEach((outputFile, index) => {
|
|
|
|
|
console.log(`[${index + 1}] : ${outputFile}`);
|
2025-04-15 17:44:45 +09:00
|
|
|
});
|
|
|
|
|
|
2025-03-21 17:26:51 +09:00
|
|
|
|
2025-02-07 17:33:38 +09:00
|
|
|
// xml 형식의 gmep 파일을 읽어서 점수를 계산
|
|
|
|
|
// scoring.json 파일 내에 있는 ele 요소는 xpath 형식으로 접근하여 요소를 탐색하고 나오는 값을 value와 비교하여 점수를 계산
|
|
|
|
|
// scoring.json 파일 내에 있는 type은 비교할 값의 타입을 의미하며, boolean, array 등이 있음
|
|
|
|
|
// scoring.json 파일 내에 있는 type에 따라 비교하는 방식이 달라짐
|
|
|
|
|
// 채점 결과를 scoringResultList 배열에 저장
|
|
|
|
|
function getGmepScore(gmepData, scoringJson, index) {
|
2025-06-17 18:01:02 +09:00
|
|
|
function compareAndScore(user, right, point, key, scoringResult, options = {}) {
|
2025-05-30 18:05:46 +09:00
|
|
|
let score = 0;
|
2025-06-17 18:01:02 +09:00
|
|
|
let isEqual = false;
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
tolerance = 0, // 숫자 비교 시 허용 오차
|
|
|
|
|
type = 'auto', // 'auto' | 'number[]' | 'string[]' | 'object' | 'primitive'
|
|
|
|
|
} = options;
|
2025-06-18 17:58:12 +09:00
|
|
|
|
2025-06-17 18:01:02 +09:00
|
|
|
if (type === 'force-correct') {
|
|
|
|
|
isEqual = true;
|
|
|
|
|
}
|
|
|
|
|
else if (Array.isArray(right) && Array.isArray(user)) {
|
|
|
|
|
if (right.length === user.length) {
|
2025-06-20 17:47:47 +09:00
|
|
|
if
|
|
|
|
|
(type === 'number[]' ||
|
|
|
|
|
(type === 'auto' && typeof right[0] === 'number')) {
|
2025-06-17 18:01:02 +09:00
|
|
|
isEqual = right.every((val, idx) => Math.abs(val - user[idx]) <= tolerance);
|
2025-06-20 17:47:47 +09:00
|
|
|
}
|
|
|
|
|
else if
|
|
|
|
|
(type === 'string[]' ||
|
|
|
|
|
(type === 'auto' && typeof right[0] === 'string')) {
|
2025-06-17 18:01:02 +09:00
|
|
|
isEqual = right.every((val, idx) => val === user[idx]);
|
|
|
|
|
}
|
2025-06-16 16:43:57 +09:00
|
|
|
}
|
2025-06-20 17:47:47 +09:00
|
|
|
}
|
|
|
|
|
else if
|
|
|
|
|
(type === 'object' ||
|
|
|
|
|
(type === 'auto' && typeof right === 'object' && typeof user === 'object')) {
|
2025-06-17 18:01:02 +09:00
|
|
|
isEqual = JSON.stringify(user) === JSON.stringify(right);
|
2025-06-20 17:47:47 +09:00
|
|
|
}
|
|
|
|
|
else {
|
2025-06-17 18:01:02 +09:00
|
|
|
isEqual = user == right; // primitive 비교
|
2025-06-16 16:43:57 +09:00
|
|
|
}
|
2025-05-30 18:05:46 +09:00
|
|
|
|
|
|
|
|
if (isEqual) {
|
|
|
|
|
score = point;
|
2025-06-17 18:01:02 +09:00
|
|
|
console.log('작성답안: ', user);
|
|
|
|
|
console.log('>⭕ 정답: ', right);
|
2025-05-30 18:05:46 +09:00
|
|
|
} else {
|
2025-06-17 18:01:02 +09:00
|
|
|
console.log('작성답안: ', user);
|
|
|
|
|
console.log('>❌ 오답: ', right);
|
2025-05-30 18:05:46 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scoringResult[key] = score;
|
2025-06-20 17:47:47 +09:00
|
|
|
// totalScore += score;
|
2025-05-30 18:05:46 +09:00
|
|
|
return score;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-16 16:43:57 +09:00
|
|
|
function convertColorToHex(colorValue) {
|
|
|
|
|
// 문자열이면 정수로 변환
|
|
|
|
|
const intValue = typeof colorValue === 'string' ? parseInt(colorValue, 10) : colorValue;
|
|
|
|
|
|
|
|
|
|
// 부호 없는 32비트 정수로 변환 → 8자리 16진수 문자열로
|
|
|
|
|
const hex = (intValue >>> 0).toString(16).padStart(8, '0');
|
|
|
|
|
|
|
|
|
|
// 하위 6자리 추출 (BGR 순서)
|
|
|
|
|
const bgr = hex.slice(2); // 예: "fff1b01d" → "f1b01d"
|
|
|
|
|
|
|
|
|
|
// BGR → RGB로 재배열
|
|
|
|
|
const b = bgr.slice(0, 2);
|
|
|
|
|
const g = bgr.slice(2, 4);
|
|
|
|
|
const r = bgr.slice(4, 6);
|
|
|
|
|
|
|
|
|
|
// RGB 순서로 합치고 소문자로 반환
|
|
|
|
|
return (r + g + b).toLowerCase(); // e.g., "fd5721"
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-07 17:33:38 +09:00
|
|
|
const gmepXmlDoc = gmepData;
|
|
|
|
|
const scoringResult = {};
|
|
|
|
|
|
|
|
|
|
const scoringData = scoringJson[index];
|
|
|
|
|
// console.log(scoringData);
|
|
|
|
|
|
2025-06-18 17:58:12 +09:00
|
|
|
// 동영상 시작시간, 오프닝 시작시간 상수값 저장
|
|
|
|
|
const videoStartTime = scoringData['10'].value;
|
|
|
|
|
const openingStartTime = scoringData['28'].value;
|
2025-03-17 18:51:45 +09:00
|
|
|
|
2025-02-07 17:33:38 +09:00
|
|
|
let totalScore = 0;
|
2025-03-17 18:51:45 +09:00
|
|
|
|
2025-02-07 17:33:38 +09:00
|
|
|
// 채점기준표 문항별 분류
|
|
|
|
|
for (const key in scoringData) {
|
2025-06-20 17:47:47 +09:00
|
|
|
|
|
|
|
|
// XML <CRClip> 요소의 index값을 구함
|
2025-06-18 17:58:12 +09:00
|
|
|
function getCRClipIndex(mediaName) {
|
2025-06-13 17:03:43 +09:00
|
|
|
// CRClipArr/CRClip 요소의 Path속성 리스트를 구함
|
|
|
|
|
// 모션 클립 이미지도 고려해 처리
|
|
|
|
|
const mediaPathList = xpath.select("//CRClipArr/CRClip[@Type='11']/CRCUnitArr/@Path | //CRClipArr/CRClip[not(@Type='11')]/@Path", gmepXmlDoc);
|
|
|
|
|
|
|
|
|
|
// "동영상.mp4"의 clipIndex를 구함
|
|
|
|
|
// clipIndex가 -1이면 해당 미디어가 존재하지 않는 것
|
2025-06-17 18:01:02 +09:00
|
|
|
const crclipIndex = mediaPathList.findIndex(mediaPath => mediaPath.value === mediaName);
|
|
|
|
|
return crclipIndex;
|
2025-06-13 17:03:43 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 자막 텍스트로 자막클립인덱스 반환
|
|
|
|
|
function getClipIndexByText(text) {
|
|
|
|
|
const crOwneUnits = xpath.select(`//CROwneUnitArr/CROwneUnit`, gmepXmlDoc);
|
|
|
|
|
|
|
|
|
|
let subtitleClipIndex = null;
|
|
|
|
|
// 자막 텍스트와 일치하는 요소의 인덱스를 반환
|
|
|
|
|
for (let i = 0; i < crOwneUnits.length; i++) {
|
|
|
|
|
const crcUnitArr = xpath.select1('.//CRCUnitArr', crOwneUnits[i]);
|
|
|
|
|
if (crcUnitArr && crcUnitArr.getAttribute('Name') === text) {
|
|
|
|
|
subtitleClipIndex = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-17 18:01:02 +09:00
|
|
|
// console.log('🟢 자막 텍스트로 검색한 CROwneUnit 인덱스 : ', subtitleClipIndex);
|
2025-06-13 17:03:43 +09:00
|
|
|
return subtitleClipIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getClipIndexByOrder(order) {
|
|
|
|
|
// 자막의 갯수가 2개 이상 (오프닝과 동영상 자막이 있을 경우)
|
|
|
|
|
// 앞은 오프닝 뒤는 동영상 자막으로 판단
|
|
|
|
|
// crTrackClips[0] : 오프닝 자막
|
|
|
|
|
// crTrackClips[1] : 동영상 자막
|
|
|
|
|
const crOwneUnits = xpath.select(`//CROwneUnitArr/CROwneUnit`, gmepXmlDoc);
|
|
|
|
|
const crTrackClips = xpath.select("//CRTrackList[@Name='텍스트' or @Name='비디오2']/CRTrackClip[not(@Type='0') and not(@ClipIndex='-1')]", gmepXmlDoc);
|
|
|
|
|
let subtitleClipIndex = null;
|
|
|
|
|
if (subtitleClipIndex === null && crOwneUnits.length >= 2) {
|
|
|
|
|
// if (crOwneUnits.length >= 2) {
|
|
|
|
|
for (let i = 0; i < crTrackClips.length; i++) {
|
|
|
|
|
if ((order - 1) === i) {
|
|
|
|
|
subtitleClipIndex = parseInt(crTrackClips[i].getAttribute('ClipIndex'), 10);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-17 18:01:02 +09:00
|
|
|
// console.log('🟡 자막 순서로 검색한 CROwneUnit 인덱스 : ', subtitleClipIndex);
|
2025-06-13 17:03:43 +09:00
|
|
|
return subtitleClipIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 자막들의 시작 시간을 가지는 리스트에서
|
|
|
|
|
// 구하고자 하는 영상의 시작시간(startTime)과 일치하는 시간이 있다면 인덱스를 가져와
|
|
|
|
|
// 자막의 인덱스를 구함
|
|
|
|
|
function getCilpIndexByStartTime(startTime) {
|
|
|
|
|
const crTrackClips = xpath.select("//CRTrackList[@Name='텍스트' or @Name='비디오2']/CRTrackClip", gmepXmlDoc);
|
2025-06-18 17:58:12 +09:00
|
|
|
const subtitleStartTimeList = getStartTimeList('텍스트');
|
2025-06-13 17:03:43 +09:00
|
|
|
const startTimeIndex = subtitleStartTimeList.findIndex(value => value === startTime);
|
|
|
|
|
|
|
|
|
|
let subtitleClipIndex = null;
|
|
|
|
|
for (let i = 0; i < crTrackClips.length; i++) {
|
|
|
|
|
if (parseInt(crTrackClips[i].getAttribute('ClipIndex'), 10) == -1) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const clipIndex = parseInt(crTrackClips[i].getAttribute('ClipIndex'), 10);
|
|
|
|
|
if (startTimeIndex === i) {
|
|
|
|
|
subtitleClipIndex = clipIndex;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-17 18:01:02 +09:00
|
|
|
// console.log('🟠 자막 시작시간으로 검색한 CROwneUnit 인덱스 : ', subtitleClipIndex);
|
2025-06-13 17:03:43 +09:00
|
|
|
return subtitleClipIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 영상내 존재하는 자막과 자막사이 공백의 시작시간 리스트를 구함
|
2025-06-18 17:58:12 +09:00
|
|
|
function getStartTimeList(type) {
|
|
|
|
|
let trackClips = null;
|
|
|
|
|
|
|
|
|
|
if (type === '텍스트') {
|
|
|
|
|
trackClips = xpath.select(`//CRTrackList[@Name='${type}' or @Name='비디오2']/CRTrackClip`, gmepXmlDoc);
|
|
|
|
|
}
|
|
|
|
|
else if (type === '비디오1' || type === '오디오1') {
|
|
|
|
|
trackClips = xpath.select(`//CRTrackList[@Name='${type}']/CRTrackClip`, gmepXmlDoc);
|
|
|
|
|
}
|
2025-06-13 17:03:43 +09:00
|
|
|
|
|
|
|
|
let cumulativeLengths = [];
|
|
|
|
|
let total = 0;
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < trackClips.length; i++) {
|
|
|
|
|
const length = parseInt(trackClips[i].getAttribute('Length'), 10);
|
|
|
|
|
|
|
|
|
|
cumulativeLengths.push(total);
|
|
|
|
|
total += length;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-17 18:01:02 +09:00
|
|
|
// console.log("🔵 자막 구간 시작시간 : ", cumulativeLengths);
|
2025-06-13 17:03:43 +09:00
|
|
|
return cumulativeLengths;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-18 17:58:12 +09:00
|
|
|
function getCRTrackClipIndex(crclipIndex, type) {
|
|
|
|
|
let xpathQuery;
|
|
|
|
|
if (type === '텍스트') {
|
|
|
|
|
xpathQuery = `//CRTrackList[@Name='${type}' or @Name='비디오2']/CRTrackClip`;
|
|
|
|
|
}
|
|
|
|
|
else if (type === '비디오1' || type === '오디오1') {
|
|
|
|
|
xpathQuery = `//CRTrackList[@Name='${type}']/CRTrackClip`;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
throw new Error(`Unknown type: ${type}`);
|
2025-06-13 17:03:43 +09:00
|
|
|
}
|
|
|
|
|
|
2025-06-18 17:58:12 +09:00
|
|
|
const crTrackClips = xpath.select(xpathQuery, gmepXmlDoc);
|
2025-06-17 18:01:02 +09:00
|
|
|
|
2025-06-18 17:58:12 +09:00
|
|
|
let index = -1;
|
|
|
|
|
// crTrackClips에서 ClipIndex가 crclipIndex와 일치하는 요소의 인덱스를 찾음
|
|
|
|
|
// 처음 발견하는 요소의 인덱스를 반환
|
|
|
|
|
for (let i = 0; i < crTrackClips.length; i++) {
|
|
|
|
|
if (crclipIndex == parseInt(crTrackClips[i].getAttribute('ClipIndex'), 10)) {
|
2025-06-17 18:01:02 +09:00
|
|
|
index = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-18 17:58:12 +09:00
|
|
|
|
2025-06-17 18:01:02 +09:00
|
|
|
return index;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-07 17:33:38 +09:00
|
|
|
let ele = scoringData[key].ele;
|
2025-02-15 17:00:21 +09:00
|
|
|
const rightAnswer = scoringData[key].value;
|
2025-02-07 17:33:38 +09:00
|
|
|
const point = scoringData[key].point;
|
2025-06-17 18:01:02 +09:00
|
|
|
const type = scoringData[key].type ? scoringData[key].type : '';
|
2025-06-16 16:43:57 +09:00
|
|
|
let search = scoringData[key].search;
|
2025-05-30 18:05:46 +09:00
|
|
|
const media = scoringData[key].media;
|
2025-06-17 18:01:02 +09:00
|
|
|
|
2025-06-18 17:58:12 +09:00
|
|
|
// const videoStartTime = scoringData.videoStartTime;
|
|
|
|
|
// const openingStartTime = scoringData.openingStartTime;
|
|
|
|
|
|
2025-05-28 17:35:53 +09:00
|
|
|
const image = scoringData[key].image;
|
|
|
|
|
|
2025-06-17 18:01:02 +09:00
|
|
|
let userAnswer = null;
|
|
|
|
|
|
2025-03-21 17:26:51 +09:00
|
|
|
console.log(`example number: ${key}`)
|
|
|
|
|
|
2025-06-16 16:43:57 +09:00
|
|
|
const subtitleOrder = type.includes('opening') ? 1 : type.includes('video') ? 2 : null;
|
2025-05-28 17:35:53 +09:00
|
|
|
|
2025-02-07 17:33:38 +09:00
|
|
|
// search 값이 undefined 아니면 ele의 {search}부분을 search로 치환
|
|
|
|
|
/**
|
|
|
|
|
* JSON파일 곰믹스 5번문항/22번 문항
|
2025-03-20 15:35:04 +09:00
|
|
|
* type : "video" 인 항목들
|
2025-02-07 17:33:38 +09:00
|
|
|
* GPString태그 VID7속성 찾는 xpath구문
|
|
|
|
|
* CRCUnitArr태그 Name속성 찾는 구문으로 변환
|
|
|
|
|
* > 멀티라인 텍스트 유사도 판별하기 어려움
|
|
|
|
|
*/
|
|
|
|
|
if (search !== undefined) {
|
2025-03-17 18:51:45 +09:00
|
|
|
let result = findSimilarString(gmepXmlDoc, search, 0.8);
|
2025-02-27 18:11:34 +09:00
|
|
|
if (result !== null) {
|
|
|
|
|
result = result.replace(/"/g, "'");
|
2025-06-16 16:43:57 +09:00
|
|
|
search = result;
|
2025-06-20 17:47:47 +09:00
|
|
|
ele = ele?.replace(/{search}/g, search);
|
2025-07-03 16:54:25 +09:00
|
|
|
}
|
2025-06-20 17:47:47 +09:00
|
|
|
else {
|
|
|
|
|
ele = ele?.includes('{search}') ? null : ele;
|
2025-02-15 17:00:21 +09:00
|
|
|
}
|
2025-02-07 17:33:38 +09:00
|
|
|
}
|
2025-03-28 17:59:53 +09:00
|
|
|
|
2025-02-07 17:33:38 +09:00
|
|
|
// xpath
|
|
|
|
|
if (ele === 'none') {
|
|
|
|
|
scoringResult[key] = "확인필요";
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-20 17:47:47 +09:00
|
|
|
if (type == "oneAnswer") {
|
2025-05-30 18:05:46 +09:00
|
|
|
const result = xpath.select1(ele, gmepXmlDoc);
|
|
|
|
|
|
2025-06-17 18:01:02 +09:00
|
|
|
// userAnswer = {};
|
2025-05-30 18:05:46 +09:00
|
|
|
if ("speed" in rightAnswer) {
|
|
|
|
|
userAnswer = {
|
|
|
|
|
"speed": result ? result.value : null,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
userAnswer = result ? result.value : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-17 18:01:02 +09:00
|
|
|
// [3-1] 문항
|
2025-05-30 18:05:46 +09:00
|
|
|
else if (type == "mediaOrder") {
|
|
|
|
|
// 미디어 순서를 저장할 배열
|
|
|
|
|
const mediaOrderList = [];
|
|
|
|
|
|
|
|
|
|
// 미디어의 인덱스 순서
|
|
|
|
|
const clipIndexOrder = xpath.select(ele, gmepXmlDoc);
|
2025-06-13 17:03:43 +09:00
|
|
|
|
2025-05-30 18:05:46 +09:00
|
|
|
clipIndexOrder.forEach((clipIndex) => {
|
|
|
|
|
CRClipIndex = parseInt(clipIndex.value, 10) + 1; // XPath는 1-based index를 사용
|
|
|
|
|
|
|
|
|
|
// 인덱스 순서에 따른 CRClip 요소의 Path를 찾기
|
|
|
|
|
const mediaPath = xpath.select1(`//CRClipArr/CRClip[${CRClipIndex}]/@Path`, gmepXmlDoc);
|
2025-06-13 17:03:43 +09:00
|
|
|
|
2025-05-30 18:05:46 +09:00
|
|
|
// 만약 CRClip 요소가 motion clip인 경우 CRCUnitArr의 Path를 찾기
|
|
|
|
|
if (mediaPath == null) {
|
|
|
|
|
const motionClipPath = xpath.select1(`//CRClipArr/CRClip[${CRClipIndex}]/CRCUnitArr/@Path`, gmepXmlDoc);
|
2025-06-30 17:04:10 +09:00
|
|
|
if (motionClipPath != null) {
|
2025-06-13 17:03:43 +09:00
|
|
|
const fileName = path.basename(motionClipPath.value);
|
|
|
|
|
mediaOrderList.push(fileName);
|
2025-02-07 17:33:38 +09:00
|
|
|
}
|
|
|
|
|
}
|
2025-05-30 18:05:46 +09:00
|
|
|
else if (mediaPath != null) {
|
2025-06-13 17:03:43 +09:00
|
|
|
const fileName = path.basename(mediaPath.value);
|
|
|
|
|
mediaOrderList.push(fileName);
|
2025-05-30 18:05:46 +09:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
const userAnswer = mediaOrderList;
|
2025-06-17 18:01:02 +09:00
|
|
|
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult, {
|
|
|
|
|
type: 'string[]'
|
|
|
|
|
});
|
2025-02-07 17:33:38 +09:00
|
|
|
}
|
2025-05-30 18:05:46 +09:00
|
|
|
|
|
|
|
|
else if (type == "startEnd") {
|
2025-06-18 17:58:12 +09:00
|
|
|
const crclipIndex = getCRClipIndex(media);
|
2025-06-13 17:03:43 +09:00
|
|
|
// 해당 미디어가 없을경우 clipIndex값 -1
|
2025-06-17 18:01:02 +09:00
|
|
|
if (crclipIndex == -1) {
|
|
|
|
|
userAnswer = null;
|
2025-02-07 17:33:38 +09:00
|
|
|
}
|
2025-05-30 18:05:46 +09:00
|
|
|
else {
|
2025-06-17 18:01:02 +09:00
|
|
|
//CRTrackList[@Name='비디오1']/CRTrackClip[@ClipIndex='동영상.mp4'] 요소를 찾음
|
|
|
|
|
const xpathExpr = ele?.replace(/{CRClipIndex}/g, crclipIndex);
|
|
|
|
|
const crTrackClip = xpath.select1(xpathExpr, gmepXmlDoc);
|
|
|
|
|
if (!crTrackClip) {
|
|
|
|
|
userAnswer = null;
|
2025-05-30 18:05:46 +09:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// CRTrackClip 요소의 Pos(시작시간)과 Length(재생길이)를 구함
|
2025-06-17 18:01:02 +09:00
|
|
|
const pos = xpath.select1('@Pos', crTrackClip);
|
|
|
|
|
const length = xpath.select1('@Length', crTrackClip);
|
2025-07-03 16:54:25 +09:00
|
|
|
|
|
|
|
|
userAnswer = {
|
|
|
|
|
start: pos.value,
|
|
|
|
|
end: length.value
|
|
|
|
|
}
|
2025-05-30 18:05:46 +09:00
|
|
|
}
|
|
|
|
|
}
|
2025-06-17 18:01:02 +09:00
|
|
|
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
|
2025-06-13 17:03:43 +09:00
|
|
|
}
|
2025-06-17 18:01:02 +09:00
|
|
|
|
|
|
|
|
// 동영상 클립 이펙트 [2-4]
|
|
|
|
|
// 이미지 클립 오버레이 [2-14, 17, 20]
|
|
|
|
|
else if (type == "effect" || type === "imageOverlay") {
|
2025-06-18 17:58:12 +09:00
|
|
|
const crclipIndex = getCRClipIndex(media);
|
2025-06-17 18:01:02 +09:00
|
|
|
// 해당 미디어가 없을경우 clipIndex값 -1
|
|
|
|
|
if (crclipIndex == -1) {
|
|
|
|
|
userAnswer = null;
|
2025-06-13 17:03:43 +09:00
|
|
|
}
|
|
|
|
|
else {
|
2025-06-17 18:01:02 +09:00
|
|
|
//CRTrackList[@Name='비디오1']/CRTrackClip[@ClipIndex='{CRClipIndex}']//CRFilter
|
|
|
|
|
const xpathExpr = ele?.replace(/{CRClipIndex}/g, crclipIndex);
|
|
|
|
|
const crFilter = xpath.select1(xpathExpr, gmepXmlDoc);
|
|
|
|
|
if (!crFilter) {
|
|
|
|
|
userAnswer = null;
|
2025-07-04 17:41:58 +09:00
|
|
|
// totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
|
2025-06-13 17:03:43 +09:00
|
|
|
}
|
|
|
|
|
else {
|
2025-06-17 18:01:02 +09:00
|
|
|
userAnswer = {}
|
|
|
|
|
const attributes = crFilter.attributes;
|
2025-06-13 17:03:43 +09:00
|
|
|
|
|
|
|
|
// rightAnswer의 key값을 순회하면서
|
|
|
|
|
// CRFilterNode의 속성명과 일치하는 값을 userAnswer에 저장
|
|
|
|
|
// for (const [keyName, expectedValue] of Object.keys(rightAnswer)) {
|
|
|
|
|
for (const keyName of Object.keys(rightAnswer)) {
|
|
|
|
|
const attr = attributes.getNamedItem(keyName);
|
|
|
|
|
userAnswer[keyName] = attr ? attr.value : null;
|
|
|
|
|
}
|
2025-07-04 17:41:58 +09:00
|
|
|
// totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
|
2025-06-13 17:03:43 +09:00
|
|
|
}
|
|
|
|
|
}
|
2025-07-04 17:41:58 +09:00
|
|
|
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
|
2025-06-13 17:03:43 +09:00
|
|
|
}
|
2025-05-30 18:05:46 +09:00
|
|
|
|
2025-06-17 18:01:02 +09:00
|
|
|
// 동영상 클립 트랜지션 [2-15, 18, 21]
|
|
|
|
|
else if (type === 'clipTransition') {
|
2025-06-18 17:58:12 +09:00
|
|
|
const crclipIndex = getCRClipIndex(media);
|
|
|
|
|
let crtrackClipIndex = getCRTrackClipIndex(crclipIndex, "비디오1");
|
2025-07-04 17:41:58 +09:00
|
|
|
let isMatched = false;
|
2025-06-17 18:01:02 +09:00
|
|
|
|
|
|
|
|
if (crtrackClipIndex == -1) {
|
|
|
|
|
userAnswer = null;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// 트랜지션 위치
|
|
|
|
|
// - 앞으로 이동 : Type = '1'
|
|
|
|
|
// - 뒤로 이동 : Type = '2'
|
|
|
|
|
// - 오버랩 : Type = '16'
|
|
|
|
|
// 트랜지션 위치가 오버랩 일 경우 ( Type 속성이 16인 경우 )
|
|
|
|
|
// 적용된 이미지(ClipIndex속성값은) 끝나는 지점의 이미지로 적용된다
|
|
|
|
|
if (rightAnswer['Type'] === '16') {
|
|
|
|
|
crtrackClipIndex += 1;
|
|
|
|
|
}
|
|
|
|
|
const xpathExpr = ele?.replace(/{CRTrackClipIndex}/g, crtrackClipIndex);
|
|
|
|
|
const crTransFilter = xpath.select(xpathExpr, gmepXmlDoc);
|
|
|
|
|
if (!crTransFilter) {
|
|
|
|
|
userAnswer = null;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
userAnswer = {};
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < crTransFilter.length; i++) {
|
|
|
|
|
const crTransFilterNode = crTransFilter[i];
|
|
|
|
|
const attributes = crTransFilterNode.attributes;
|
|
|
|
|
|
|
|
|
|
const idAttr = attributes.getNamedItem('ID');
|
|
|
|
|
const typeAttr = attributes.getNamedItem('Type');
|
|
|
|
|
const rangeAttr = attributes.getNamedItem('Range');
|
|
|
|
|
|
|
|
|
|
const userId = idAttr ? idAttr.value : null;
|
|
|
|
|
const userType = typeAttr ? typeAttr.value : null;
|
|
|
|
|
const userRange = rangeAttr ? rangeAttr.value : null;
|
|
|
|
|
|
|
|
|
|
userAnswer = {
|
|
|
|
|
ID: userId,
|
|
|
|
|
Range: userRange,
|
|
|
|
|
Type: userType,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ID와 Type은 같고, Range(재생시간 = 종료시간 - 시작시간)도 일치하는지 확인
|
|
|
|
|
if (
|
|
|
|
|
userId === rightAnswer.ID &&
|
|
|
|
|
userType === rightAnswer.Type &&
|
|
|
|
|
userRange &&
|
|
|
|
|
rightAnswer.Range
|
|
|
|
|
) {
|
|
|
|
|
const [start1, end1] = userRange.split(':').map(Number);
|
|
|
|
|
const [start2, end2] = rightAnswer.Range.split(':').map(Number);
|
|
|
|
|
|
|
|
|
|
const userPlayTime = end1 - start1;
|
|
|
|
|
const rightPlayTime = end2 - start2;
|
|
|
|
|
|
|
|
|
|
if (userPlayTime === rightPlayTime) {
|
|
|
|
|
isMatched = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-04 17:41:58 +09:00
|
|
|
// 일치하지 않으면 null 처리
|
|
|
|
|
if (!isMatched) {
|
|
|
|
|
// userAnswer = null;
|
|
|
|
|
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult, {
|
|
|
|
|
type: 'force-correct'
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-06-17 18:01:02 +09:00
|
|
|
}
|
2025-06-16 16:43:57 +09:00
|
|
|
|
2025-06-17 18:01:02 +09:00
|
|
|
else if (type == "Mute") {
|
2025-06-18 17:58:12 +09:00
|
|
|
const crclipIndex = getCRClipIndex(media);
|
2025-06-17 18:01:02 +09:00
|
|
|
if (crclipIndex == -1) {
|
|
|
|
|
userAnswer = null;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const xpathExpr = ele?.replace(/{CRClipIndex}/g, crclipIndex);
|
|
|
|
|
const muteStatus = xpath.select1(xpathExpr, gmepXmlDoc);
|
2025-06-30 17:04:10 +09:00
|
|
|
userAnswer = muteStatus?.value;
|
2025-06-16 16:43:57 +09:00
|
|
|
}
|
2025-06-17 18:01:02 +09:00
|
|
|
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
|
|
|
|
|
}
|
|
|
|
|
// 이미지 클립 길이 [2-13, 16, 19]
|
|
|
|
|
else if (type === 'imageLength') {
|
2025-06-18 17:58:12 +09:00
|
|
|
const crclipIndex = getCRClipIndex(media);
|
2025-06-17 18:01:02 +09:00
|
|
|
if (crclipIndex == -1) {
|
|
|
|
|
userAnswer = null;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const xpathExpr = ele?.replace(/{CRClipIndex}/g, crclipIndex);
|
|
|
|
|
const imageLength = xpath.select1(xpathExpr, gmepXmlDoc);
|
2025-07-04 17:41:58 +09:00
|
|
|
userAnswer = parseInt(imageLength?.value ?? '0', 10);
|
2025-06-17 18:01:02 +09:00
|
|
|
}
|
|
|
|
|
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
|
|
|
|
|
}
|
2025-06-16 16:43:57 +09:00
|
|
|
|
2025-06-18 17:58:12 +09:00
|
|
|
else if (type.includes('audio')) {
|
|
|
|
|
const crclipIndex = getCRClipIndex(media);
|
|
|
|
|
const crtrackClipIndex = getCRTrackClipIndex(crclipIndex, "오디오1")
|
|
|
|
|
const startTimeList = getStartTimeList('오디오1');
|
|
|
|
|
|
|
|
|
|
if (type.includes('StartTime')) {
|
|
|
|
|
const startTime = startTimeList[crtrackClipIndex];
|
|
|
|
|
userAnswer = startTime;
|
|
|
|
|
}
|
|
|
|
|
else if (type.includes('EndTime')) {
|
|
|
|
|
const xpathQuery = ele?.replace(/{CRClipIndex}/g, crclipIndex);
|
|
|
|
|
const crTrackClip = xpath.select1(xpathQuery, gmepXmlDoc);
|
|
|
|
|
if (!crTrackClip) {
|
|
|
|
|
userAnswer = null;
|
|
|
|
|
} else {
|
2025-06-30 17:04:10 +09:00
|
|
|
const length = crTrackClip.getAttribute('Length');
|
2025-07-04 17:41:58 +09:00
|
|
|
userAnswer = parseInt(length ?? '0', 10);
|
2025-06-18 17:58:12 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (type.includes('Effect')) {
|
|
|
|
|
const xpathQuery = ele?.replace(/{CRClipIndex}/g, crclipIndex);
|
|
|
|
|
const fadeoutEffect = xpath.select1(xpathQuery, gmepXmlDoc);
|
|
|
|
|
if (!fadeoutEffect) {
|
|
|
|
|
userAnswer = null;
|
2025-06-20 17:47:47 +09:00
|
|
|
}
|
2025-06-18 17:58:12 +09:00
|
|
|
else {
|
|
|
|
|
const attributes = fadeoutEffect.attributes;
|
|
|
|
|
const id = attributes.getNamedItem('ID').value;
|
2025-07-30 17:40:02 +09:00
|
|
|
const duration = attributes.getNamedItem('VID8')?.value;
|
2025-06-18 17:58:12 +09:00
|
|
|
|
|
|
|
|
userAnswer = {
|
|
|
|
|
"ID": id,
|
2025-07-30 17:40:02 +09:00
|
|
|
"Duration": duration,
|
2025-06-18 17:58:12 +09:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-17 18:01:02 +09:00
|
|
|
else if (type.includes('opening') || type.includes('video')) {
|
2025-06-13 17:03:43 +09:00
|
|
|
// 자막의 정보를 이용해 CROwneUnit의 인덱스를 구함
|
|
|
|
|
// 1. 텍스트
|
|
|
|
|
// 2. 순서
|
|
|
|
|
// 3. 시작시간
|
2025-06-16 16:43:57 +09:00
|
|
|
const indexByText = getClipIndexByText(search);
|
2025-06-13 17:03:43 +09:00
|
|
|
const indexByOrder = getClipIndexByOrder(subtitleOrder);
|
|
|
|
|
|
|
|
|
|
if (type.includes('opening')) time = openingStartTime;
|
|
|
|
|
else if (type.includes('video')) time = videoStartTime;
|
|
|
|
|
else time = null;
|
|
|
|
|
const indexByStartTime = getCilpIndexByStartTime(time);
|
|
|
|
|
|
|
|
|
|
// 1, 2, 3순으로 자막을 찾음
|
2025-06-20 17:47:47 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// 권수혁 김재은 27, 28, 29 문제 오답 0점 채점 안되는 부분 처리
|
|
|
|
|
// 06.18(목) 시작
|
|
|
|
|
|
|
|
|
|
|
2025-06-13 17:03:43 +09:00
|
|
|
const index = indexByText ?? indexByOrder ?? indexByStartTime;
|
|
|
|
|
if (index != null) {
|
2025-06-16 16:43:57 +09:00
|
|
|
// 자막 시작시간 [2-10] [2-28]
|
2025-06-17 18:01:02 +09:00
|
|
|
// <CRTrackClip> 요소들의 시작시간을 갖고 있는 startTimeList를 구하고
|
|
|
|
|
// 해당 인덱스의 자막 시작시간을 구함
|
2025-06-13 17:03:43 +09:00
|
|
|
if (type.includes('StartTime')) {
|
2025-06-18 17:58:12 +09:00
|
|
|
const crtrackClipIndex = getCRTrackClipIndex(index, "텍스트")
|
|
|
|
|
const startTimeList = getStartTimeList('텍스트');
|
2025-06-13 17:03:43 +09:00
|
|
|
const startTime = startTimeList[crtrackClipIndex];
|
2025-06-16 16:43:57 +09:00
|
|
|
|
2025-06-13 17:03:43 +09:00
|
|
|
userAnswer = startTime;
|
2025-06-16 16:43:57 +09:00
|
|
|
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
|
2025-06-13 17:03:43 +09:00
|
|
|
}
|
2025-06-16 16:43:57 +09:00
|
|
|
// 자막 길이 [2-11] [2-29]
|
2025-06-17 18:01:02 +09:00
|
|
|
// <CRTrackClip> 요소의 Length 속성을 구함
|
2025-06-13 17:03:43 +09:00
|
|
|
else if (type.includes('Length')) {
|
2025-06-18 17:58:12 +09:00
|
|
|
const crtrackClipIndex = getCRTrackClipIndex(index, "텍스트") + 1 // XML 1-based index
|
2025-06-13 17:03:43 +09:00
|
|
|
const clipLength = xpath.select1(`//CRTrackList[@Name='텍스트' or @Name='비디오2']/CRTrackClip[${crtrackClipIndex}]/@Length`, gmepXmlDoc);
|
2025-05-30 18:05:46 +09:00
|
|
|
|
2025-07-04 17:41:58 +09:00
|
|
|
userAnswer = parseInt(clipLength?.value ?? '0', 10);
|
2025-06-16 16:43:57 +09:00
|
|
|
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
|
|
|
|
|
}
|
|
|
|
|
// 자막 텍스트(글자, 폰트, 크기, 색상) [2-5, 6, 7, 8] [2-22, 23, 24, 25]
|
2025-06-18 17:58:12 +09:00
|
|
|
else if (type.includes('Text')) {
|
2025-06-16 16:43:57 +09:00
|
|
|
const xmlIndex = index + 1 // XML 1-based index
|
|
|
|
|
const subtitleXpath = ele?.replace(/{index}/g, xmlIndex);
|
|
|
|
|
const subtitleResult = xpath.select1(subtitleXpath, gmepXmlDoc);
|
|
|
|
|
|
|
|
|
|
if (subtitleResult) {
|
|
|
|
|
if (type.includes('Color')) {
|
|
|
|
|
const hex = convertColorToHex(subtitleResult.value);
|
|
|
|
|
userAnswer = hex;
|
|
|
|
|
}
|
2025-06-18 17:58:12 +09:00
|
|
|
else if (type.includes('Outline')) {
|
|
|
|
|
const attributes = subtitleResult.attributes;
|
|
|
|
|
const width = Math.round(parseFloat(attributes.getNamedItem('VID100').value * 100)).toString();
|
|
|
|
|
const color = convertColorToHex(attributes.getNamedItem('VID101').value);
|
|
|
|
|
|
|
|
|
|
userAnswer = {
|
|
|
|
|
"width": width,
|
|
|
|
|
"color": color,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else if (type.includes('FadeInEffect')) {
|
|
|
|
|
const attributes = subtitleResult.attributes;
|
2025-07-03 16:54:25 +09:00
|
|
|
const VID505 = attributes.getNamedItem('VID505').value;
|
|
|
|
|
const VID507 = attributes.getNamedItem('VID507').value;
|
2025-06-18 17:58:12 +09:00
|
|
|
|
|
|
|
|
userAnswer = {
|
2025-07-03 16:54:25 +09:00
|
|
|
"VID505": VID505,
|
|
|
|
|
"VID507": VID507,
|
2025-06-18 17:58:12 +09:00
|
|
|
};
|
|
|
|
|
}
|
2025-06-16 16:43:57 +09:00
|
|
|
else {
|
|
|
|
|
userAnswer = subtitleResult.value;
|
|
|
|
|
}
|
2025-06-18 17:58:12 +09:00
|
|
|
}
|
|
|
|
|
else {
|
2025-06-16 16:43:57 +09:00
|
|
|
userAnswer = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 자막 위치 [2-9] (화면 정가운데 아래)
|
|
|
|
|
// 정답 좌표를 기준으로
|
|
|
|
|
else if (type.includes('Location')) {
|
|
|
|
|
const xmlIndex = index + 1 // XML 1-based index
|
|
|
|
|
const subtitleXpath = ele?.replace(/{index}/g, xmlIndex);
|
|
|
|
|
const subtitleResult = xpath.select(subtitleXpath, gmepXmlDoc);
|
|
|
|
|
|
|
|
|
|
userAnswer = subtitleResult.map(r => r.value);
|
|
|
|
|
const errorRange = 0.1;
|
|
|
|
|
|
2025-06-18 17:58:12 +09:00
|
|
|
// userAnswer가 정수형 배열인 경우 type을 'number[]'로 설정
|
2025-06-17 18:01:02 +09:00
|
|
|
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult, {
|
|
|
|
|
tolerance: errorRange,
|
|
|
|
|
type: 'number[]',
|
|
|
|
|
});
|
2025-06-13 17:03:43 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
userAnswer = null;
|
2025-06-20 17:47:47 +09:00
|
|
|
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
|
2025-06-13 17:03:43 +09:00
|
|
|
}
|
|
|
|
|
}
|
2025-06-16 16:43:57 +09:00
|
|
|
|
2025-02-07 17:33:38 +09:00
|
|
|
|
2025-03-17 18:51:45 +09:00
|
|
|
}
|
2025-02-07 17:33:38 +09:00
|
|
|
scoringResult['총점'] = totalScore;
|
|
|
|
|
return scoringResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// psdData를 scoring.json 파일 내에 있는 ele 요소의 jsonpath로 접근하여 요소를 탐색하고 나오는 값을 value와 비교하여 점수를 계산
|
|
|
|
|
// 학생 별로 psdData는 2개씩 있으므로 PSD 파일 1번과 2번에 대해서 채점
|
|
|
|
|
// scoring.json 파일에 있는 항목 수만큼 점수를 계산
|
|
|
|
|
// scoring.json 파일의 1번째 배열은 PSD 파일 1번에 대한 점수 계산
|
|
|
|
|
// scoring.json 파일의 2번째 배열은 PSD 파일 2번에 대한 점수 계산
|
|
|
|
|
// 채점 결과를 scoringResultList 배열에 저장
|
|
|
|
|
function getScore(psdData, scoring, index) {
|
|
|
|
|
const psdTree = psdData[index].tree().export();
|
|
|
|
|
const jsonData = JSON.stringify(psdTree, null, 2);
|
|
|
|
|
// console.log(jsonData);
|
|
|
|
|
const scoringResult = {};
|
|
|
|
|
|
|
|
|
|
const scoringData = scoring[index];
|
|
|
|
|
let totalScore = 0;
|
|
|
|
|
for (const key in scoringData) {
|
|
|
|
|
const ele = scoringData[key].ele;
|
|
|
|
|
const value = scoringData[key].value;
|
|
|
|
|
const point = scoringData[key].point;
|
|
|
|
|
const type = scoringData[key].type;
|
|
|
|
|
|
|
|
|
|
if (ele === 'none') {
|
|
|
|
|
scoringResult[key] = "확인필요";
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const result = jsonPath.query(psdTree, ele);
|
|
|
|
|
console.log(`ele: ${ele}, value: ${value} result: ${result}`);
|
|
|
|
|
if (result.length == 0) {
|
|
|
|
|
scoringResult[key] = 0;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2025-04-04 17:28:05 +09:00
|
|
|
if (type == "size") {
|
2025-03-17 18:51:45 +09:00
|
|
|
// console.log(`result ${result.length}`);
|
2025-04-07 17:18:13 +09:00
|
|
|
if (result[0].height == value['height'] && result[0].width == value['width']) {
|
2025-04-04 17:28:05 +09:00
|
|
|
scoringResult[key] = point;
|
|
|
|
|
totalScore += point;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
scoringResult[key] = 0;
|
|
|
|
|
}
|
2025-02-07 17:33:38 +09:00
|
|
|
}
|
|
|
|
|
// value가 color code인 경우 R,G,B를 16진수로 변환하여 비교하고 같다면 점수 부여
|
|
|
|
|
// value: "ffa200"
|
|
|
|
|
// result: [255,162,0,255]
|
|
|
|
|
// 255,162,0,255 -> ffa200
|
|
|
|
|
else if (type == "color") {
|
2025-03-17 18:51:45 +09:00
|
|
|
// console.log(`result ${result}`); // result 255,162,0,255
|
2025-02-07 17:33:38 +09:00
|
|
|
const temp = result[0].slice(0, 3).join(','); // 255,162,0
|
2025-03-17 18:51:45 +09:00
|
|
|
|
2025-02-15 17:00:21 +09:00
|
|
|
// RGB의 각 색상값이 한자리수 일 경우 0을 채워 두자리로 만듬
|
|
|
|
|
color = temp.split(',').map(v => parseInt(v).toString(16).padStart(2, '0')).join(''); // ffa200
|
2025-02-07 17:33:38 +09:00
|
|
|
// ffa20 -> ffa200
|
2025-02-15 17:00:21 +09:00
|
|
|
// if (color.length == 5) {
|
|
|
|
|
// color = color + '0';
|
|
|
|
|
// }
|
2025-02-07 17:33:38 +09:00
|
|
|
|
2025-03-17 18:51:45 +09:00
|
|
|
// console.log(`color: ${color}`);
|
2025-04-07 17:18:13 +09:00
|
|
|
if (color === value) {
|
2025-04-04 17:28:05 +09:00
|
|
|
scoringResult[key] = point;
|
|
|
|
|
totalScore += point;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
scoringResult[key] = 0;
|
|
|
|
|
}
|
2025-02-07 17:33:38 +09:00
|
|
|
}
|
|
|
|
|
// type이 font인 경우 font의 이름만 추출하여 비교
|
|
|
|
|
// value: "Arial"
|
|
|
|
|
// result: ["Arial-BoldItalicMT"]
|
|
|
|
|
else if (type == "font") {
|
|
|
|
|
const font = result[0].split('-')[0];
|
2025-04-03 17:40:52 +09:00
|
|
|
// console.log(`result ${result}`);
|
2025-03-17 18:51:45 +09:00
|
|
|
// console.log(`font: ${font}`);
|
2025-02-07 17:33:38 +09:00
|
|
|
|
2025-04-07 17:18:13 +09:00
|
|
|
if (font === value) {
|
2025-04-04 17:28:05 +09:00
|
|
|
scoringResult[key] = point;
|
|
|
|
|
totalScore += point;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
scoringResult[key] = 0;
|
|
|
|
|
}
|
|
|
|
|
// font가 여러개일 경우
|
|
|
|
|
// scoringResult[key] = result.length > 0 && value === font ? point : 0;
|
|
|
|
|
}
|
2025-02-07 17:33:38 +09:00
|
|
|
else if (result[0] === value) {
|
|
|
|
|
scoringResult[key] = point;
|
|
|
|
|
totalScore += point;
|
|
|
|
|
} else {
|
|
|
|
|
scoringResult[key] = 0;
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(`Error processing JSONPath query for ele: ${ele}`, error);
|
|
|
|
|
scoringResult[key] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scoringResult['총점'] = totalScore;
|
|
|
|
|
return scoringResult;
|
2025-03-17 18:51:45 +09:00
|
|
|
}
|
2025-04-08 16:11:38 +09:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* scoringResultList 배열을 엑셀에 출력하기 위한 데이터 정리 함수
|
|
|
|
|
* @param {Array} scoringResultList - 학생별 채점 결과 리스트
|
|
|
|
|
* @returns {Array} - 엑셀에 출력할 데이터 배열
|
|
|
|
|
*/
|
|
|
|
|
function prepareExcelData(scoringResultList) {
|
|
|
|
|
return scoringResultList.map(student => {
|
|
|
|
|
// const flattened = { "학생": student["0"] }; // 학생 이름을 첫 번째 열로 설정
|
|
|
|
|
const flattened = { "문항": student["0"] }; // 행열을 변환 할 경우 첫 행의 제목을 "문항"으로 설정
|
|
|
|
|
|
|
|
|
|
// 제외할 키와 서브키 정의
|
|
|
|
|
const exceptKeys = [
|
|
|
|
|
"0", // 학생 이름 제외
|
|
|
|
|
// "1", // psd1
|
|
|
|
|
// "2", // psd2
|
|
|
|
|
];
|
|
|
|
|
const exceptSubkeys = ["videoStartTime", "openingStartTime"]; // 제외할 서브키
|
|
|
|
|
|
|
|
|
|
// 학생 데이터 순회
|
|
|
|
|
Object.keys(student).forEach(key => {
|
|
|
|
|
if (exceptKeys.includes(key)) {
|
|
|
|
|
return; // 제외할 키는 건너뜀
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 서브키 순회
|
|
|
|
|
if (typeof student[key] === "object") {
|
|
|
|
|
Object.keys(student[key]).forEach(subKey => {
|
|
|
|
|
if (exceptSubkeys.includes(subKey)) {
|
|
|
|
|
return; // 제외할 서브키는 건너뜀
|
|
|
|
|
}
|
|
|
|
|
flattened[`${key}-${subKey}`] = student[key][subKey];
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// 서브키가 없는 경우
|
|
|
|
|
flattened[key] = student[key];
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return flattened;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-11 15:14:28 +09:00
|
|
|
// 데이터 행렬 변환
|
2025-04-08 16:11:38 +09:00
|
|
|
function transposeData(data) {
|
|
|
|
|
// 데이터가 없으면 빈 배열 반환
|
|
|
|
|
if (data.length === 0) return [];
|
|
|
|
|
|
|
|
|
|
// 첫 번째 객체의 키(열 제목) 가져오기
|
|
|
|
|
const keys = Object.keys(data[0]);
|
|
|
|
|
|
|
|
|
|
// 행과 열을 변환
|
|
|
|
|
const transposed = keys.map(key => {
|
|
|
|
|
const row = { "항목": key }; // 각 열 제목을 "항목"으로 설정
|
|
|
|
|
data.forEach((item, index) => {
|
|
|
|
|
//console.log(data[index]['문항']);
|
|
|
|
|
row[data[index]['문항']] = item[key]; // 각 학생의 데이터를 열로 추가
|
|
|
|
|
});
|
|
|
|
|
return row;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return transposed;
|
|
|
|
|
}
|
|
|
|
|
|