곰믹스 자막관련 문항 코드/채점기준표(json) 수정
This commit is contained in:
122
psdExport_2.js
122
psdExport_2.js
@@ -36,7 +36,7 @@ const answerFilesDir = './output/C/TEST';
|
||||
// --------------------------------------------------------
|
||||
// const outputExcelFile = './'+todayDate+'_DIC_2502A_채점결과.xlsx';
|
||||
// const outputExcelFile = './'+todayDate+'_DIC_2502B_채점결과.xlsx';
|
||||
// const outputExcelFile = './'+todayDate+'_DIC_2502C_채점결과.xlsx';
|
||||
// const outputExcelFile = './' + todayDate + '_DIC_2502C_채점결과.xlsx';
|
||||
// const outputExcelFile = './'+todayDate+'_DIC_2502D_채점결과.xlsx';
|
||||
|
||||
// TEST
|
||||
@@ -102,14 +102,29 @@ studentDirs.forEach(student => {
|
||||
|
||||
// Flatten the resultData for better representation in Excel
|
||||
const flattenedData = scoringResultList.map(student => {
|
||||
const name = student["0"]
|
||||
const name = student["0"];
|
||||
const flattened = { "학생": student["0"] };
|
||||
|
||||
// excel에 표시하지 않을 key값들
|
||||
const exceptKeys = [
|
||||
"0", // 학생 이름 항상 제외
|
||||
"1", // 1번 PSD 파일 채점 결과
|
||||
"2", // 2번 PSD 파일 채점 결과
|
||||
]
|
||||
const exceptSubkeys = [
|
||||
"videoStartTime",
|
||||
"openingStartTime",
|
||||
];
|
||||
Object.keys(student).forEach(key => {
|
||||
if (key !== "0") {
|
||||
Object.keys(student[key]).forEach(subKey => {
|
||||
flattened[`${key}_${subKey}`] = student[key][subKey];
|
||||
});
|
||||
if (exceptKeys.includes(key)) {
|
||||
return;
|
||||
}
|
||||
Object.keys(student[key]).forEach(subKey => {
|
||||
if (exceptSubkeys.includes(subKey)) {
|
||||
return;
|
||||
}
|
||||
flattened[`${key}_${subKey}`] = student[key][subKey];
|
||||
});
|
||||
});
|
||||
return flattened;
|
||||
});
|
||||
@@ -130,15 +145,15 @@ console.log('채점 결과가 ' + outputExcelFile + ' 파일에 저장되었습
|
||||
* 자막 태그의 인덱스를 구할 때 사용
|
||||
* 1. CRTrackClip 요소의 순서에 따라 그 요소에 해당하는 CROwneUnit 태그의 순서를 구함
|
||||
* 2. CRTrackClip 요소의 시작시간에 따라 그 요소에 해당하는 CROwneUnit 태그의 순서를 구함
|
||||
* @returns subtitle index
|
||||
* @returns video index
|
||||
*
|
||||
*/
|
||||
function getTrackClipNode(xmlDoc, type, subtitleStartTime, openingStartTime) {
|
||||
function getTrackClipNode(xmlDoc, type, videoStartTime, openingStartTime) {
|
||||
let trackClipNode = null;
|
||||
|
||||
// 동영상 자막이면 2, 오프닝 자막이면 1, 그 외는 0
|
||||
const subtitleOrder = type === 'subtitle' ? 2 : type === 'opening' ? 1 : 0;
|
||||
const startTime = type === 'subtitle' ? subtitleStartTime : openingStartTime;
|
||||
const subtitleOrder = type === 'video' ? 2 : type === 'opening' ? 1 : 0;
|
||||
const startTime = type === 'video' ? videoStartTime : openingStartTime;
|
||||
|
||||
// xpath 구문을 통해 CRTrackClip 요소의 ClipIndex를 찾음
|
||||
const trackClipNode1 = xpath.select1(`//CRTrackList[@Name="텍스트"]/CRTrackClip[not(@ClipIndex='-1')][${subtitleOrder}]`, xmlDoc);
|
||||
@@ -172,15 +187,14 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
const point = scoringData[key].point;
|
||||
const type = scoringData[key].type;
|
||||
const search = scoringData[key].search;
|
||||
const subtitleStartTime = scoringData.subtitleStartTime;
|
||||
const videoStartTime = scoringData.videoStartTime;
|
||||
const openingStartTime = scoringData.openingStartTime;
|
||||
|
||||
// xpath 전처리
|
||||
const trackClipNode = getTrackClipNode(gmepXmlDoc, type, subtitleStartTime,
|
||||
openingStartTime);
|
||||
const trackClipNode = getTrackClipNode(gmepXmlDoc, type, videoStartTime, openingStartTime);
|
||||
const subtitleIndex = trackClipNode ? parseInt(trackClipNode.getAttribute('ClipIndex'), 10) + 1 : null;
|
||||
const subtitleOrder = type === 'subtitle' ? 2 : type === 'opening' ? 1 : null;
|
||||
const startTime = type === 'subtitle' ? subtitleStartTime
|
||||
const subtitleOrder = type === 'video' ? 2 : type === 'opening' ? 1 : null;
|
||||
const startTime = type === 'video' ? videoStartTime
|
||||
: type === 'opening' ? openingStartTime : null;
|
||||
|
||||
[ele, ele2] = [ele, ele2].map(e => e?.replace(/{subtitleIndex}/g, subtitleIndex));
|
||||
@@ -193,7 +207,7 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
// search 값이 undefined 아니면 ele의 {search}부분을 search로 치환
|
||||
/**
|
||||
* JSON파일 곰믹스 5번문항/22번 문항
|
||||
* type : "subtitle" 인 항목들
|
||||
* type : "video" 인 항목들
|
||||
* GPString태그 VID7속성 찾는 xpath구문
|
||||
* CRCUnitArr태그 Name속성 찾는 구문으로 변환
|
||||
* > 멀티라인 텍스트 유사도 판별하기 어려움
|
||||
@@ -294,7 +308,7 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
totalScore += posNode.value === start && lengthNode.value === end ? point : 0;
|
||||
|
||||
}
|
||||
// else if (type == "subtitle") {
|
||||
// else if (type == "video") {
|
||||
// const result = xpath.select(ele, gmepXmlDoc);
|
||||
// const length = scoringData[key].length;
|
||||
|
||||
@@ -321,51 +335,6 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
scoringResult[key] = result.length > 0 && rightAnswer === result[0].value ? point : 0;
|
||||
|
||||
}
|
||||
|
||||
// [3-9]문제 : 자막 '화면 정가운데 아래'
|
||||
// 자막의 글자 갯수, 글자 크기, 폰트에 따라 위치가 유동적으로 바뀌어서
|
||||
// 예상되는 최소 좌표부터 최대 좌표를 미리 입력하고 (JSON파일 start/end 속성)
|
||||
// 수험자가 입력한 자막의 좌표값이 범위 안에 들어가면 정답으로 채점
|
||||
else if (type == "range") {
|
||||
const start = scoringData[key].start;
|
||||
const end = scoringData[key].end;
|
||||
|
||||
try {
|
||||
let result = xpath.select(ele, gmepXmlDoc);
|
||||
if (!result) {
|
||||
result = xpath.select(ele2, gmepXmlDoc);
|
||||
if (!result) {
|
||||
scoringResult[key] = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 수험자 답안 자막 좌표 (x,y)
|
||||
const x = parseFloat(result[0]?.value);
|
||||
const y = parseFloat(result[1]?.value);
|
||||
// 최소 좌표 (x1, y1)
|
||||
const x1 = parseFloat(start[0]);
|
||||
const y1 = parseFloat(start[1]);
|
||||
// 최대 좌표 (x2, y2)
|
||||
const x2 = parseFloat(end[0]);
|
||||
const y2 = parseFloat(end[1]);
|
||||
|
||||
// (x1,y1) <= (x,y) <= (x2,y2) 이면 true
|
||||
const isPointInRange = (x, y, x1, y1, x2, y2) =>
|
||||
(x >= x1 && x <= x2) && (y >= y1 && y <= y2);
|
||||
|
||||
if (isPointInRange(x, y, x1, y1, x2, y2) === true) {
|
||||
totalScore += point;
|
||||
scoringResult[key] = point;
|
||||
}
|
||||
else
|
||||
scoringResult[key] = 0;
|
||||
}
|
||||
catch (e) {
|
||||
console.log('err :', e);
|
||||
scoringResult[key] = 0;
|
||||
}
|
||||
}
|
||||
else if (type == "multi") {
|
||||
try {
|
||||
const result = xpath.select(ele, gmepXmlDoc);
|
||||
@@ -464,19 +433,28 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
* 시작시간이 170이 아닌 경우 false값이 반환되고 0으로 인식되어
|
||||
* //CROwneUnit[0]/CRCUnitArr/@Name 의 값이 반환됨
|
||||
****************************************************************/
|
||||
else if (type == "subtitle" || type == "opening") {
|
||||
|
||||
// 문제의 타입이 video(동영상자막) 또는 opening(오프닝자막)일 경우
|
||||
else if (type == "video" || type == "opening") {
|
||||
const result = ele ? xpath.select(ele, gmepXmlDoc) : [];
|
||||
const result2 = ele2 ? xpath.select(ele2, gmepXmlDoc) : [];
|
||||
const result3 = ele3 ? xpath.select(ele3, gmepXmlDoc) : [];
|
||||
|
||||
const resultValues = Array.isArray(result) ? result.map(r => (typeof r === 'object' ? r.value : r)) : [result];
|
||||
const resultValues2 = Array.isArray(result2) ? result2.map(r => (typeof r === 'object' ? r.value : r)) : [result2];
|
||||
const resultValues3 = Array.isArray(result3) ? result3.map(r => (typeof r === 'object' ? r.value : r)) : [result3];
|
||||
// 결과값이 배열이 아닌 경우 배열로 변환
|
||||
// 예시) (2-9)는 xpath를 통해 클립(자막) 시작시간(number자료형)을 반환받으므로 배열로 변환하여 비교
|
||||
const resultValues = Array.isArray(result) ?
|
||||
result.map(r => (typeof r === 'object' ? r.value : r)) : [result];
|
||||
const resultValues2 = Array.isArray(result2) ?
|
||||
result2.map(r => (typeof r === 'object' ? r.value : r)) : [result2];
|
||||
const resultValues3 = Array.isArray(result3) ?
|
||||
result3.map(r => (typeof r === 'object' ? r.value : r)) : [result3];
|
||||
|
||||
// 결과값들을 하나의 배열로 합침
|
||||
const allResults = [...[resultValues], ...[resultValues2], ...[resultValues3]];
|
||||
console.log("🚀 ~ allResults:", allResults)
|
||||
|
||||
// rightAnswer가 배열일 경우 배열로 변환
|
||||
// 정답(rightAnswer)의 값이 단일값이 아닐 경우 값 비교를 위해 단일 배열로 변환
|
||||
// (2-11) 자막의 위치 좌표값 비교를 위해 [x, y] 값을 가져오므로 배열로 변환하여 비교
|
||||
const rightAnswerArray = Array.isArray(rightAnswer) ? rightAnswer : [rightAnswer];
|
||||
|
||||
// 결과값이 범위값인 경우 소수점 3자리까지 비교
|
||||
@@ -484,8 +462,12 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
// result의 길이가 1이상인 조건은 result값이 [x, y] 좌표값인 경우를 말한다
|
||||
if (Array.isArray(result) && result.length > 1) {
|
||||
return result.map(r => {
|
||||
if (typeof r === 'string') {
|
||||
return (Math.floor(parseFloat(r) * 1000) / 1000).toFixed(3);
|
||||
// xml파일에 저장된 곰믹스 좌표값 소수점 3자리 아래 버리는 형식이므로
|
||||
// 동일하게 결과값 소수점 3자리 아래 버린 후 반환
|
||||
const parsedValue = parseFloat(r);
|
||||
if (parsedValue >= 0 && parsedValue < 1) {
|
||||
// 소수점 3자리 아래 버림
|
||||
return (Math.floor(parsedValue * 1000) / 1000).toFixed(3);
|
||||
}
|
||||
return r;
|
||||
});
|
||||
@@ -523,7 +505,7 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
scoringResult[key] = 0;
|
||||
}
|
||||
}
|
||||
// else if (type == "subtitle" || type == "opening") {
|
||||
// else if (type == "video" || type == "opening") {
|
||||
// const result = ele && xpath.select(ele, gmepXmlDoc);
|
||||
// const result2 = ele2 && xpath.select(ele2, gmepXmlDoc);
|
||||
// const result3 = ele3 && xpath.select(ele3, gmepXmlDoc);
|
||||
|
||||
Reference in New Issue
Block a user