2508회 채점자료 업데이트

This commit is contained in:
2025-08-27 18:00:29 +09:00
parent 57427f437f
commit d4a5a604ce
57 changed files with 11782 additions and 992 deletions

View File

@@ -11,14 +11,18 @@ const getGpdpScore = require('./gpdpScoring.js');
const getToday = require('./getToday.js');
const todayDate = getToday();
const examRound = '2507';
const examRound = '2508';
const DICorDPI = 'DIC'
const codeTypes = [
// 'DIC',
'DPI',
];
// const DICorDPI = 'DIC'
// const DICorDPI = 'DPI'
const examTypes = [
// 'A',
'B',
// 'C',
// 'B',
'C',
// 'D'
];
@@ -27,133 +31,134 @@ const testMode = false;
// const testMode = true;
const outputExcelFiles = [];
examTypes.forEach(type => {
const jsonPath = `./${DICorDPI}_${examRound}${type}.json`
if (!fs.existsSync(jsonPath)) return;
const scoringJson = require(jsonPath);
const answerFilesDir = `./output/${examRound}/${type}/${testMode ? 'TEST' : DICorDPI}`;
let outputExcelFile = `./${todayDate}_${DICorDPI}_${examRound}${type}_채점결과.xlsx`;
if (testMode) {
outputExcelFile = `./00_${DICorDPI}_${examRound}${type}_TEST.xlsx`;
}
// 답안 폴더 내부에 디렉토리가 아닌 일반 파일이 있을 경우 디렉토리만 필터링 해서 불러옴
const studentDirs = fs.readdirSync(answerFilesDir).filter(file => {
const filePath = path.join(answerFilesDir, file);
return fs.statSync(filePath).isDirectory();
});
// 채점 결과 리스트
const scoringResultList = [];
const psdData = [];
studentDirs.forEach(student => {
// 맥에서 한글 디렉토리 이름을 읽어서 엑셀에 저장 할 시 자소 분리가 되어 저장되는 문제 노말라이즈해서 해결
const name = student.normalize('NFC');
const studentDir = path.join(answerFilesDir, student);
// const psdFiles = fs.readdirSync(studentDir).filter(file => file.endsWith('.psd'));
const psdFiles = fs.readdirSync(studentDir).filter(file => file.toLowerCase().endsWith('.psd'));
// DIAT시험 프로젝트로 생성시 gmep확장자로
// 교육용 프로젝프로 생성시 gmdp확장자로 생성됨
const gmepFile = fs.readdirSync(studentDir).filter(
file => file.toLowerCase().endsWith('.gmep')
// || file.toLowerCase().endsWith('.gmdp')
);
// 곰픽 파일 gpdp 파일 이거나 xml 파일
const gpdpFiles = fs.readdirSync(studentDir).filter(
file => file.toLowerCase().endsWith('.xml')
|| (file === null && (name + '.xml'))
);
// 학생 이름을 key로 하는 객체 생성
// 채점결과
const scoringResult = {
0: name
};
psdFiles.forEach((psdFile, index) => {
const psdPath = path.join('./', studentDir, psdFile);
console.log('');
console.log(`➡️ Reading ${psdPath}...`);
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);
}
});
gpdpFiles.forEach((gpdpFile, index) => {
const gpdpPath = path.join('./', studentDir, gpdpFile);
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 + 4);
});
if (gmepFile.length === 0) {
// 곰믹스 채점 항목 갯수
const gmepItemCount = Object.keys(scoringJson[2]).length - 2;
// console.log("🚀 ~ gmepItemCount:", gmepItemCount)
scoringResult[3] = {};
for (let i = 1; i <= gmepItemCount; i++) {
scoringResult[3][i] = 0;
}
scoringResult[3]['총점'] = 0;
codeTypes.forEach(codeType => {
examTypes.forEach(type => {
const jsonPath = `./${codeType}_${examRound}${type}.json`
if (!fs.existsSync(jsonPath)) return;
const scoringJson = require(jsonPath);
const answerFilesDir = `./output/${examRound}/${type}/${testMode ? 'TEST' : codeType}`;
let outputExcelFile = `./${todayDate}_${codeType}_${examRound}${type}_채점결과.xlsx`;
if (testMode) {
outputExcelFile = `./00_${codeType}_${examRound}${type}_TEST.xlsx`;
}
else {
gmepFile.forEach((gmep, index) => {
const gmepPath = path.join('./', studentDir, gmep);
// 답안 폴더 내부에 디렉토리가 아닌 일반 파일이 있을 경우 디렉토리만 필터링 해서 불러옴
const studentDirs = fs.readdirSync(answerFilesDir).filter(file => {
const filePath = path.join(answerFilesDir, file);
return fs.statSync(filePath).isDirectory();
});
// 채점 결과 리스트
const scoringResultList = [];
const psdData = [];
studentDirs.forEach(student => {
// 맥에서 한글 디렉토리 이름을 읽어서 엑셀에 저장 할 시 자소 분리가 되어 저장되는 문제 노말라이즈해서 해결
const name = student.normalize('NFC');
const studentDir = path.join(answerFilesDir, student);
// const psdFiles = fs.readdirSync(studentDir).filter(file => file.endsWith('.psd'));
const psdFiles = fs.readdirSync(studentDir).filter(file => file.toLowerCase().endsWith('.psd'));
// DIAT시험 프로젝트로 생성시 gmep확장자로
// 교육용 프로젝프로 생성시 gmdp확장자로 생성됨
const gmepFile = fs.readdirSync(studentDir).filter(
file => file.toLowerCase().endsWith('.gmep')
// || file.toLowerCase().endsWith('.gmdp')
);
// 곰픽 파일 gpdp 파일 이거나 xml 파일
const gpdpFiles = fs.readdirSync(studentDir).filter(
file => file.toLowerCase().endsWith('.xml')
|| (file === null && (name + '.xml'))
);
// 학생 이름을 key로 하는 객체 생성
// 채점결과
const scoringResult = {
0: name
};
psdFiles.forEach((psdFile, index) => {
const psdPath = path.join('./', studentDir, psdFile);
console.log('');
console.log(`➡️ Reading ${gmepPath}...`);
console.log(`➡️ Reading ${psdPath}...`);
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);
}
});
gpdpFiles.forEach((gpdpFile, index) => {
const gpdpPath = path.join('./', studentDir, gpdpFile);
console.log(`Reading ${gpdpPath}...`);
const xmlString = fs.readFileSync(gmepPath, 'utf8');
const xmlString = fs.readFileSync(gpdpPath, 'utf8');
// XML 문자열을 파싱하여 XML 문서 객체로 변환
const xmlDocument = new DOMParser().parseFromString(xmlString, 'application/xml');
// console.log('xmlDocument:', xmlDocument);
scoringResult[3] = getGmepScore(xmlDocument, scoringJson, 2);
scoringResult[index + 1] = getGpdpScore(xmlDocument, scoringJson, index + 4);
});
}
scoringResultList.push(scoringResult);
if (gmepFile.length === 0) {
// 곰믹스 채점 항목 갯수
const gmepItemCount = Object.keys(scoringJson[2]).length;
// console.log("🚀 ~ gmepItemCount:", gmepItemCount)
scoringResult[3] = {};
for (let i = 1; i <= gmepItemCount; i++) {
scoringResult[3][i] = 0;
}
scoringResult[3]['총점'] = 0;
}
else {
gmepFile.forEach((gmep, index) => {
const gmepPath = path.join('./', studentDir, gmep);
console.log('');
console.log(`➡️ Reading ${gmepPath}...`);
const xmlString = fs.readFileSync(gmepPath, 'utf8');
// XML 문자열을 파싱하여 XML 문서 객체로 변환
const xmlDocument = new DOMParser().parseFromString(xmlString, 'application/xml');
// console.log('xmlDocument:', xmlDocument);
scoringResult[3] = getGmepScore(xmlDocument, scoringJson, 2);
});
}
scoringResultList.push(scoringResult);
});
const flattenedData = prepareExcelData(scoringResultList);
const transposedData = transposeData(flattenedData);
// 엑셀 파일 생성
const worksheet = XLSX.utils.json_to_sheet(transposedData, { skipHeader: true });
const workbook = XLSX.utils.book_new();
// 열 너비 계산
const columnWidths = Object.keys(transposedData[0]).map(key => {
// 각 열의 최대 길이를 계산
const maxLength = Math.max(
// key.length, // 열 제목의 길이
// ...transposedData.map(row => (row[key] ? row[key].toString().length : 0)) // 각 셀의 데이터 길이
4 // 고정 너비
);
return { wch: maxLength + 1 }; // 여유 공간 추가
});
// 열 너비 설정
worksheet['!cols'] = columnWidths;
// Add the worksheet to the workbook
XLSX.utils.book_append_sheet(workbook, worksheet, '채점 결과');
// 엑셀 파일 저장
XLSX.writeFile(workbook, outputExcelFile);
outputExcelFiles.push(outputExcelFile);
});
const flattenedData = prepareExcelData(scoringResultList);
const transposedData = transposeData(flattenedData);
// 엑셀 파일 생성
const worksheet = XLSX.utils.json_to_sheet(transposedData, { skipHeader: true });
const workbook = XLSX.utils.book_new();
// 열 너비 계산
const columnWidths = Object.keys(transposedData[0]).map(key => {
// 각 열의 최대 길이를 계산
const maxLength = Math.max(
// key.length, // 열 제목의 길이
// ...transposedData.map(row => (row[key] ? row[key].toString().length : 0)) // 각 셀의 데이터 길이
4 // 고정 너비
);
return { wch: maxLength + 1 }; // 여유 공간 추가
});
// 열 너비 설정
worksheet['!cols'] = columnWidths;
// Add the worksheet to the workbook
XLSX.utils.book_append_sheet(workbook, worksheet, '채점 결과');
// 엑셀 파일 저장
XLSX.writeFile(workbook, outputExcelFile);
outputExcelFiles.push(outputExcelFile);
});
console.log('채점 결과');