곰픽 문제1 채점 수정완료

This commit is contained in:
2025-06-23 16:37:20 +09:00
parent 6f5d1c20f7
commit afe8b02625
2 changed files with 78 additions and 93 deletions

View File

@@ -278,9 +278,69 @@ function getGpdpScore(gpdpData, scoringJson, index) {
}
// [1-6] 세피아
else if (type === "sepia.Exists") {
// [1-6][1-7]
else if (type === "exists") {
const existsValues = xpath.select(ele, gpdpXmlDoc);
for (const v of existsValues) {
if (v.value === rightAnswer) {
userAnswer = v.value;
break;
}
}
totalScore = compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
}
else if (type === "shape.size") {
const items = xpath.select(ele, gpdpXmlDoc);
// 각 Item 요소별 x,y 좌표 시작점과 끝점의 거리를 계산해 정답과 비교
for (const item of items) {
const x1 = Number(xpath.select1('Item[1]/X/@value', item)?.value);
const x2 = Number(xpath.select1('Item[last()]/X/@value', item)?.value);
const y1 = Number(xpath.select1('Item[1]/Y/@value', item)?.value);
const y2 = Number(xpath.select1('Item[last()]/Y/@value', item)?.value);
const width = Math.round(Math.abs(x2 - x1));
const height = Math.round(Math.abs(y2 - y1));
userAnswer = {
width: width,
height: height,
};
}
totalScore = compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
}
// [1-8]
else if (type === "shape.color") {
const items = xpath.select(ele, gpdpXmlDoc);
for (const item of items) {
const color = parseColorToHex(item.value);
userAnswer = color;
}
const normalizedRA = rightAnswer.toLowerCase?.();
totalScore = compareAndScore(userAnswer, normalizedRA, point, key, scoringResult);
}
else if (type === 'layer.blend.opacity') {
const layers = xpath.select(ele, gpdpXmlDoc);
for (const layer of layers) {
const blendop = xpath.select1('BlendOp/@value', layer).value;
const opacity = xpath.select1('Opacity/@value', layer).value;
userAnswer = {
BlendOp: blendop,
Opacity: opacity,
}
}
totalScore = compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
}
else if (type == "boolean") {
const items = xpath.select(ele, gpdpXmlDoc);
@@ -354,28 +414,6 @@ function getGpdpScore(gpdpData, scoringJson, index) {
}
}
}
else if (type == "exists") {
const result = xpath.select(ele, gpdpXmlDoc);
const isMatch = result.some(v => {
// 문자열 앞뒤 공백 제거
v.value = typeof v.value === 'string' ? v.value.trim() : v.value
rightAnswer = typeof rightAnswer === 'string' ? rightAnswer.trim() : rightAnswer
if (v.value === rightAnswer) {
totalScore += point;
scoringResult[key] = point;
console.log(`✅ 정답 일치 > [작성답안]:${v.value} [정답]:${rightAnswer}`);
return true;
}
return false;
});
if (!isMatch) {
scoringResult[key] = 0;
console.log(`❌ 정답 없음 > [정답]:${rightAnswer}`);
}
}
else if (type == "exact") {
let result = xpath.select(ele, gpdpXmlDoc);
@@ -393,27 +431,6 @@ function getGpdpScore(gpdpData, scoringJson, index) {
}
}
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(`❌ 정답 없음 > [정답]:${rightAnswer}`);
}
}
else if (type == "multi") {
try {
@@ -460,33 +477,6 @@ function getGpdpScore(gpdpData, scoringJson, index) {
scoringResult[key] = 0;
}
}
else if (type == "size") {
const items = xpath.select(ele, gpdpXmlDoc);
let matched = false;
// 각 Item 요소별 x,y 좌표 시작점과 끝점의 거리를 계산해 정답과 비교
for (const item of items) {
const x1 = Number(xpath.select1('Item[1]/X/@value', item)?.value);
const x2 = Number(xpath.select1('Item[last()]/X/@value', item)?.value);
const y1 = Number(xpath.select1('Item[1]/Y/@value', item)?.value);
const y2 = Number(xpath.select1('Item[last()]/Y/@value', item)?.value);
const width = Math.round(Math.abs(x2 - x1));
const height = Math.round(Math.abs(y2 - y1));
if (width === rightAnswer["width"] && height === rightAnswer["height"]) {
totalScore += point;
scoringResult[key] = point;
matched = true;
console.log("✅ 정답 일치:", rightAnswer);
break;
}
}
if (!matched) {
scoringResult[key] = 0;
console.log("❌ 정답 없음:", rightAnswer);
}
}
else if (type == "gradient") {
const items = xpath.select(ele, gpdpXmlDoc);
const startColorXpath = scoringData[key].startColor;
@@ -553,11 +543,6 @@ function getGpdpScore(gpdpData, scoringJson, index) {
const result2 = null;
let isCheck = false;
if (ele === 'none') {
scoringResult[key] = "확인필요";
continue;
}
if (result.length == 0) {
isCheck = true;
}