곰픽 채점 수정버전 진행중 [1-6]
This commit is contained in:
224
gpdpScoring.js
224
gpdpScoring.js
@@ -42,6 +42,54 @@ module.exports = getGpdpScore;
|
||||
// scoring.json 파일 내에 있는 type에 따라 비교하는 방식이 달라짐
|
||||
// 채점 결과를 scoringResultList 배열에 저장
|
||||
function getGpdpScore(gpdpData, scoringJson, index) {
|
||||
function compareAndScore(user, right, point, key, scoringResult, options = {}) {
|
||||
let score = 0;
|
||||
let isEqual = false;
|
||||
|
||||
const {
|
||||
tolerance = 0, // 숫자 비교 시 허용 오차
|
||||
type = 'auto', // 'auto' | 'number[]' | 'string[]' | 'object' | 'primitive'
|
||||
} = options;
|
||||
|
||||
if (type === 'force-correct') {
|
||||
isEqual = true;
|
||||
}
|
||||
else if (Array.isArray(right) && Array.isArray(user)) {
|
||||
if (right.length === user.length) {
|
||||
if
|
||||
(type === 'number[]' ||
|
||||
(type === 'auto' && typeof right[0] === 'number')) {
|
||||
isEqual = right.every((val, idx) => Math.abs(val - user[idx]) <= tolerance);
|
||||
}
|
||||
else if
|
||||
(type === 'string[]' ||
|
||||
(type === 'auto' && typeof right[0] === 'string')) {
|
||||
isEqual = right.every((val, idx) => val === user[idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if
|
||||
(type === 'object' ||
|
||||
(type === 'auto' && typeof right === 'object' && typeof user === 'object')) {
|
||||
isEqual = JSON.stringify(user) === JSON.stringify(right);
|
||||
}
|
||||
else {
|
||||
isEqual = user == right; // primitive 비교
|
||||
}
|
||||
|
||||
if (isEqual) {
|
||||
score = point;
|
||||
console.log('작성답안: ', user);
|
||||
console.log('>⭕ 정답: ', right);
|
||||
} else {
|
||||
console.log('작성답안: ', user);
|
||||
console.log('>❌ 오답: ', right);
|
||||
}
|
||||
|
||||
scoringResult[key] = score;
|
||||
// totalScore += score;
|
||||
return score;
|
||||
}
|
||||
const gpdpXmlDoc = gpdpData;
|
||||
const scoringResult = {};
|
||||
|
||||
@@ -64,11 +112,13 @@ function getGpdpScore(gpdpData, scoringJson, index) {
|
||||
let ele = scoringData[key].ele;
|
||||
let ele2 = scoringData[key].ele2;
|
||||
let existEle = scoringData[key].existEle;
|
||||
let rightAnswer = scoringData[key].value;
|
||||
let point = scoringData[key].point;
|
||||
let type = scoringData[key].type;
|
||||
const rightAnswer = scoringData[key].value;
|
||||
const point = scoringData[key].point;
|
||||
const type = scoringData[key].type;
|
||||
let search = scoringData[key].search;
|
||||
|
||||
let userAnswer = null;
|
||||
|
||||
const layer = scoringData[key].layer;
|
||||
const option = scoringData[key].option;
|
||||
const style = scoringData[key].style;
|
||||
@@ -88,33 +138,151 @@ function getGpdpScore(gpdpData, scoringJson, index) {
|
||||
existEle = existEle.replace(/{search}/g, result);
|
||||
}
|
||||
}
|
||||
console.log(`example number: ${key}`)
|
||||
console.log("🚀 ~ getGpdpScore ~ ele:", ele)
|
||||
|
||||
// if (type == "effects") {
|
||||
// // Layer/Effects/Item요소를 가져옴
|
||||
// const items = xpath.select(ele, gpdpXmlDoc);
|
||||
console.log(`❔문제번호 : [4-${key}]`)
|
||||
|
||||
// // let isRight = false;
|
||||
// // 각 Item 요소별 이름과 속성값을 구하고 정답과 비교
|
||||
// items.forEach((item) => {
|
||||
// const name = xpath.select1('Name/@value', item)?.value;
|
||||
// const value = xpath.select1(`EffectData/${option?.replace(/"/g, '')}/@value`, item)?.value;
|
||||
// const resultArray = [name, value];
|
||||
// // if (isRight) return;
|
||||
// if (JSON.stringify(resultArray) === JSON.stringify(rightAnswer)) {
|
||||
// totalScore += point;
|
||||
// scoringResult[key] = point;
|
||||
// console.log("🚀 ~ 정답 일치:", rightAnswer);
|
||||
// // isRight = true;
|
||||
// return;
|
||||
// } else {
|
||||
// scoringResult[key] = 0;
|
||||
// console.log("🚀 ~ 오답:", rightAnswer);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
if (type == "boolean") {
|
||||
if (type === "none") {
|
||||
console.log("❌ 채점하지 않음");
|
||||
scoringResult[key] = "확인필요";
|
||||
continue;
|
||||
}
|
||||
|
||||
else if (type === "canvas.Size") {
|
||||
const result = xpath.select(ele, gpdpXmlDoc);
|
||||
const width = result[0].value;
|
||||
const height = result[1].value;
|
||||
|
||||
userAnswer = [width, height];
|
||||
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult, { type: 'number[]' });
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// []
|
||||
else if (type === "layer.Exists") {
|
||||
const layerNameList = xpath.select(ele, gpdpXmlDoc);
|
||||
const layerNames = layerNameList.map(layer => layer.value);
|
||||
console.log("🚀 ~ getGpdpScore ~ layerNames:", layerNames);
|
||||
|
||||
// userAnswer = layerNames.find(name => name === rightAnswer);
|
||||
for (const layerName of layerNames) {
|
||||
if (layerName.trim().toLowerCase() === rightAnswer.trim().toLowerCase()) {
|
||||
userAnswer = layerName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
totalScore += compareAndScore(userAnswer, rightAnswer, point, key, scoringResult);
|
||||
continue;
|
||||
}
|
||||
|
||||
// [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
|
||||
// 설정한 값 그대로 적용되는 경우도 있어서 오차범위를 설정
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
// [1-6] 세피아
|
||||
else if (type === "sepia.Exists") {
|
||||
|
||||
}
|
||||
else if (type == "boolean") {
|
||||
const items = xpath.select(ele, gpdpXmlDoc);
|
||||
|
||||
// xpath 결과값을 반환하는 요소가 없을 경우
|
||||
|
||||
Reference in New Issue
Block a user