Refactor scoring logic and update file paths for consistency
This commit is contained in:
111
psdExport.js
111
psdExport.js
@@ -7,11 +7,11 @@ const xpath = require('xpath');
|
||||
const { DOMParser } = require('xmldom');
|
||||
|
||||
|
||||
const sampleDir = './output/C/DIC';
|
||||
const sampleDir = './output/C/DIC/';
|
||||
const students = fs.readdirSync(sampleDir);
|
||||
|
||||
// 기준표 파일 읽기
|
||||
const scoring = require('./scoring.json');
|
||||
const scoring = require('./제2501회 정기 DIC C형.json');
|
||||
|
||||
const psdData = [];
|
||||
const gradingResults = [];
|
||||
@@ -94,7 +94,7 @@ function getGmepScore(gmepData, scoring, index) {
|
||||
const value = scoringData[key].value;
|
||||
const point = scoringData[key].point;
|
||||
const type = scoringData[key].type;
|
||||
|
||||
console.log(`example number: ${key}`);
|
||||
if (ele === 'none') {
|
||||
gradingResult[key] = "확인필요";
|
||||
continue;
|
||||
@@ -259,12 +259,12 @@ function getGmepScore(gmepData, scoring, index) {
|
||||
continue;
|
||||
}
|
||||
if (unitOrderNode.value === value) {
|
||||
console.log(`${unitOrderNode.value} === ${value}`);
|
||||
console.log(`unit: ${unitOrderNode.value} === ${value}`);
|
||||
gradingResult[key] = point;
|
||||
totalScore += point;
|
||||
}
|
||||
else if (unitOrderNode === value) {
|
||||
console.log(`${unitOrderNode} === ${value}`);
|
||||
console.log(`unitValue: ${unitOrderNode} === ${value}`);
|
||||
gradingResult[key] = point;
|
||||
totalScore += point;
|
||||
}
|
||||
@@ -278,17 +278,34 @@ function getGmepScore(gmepData, scoring, index) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log('Unknown type:', type);
|
||||
const result = xpath.select(ele, doc);
|
||||
const ele2 = scoringData[key].ele2;
|
||||
|
||||
console.log('Unknown type:', ele);
|
||||
let result = xpath.select(ele, doc);
|
||||
let result2 = null;
|
||||
let isCheck = false;
|
||||
|
||||
if (result.length == 0) {
|
||||
gradingResult[key] = 0;
|
||||
continue;
|
||||
isCheck = true;
|
||||
}
|
||||
if (isCheck && ele2) {
|
||||
result2 = xpath.select(ele2, doc);
|
||||
|
||||
if (result2.length == 0) {
|
||||
gradingResult[key] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
result = result2;
|
||||
console.log(`1st isChecked: ${isCheck}, result: ${result}`)
|
||||
}
|
||||
|
||||
// console.log(`result: ${result[0].value}`);
|
||||
// value와 result[0].value를 비교하여 같으면 점수 point 부여
|
||||
totalScore += result.length > 0 && value === result[0].value ? point : 0;
|
||||
gradingResult[key] = result.length > 0 && value === result[0].value ? point : 0;
|
||||
// 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;
|
||||
gradingResult[key] = result.length > 0 ? point : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,50 +340,54 @@ function getScore(psdData, scoring, index) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
const result = jsonPath.query(psdTree, ele);
|
||||
console.log(`ele: ${ele}, value: ${value} result: ${result}`);
|
||||
if (result.length == 0) {
|
||||
gradingResult[key] = 0;
|
||||
continue;
|
||||
}
|
||||
if (type == "boolean") {
|
||||
try {
|
||||
const result = jsonPath.query(psdTree, ele);
|
||||
console.log(`ele: ${ele}, value: ${value} result: ${result}`);
|
||||
if (result.length == 0) {
|
||||
gradingResult[key] = 0;
|
||||
continue;
|
||||
}
|
||||
if (type == "boolean") {
|
||||
// console.log(`result ${result.length}`);
|
||||
|
||||
gradingResult[key] = result.length > 0 ? point : 0;
|
||||
}
|
||||
// value가 color code인 경우 R,G,B를 16진수로 변환하여 비교하고 같다면 점수 부여
|
||||
// value: "ffa200"
|
||||
// result: [255,162,0,255]
|
||||
// 255,162,0,255 -> ffa200
|
||||
else if (type == "color") {
|
||||
// console.log(`result ${result}`); // result 255,162,0,255
|
||||
const temp = result[0].slice(0, 3).join(','); // 255,162,0
|
||||
color = temp.split(',').map(v => parseInt(v).toString(16)).join(''); // ffa20
|
||||
// ffa20 -> ffa200
|
||||
if (color.length == 5) {
|
||||
color = color + '0';
|
||||
gradingResult[key] = result.length > 0 ? point : 0;
|
||||
}
|
||||
// value가 color code인 경우 R,G,B를 16진수로 변환하여 비교하고 같다면 점수 부여
|
||||
// value: "ffa200"
|
||||
// result: [255,162,0,255]
|
||||
// 255,162,0,255 -> ffa200
|
||||
else if (type == "color") {
|
||||
// console.log(`result ${result}`); // result 255,162,0,255
|
||||
const temp = result[0].slice(0, 3).join(','); // 255,162,0
|
||||
color = temp.split(',').map(v => parseInt(v).toString(16)).join(''); // ffa20
|
||||
// ffa20 -> ffa200
|
||||
if (color.length == 5) {
|
||||
color = color + '0';
|
||||
}
|
||||
|
||||
// console.log(`color: ${color}`);
|
||||
gradingResult[key] = result.length > 0 && value === color ? point : 0;
|
||||
}
|
||||
gradingResult[key] = result.length > 0 && value === color ? point : 0;
|
||||
}
|
||||
|
||||
|
||||
// type이 font인 경우 font의 이름만 추출하여 비교
|
||||
// value: "Arial"
|
||||
// result: ["Arial-BoldItalicMT"]
|
||||
else if (type == "font") {
|
||||
// type이 font인 경우 font의 이름만 추출하여 비교
|
||||
// value: "Arial"
|
||||
// result: ["Arial-BoldItalicMT"]
|
||||
else if (type == "font") {
|
||||
// console.log(`result ${result}`);
|
||||
const font = result[0].split('-')[0];
|
||||
const font = result[0].split('-')[0];
|
||||
// console.log(`font: ${font}`);
|
||||
gradingResult[key] = result.length > 0 && value === font ? point : 0;
|
||||
}
|
||||
gradingResult[key] = result.length > 0 && value === font ? point : 0;
|
||||
}
|
||||
|
||||
else if (result[0] === value) {
|
||||
gradingResult[key] = point;
|
||||
totalScore += point;
|
||||
} else {
|
||||
else if (result[0] === value) {
|
||||
gradingResult[key] = point;
|
||||
totalScore += point;
|
||||
} else {
|
||||
gradingResult[key] = 0;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error processing JSONPath query for ele: ${ele}`, error);
|
||||
gradingResult[key] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user