곰픽 채점 기준 수정버전

This commit is contained in:
2025-06-30 17:04:10 +09:00
parent 9aa1425d81
commit db5176bc75
8 changed files with 2607 additions and 2652 deletions

View File

@@ -192,29 +192,157 @@ function getGpdpScore(gpdpData, scoringJson, index) {
}
// []
else if (type === "layer.Exists") {
const layerNameList = xpath.select(ele, gpdpXmlDoc);
const layerNames = layerNameList.map(layer => layer.value);
let isMatched = false
// else if (type === "layer.exists") {
// const layerNameList = xpath.select(ele, gpdpXmlDoc);
// const layerNames = layerNameList.map(layer => layer.value);
// let isMatched = false
// for (const layerName of layerNames) {
// if (layerName.trim().toLowerCase() === rightAnswer.trim().toLowerCase()) {
// userAnswer = layerName;
// isMatched = true;
// break;
// }
// }
// let result = findSimilarString(gpdpXmlDoc, rightAnswer, 0.8);
// if (result !== null) {
// userAnswer = result;
// isMatched = true;
// }
// if (isMatched) {
// totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
// }
// if (isMatched) {
// totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult, {
// type: 'force-correct'
// });
// }
// else {
// totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
// }
// }
let result = findSimilarString(gpdpXmlDoc, rightAnswer, 0.8);
if (result !== null) {
userAnswer = result;
isMatched = true;
// [1-4] 사진1 > 조정
else if (type === "layer.Effects") {
const effects = xpath.select(ele, gpdpXmlDoc);
let isMatched = false;
for (const item of effects) {
const name = xpath.select1('Name/@value', item)?.value;
const effectData = xpath.select1(`EffectData`, item);
// 동일한 이펙트 요소만 검사
if (rightAnswer['name'] !== name) {
continue;
}
userAnswer = {
name: name,
option: {},
}
if (name === '흑백') {
const Intensity = xpath.select1('Intensity/@value', effectData)?.value;
const optionKeys = Object.keys(rightAnswer['option']);
if (optionKeys.includes('강도')) userAnswer['option']['강도'] = Intensity;
}
else if (name === '밝기/대비') {
const brightness = xpath.select1('brightness/@value', effectData)?.value;
const contrast = xpath.select1('contrast/@value', effectData)?.value;
const optionKeys = Object.keys(rightAnswer['option']);
if (optionKeys.includes('밝기')) userAnswer['option']['밝기'] = brightness;
if (optionKeys.includes('대비')) userAnswer['option']['대비'] = contrast;
}
else if (name === '노출') {
const ExposureValue = xpath.select1('ExposureValue/@value', effectData)?.value;
const optionKeys = Object.keys(rightAnswer['option']);
if (optionKeys.includes('노출')) userAnswer['option']['노출'] = ExposureValue;
}
else if (name === '색조/채도') {
const hue = xpath.select1('hue/@value', effectData)?.value;
const saturation = xpath.select1('saturation/@value', effectData)?.value;
const lightness = xpath.select1('lightness/@value', effectData)?.value;
const optionKeys = Object.keys(rightAnswer['option']);
if (optionKeys.includes('색조')) userAnswer['option']['색조'] = hue;
if (optionKeys.includes('채도')) userAnswer['option']['채도'] = saturation;
if (optionKeys.includes('명도')) userAnswer['option']['명도'] = lightness;
}
else if (name === '감마') {
const lift = xpath.select1('Lift/@value', effectData)?.value;
const gamma = xpath.select1('Gamma/@value', effectData)?.value;
const gain = xpath.select1('Gain/@value', effectData)?.value;
const optionKeys = Object.keys(rightAnswer['option']);
if (optionKeys.includes('리프트')) userAnswer['option']['리프트'] = lift;
if (optionKeys.includes('감마')) userAnswer['option']['감마'] = gamma;
if (optionKeys.includes('게인')) userAnswer['option']['게인'] = gain;
}
else if (name === '세피아') {
const u = xpath.select1('U/@value', effectData)?.value;
const v = xpath.select1('V/@value', effectData)?.value;
const optionKeys = Object.keys(rightAnswer['option']).map(key => key.toUpperCase());
if (optionKeys.includes('U')) userAnswer['option']['U'] = u;
if (optionKeys.includes('V')) userAnswer['option']['V'] = v;
}
else if (name === '생동감') {
const vibranceValue = xpath.select1('VibranceValue/@value', effectData)?.value;
// 생동감 옵션값이 프로그램에서 적용한 값에 오차가 발생하는 경우가 있음
// 곰픽>XML / 30>29 / 40>39
// 설정한 값 그대로 적용되는 경우도 있어서 오차범위 2로 설정
const userValue = parseInt(vibranceValue, 10);
const rightValue = parseInt(rightAnswer.option['생동감'], 10);
if (Math.abs(rightValue - userValue) <= 2) {
const optionKeys = Object.keys(rightAnswer['option']);
if (optionKeys.includes('생동감')) {
userAnswer['option']['생동감'] = rightValue.toString();
}
}
}
for (const key in rightAnswer.option) {
// 속성값이 정답과 다른 경우가 있으면 오답처리
if (rightAnswer.option[key] !== userAnswer.option[key]) {
isMatched = false;
break;
}
else {
isMatched = true;
}
}
// 속성값이 하나라도 일치하지 않으면 오답
if (isMatched === false) {
break;
}
}
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
continue;
}
//
// else if (type === "exists") {
else if (type.includes("exists")) {
const existsValues = xpath.select(ele, gpdpXmlDoc);
let isMatched = false;
for (const v of existsValues) {
userAnswer = v.value;
if (type.includes('layer') || type.includes('text')) {
// 공백, 대소문자 무시
const cleanUserAnswer = userAnswer.replace(/\s+/g, '').toLowerCase();
const cleanRightAnswer = rightAnswer.replace(/\s+/g, '').toLowerCase();
// 하나라도 일치하면 정답
if (cleanUserAnswer === cleanRightAnswer) {
isMatched = true;
break;
}
}
else {
if (userAnswer === rightAnswer) {
isMatched = true;
break;
}
}
}
if (isMatched) {
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult, {
type: 'force-correct'
@@ -223,506 +351,383 @@ function getGpdpScore(gpdpData, scoringJson, index) {
else {
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
}
}
// [1-4] 사진1 > 조정
else if (type === "layer.Effects") {
const effects = xpath.select(ele, gpdpXmlDoc);
let isMatched = false;
for (const item of effects) {
const name = xpath.select1('Name/@value', item)?.value;
const effectData = xpath.select1(`EffectData`, item);
// else if (type === "shape.size") {
else if (type.includes("size")) {
const items = xpath.select(ele, gpdpXmlDoc);
let isMatched = false;
// 동일한 이펙트 요소만 검사
if (rightAnswer['name'] !== name) {
continue;
// 각 Item 요소별 x,y 좌표 시작점과 끝점의 거리를 계산해 정답과 비교
for (const item of items) {
const x1 = Number(xpath.select1('Item[1]/X/@value', item)?.value);
const y1 = Number(xpath.select1('Item[1]/Y/@value', item)?.value);
const x2 = Number(xpath.select1('Item[last()]/X/@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,
};
// 하나라도 일치하면 정답
if (JSON.stringify(userAnswer) == JSON.stringify(rightAnswer)) {
isMatched = true;
break;
}
}
userAnswer = {
name: name,
option: {},
}
if (name === '흑백') {
const Intensity = xpath.select1('Intensity/@value', effectData)?.value;
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
continue;
}
const optionKeys = Object.keys(rightAnswer['option']);
if (optionKeys.includes('강도')) userAnswer['option']['강도'] = Intensity;
}
else if (name === '밝기/대비') {
const brightness = xpath.select1('brightness/@value', effectData)?.value;
const contrast = xpath.select1('contrast/@value', effectData)?.value;
// [1-8]
else if (type.includes("color")) {
const items = xpath.select(ele, gpdpXmlDoc);
let normalizedAnswer = null;
let isMatched = false;
const optionKeys = Object.keys(rightAnswer['option']);
if (optionKeys.includes('밝기')) userAnswer['option']['밝기'] = brightness;
if (optionKeys.includes('대비')) userAnswer['option']['대비'] = contrast;
}
else if (name === '노출') {
const ExposureValue = xpath.select1('ExposureValue/@value', effectData)?.value;
for (const item of items) {
if (type.includes('gradient')) {
const startColorXpath = scoringData[key].startColor;
const endColorXpath = scoringData[key].endColor;
const optionKeys = Object.keys(rightAnswer['option']);
if (optionKeys.includes('노출')) userAnswer['option']['노출'] = ExposureValue;
}
else if (name === '색조/채도') {
const hue = xpath.select1('hue/@value', effectData)?.value;
const saturation = xpath.select1('saturation/@value', effectData)?.value;
const lightness = xpath.select1('lightness/@value', effectData)?.value;
const startColorRGB = xpath.select1(startColorXpath, item).value;
const endColorRGB = xpath.select1(endColorXpath, item).value;
const optionKeys = Object.keys(rightAnswer['option']);
if (optionKeys.includes('색조')) userAnswer['option']['색조'] = hue;
if (optionKeys.includes('채도')) userAnswer['option']['채도'] = saturation;
if (optionKeys.includes('명도')) userAnswer['option']['명도'] = lightness;
}
else if (name === '감마') {
const lift = xpath.select1('Lift/@value', effectData)?.value;
const gamma = xpath.select1('Gamma/@value', effectData)?.value;
const gain = xpath.select1('Gain/@value', effectData)?.value;
const startColor = parseColorToHex(startColorRGB);
const endColor = parseColorToHex(endColorRGB);
const optionKeys = Object.keys(rightAnswer['option']);
if (optionKeys.includes('리프트')) userAnswer['option']['리프트'] = lift;
if (optionKeys.includes('감마')) userAnswer['option']['감마'] = gamma;
if (optionKeys.includes('게인')) userAnswer['option']['게인'] = gain;
}
else if (name === '세피아') {
const u = xpath.select1('U/@value', effectData)?.value;
const v = xpath.select1('V/@value', effectData)?.value;
userAnswer = {
startColor: startColor,
endColor: endColor,
}
const optionKeys = Object.keys(rightAnswer['option']).map(key => key.toUpperCase());
if (optionKeys.includes('U')) userAnswer['option']['U'] = u;
if (optionKeys.includes('V')) userAnswer['option']['V'] = v;
}
else if (name === '생동감') {
const vibranceValue = xpath.select1('VibranceValue/@value', effectData)?.value;
// 생동감 옵션값이 프로그램에서 적용한 값에 오차가 발생하는 경우가 있음
// 곰픽>XML / 30>29 / 40>39
// 설정한 값 그대로 적용되는 경우도 있어서 오차범위 2로 설정
const userValue = parseInt(vibranceValue, 10);
const rightValue = parseInt(rightAnswer.option['생동감'], 10);
// JSON파일에서 대문자로 입력된 경우 소문자로 변환
normalizedAnswer = {
startColor: rightAnswer.startColor.toLowerCase(),
endColor: rightAnswer.endColor.toLowerCase(),
}
if (Math.abs(rightValue - userValue) <= 2) {
const optionKeys = Object.keys(rightAnswer['option']);
if (optionKeys.includes('생동감')) {
userAnswer['option']['생동감'] = rightValue.toString();
// 하나라도 일치하면 정답
if (JSON.stringify(userAnswer) == JSON.stringify(normalizedAnswer)) {
isMatched = true;
break;
}
}
// else {
else if (type.includes('shape') || type.includes('text') || type.includes('clipping')) {
const color = parseColorToHex(item.value);
userAnswer = color;
normalizedAnswer = rightAnswer.toLowerCase?.();
// 하나라도 일치하면 정답
if (userAnswer === normalizedAnswer) {
isMatched = true;
break;
}
}
}
totalScore += compareAndScore(userAnswer, normalizedAnswer, point, key, scoringResult);
}
for (const key in rightAnswer.option) {
// 속성값이 정답과 다른 경우가 있으면 오답처리
if (rightAnswer.option[key] !== userAnswer.option[key]) {
isMatched = false;
else if (type === 'layer.blend.opacity') {
const layers = xpath.select(ele, gpdpXmlDoc);
let isMatched = false;
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,
}
// 하나라도 일치하면 정답
if (JSON.stringify(userAnswer) == JSON.stringify(rightAnswer)) {
isMatched = true;
break;
}
}
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
continue;
}
// [5-20]
else if (type === 'shadow') {
const shapes = xpath.select(ele, gpdpXmlDoc);
for (const shape of shapes) {
// 그림자 설정 여부
const shadowExists = xpath.select1('contains(draw_type/@value, "Shadow")', shape);
// Shadow 옵션이 있다면
if (shadowExists) {
// 두께
const width = xpath.select1('shadow_width/@value', shape).value;
// 거리
const distance = xpath.select1('shadow_distance/@value', shape).value;
// 분산도
const blur = xpath.select1('shadow_blur/@value', shape).value;
// 각도
const angle = xpath.select1('shadow_angle/@value', shape).value;
userAnswer = {
shadow: shadowExists,
width: width,
distance: distance,
blur: blur,
angle: angle,
}
}
else {
isMatched = true;
userAnswer = {
shadow: shadowExists,
width: null,
distance: null,
blur: null,
angle: null,
}
}
}
// 속성값이 하나라도 일치하지 않으면 오답
if (isMatched === false) {
break;
}
// console.log("🚀 ~ userAnswer:", userAnswer);
// console.log("🚀 ~ rightAnswer : ", rightAnswer)
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult, {
partial: true
})
continue;
}
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
continue;
}
//
else if (type === "exists") {
const existsValues = xpath.select(ele, gpdpXmlDoc);
let isMatched = false;
else if (type == "boolean") {
const items = xpath.select(ele, gpdpXmlDoc);
for (const v of existsValues) {
// 하나라도 일치하면 정답
if (v.value === rightAnswer) {
userAnswer = v.value;
isMatched = true;
break;
// xpath 결과값을 반환하는 요소가 없을 경우
if (!items) {
scoringResult[key] = 0;
console.log("❌ 찾는 요소 없음");
}
}
// if (isMatched) {
// }
// else {
// }
totalScore = compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
}
// else if (type === "shape.size") {
else if (type.includes("size")) {
const items = xpath.select(ele, gpdpXmlDoc);
let isMatched = false;
// 각 Item 요소별 x,y 좌표 시작점과 끝점의 거리를 계산해 정답과 비교
for (const item of items) {
const x1 = Number(xpath.select1('Item[1]/X/@value', item)?.value);
const y1 = Number(xpath.select1('Item[1]/Y/@value', item)?.value);
const x2 = Number(xpath.select1('Item[last()]/X/@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,
};
// 하나라도 일치하면 정답
if (JSON.stringify(userAnswer) == JSON.stringify(rightAnswer)) {
isMatched = true;
break;
else {
totalScore += point;
scoringResult[key] = point;
console.log("✅ 찾는 요소 존재함");
}
}
totalScore = compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
continue;
}
// 이펙트 효과의 이름과 속성값을 비교
else if (type == "effects") {
const items = xpath.select(ele, gpdpXmlDoc);
let matched = false;
// [1-8]
else if (type.includes("color")) {
const items = xpath.select(ele, gpdpXmlDoc);
let normalizedAnswer = null;
let isMatched = false;
// 각 Item 요소별 이름과 속성값을 구하고 정답과 비교
for (const item of items) {
const name = xpath.select1('Name/@value', item)?.value;
const attr = xpath.select1(`EffectData/${option?.replace(/"/g, '')}/@value`, item)?.value;
for (const item of items) {
if (type.includes('gradient')) {
const startColorXpath = scoringData[key].startColor;
const endColorXpath = scoringData[key].endColor;
const startColorRGB = xpath.select1(startColorXpath, item).value;
const endColorRGB = xpath.select1(endColorXpath, item).value;
const startColor = parseColorToHex(startColorRGB);
const endColor = parseColorToHex(endColorRGB);
userAnswer = {
startColor: startColor,
endColor: endColor,
}
// JSON파일에서 대문자로 입력된 경우 소문자로 변환
normalizedAnswer = {
startColor: rightAnswer.startColor.toLowerCase(),
endColor: rightAnswer.endColor.toLowerCase(),
}
// 하나라도 일치하면 정답
if (JSON.stringify(userAnswer) == JSON.stringify(normalizedAnswer)) {
isMatched = true;
if (name === rightAnswer[0] && attr === rightAnswer[1]) {
totalScore += point;
scoringResult[key] = point;
matched = true;
console.log("✅ 정답 일치:", rightAnswer);
break;
}
}
// else if (type.includes('shape') || type.includes('text') || type.includes('clipping')) {
else {
const color = parseColorToHex(item.value);
userAnswer = color;
normalizedAnswer = rightAnswer.toLowerCase?.();
if (!matched) {
scoringResult[key] = 0;
console.log("❌ 정답 없음:", rightAnswer);
}
}
// 하나라도 일치하면 정답
if (userAnswer === normalizedAnswer) {
isMatched = true;
break;
else if (type == "multiValue") {
if (Array.isArray(rightAnswer)) {
const result = ele ? xpath.select(ele, gpdpXmlDoc) : [];
const resultValues = Array.isArray(result) ? result.map(r => (typeof r === 'object' ? r.value : r)) : [result];
console.log("🚀 ~ getGpdpScore ~ resultValues:", resultValues)
const groupSize = rightAnswer.length;
const groupedResult = [];
for (let i = 0; i < resultValues.length; i += groupSize) {
groupedResult.push(resultValues.slice(i, i + groupSize));
}
console.log("🚀 ~ getGpdpScore ~ groupedResult:", groupedResult)
// 배열 비교 함수
function arraysEqual(arr1, arr2) {
if (arr1.length !== arr2.length) return false;
return arr1.every((value, index) => value === arr2[index]);
}
// groupedResult 내부 배열에서 rightAnswer와 일치하는 배열이 있는지 확인
const isMatch = groupedResult.some(group => arraysEqual(group, rightAnswer));
if (isMatch) {
totalScore += point;
scoringResult[key] = point;
console.log("🚀 ~ 정답 포함");
} else {
scoringResult[key] = 0;
console.log("🚀 ~ 오답");
}
}
}
totalScore = compareAndScore(userAnswer, normalizedAnswer, point, key, scoringResult);
}
else if (type === 'layer.blend.opacity') {
const layers = xpath.select(ele, gpdpXmlDoc);
let isMatched = false;
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,
else if (type == "exact") {
let result = xpath.select(ele, gpdpXmlDoc);
if (result.length == 0) {
scoringResult[key] = 0;
console.log('ele not found');
continue;
}
// 하나라도 일치하면 정답
if (JSON.stringify(userAnswer) == JSON.stringify(rightAnswer)) {
isMatched = true;
break;
}
}
totalScore = compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
continue;
}
// [5-20]
else if (type === 'shadow') {
const shapes = xpath.select(ele, gpdpXmlDoc);
for (const shape of shapes) {
// 그림자 설정 여부
const shadowExists = xpath.select1('contains(draw_type/@value, "Shadow")', shape);
// Shadow 옵션이 있다면
if (shadowExists) {
// 두께
const width = xpath.select1('shadow_width/@value', shape).value;
// 거리
const distance = xpath.select1('shadow_distance/@value', shape).value;
// 분산도
const blur = xpath.select1('shadow_blur/@value', shape).value;
// 각도
const angle = xpath.select1('shadow_angle/@value', shape).value;
userAnswer = {
shadow: shadowExists,
width: width,
distance: distance,
blur: blur,
angle: angle,
}
}
else {
userAnswer = {
shadow: shadowExists,
width: null,
distance: null,
blur: null,
angle: null,
}
}
}
console.log("🚀 ~ userAnswer:", userAnswer);
console.log("🚀 ~ rightAnswer : ", rightAnswer)
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult, {
partial: true
})
continue;
}
else if (type == "boolean") {
const items = xpath.select(ele, gpdpXmlDoc);
// xpath 결과값을 반환하는 요소가 없을 경우
if (!items) {
scoringResult[key] = 0;
console.log("❌ 찾는 요소 없음");
}
else {
totalScore += point;
scoringResult[key] = point;
console.log("✅ 찾는 요소 존재함");
}
}
// 이펙트 효과의 이름과 속성값을 비교
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 attr = xpath.select1(`EffectData/${option?.replace(/"/g, '')}/@value`, item)?.value;
if (name === rightAnswer[0] && attr === rightAnswer[1]) {
if (result[0].value === rightAnswer) {
totalScore += point;
scoringResult[key] = point;
matched = true;
console.log("✅ 정답 일치:", rightAnswer);
break;
}
}
if (!matched) {
scoringResult[key] = 0;
console.log("❌ 정답 없음:", rightAnswer);
}
}
else if (type == "multiValue") {
if (Array.isArray(rightAnswer)) {
const result = ele ? xpath.select(ele, gpdpXmlDoc) : [];
const resultValues = Array.isArray(result) ? result.map(r => (typeof r === 'object' ? r.value : r)) : [result];
console.log("🚀 ~ getGpdpScore ~ resultValues:", resultValues)
const groupSize = rightAnswer.length;
const groupedResult = [];
for (let i = 0; i < resultValues.length; i += groupSize) {
groupedResult.push(resultValues.slice(i, i + groupSize));
}
console.log("🚀 ~ getGpdpScore ~ groupedResult:", groupedResult)
// 배열 비교 함수
function arraysEqual(arr1, arr2) {
if (arr1.length !== arr2.length) return false;
return arr1.every((value, index) => value === arr2[index]);
}
// groupedResult 내부 배열에서 rightAnswer와 일치하는 배열이 있는지 확인
const isMatch = groupedResult.some(group => arraysEqual(group, rightAnswer));
if (isMatch) {
totalScore += point;
scoringResult[key] = point;
console.log("🚀 ~ 정답 포함");
} else {
scoringResult[key] = 0;
console.log("🚀 ~ 오답");
console.log('ele not matched, ' + result[0].value);
}
}
}
else if (type == "exact") {
let result = xpath.select(ele, gpdpXmlDoc);
if (result.length == 0) {
scoringResult[key] = 0;
console.log('ele not found');
continue;
else if (type == "multi") {
try {
const result = xpath.select(ele, gpdpXmlDoc);
let isSame = true;
// console.log(`ele: ${ele}, value: ${value} result: ${result}`);
if (result.length == 0) {
console.log('result length 0');
scoringResult[key] = 0;
continue;
}
result.forEach((v, i) => {
// value[i] 값이 정수형인 경우에는 float로 변환하여 비교
// 정수형 v값을 float 형으로 변환하고 소수점 3자리까지 버림
let temp = v.value;
let answer = rightAnswer[i];
if (Number.isFinite(rightAnswer[i]) && !Number.isInteger(rightAnswer[i])) {
temp = parseFloat(v.value);
answer = parseFloat(rightAnswer[i]);
// 소수점 3자리까지 버림
temp = Math.floor(temp * 1000) / 1000;
}
// answer 문자열 중 : 가 포함되어 있다면 각각 분리하고 그 값의 차이를 구함
if (typeof answer == "string" && answer.indexOf(':') > -1) {
const [answerStart, answerEnd] = answer.split(':').map(Number);
const [tempStart, tempEnd] = temp.split(':').map(Number);
answer = answerEnd - answerStart;
temp = tempEnd - tempStart;
}
console.log(`temp: ${temp} answer: ${answer}`);
if (answer !== temp) {
console.log(`answer !== temp`);
isSame = false;
}
});
totalScore += isSame ? point : 0;
scoringResult[key] = isSame ? point : 0;
} catch (e) {
console.log('err :', e);
scoringResult[key] = 0;
}
}
if (result[0].value === rightAnswer) {
totalScore += point;
scoringResult[key] = point;
} else {
scoringResult[key] = 0;
console.log('ele not matched, ' + result[0].value);
else if (type == "gradient") {
const items = xpath.select(ele, gpdpXmlDoc);
const startColorXpath = scoringData[key].startColor;
const endColorXpath = scoringData[key].endColor;
let matched = false;
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"]) {
totalScore += point;
scoringResult[key] = point;
matched = true;
console.log("✅ 정답 일치:", rightAnswer);
break;
}
}
if (!matched) {
scoringResult[key] = 0;
console.log("❌ 정답 없음:", rightAnswer);
}
}
}
// 그림자 속성이 있는지 여부 파악해서 그림자 속성 별로 점수 1 점씩 부여
else if (type == "shadow") {
const result = xpath.select(ele["shadow"], gpdpXmlDoc);
let shadowScore = 0;
if (result.length == 0) {
scoringResult[key] = 0;
console.log('shadow not found');
continue;
}
else if (type == "multi") {
try {
shadowScore += 1;
const width = xpath.select(ele["width"], gpdpXmlDoc);
const distance = xpath.select(ele["distance"], gpdpXmlDoc);
const blur = xpath.select(ele["blur"], gpdpXmlDoc);
const angle = xpath.select(ele["angle"], gpdpXmlDoc);
if (width.length !== 0 && width[0].value == rightAnswer["width"]) {
shadowScore += 1;
console.log('width matched');
}
if (distance.length !== 0 && distance[0].value == rightAnswer["distance"]) {
shadowScore += 1;
console.log('distance matched');
}
if (blur.length !== 0 && blur[0].value == rightAnswer["blur"]) {
shadowScore += 1;
console.log('blur matched');
}
if (angle.length !== 0 && angle[0].value == rightAnswer["angle"]) {
shadowScore += 1;
console.log('angle matched');
}
totalScore += shadowScore;
scoringResult[key] = shadowScore;
}
else {
const result = xpath.select(ele, gpdpXmlDoc);
let isSame = true;
// console.log(`ele: ${ele}, value: ${value} result: ${result}`);
const result2 = null;
let isCheck = false;
if (result.length == 0) {
console.log('result length 0');
scoringResult[key] = 0;
continue;
isCheck = true;
}
if (isCheck && ele2) {
result2 = xpath.select(ele2, gpdpXmlDoc);
result.forEach((v, i) => {
// value[i] 값이 정수형인 경우에는 float로 변환하여 비교
// 정수형 v값을 float 형으로 변환하고 소수점 3자리까지 버림
let temp = v.value;
let answer = rightAnswer[i];
if (Number.isFinite(rightAnswer[i]) && !Number.isInteger(rightAnswer[i])) {
temp = parseFloat(v.value);
answer = parseFloat(rightAnswer[i]);
// 소수점 3자리까지 버림
temp = Math.floor(temp * 1000) / 1000;
if (result2.length == 0) {
scoringResult[key] = 0;
continue;
}
// answer 문자열 중 : 가 포함되어 있다면 각각 분리하고 그 값의 차이를 구함
if (typeof answer == "string" && answer.indexOf(':') > -1) {
const [answerStart, answerEnd] = answer.split(':').map(Number);
const [tempStart, tempEnd] = temp.split(':').map(Number);
answer = answerEnd - answerStart;
temp = tempEnd - tempStart;
}
console.log(`temp: ${temp} answer: ${answer}`);
if (answer !== temp) {
console.log(`answer !== temp`);
isSame = false;
}
});
totalScore += isSame ? point : 0;
scoringResult[key] = isSame ? point : 0;
} catch (e) {
console.log('err :', e);
scoringResult[key] = 0;
}
}
else if (type == "gradient") {
const items = xpath.select(ele, gpdpXmlDoc);
const startColorXpath = scoringData[key].startColor;
const endColorXpath = scoringData[key].endColor;
let matched = false;
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"]) {
totalScore += point;
scoringResult[key] = point;
matched = true;
console.log("✅ 정답 일치:", rightAnswer);
break;
result = result2;
// console.log(`1st isChecked: ${isCheck}, result: ${result}`)
}
}
if (!matched) {
scoringResult[key] = 0;
console.log("❌ 정답 없음:", rightAnswer);
// value와 result[0].value를 비교하여 같으면 점수 point 부여
// console.log(`${(value === result[0].value)}, ${result.length > 0 && value === result[0].value} `)
// console.log(`2nd isChecked: ${isCheck}, result: ${result}`)
totalScore += result.length > 0 ? point : 0;
scoringResult[key] = result.length > 0 ? point : 0;
}
}
// 그림자 속성이 있는지 여부 파악해서 그림자 속성 별로 점수 1 점씩 부여
else if (type == "shadow") {
const result = xpath.select(ele["shadow"], gpdpXmlDoc);
let shadowScore = 0;
if (result.length == 0) {
scoringResult[key] = 0;
console.log('shadow not found');
continue;
}
shadowScore += 1;
const width = xpath.select(ele["width"], gpdpXmlDoc);
const distance = xpath.select(ele["distance"], gpdpXmlDoc);
const blur = xpath.select(ele["blur"], gpdpXmlDoc);
const angle = xpath.select(ele["angle"], gpdpXmlDoc);
if (width.length !== 0 && width[0].value == rightAnswer["width"]) {
shadowScore += 1;
console.log('width matched');
}
if (distance.length !== 0 && distance[0].value == rightAnswer["distance"]) {
shadowScore += 1;
console.log('distance matched');
}
if (blur.length !== 0 && blur[0].value == rightAnswer["blur"]) {
shadowScore += 1;
console.log('blur matched');
}
if (angle.length !== 0 && angle[0].value == rightAnswer["angle"]) {
shadowScore += 1;
console.log('angle matched');
}
totalScore += shadowScore;
scoringResult[key] = shadowScore;
}
else {
const result = xpath.select(ele, gpdpXmlDoc);
const result2 = null;
let isCheck = false;
if (result.length == 0) {
isCheck = true;
}
if (isCheck && ele2) {
result2 = xpath.select(ele2, gpdpXmlDoc);
if (result2.length == 0) {
scoringResult[key] = 0;
continue;
}
result = result2;
// console.log(`1st isChecked: ${isCheck}, result: ${result}`)
}
// value와 result[0].value를 비교하여 같으면 점수 point 부여
// console.log(`${(value === result[0].value)}, ${result.length > 0 && value === result[0].value} `)
// console.log(`2nd isChecked: ${isCheck}, result: ${result}`)
totalScore += result.length > 0 ? point : 0;
scoringResult[key] = result.length > 0 ? point : 0;
}
}
scoringResult['총점'] = totalScore;
return scoringResult;
scoringResult['총점'] = totalScore;
return scoringResult;
}