1번문항채점가능

This commit is contained in:
devdra9
2025-01-08 17:43:24 +09:00
parent ec3a3ba833
commit a4b6e22e4f
80 changed files with 1219 additions and 56 deletions

View File

@@ -6,11 +6,16 @@ import pandas as pd
from datetime import datetime
from difflib import SequenceMatcher
import re
import demicalToRGB
class XMLScorer:
# 채점 기준 경로 초기화
def __init__(self, scoring_criteria_path):
# 채점 기준 로드
self.scoring_criteria = self._load_scoring_criteria(scoring_criteria_path)
print(self.scoring_criteria)
# 채점 기준파일 로드(JSON 파일)
def _load_scoring_criteria(self, file_path):
with open(file_path, 'r', encoding='utf-8') as f:
return json.load(f)
@@ -113,15 +118,17 @@ class XMLScorer:
return None, False
# XML 파일 채점
def score_xml_file(self, xml_path):
try:
tree = ET.parse(xml_path)
root = tree.getroot()
total_score = 0
# 결과값을 Dictionary로 저장
results = {
'filename': os.path.basename(xml_path),
'criteria_matches': [],
'criteria_matches': [], # 채점 항목별 결과
'total_score': 0,
'deductions': [] # 감점 상세 내역 추가
}
@@ -133,13 +140,14 @@ class XMLScorer:
points = criterion['points']
actual_value, has_element_typo = self._find_element_value(
root, element_name, attribute_name)
root, element_name, attribute_name)
# 채점 결과 저장
match = {
'criterion': f"{element_name}.{attribute_name}",
'expected': expected_value,
'actual': actual_value,
'points': 0,
'criterion': f"{element_name}.{attribute_name}", # 채점 항목
'expected': expected_value, # 기대값
'actual': actual_value, # 실제값
'points': 0, # 획득 점수
'deductions': [] # 각 기준별 감점 내역
}
@@ -247,7 +255,8 @@ class XMLScorer:
def score_directory(self, xml_directory):
results = []
xml_files = Path(xml_directory).glob('*.xml')
# xml_files = Path(xml_directory).glob('*.xml')
xml_files = Path(xml_directory).glob('*.hml')
for xml_file in xml_files:
result = self.score_xml_file(str(xml_file))
@@ -255,14 +264,13 @@ class XMLScorer:
return results
# 사용 예시
def main():
# 채점기준표 파일 경로
scoring_criteria_path = "scoring_criteria.json"
# XML 파일들이 있는 디렉토리 경로
xml_directory = r"C:\Users\gzero-ser7-win11\Documents\hwpTest\Output"
# xml_directory = r"C:\Users\gzero-ser7-win11\Documents\hwpTest\Output"
xml_directory = r"C:\Users\dra\project\HWP-Scoring\output"
# 채점기 초기화
scorer = XMLScorer(scoring_criteria_path)
@@ -291,6 +299,6 @@ def main():
print(f"\n채점 결과가 다음 경로에 저장되었습니다: {excel_path}")
if __name__ == "__main__":
main()
main()