2521회 채점기준표 추가
This commit is contained in:
101
psdExport_2.js
101
psdExport_2.js
@@ -6,10 +6,36 @@ const path = require('path');
|
||||
const xpath = require('xpath');
|
||||
const { DOMParser } = require('xmldom');
|
||||
|
||||
const findSimilarString = require('./findSimilarString'); // 함수 가져오기
|
||||
const findSimilarString = require('./findSimilarString');
|
||||
|
||||
// 복사된 답안파일 폴더
|
||||
const answerFilesDir = './output/B/DIC/';
|
||||
// --------------------------------------------------------
|
||||
const scoringJson = require('./DIC_2521A.json');
|
||||
// const scoringJson = require('./DIC_2521B.json');
|
||||
// const scoringJson = require('./DIC_2521C.json');
|
||||
// const scoringJson = require('./DIC_2521D.json');
|
||||
|
||||
// --------------------------------------------------------
|
||||
const answerFilesDir = './output/A/DIC';
|
||||
// const answerFilesDir = './output/B/DIC';
|
||||
// const answerFilesDir = './output/C/DIC';
|
||||
// const answerFilesDir = './output/D/DIC';
|
||||
|
||||
// TEST
|
||||
// const answerFilesDir = './output/A/TEST';
|
||||
// const answerFilesDir = './output/B/TEST';
|
||||
// const answerFilesDir = './output/D/TEST';
|
||||
|
||||
// --------------------------------------------------------
|
||||
const outputExcelFile = './DIC_2521A_result.xlsx';
|
||||
// const outputExcelFile = './DIC_2521B_result.xlsx';
|
||||
// const outputExcelFile = './DIC_2521C_result.xlsx';
|
||||
// const outputExcelFile = './DIC_2521D_result.xlsx';
|
||||
|
||||
// TEST
|
||||
// const outputExcelFile = './DIC_2521A_TEST.xlsx';
|
||||
// const outputExcelFile = './DIC_2521B_TEST.xlsx';
|
||||
// const outputExcelFile = './DIC_2521D_TEST.xlsx';
|
||||
// --------------------------------------------------------
|
||||
|
||||
// 답안 폴더 내부에 디렉토리가 아닌 일반 파일이 있을 경우 디렉토리만 필터링 해서 불러옴
|
||||
const studentDirs = fs.readdirSync(answerFilesDir).filter(file => {
|
||||
@@ -17,8 +43,6 @@ const studentDirs = fs.readdirSync(answerFilesDir).filter(file => {
|
||||
return fs.statSync(filePath).isDirectory();
|
||||
});
|
||||
|
||||
// 기준표 파일 읽기
|
||||
const scoringJson = require('./제2501회 정기 DIC B형.json');
|
||||
|
||||
// 채점 결과 리스트
|
||||
const scoringResultList = [];
|
||||
@@ -37,17 +61,24 @@ studentDirs.forEach(student => {
|
||||
0: name
|
||||
};
|
||||
|
||||
// psdFiles
|
||||
psdFiles.forEach((psdFile, index) => {
|
||||
const psdPath = path.join('./', studentDir, psdFile);
|
||||
console.log(`Reading ${psdPath}...`);
|
||||
psdData[index] = psd.fromFile(psdPath);
|
||||
psdData[index].parse();
|
||||
scoringResult[index + 1] = getScore(psdData, scoringJson, index);
|
||||
try {
|
||||
const psdFileData = psd.fromFile(psdPath);
|
||||
psdFileData.parse();
|
||||
psdData[index] = psdFileData;
|
||||
scoringResult[index + 1] = getScore(psdData, scoringJson, index);
|
||||
} catch (error) {
|
||||
console.error(`Error reading PSD file: ${psdPath}`, error);
|
||||
// 잘못된 파일을 건너뛰기
|
||||
// scoringResult[index + 1] = null;
|
||||
}
|
||||
});
|
||||
gmepFile.forEach((gmep, index) => {
|
||||
const gmepPath = path.join('./', studentDir, gmep);
|
||||
console.log(`Reading ${gmepPath}...`);
|
||||
|
||||
const xmlString = fs.readFileSync(gmepPath, 'utf8');
|
||||
// XML 문자열을 파싱하여 XML 문서 객체로 변환
|
||||
const xmlDocument = new DOMParser().parseFromString(xmlString, 'application/xml');
|
||||
@@ -82,8 +113,8 @@ const workbook = XLSX.utils.book_new();
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, '채점 결과');
|
||||
|
||||
// 엑셀 파일 저장
|
||||
XLSX.writeFile(workbook, 'output2.xlsx');
|
||||
console.log('채점 결과가 output2.xlsx 파일에 저장되었습니다.');
|
||||
XLSX.writeFile(workbook, outputExcelFile);
|
||||
console.log('채점 결과가 '+outputExcelFile+' 파일에 저장되었습니다.');
|
||||
|
||||
|
||||
// xml 형식의 gmep 파일을 읽어서 점수를 계산
|
||||
@@ -103,7 +134,8 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
// 채점기준표 문항별 분류
|
||||
for (const key in scoringData) {
|
||||
let ele = scoringData[key].ele;
|
||||
const value = scoringData[key].value;
|
||||
let existEle = scoringData[key].existEle;
|
||||
const rightAnswer = scoringData[key].value;
|
||||
const point = scoringData[key].point;
|
||||
const type = scoringData[key].type;
|
||||
const search = scoringData[key].search;
|
||||
@@ -121,9 +153,14 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
let result = findSimilarString(gmepXmlDoc, search, 0.2)
|
||||
console.log("🚀 ~ getGmepScore ~ result:", result)
|
||||
|
||||
ele = ele.replace('{search}', result);
|
||||
ele = ele.replace(/{search}/g, result);
|
||||
console.log("🚀 ~ getGmepScore ~ ele:", ele)
|
||||
if ( existEle !== undefined ){
|
||||
existEle = existEle.replace(/{search}/g, result);
|
||||
}
|
||||
}
|
||||
console.log(`example number: ${key}`);
|
||||
console.log(`example number: ${key}`)
|
||||
|
||||
|
||||
// xpath
|
||||
if (ele === 'none') {
|
||||
@@ -169,8 +206,8 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
continue;
|
||||
}
|
||||
values.forEach((v, i) => {
|
||||
console.log(`values: ${v} value: ${value[i]}`);
|
||||
if (value[i] !== v) {
|
||||
console.log(`values: ${v} value: ${rightAnswer[i]}`);
|
||||
if (rightAnswer[i] !== v) {
|
||||
isSame = false;
|
||||
}
|
||||
});
|
||||
@@ -225,10 +262,10 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(`value: ${value} result: ${result[0].value}`);
|
||||
console.log(`value: ${rightAnswer} result: ${result[0].value}`);
|
||||
// value와 result[0].value를 비교하여 같으면 점수 point 부여
|
||||
totalScore += result.length > 0 && value === result[0].value ? point : 0;
|
||||
scoringResult[key] = result.length > 0 && value === result[0].value ? point : 0;
|
||||
totalScore += result.length > 0 && rightAnswer === result[0].value ? point : 0;
|
||||
scoringResult[key] = result.length > 0 && rightAnswer === result[0].value ? point : 0;
|
||||
|
||||
}
|
||||
else if (type == "multi") {
|
||||
@@ -247,11 +284,11 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
// value[i] 값이 정수형인 경우에는 float로 변환하여 비교
|
||||
// 정수형 v값을 float 형으로 변환하고 소수점 3자리까지 버림
|
||||
let temp = v.value;
|
||||
let answer = value[i];
|
||||
let answer = rightAnswer[i];
|
||||
|
||||
if (Number.isFinite(value[i]) && !Number.isInteger(value[i])) {
|
||||
if (Number.isFinite(rightAnswer[i]) && !Number.isInteger(rightAnswer[i])) {
|
||||
temp = parseFloat(v.value);
|
||||
answer = parseFloat(value[i]);
|
||||
answer = parseFloat(rightAnswer[i]);
|
||||
// 소수점 3자리까지 버림
|
||||
temp = Math.floor(temp * 1000) / 1000;
|
||||
}
|
||||
@@ -277,7 +314,7 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
}
|
||||
}
|
||||
else if (type == "searchIndex") {
|
||||
let existEle = scoringData[key].existEle;
|
||||
// let existEle = scoringData[key].existEle;
|
||||
// XPath를 사용하여 ELE 요소가 존재하는지 확인
|
||||
const crcUnitArrNode = xpath.select1(existEle, gmepXmlDoc);
|
||||
|
||||
@@ -289,13 +326,13 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
scoringResult[key] = 0;
|
||||
continue;
|
||||
}
|
||||
if (unitOrderNode.value === value) {
|
||||
console.log(`unit: ${unitOrderNode.value} === ${value}`);
|
||||
if (unitOrderNode.value === rightAnswer) {
|
||||
console.log(`unit: ${unitOrderNode.value} === ${rightAnswer}`);
|
||||
scoringResult[key] = point;
|
||||
totalScore += point;
|
||||
}
|
||||
else if (unitOrderNode === value) {
|
||||
console.log(`unitValue: ${unitOrderNode} === ${value}`);
|
||||
else if (unitOrderNode === rightAnswer) {
|
||||
console.log(`unitValue: ${unitOrderNode} === ${rightAnswer}`);
|
||||
scoringResult[key] = point;
|
||||
totalScore += point;
|
||||
}
|
||||
@@ -389,11 +426,13 @@ function getScore(psdData, scoring, index) {
|
||||
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
|
||||
|
||||
// RGB의 각 색상값이 한자리수 일 경우 0을 채워 두자리로 만듬
|
||||
color = temp.split(',').map(v => parseInt(v).toString(16).padStart(2, '0')).join(''); // ffa200
|
||||
// ffa20 -> ffa200
|
||||
if (color.length == 5) {
|
||||
color = color + '0';
|
||||
}
|
||||
// if (color.length == 5) {
|
||||
// color = color + '0';
|
||||
// }
|
||||
|
||||
// console.log(`color: ${color}`);
|
||||
scoringResult[key] = result.length > 0 && value === color ? point : 0;
|
||||
|
||||
Reference in New Issue
Block a user