곰픽 문제 채점 관련 내용 추가
This commit is contained in:
@@ -7,6 +7,7 @@ const xpath = require('xpath');
|
||||
const { DOMParser } = require('xmldom');
|
||||
|
||||
const findSimilarString = require('./findSimilarString');
|
||||
const getGpdpScore = require('./gpdpScoring.js');
|
||||
const getToday = require('./getToday.js');
|
||||
const todayDate = getToday();
|
||||
|
||||
@@ -25,8 +26,8 @@ const scoringJson = require('./DIC_2502D.json');
|
||||
// const answerFilesDir = './output/A/DIC';
|
||||
// const answerFilesDir = './output/B/DIC';
|
||||
// const answerFilesDir = './output/C/DIC';
|
||||
const answerFilesDir = './output/D/DIC';
|
||||
|
||||
// const answerFilesDir = './output/D/DIC';
|
||||
const answerFilesDir = './samples/';
|
||||
// TEST
|
||||
// const answerFilesDir = './output/A/TEST';
|
||||
// const answerFilesDir = './output/B/TEST';
|
||||
@@ -37,7 +38,7 @@ const answerFilesDir = './output/D/DIC';
|
||||
// const outputExcelFile = './'+todayDate+'_DIC_2502A_채점결과.xlsx';
|
||||
// const outputExcelFile = './'+todayDate+'_DIC_2502B_채점결과.xlsx';
|
||||
// const outputExcelFile = './'+todayDate+'_DIC_2502C_채점결과.xlsx';
|
||||
const outputExcelFile = './'+todayDate+'_DIC_2502D_채점결과.xlsx';
|
||||
const outputExcelFile = './' + todayDate + '_DIC_2502D_채점결과.xlsx';
|
||||
|
||||
// TEST
|
||||
// const outputExcelFile = './'+todayDate+'_DIC_2502A_TEST.xlsx';
|
||||
@@ -46,6 +47,7 @@ const outputExcelFile = './'+todayDate+'_DIC_2502D_채점결과.xlsx';
|
||||
// const outputExcelFile = './'+todayDate+'_DIC_2502D_TEST.xlsx';
|
||||
// --------------------------------------------------------
|
||||
|
||||
|
||||
// 답안 폴더 내부에 디렉토리가 아닌 일반 파일이 있을 경우 디렉토리만 필터링 해서 불러옴
|
||||
const studentDirs = fs.readdirSync(answerFilesDir).filter(file => {
|
||||
const filePath = path.join(answerFilesDir, file);
|
||||
@@ -69,6 +71,11 @@ studentDirs.forEach(student => {
|
||||
file => file.endsWith('.gmep') || file.endsWith('.gmdp')
|
||||
);
|
||||
|
||||
// 곰픽 파일 gpdp 파일 이거나 xml 파일
|
||||
const gpdpFile = fs.readdirSync(studentDir).filter(
|
||||
file => file.endsWith('.xml')
|
||||
);
|
||||
|
||||
// 학생 이름을 key로 하는 객체 생성
|
||||
// 채점결과
|
||||
const scoringResult = {
|
||||
@@ -87,10 +94,21 @@ studentDirs.forEach(student => {
|
||||
console.error(`Error reading PSD file: ${psdPath}`, error);
|
||||
}
|
||||
});
|
||||
gpdpFile.forEach((gpdp, index) => {
|
||||
const gpdpPath = path.join('./', studentDir, gpdp);
|
||||
console.log(`Reading ${gpdpPath}...`);
|
||||
|
||||
const xmlString = fs.readFileSync(gpdpPath, 'utf8');
|
||||
// XML 문자열을 파싱하여 XML 문서 객체로 변환
|
||||
const xmlDocument = new DOMParser().parseFromString(xmlString, 'application/xml');
|
||||
// console.log('xmlDocument:', xmlDocument);
|
||||
|
||||
scoringResult[index + 1] = getGpdpScore(xmlDocument, scoringJson, index + 3);
|
||||
});
|
||||
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');
|
||||
@@ -125,7 +143,9 @@ XLSX.utils.book_append_sheet(workbook, worksheet, '채점 결과');
|
||||
|
||||
// 엑셀 파일 저장
|
||||
XLSX.writeFile(workbook, outputExcelFile);
|
||||
console.log('채점 결과가 '+outputExcelFile+' 파일에 저장되었습니다.');
|
||||
console.log('채점 결과가 ' + outputExcelFile + ' 파일에 저장되었습니다.');
|
||||
|
||||
|
||||
|
||||
|
||||
// xml 형식의 gmep 파일을 읽어서 점수를 계산
|
||||
@@ -141,7 +161,7 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
// console.log(scoringData);
|
||||
|
||||
let totalScore = 0;
|
||||
|
||||
|
||||
// 채점기준표 문항별 분류
|
||||
for (const key in scoringData) {
|
||||
let ele = scoringData[key].ele;
|
||||
@@ -167,7 +187,7 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
result = result.replace(/"/g, "'");
|
||||
}
|
||||
ele = ele.replace(/{search}/g, result);
|
||||
if ( existEle !== undefined ){
|
||||
if (existEle !== undefined) {
|
||||
existEle = existEle.replace(/{search}/g, result);
|
||||
}
|
||||
}
|
||||
@@ -208,7 +228,7 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
const motionClipPathNode = xpath.select1(`//CRClipArr/CRClip[${clipIndex}]/CRCUnitArr/@Path`, gmepXmlDoc);
|
||||
const notUndefinedClipNode = clipPathNode ?? motionClipPathNode;
|
||||
|
||||
if ( notUndefinedClipNode === undefined ) {
|
||||
if (notUndefinedClipNode === undefined) {
|
||||
console.log("🚀 ~ getGmepScore ~ notUndefinedClipNode:", notUndefinedClipNode)
|
||||
return;
|
||||
}
|
||||
@@ -260,7 +280,7 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
// else if (type == "subtitle") {
|
||||
// const result = xpath.select(ele, gmepXmlDoc);
|
||||
// const length = scoringData[key].length;
|
||||
|
||||
|
||||
// // 결과는 배열로 나오는데 2개 일 경우가 있음
|
||||
// if (result.length !== length) {
|
||||
// scoringResult[key] = 0;
|
||||
@@ -293,11 +313,11 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
const start = scoringData[key].start;
|
||||
const end = scoringData[key].end;
|
||||
|
||||
try{
|
||||
try {
|
||||
let result = xpath.select(ele, gmepXmlDoc);
|
||||
if (result.length == 0) {
|
||||
result = xpath.select(ele2, gmepXmlDoc);
|
||||
if (result.length == 0 ) {
|
||||
if (result.length == 0) {
|
||||
scoringResult[key] = 0;
|
||||
continue;
|
||||
}
|
||||
@@ -314,10 +334,10 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
const y2 = parseFloat(end[1]);
|
||||
|
||||
// (x1,y1) <= (x,y) <= (x2,y2) 이면 true
|
||||
const isPointInRange = (x, y, x1, y1, x2, y2) =>
|
||||
const isPointInRange = (x, y, x1, y1, x2, y2) =>
|
||||
(x >= x1 && x <= x2) && (y >= y1 && y <= y2);
|
||||
|
||||
if (isPointInRange(x, y, x1, y1, x2, y2) === true ) {
|
||||
|
||||
if (isPointInRange(x, y, x1, y1, x2, y2) === true) {
|
||||
totalScore += point;
|
||||
scoringResult[key] = point;
|
||||
}
|
||||
@@ -405,7 +425,7 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
console.log(`not found. ${existEle} `);
|
||||
const result = xpath.select1(ele, gmepXmlDoc);
|
||||
console.log("🚀 ~ getGmepScore ~ result:", result)
|
||||
if ( result == rightAnswer ) {
|
||||
if (result == rightAnswer) {
|
||||
totalScore += point;
|
||||
scoringResult[key] = point;
|
||||
}
|
||||
@@ -419,14 +439,14 @@ function getGmepScore(gmepData, scoringJson, index) {
|
||||
let result = xpath.select(ele, gmepXmlDoc);
|
||||
let result2 = null;
|
||||
let isCheck = false;
|
||||
|
||||
|
||||
if (result.length == 0) {
|
||||
isCheck = true;
|
||||
}
|
||||
if (isCheck && ele2) {
|
||||
result2 = xpath.select(ele2, gmepXmlDoc);
|
||||
|
||||
if (result2.length == 0) {
|
||||
if (result2.length == 0) {
|
||||
scoringResult[key] = 0;
|
||||
continue;
|
||||
}
|
||||
@@ -479,7 +499,7 @@ function getScore(psdData, scoring, index) {
|
||||
continue;
|
||||
}
|
||||
if (type == "boolean") {
|
||||
// console.log(`result ${result.length}`);
|
||||
// console.log(`result ${result.length}`);
|
||||
|
||||
scoringResult[key] = result.length > 0 ? point : 0;
|
||||
}
|
||||
@@ -488,9 +508,9 @@ function getScore(psdData, scoring, index) {
|
||||
// result: [255,162,0,255]
|
||||
// 255,162,0,255 -> ffa200
|
||||
else if (type == "color") {
|
||||
// console.log(`result ${result}`); // result 255,162,0,255
|
||||
// console.log(`result ${result}`); // result 255,162,0,255
|
||||
const temp = result[0].slice(0, 3).join(','); // 255,162,0
|
||||
|
||||
|
||||
// RGB의 각 색상값이 한자리수 일 경우 0을 채워 두자리로 만듬
|
||||
color = temp.split(',').map(v => parseInt(v).toString(16).padStart(2, '0')).join(''); // ffa200
|
||||
// ffa20 -> ffa200
|
||||
@@ -498,16 +518,16 @@ function getScore(psdData, scoring, index) {
|
||||
// color = color + '0';
|
||||
// }
|
||||
|
||||
// console.log(`color: ${color}`);
|
||||
// console.log(`color: ${color}`);
|
||||
scoringResult[key] = result.length > 0 && value === color ? point : 0;
|
||||
}
|
||||
// type이 font인 경우 font의 이름만 추출하여 비교
|
||||
// value: "Arial"
|
||||
// result: ["Arial-BoldItalicMT"]
|
||||
else if (type == "font") {
|
||||
// console.log(`result ${result}`);
|
||||
// console.log(`result ${result}`);
|
||||
const font = result[0].split('-')[0];
|
||||
// console.log(`font: ${font}`);
|
||||
// console.log(`font: ${font}`);
|
||||
scoringResult[key] = result.length > 0 && value === font ? point : 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user