텍스트 유사도 검사 기능 추가
This commit is contained in:
18
.vscode/launch.json
vendored
18
.vscode/launch.json
vendored
@@ -1,18 +0,0 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch Program",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"program": "${workspaceFolder}/psdExport.js"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -12,7 +12,7 @@ xpath 테스트 웹: http://xpather.com/
|
||||
* PSD 관련해서 좀 더 추가적인 채점이 되도록 기능 개선
|
||||
* PSD 라이브러리 변경도 생각해볼 것
|
||||
|
||||
### psdExxport.js
|
||||
### psdExport.js
|
||||
nodejs 기반, scoring.json 파일에 채점기준표 만들어서 채점
|
||||
|
||||
1. 지정 폴더 내 PSD 파일 scoring.json 파일 내 1,2 참조해서 채점
|
||||
|
||||
41
findSimilarString.js
Normal file
41
findSimilarString.js
Normal file
@@ -0,0 +1,41 @@
|
||||
const xpath = require("xpath");
|
||||
const { DOMParser } = require("xmldom");
|
||||
const stringSimilarity = require("string-similarity");
|
||||
|
||||
/**
|
||||
* XML 문서에서 유사한 문자열 찾기
|
||||
* @param {string} xmlDoc - XML 문자열
|
||||
* @param {string} targetString - 비교할 문자열
|
||||
* @param {number} threshold - 유사도 기준 (0~1)
|
||||
* @returns {string} - 유사한 문자열
|
||||
*/
|
||||
function findSimilarString(xmlDoc, targetString, threshold = 0.8) {
|
||||
// XML 내부의 비교 대상 텍스트 리스트 찾기
|
||||
function getTextNodes(xmlDoc, stringList = []) {
|
||||
const stringNodes = xpath.select("//CRCUnitArr/@Name", xmlDoc);
|
||||
stringNodes.forEach(stringNode => {
|
||||
console.log("🚀 ~ getTextNodes ~ stringNode:", stringNode.value);
|
||||
stringList.push(stringNode.value);
|
||||
});
|
||||
return stringList;
|
||||
}
|
||||
|
||||
// XML에서 모든 텍스트 추출
|
||||
const stringList = getTextNodes(xmlDoc);
|
||||
|
||||
// 유사도 비교하여 가장 유사한 문자열 찾기
|
||||
let bestMatch = null;
|
||||
let highestSimilarity = 0;
|
||||
|
||||
stringList.forEach(text => {
|
||||
const similarity = stringSimilarity.compareTwoStrings(targetString, text);
|
||||
if (similarity > highestSimilarity && similarity >= threshold) {
|
||||
highestSimilarity = similarity;
|
||||
bestMatch = text;
|
||||
}
|
||||
});
|
||||
|
||||
return bestMatch;
|
||||
}
|
||||
|
||||
module.exports = findSimilarString;
|
||||
BIN
output.xlsx
Normal file
BIN
output.xlsx
Normal file
Binary file not shown.
BIN
output2.xlsx
Normal file
BIN
output2.xlsx
Normal file
Binary file not shown.
8
package-lock.json
generated
8
package-lock.json
generated
@@ -11,6 +11,7 @@
|
||||
"dependencies": {
|
||||
"jsonpath": "^1.1.1",
|
||||
"psd": "^3.4.0",
|
||||
"string-similarity": "^4.0.4",
|
||||
"xlsx": "^0.18.5",
|
||||
"xmldom": "^0.6.0",
|
||||
"xpath": "^0.0.34"
|
||||
@@ -322,6 +323,13 @@
|
||||
"escodegen": "^1.8.1"
|
||||
}
|
||||
},
|
||||
"node_modules/string-similarity": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/string-similarity/-/string-similarity-4.0.4.tgz",
|
||||
"integrity": "sha512-/q/8Q4Bl4ZKAPjj8WerIBJWALKkaPRfrvhfF8k/B23i4nzrlRj2/go1m90In7nG/3XDSbOo0+pu6RvCTM9RGMQ==",
|
||||
"deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/type-check": {
|
||||
"version": "0.3.2",
|
||||
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "psd-test",
|
||||
"version": "1.0.0",
|
||||
"description": "### psdExxport.js nodejs 기반, scoring.json 파일에 채점기준표 만들어서 채점",
|
||||
"description": "### psdExport.js nodejs 기반, scoring.json 파일에 채점기준표 만들어서 채점",
|
||||
"main": "psdExport.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
@@ -13,6 +13,7 @@
|
||||
"dependencies": {
|
||||
"jsonpath": "^1.1.1",
|
||||
"psd": "^3.4.0",
|
||||
"string-similarity": "^4.0.4",
|
||||
"xlsx": "^0.18.5",
|
||||
"xmldom": "^0.6.0",
|
||||
"xpath": "^0.0.34"
|
||||
|
||||
18
psdExport.js
18
psdExport.js
@@ -6,20 +6,28 @@ const path = require('path');
|
||||
const xpath = require('xpath');
|
||||
const { DOMParser } = require('xmldom');
|
||||
|
||||
// 복사된 답안 파일 폴더
|
||||
const answerFilesDir = './output/B/DIC/';
|
||||
|
||||
const sampleDir = './output/C/DIC/';
|
||||
const students = fs.readdirSync(sampleDir);
|
||||
// 답안 폴더 내부에 디렉토리가 아닌 일반 파일이 있을 경우 디렉토리만 필터링 해서 불러옴
|
||||
const studentDirs = fs.readdirSync(answerFilesDir).filter(file => {
|
||||
const filePath = path.join(answerFilesDir, file);
|
||||
return fs.statSync(filePath).isDirectory();
|
||||
});
|
||||
|
||||
//const students = fs.readdirSync(answerFilesDir);
|
||||
|
||||
// 기준표 파일 읽기
|
||||
const scoring = require('./제2501회 정기 DIC C형.json');
|
||||
const scoring = require('./제2501회 정기 DIC B형.json');
|
||||
|
||||
const psdData = [];
|
||||
// 채점 결과 리스트
|
||||
const gradingResults = [];
|
||||
|
||||
students.forEach(student => {
|
||||
studentDirs.forEach(student => {
|
||||
// 맥에서 한글 디렉토리 이름을 읽어서 엑셀에 저장 할 시 자소 분리가 되어 저장되는 문제 노말라이즈해서 해결
|
||||
const name = student.normalize('NFC');
|
||||
const studentDir = path.join(sampleDir, student);
|
||||
const studentDir = path.join(answerFilesDir, student);
|
||||
const psdFiles = fs.readdirSync(studentDir).filter(file => file.endsWith('.psd'));
|
||||
const gmepFile = fs.readdirSync(studentDir).filter(file => file.endsWith('.gmep'));
|
||||
|
||||
|
||||
427
psdExport_2.js
Normal file
427
psdExport_2.js
Normal file
@@ -0,0 +1,427 @@
|
||||
const jsonPath = require('jsonpath');
|
||||
const XLSX = require('xlsx');
|
||||
const psd = require('psd');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const xpath = require('xpath');
|
||||
const { DOMParser } = require('xmldom');
|
||||
|
||||
const findSimilarString = require('./findSimilarString'); // 함수 가져오기
|
||||
|
||||
// 복사된 답안파일 폴더
|
||||
const answerFilesDir = './output/B/DIC/';
|
||||
|
||||
// 답안 폴더 내부에 디렉토리가 아닌 일반 파일이 있을 경우 디렉토리만 필터링 해서 불러옴
|
||||
const studentDirs = fs.readdirSync(answerFilesDir).filter(file => {
|
||||
const filePath = path.join(answerFilesDir, file);
|
||||
return fs.statSync(filePath).isDirectory();
|
||||
});
|
||||
|
||||
// 기준표 파일 읽기
|
||||
const scoringJson = require('./제2501회 정기 DIC B형.json');
|
||||
|
||||
// 채점 결과 리스트
|
||||
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 gmepFile = fs.readdirSync(studentDir).filter(file => file.endsWith('.gmep'));
|
||||
|
||||
// 학생 이름을 key로 하는 객체 생성
|
||||
// 채점결과
|
||||
const scoringResult = {
|
||||
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);
|
||||
});
|
||||
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');
|
||||
// console.log('xmlDocument:', xmlDocument);
|
||||
|
||||
scoringResult[3] = getGmepScore(xmlDocument, scoringJson, 2);
|
||||
});
|
||||
scoringResultList.push(scoringResult);
|
||||
});
|
||||
|
||||
// 엑셀 파일 생성
|
||||
|
||||
// Flatten the resultData for better representation in Excel
|
||||
const flattenedData = scoringResultList.map(student => {
|
||||
const name = student["0"]
|
||||
const flattened = { "학생": student["0"] };
|
||||
Object.keys(student).forEach(key => {
|
||||
if (key !== "0") {
|
||||
Object.keys(student[key]).forEach(subKey => {
|
||||
flattened[`${key}_${subKey}`] = student[key][subKey];
|
||||
});
|
||||
}
|
||||
});
|
||||
return flattened;
|
||||
});
|
||||
// console.log(flattenedData);
|
||||
|
||||
const worksheet = XLSX.utils.json_to_sheet(flattenedData);
|
||||
const workbook = XLSX.utils.book_new();
|
||||
|
||||
// Add the worksheet to the workbook
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, '채점 결과');
|
||||
|
||||
// 엑셀 파일 저장
|
||||
XLSX.writeFile(workbook, 'output2.xlsx');
|
||||
console.log('채점 결과가 output2.xlsx 파일에 저장되었습니다.');
|
||||
|
||||
|
||||
// xml 형식의 gmep 파일을 읽어서 점수를 계산
|
||||
// scoring.json 파일 내에 있는 ele 요소는 xpath 형식으로 접근하여 요소를 탐색하고 나오는 값을 value와 비교하여 점수를 계산
|
||||
// scoring.json 파일 내에 있는 type은 비교할 값의 타입을 의미하며, boolean, array 등이 있음
|
||||
// scoring.json 파일 내에 있는 type에 따라 비교하는 방식이 달라짐
|
||||
// 채점 결과를 scoringResultList 배열에 저장
|
||||
function getGmepScore(gmepData, scoringJson, index) {
|
||||
const gmepXmlDoc = gmepData;
|
||||
const scoringResult = {};
|
||||
|
||||
const scoringData = scoringJson[index];
|
||||
// console.log(scoringData);
|
||||
|
||||
let totalScore = 0;
|
||||
|
||||
// 채점기준표 문항별 분류
|
||||
for (const key in scoringData) {
|
||||
let ele = scoringData[key].ele;
|
||||
const value = scoringData[key].value;
|
||||
const point = scoringData[key].point;
|
||||
const type = scoringData[key].type;
|
||||
const search = scoringData[key].search;
|
||||
|
||||
// search 값이 undefined 아니면 ele의 {search}부분을 search로 치환
|
||||
/**
|
||||
* JSON파일 곰믹스 5번문항/22번 문항
|
||||
* type : "subtitle" 인 항목들
|
||||
* GPString태그 VID7속성 찾는 xpath구문
|
||||
* CRCUnitArr태그 Name속성 찾는 구문으로 변환
|
||||
* > 멀티라인 텍스트 유사도 판별하기 어려움
|
||||
*/
|
||||
|
||||
if (search !== undefined) {
|
||||
let result = findSimilarString(gmepXmlDoc, search, 0.2)
|
||||
console.log("🚀 ~ getGmepScore ~ result:", result)
|
||||
|
||||
ele = ele.replace('{search}', result);
|
||||
}
|
||||
console.log(`example number: ${key}`);
|
||||
|
||||
// xpath
|
||||
if (ele === 'none') {
|
||||
scoringResult[key] = "확인필요";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type == "boolean") {
|
||||
scoringResult[key] = result.length > 0 ? point : 0;
|
||||
}
|
||||
else if (type == "array") {
|
||||
// result: Path="동영상.mp4", Path="음악.mp3", Path="이미지2.jpg", Path="이미지1.jpg"
|
||||
// value: 동영상.mp4,이미지1.jpg,이미지3.jpg,이미지2.jpg
|
||||
// result 와 value를 순서대로 비교하여 모두 같으면 점수 point 부여
|
||||
|
||||
// XPath를 사용하여 CRTrackList Name="비디오1" 요소 찾기
|
||||
const trackListNode = xpath.select1('//CRVideoTrackArr/CRTrackList[@Name="비디오1"]', gmepXmlDoc);
|
||||
const values = [];
|
||||
let isSame = true;
|
||||
|
||||
if (trackListNode) {
|
||||
// CRTrackClip 요소의 ClipIndex를 참조하여 CRClip 요소의 Path와 Type 출력
|
||||
const clipIndexes = xpath.select('CRTrackClip/@ClipIndex', trackListNode);
|
||||
clipIndexes.forEach(indexNode => {
|
||||
const clipIndex = parseInt(indexNode.value, 10) + 1; // XPath는 1-based index를 사용
|
||||
console.log(`clipIndex: ${clipIndex}`);
|
||||
if (clipIndex === 0) {
|
||||
return;
|
||||
}
|
||||
const clipPathNode = xpath.select1(`//CRClipArr/CRClip[${clipIndex}]/@Path`, gmepXmlDoc);
|
||||
|
||||
if (clipPathNode === undefined) {
|
||||
console.log(`clipPathNode: undefined`);
|
||||
return;
|
||||
}
|
||||
console.log(`clipPathNode: ${clipPathNode.value}`);
|
||||
values.push(clipPathNode.value);
|
||||
});
|
||||
// values에 값이 있는지 확인
|
||||
if (values.length == 0) {
|
||||
console.log('values length 0');
|
||||
scoringResult[key] = 0;
|
||||
continue;
|
||||
}
|
||||
values.forEach((v, i) => {
|
||||
console.log(`values: ${v} value: ${value[i]}`);
|
||||
if (value[i] !== v) {
|
||||
isSame = false;
|
||||
}
|
||||
});
|
||||
totalScore += isSame ? point : 0;
|
||||
scoringResult[key] = isSame ? point : 0;
|
||||
} else {
|
||||
console.log('CRTrackList with Name="비디오1" not found.');
|
||||
scoringResult[key] = 0;
|
||||
}
|
||||
}
|
||||
else if (type == "startend") {
|
||||
console.log('type:', type);
|
||||
const start = scoringData[key].start;
|
||||
const end = scoringData[key].end;
|
||||
// XPath를 사용하여 CRClip 요소 중 Path가 '동영상.mp4'인 요소의 위치 찾기
|
||||
const clipIndexNode = xpath.select1(ele, gmepXmlDoc);
|
||||
console.log(`clipIndexNode: ${clipIndexNode}`);
|
||||
|
||||
// XPath를 사용하여 해당 ClipIndex를 사용하는 CRTrackClip 요소 찾기
|
||||
const trackClipNodes = xpath.select1(`//CRTrackClip[@ClipIndex='${clipIndexNode}']`, gmepXmlDoc);
|
||||
|
||||
if (!trackClipNodes) {
|
||||
scoringResult[key] = 0;
|
||||
continue;
|
||||
}
|
||||
const posNode = xpath.select1('@Pos', trackClipNodes);
|
||||
const lengthNode = xpath.select1('@Length', trackClipNodes);
|
||||
console.log(`Pos: ${posNode.value}, Length: ${lengthNode.value}`);
|
||||
|
||||
scoringResult[key] = posNode.value === start && lengthNode.value === end ? point : 0;
|
||||
totalScore += posNode.value === start && lengthNode.value === end ? point : 0;
|
||||
|
||||
}
|
||||
// else if (type == "subtitle") {
|
||||
// const result = xpath.select(ele, gmepXmlDoc);
|
||||
// const length = scoringData[key].length;
|
||||
|
||||
// // 결과는 배열로 나오는데 2개 일 경우가 있음
|
||||
// if (result.length !== length) {
|
||||
// scoringResult[key] = 0;
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// scoringResult[key] = point;
|
||||
// totalScore += point;
|
||||
// }
|
||||
else if (type == "color") {
|
||||
const result = xpath.select(ele, gmepXmlDoc);
|
||||
|
||||
if (result.length == 0) {
|
||||
scoringResult[key] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(`value: ${value} 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;
|
||||
|
||||
}
|
||||
else if (type == "multi") {
|
||||
try {
|
||||
const result = xpath.select(ele, gmepXmlDoc);
|
||||
let isSame = true;
|
||||
// console.log(`ele: ${ele}, value: ${value} result: ${result}`);
|
||||
|
||||
if (result.length == 0) {
|
||||
console.log('result length 0');
|
||||
scoringResult[key] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
result.forEach((v, i) => {
|
||||
// value[i] 값이 정수형인 경우에는 float로 변환하여 비교
|
||||
// 정수형 v값을 float 형으로 변환하고 소수점 3자리까지 버림
|
||||
let temp = v.value;
|
||||
let answer = value[i];
|
||||
|
||||
if (Number.isFinite(value[i]) && !Number.isInteger(value[i])) {
|
||||
temp = parseFloat(v.value);
|
||||
answer = parseFloat(value[i]);
|
||||
// 소수점 3자리까지 버림
|
||||
temp = Math.floor(temp * 1000) / 1000;
|
||||
}
|
||||
// answer 문자열 중 : 가 포함되어 있다면 각각 분리하고 그 값의 차이를 구함
|
||||
if (typeof answer == "string" && answer.indexOf(':') > -1) {
|
||||
const [answerStart, answerEnd] = answer.split(':').map(Number);
|
||||
const [tempStart, tempEnd] = temp.split(':').map(Number);
|
||||
answer = answerEnd - answerStart;
|
||||
temp = tempEnd - tempStart;
|
||||
}
|
||||
|
||||
console.log(`temp: ${temp} answer: ${answer}`);
|
||||
if (answer !== temp) {
|
||||
console.log(`answer !== temp`);
|
||||
isSame = false;
|
||||
}
|
||||
});
|
||||
totalScore += isSame ? point : 0;
|
||||
scoringResult[key] = isSame ? point : 0;
|
||||
} catch (e) {
|
||||
console.log('err :', e);
|
||||
scoringResult[key] = 0;
|
||||
}
|
||||
}
|
||||
else if (type == "searchIndex") {
|
||||
let existEle = scoringData[key].existEle;
|
||||
// XPath를 사용하여 ELE 요소가 존재하는지 확인
|
||||
const crcUnitArrNode = xpath.select1(existEle, gmepXmlDoc);
|
||||
|
||||
if (crcUnitArrNode) {
|
||||
// ELE 요소가 몇번째 요소인지 찾고 필요한 요소 확인
|
||||
const unitOrderNode = xpath.select1(ele, gmepXmlDoc);
|
||||
console.log(`unitOrderNode: ${unitOrderNode}`);
|
||||
if (unitOrderNode === undefined) {
|
||||
scoringResult[key] = 0;
|
||||
continue;
|
||||
}
|
||||
if (unitOrderNode.value === value) {
|
||||
console.log(`unit: ${unitOrderNode.value} === ${value}`);
|
||||
scoringResult[key] = point;
|
||||
totalScore += point;
|
||||
}
|
||||
else if (unitOrderNode === value) {
|
||||
console.log(`unitValue: ${unitOrderNode} === ${value}`);
|
||||
scoringResult[key] = point;
|
||||
totalScore += point;
|
||||
}
|
||||
else {
|
||||
scoringResult[key] = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log(`not found. ${existEle} `);
|
||||
scoringResult[key] = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
const ele2 = scoringData[key].ele2;
|
||||
|
||||
console.log('Unknown type:', ele);
|
||||
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) {
|
||||
scoringResult[key] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
result = result2;
|
||||
console.log(`1st isChecked: ${isCheck}, result: ${result}`)
|
||||
}
|
||||
|
||||
// console.log(`result: ${result[0].value}`);
|
||||
// value와 result[0].value를 비교하여 같으면 점수 point 부여
|
||||
// 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;
|
||||
scoringResult[key] = result.length > 0 ? point : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
scoringResult['총점'] = totalScore;
|
||||
return scoringResult;
|
||||
}
|
||||
|
||||
// psdData를 scoring.json 파일 내에 있는 ele 요소의 jsonpath로 접근하여 요소를 탐색하고 나오는 값을 value와 비교하여 점수를 계산
|
||||
// 학생 별로 psdData는 2개씩 있으므로 PSD 파일 1번과 2번에 대해서 채점
|
||||
// scoring.json 파일에 있는 항목 수만큼 점수를 계산
|
||||
// scoring.json 파일의 1번째 배열은 PSD 파일 1번에 대한 점수 계산
|
||||
// scoring.json 파일의 2번째 배열은 PSD 파일 2번에 대한 점수 계산
|
||||
// 채점 결과를 scoringResultList 배열에 저장
|
||||
function getScore(psdData, scoring, index) {
|
||||
const psdTree = psdData[index].tree().export();
|
||||
const jsonData = JSON.stringify(psdTree, null, 2);
|
||||
// console.log(jsonData);
|
||||
const scoringResult = {};
|
||||
|
||||
const scoringData = scoring[index];
|
||||
let totalScore = 0;
|
||||
for (const key in scoringData) {
|
||||
const ele = scoringData[key].ele;
|
||||
const value = scoringData[key].value;
|
||||
const point = scoringData[key].point;
|
||||
const type = scoringData[key].type;
|
||||
|
||||
if (ele === 'none') {
|
||||
scoringResult[key] = "확인필요";
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = jsonPath.query(psdTree, ele);
|
||||
console.log(`ele: ${ele}, value: ${value} result: ${result}`);
|
||||
if (result.length == 0) {
|
||||
scoringResult[key] = 0;
|
||||
continue;
|
||||
}
|
||||
if (type == "boolean") {
|
||||
// console.log(`result ${result.length}`);
|
||||
|
||||
scoringResult[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}`);
|
||||
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}`);
|
||||
const font = result[0].split('-')[0];
|
||||
// console.log(`font: ${font}`);
|
||||
scoringResult[key] = result.length > 0 && value === font ? point : 0;
|
||||
}
|
||||
|
||||
else if (result[0] === value) {
|
||||
scoringResult[key] = point;
|
||||
totalScore += point;
|
||||
} else {
|
||||
scoringResult[key] = 0;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error processing JSONPath query for ele: ${ele}`, error);
|
||||
scoringResult[key] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
scoringResult['총점'] = totalScore;
|
||||
return scoringResult;
|
||||
}
|
||||
1
z.xbook
Normal file
1
z.xbook
Normal file
@@ -0,0 +1 @@
|
||||
[{"kind":1,"language":"markdown","value":"# XPath Notebook\nDate: 2025-02-04 Time: 17:56:45"},{"kind":2,"language":"xpath","value":"//CRClipArr/CRClip[position()=//CRTrackList[1]/CRTrackClip/@ClipIndex]/@Path"},{"kind":2,"language":"xpath","value":"//CRTrackList[@Name='텍스트']/CRTrackClip[@ClipIndex=count(//CROwneUnit[.//CRCUnitArr[@Name='추억의 말뚝박기 놀이']]/preceding::CROwneUnit)]/@Length"},{"kind":2,"language":"xpath","value":"//CRTrackList[@Name='텍스트']/CRTrackClip[(@ClipIndex=count(//CROwneUnit[1]/CRCUnitArr/preceding::CROwneUnit))][@Length='120']"},{"kind":2,"language":"xpath","value":"//CRTrackList[@Name='텍스트']/CRTrackClip"},{"kind":2,"language":"xpath","value":""},{"kind":2,"language":"xpath","value":"/CRTrackClip[][@Length='120']"},{"kind":2,"language":"xpath","value":"(@ClipIndex=count(//CROwneUnit[.//CRCUnitArr[@Name='재미있는 놀이공원']/preceding::CROwneUnit))"},{"kind":2,"language":"xpath","value":"//CRTrackList[@Name='텍스트']/CRTrackClip[(@ClipIndex=count(//CROwneUnit[.//CRCUnitArr[@Name='재미있는 놀이공원']]/preceding::CROwneUnit))][@Length='120']"},{"kind":2,"language":"xpath","value":"//CRTrackList[@Name='텍스트']/CRTrackClip[(@ClipIndex=count(//CROwneUnit[.//CRCUnitArr[@Name='재미있는 놀이공원']]/preceding::CROwneUnit))][@Length='120']"},{"kind":2,"language":"xpath","value":"//CRCUnitArr/@Name"},{"kind":2,"language":"xpath","value":"//GPStrLineArr//GPString/@VID7"}]
|
||||
@@ -184,9 +184,8 @@
|
||||
"point": 3
|
||||
},
|
||||
"5": {
|
||||
"ele": "//GPString[@VID7='추억의 말뚝박기 놀이']/@VID7",
|
||||
"type": "subtitle",
|
||||
"length": 1,
|
||||
"ele": "//CRCUnitArr[@Name='{search}']",
|
||||
"search": "추억의 말뚝박기 놀이",
|
||||
"point": 3
|
||||
},
|
||||
"6": {
|
||||
@@ -222,7 +221,7 @@
|
||||
"point": 2
|
||||
},
|
||||
"11": {
|
||||
"ele": "//CRTrackList[@Name='텍스트']/CRTrackClip[(@ClipIndex=count(//CROwneUnit[.//CRCUnitArr[@Name='재미있는 놀이공원']/preceding::CROwneUnit))][@Length='120']",
|
||||
"ele": "//CRTrackList[@Name='텍스트']/CRTrackClip[(@ClipIndex=count(//CROwneUnit[.//CRCUnitArr[@Name='재미있는 놀이공원']]/preceding::CROwneUnit))][@Length='120']",
|
||||
"ele2": "//CRTrackList[@Name='텍스트']/CRTrackClip[(@ClipIndex=count(//CROwneUnit[1]/CRCUnitArr/preceding::CROwneUnit))][@Length='120']",
|
||||
"point": 2
|
||||
},
|
||||
@@ -312,9 +311,8 @@
|
||||
"point": 2
|
||||
},
|
||||
"22": {
|
||||
"ele": "//GPString[@VID7='동네 풍경' or @VID7='(Neighborhood Scene)']/@VID7",
|
||||
"type": "subtitle",
|
||||
"length": 2,
|
||||
"ele": "//CRCUnitArr[@Name='{search}']",
|
||||
"search": "동네 풍경 (Neighborhood Scene)",
|
||||
"point": 3
|
||||
},
|
||||
"23": {
|
||||
|
||||
Reference in New Issue
Block a user