곰픽 JSON 채점기준표, 소스코드 수정

This commit is contained in:
2025-04-14 17:33:42 +09:00
parent 9158b42941
commit 547cd05a8b
6 changed files with 107 additions and 75 deletions

View File

@@ -97,9 +97,11 @@ function getGpdpScore(gpdpData, scoringJson, index) {
const layer = scoringData[key].layer;
const option = scoringData[key].option;
const style = scoringData[key].style;
ele = typeof ele === 'string' ? ele.replace(/{layer}/g, layer) : ele;
ele = typeof ele === 'string' ? ele.replace(/{option}/g, option) : ele;
ele = typeof ele === 'string' ? ele.replace(/{style}/g, style) : ele;
if (search !== undefined) {
let result = findSimilarString(gpdpXmlDoc, search, 0.8)
@@ -118,7 +120,7 @@ function getGpdpScore(gpdpData, scoringJson, index) {
// if (type == "effects") {
// // Layer/Effects/Item요소를 가져옴
// const items = xpath.select(ele, gpdpXmlDoc);
// // let isRight = false;
// // 각 Item 요소별 이름과 속성값을 구하고 정답과 비교
// items.forEach((item) => {
@@ -138,19 +140,32 @@ function getGpdpScore(gpdpData, scoringJson, index) {
// }
// });
// }
if (type == "boolean") {
const items = xpath.select(ele, gpdpXmlDoc);
// xpath 결과값을 반환하는 요소가 있을 경우
if (items) {
totalScore += point;
scoringResult[key] = point;
console.log("✅ 찾는 요소 존재함");
}
else {
scoringResult[key] = 0;
console.log("❌ 찾는 요소 없음");
}
}
// 이펙트 효과의 이름과 속성값을 비교
if (type == "effects") {
else if (type == "effects") {
const items = xpath.select(ele, gpdpXmlDoc);
let matched = false;
// 각 Item 요소별 이름과 속성값을 구하고 정답과 비교
for (const item of items) {
const name = xpath.select1('Name/@value', item)?.value;
const value = xpath.select1(`EffectData/${option?.replace(/"/g, '')}/@value`, item)?.value;
const resultArray = [name, value];
if (JSON.stringify(resultArray) === JSON.stringify(rightAnswer)) {
totalScore += point;
scoringResult[key] = point;
@@ -159,7 +174,7 @@ function getGpdpScore(gpdpData, scoringJson, index) {
break;
}
}
if (!matched) {
scoringResult[key] = 0;
console.log("❌ 정답 없음:", rightAnswer);
@@ -198,13 +213,13 @@ function getGpdpScore(gpdpData, scoringJson, index) {
}
}
}
else if (type == "isExist") {
else if (type == "exists") {
const result = xpath.select(ele, gpdpXmlDoc);
const isMatch = result.some(v => {
if (v.value === rightAnswer) {
totalScore += point;
scoringResult[key] = point;
console.log("🚀 ~ result.forEach ~ 정답 일치:", rightAnswer)
console.log(`✅ 정답 일치 > [작성답안]:${v.value} [정답]:${rightAnswer}`);
return true;
}
return false;
@@ -212,7 +227,7 @@ function getGpdpScore(gpdpData, scoringJson, index) {
if (!isMatch) {
scoringResult[key] = 0;
console.log("🚀 ~ result.forEach ~ 오답:", rightAnswer)
console.log(`❌ 정답 없음 > [정답]:${rightAnswer}`);
}
}
@@ -231,24 +246,29 @@ function getGpdpScore(gpdpData, scoringJson, index) {
console.log('ele not matched, ' + result[0].value);
}
}
else if (type == "color") {
let result = xpath.select(ele, gpdpXmlDoc);
if (result.length == 0) {
scoringResult[key] = 0;
console.log('ele not found');
continue;
}
const hexColor = parseColorToHex(result[0].value);
if (hexColor === rightAnswer) {
totalScore += point;
scoringResult[key] = point;
console.log('color matched, ' + hexColor);
} else {
else if (type === "color") {
const items = xpath.select(ele, gpdpXmlDoc);
let matched = false;
for (const item of items) {
const color = parseColorToHex(item.value);
// console.log("🚀 ~ getGpdpScore ~ color:", color);
// console.log("🚀 ~ getGpdpScore ~ rightColor:", rightAnswer);
if (color === rightAnswer) {
totalScore += point;
scoringResult[key] = point;
matched = true;
console.log(`✅ 정답 일치 > [작성답안]:${color} [정답]:${rightAnswer}`);
break;
}
}
if (!matched) {
scoringResult[key] = 0;
console.log('color not matched, ' + hexColor);
console.log(`❌ 정답 없음 > [정답]:${rightAnswer}`);
}
}
else if (type == "multi") {
try {
const result = xpath.select(ele, gpdpXmlDoc);
@@ -308,7 +328,7 @@ function getGpdpScore(gpdpData, scoringJson, index) {
const width = Math.round(Math.abs(x2 - x1));
const height = Math.round(Math.abs(y2 - y1));
if ( width === rightAnswer["width"] && height === rightAnswer["height"]) {
if (width === rightAnswer["width"] && height === rightAnswer["height"]) {
totalScore += point;
scoringResult[key] = point;
matched = true;
@@ -327,13 +347,13 @@ function getGpdpScore(gpdpData, scoringJson, index) {
const endColorXpath = scoringData[key].endColor;
let matched = false;
for ( const item of items) {
for (const item of items) {
const startColor = parseColorToHex(xpath.select1(startColorXpath, item)?.value);
const endColor = parseColorToHex(xpath.select1(endColorXpath, item)?.value);
console.log(startColor + ":" + rightAnswer["startColor"], endColor + ":" + rightAnswer["endColor"]);
if ( startColor === rightAnswer["startColor"] && endColor === rightAnswer["endColor"]) {
if (startColor === rightAnswer["startColor"] && endColor === rightAnswer["endColor"]) {
totalScore += point;
scoringResult[key] = point;
matched = true;