v2 - mm to pt, 특수문자 앞뒤 다른 경우 처리

This commit is contained in:
2025-05-12 18:24:35 +09:00
parent 59c5c7c927
commit ac655d58d3
20 changed files with 364 additions and 16 deletions

View File

@@ -10,6 +10,7 @@ import re
from difflib import SequenceMatcher
import pandas as pd
import base64
import math
# from xpathSearch import XMLPathHandler
class XMLScorer:
@@ -32,6 +33,13 @@ class XMLScorer:
with open(file_path, 'r', encoding='utf-8') as f:
return json.load(f)
# mm to pt
def convert_mm_to_pt(self, mm):
one_mm_per_pt = 2.83465
hwp_internal_conversion_method = 100
pt = math.trunc(mm * one_mm_per_pt * hwp_internal_conversion_method)
return pt
# XML 파일에서 element의 값을 찾아 반환
def query_xml(self, root, *args):
first_xpath = args[0]
@@ -188,6 +196,7 @@ class XMLScorer:
id = criterion_id
xpath = criterion.get('path', None)
xpath2 = criterion.get('path2', None)
xpath3 = criterion.get('path3', None)
search_value = criterion.get('searchValue', None)
right_answer = criterion.get('value', None)
points = criterion.get('points', 0)
@@ -277,7 +286,20 @@ class XMLScorer:
if scoring['points'] > 0:
break
elif "mmSize" in (category or ""):
items = root.xpath(xpath)
error_range = criterion.get('tolerance', 0)
for item in items:
user_answer = int(item)
right_answer = self.convert_mm_to_pt(int(right_answer))
self.evaluate_answer(scoring, user_answer, right_answer, points, method="tolerance")
if scoring['points'] > 0:
break
elif "ParaShape" in (category or ""):
items = root.xpath(xpath)
@@ -362,31 +384,36 @@ class XMLScorer:
elif "SpecialChar" in (category or ""):
ch1 = criterion.get('char1', None)
ch2 = criterion.get('char2', None)
ch3 = criterion.get('char3', None)
xpath = xpath.replace('{char1}', ch1)
xpath2 = xpath2.replace('{char2}', ch2)
xpath3 = xpath3.replace('{char3}', ch3)
char1_ele = root.xpath(xpath)
char2_ele = root.xpath(xpath2)
char3_ele = root.xpath(xpath3)
sum_char = 0
# char1 요소에서 특수문자 갯수 세기 (최대 2점)
if not char1_ele:
user_answer = 0
else:
for item in char1_ele:
count_char1 = item.text.count(ch1)
sum_char += count_char1
if sum_char >= 2:
sum_char = 2
break
for item in char1_ele or []:
count_char1 = item.text.count(ch1)
sum_char += count_char1
if sum_char >= 2:
sum_char = 2
break
# char2 요소에서 특수문자 갯수 세기 (최대 1점)
if not char2_ele:
user_answer = 0
else:
if (ch1 != ch2) and char2_ele:
count_char2 = char2_ele[0].text.count(ch2)
if count_char2 > 1:
count_char2 = 1
sum_char += count_char2
# char2 요소에서 특수문자 갯수 세기 (최대 1점)
if char3_ele:
count_char3 = char3_ele[0].text.count(ch3)
if count_char3 > 1:
count_char3 = 1
sum_char += count_char3
user_answer = sum_char
@@ -691,7 +718,7 @@ class XMLScorer:
def main():
# 시험회차 및 유형
exam_round = '2504_2'
exam_round = '2504'
exam_types = [
'A',
# 'B',
@@ -704,7 +731,7 @@ def main():
for exam_type in exam_types:
# JSON 채점기준표 파일 (예시:DIW_2503A.json)
# scoring_criteria_path = f'./DIW_{exam_round}.json'
scoring_criteria_path = f'./DIW_{exam_round}_{exam_type}_new.json'
scoring_criteria_path = f'./DIW_{exam_round}{exam_type}_new.json'
# xml(hml)파일 디렉토리 경로 (예시:./output/A/DIW)
# xml_directory = f'./output/{exam_type}/{"TEST" if test_mode else "DIW"}'