v2 - 문제2 6번문항까지

This commit is contained in:
2025-05-13 19:46:19 +09:00
parent ac655d58d3
commit 8c93c6d446
5 changed files with 163 additions and 59 deletions

View File

@@ -209,7 +209,8 @@ class XMLScorer:
# search_value를 포함하는 텍스트 찾기
similar_text = self.find_similar_text(root, search_value)
xpath = xpath.replace('{searchValue}', similar_text)
# xpath2 = xpath2.replace('{searchValue}', similar_text)
if xpath2 is not None:
xpath2 = xpath2.replace('{searchValue}', similar_text)
# 문항 별 채점 결과 저장
scoring = {
@@ -260,7 +261,14 @@ class XMLScorer:
# 수험자 답안
user_answer = {
'FontName': font_name[0],
########################################################################
# 보통 정답은 글꼴이 [바탕]이어야 하지만 대부분 설정하지 않고
# 기본 [함초롱바탕]으로 두는 경우가 많아
# 폰트명을 정답과 비교하면 감점이 많이 발생해서
# 폰트명은 정답과 비교하지 않게 적용된 상태
########################################################################
#'FontName': font_name[0],
'FontName': "바탕",
'FontSize': font_size[0],
'Alignment': alignment[0],
'LineSpacing': line_spacing[0]
@@ -287,13 +295,30 @@ class XMLScorer:
if scoring['points'] > 0:
break
elif "DoubleAnswer" in (category or ""):
items1 = root.xpath(xpath)
items2 = root.xpath(xpath2)
user_answer = []
for item1, item2 in zip(items1, items2):
user_answer.append(item1)
user_answer.append(item2)
# user_answer[0] = item1
# user_answer[1] = item2
self.evaluate_answer(scoring, user_answer, right_answer, points)
if scoring['points'] > 0:
break
# 사용자 입력값이 mm단위인 경우
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))
user_answer = float(item)
right_answer = self.convert_mm_to_pt(float(right_answer))
self.evaluate_answer(scoring, user_answer, right_answer, points, method="tolerance")
@@ -402,6 +427,7 @@ class XMLScorer:
break
# char2 요소에서 특수문자 갯수 세기 (최대 1점)
# char1과 char2가 다른 경우 (예: ▶ 행사안내 ◀)
if (ch1 != ch2) and char2_ele:
count_char2 = char2_ele[0].text.count(ch2)
if count_char2 > 1:
@@ -419,16 +445,44 @@ class XMLScorer:
self.evaluate_answer(scoring, user_answer, right_answer, points, method="partial_score")
# 쪽 테두리
# 쪽 테두리 (이중 실선, 머리말 포함) 설정
elif "PageBorder" in (category or ""):
pageBorderfills = root.xpath(xpath)
user_answer = {
"header_inside": False,
"all_double_slim": False
}
for pageBorderfill in pageBorderfills:
headerInside = pageBorderfill.get('HeaderInside')
borderfill_id = pageBorderfill.get('BorferFill')
print( f"headerInside: {headerInside}, borderfill_id: {borderfill_id}")
break
# 머릿말 포함 객체가 하나라도 있으면 정답
header_inside_elements = root.xpath(xpath)
for header_inside in header_inside_elements:
# print("머릿말포함: ",header_inside)
if "true" in header_inside:
user_answer["header_inside"] = True
# BORDERFILL요소의 자녀
# LEFTBORDER, RIGHTBORDER, TOPBORDER, BOTTOMBORDER 요소의 Type속성이
# 모두 DoubleSlim이면 정답
border_fill_elements = root.xpath(xpath2)
for bf in border_fill_elements:
border_tags = ["LEFTBORDER", "RIGHTBORDER", "TOPBORDER", "BOTTOMBORDER"]
all_double_slim = True
for tag in border_tags:
element = bf.find(tag)
if element is None or element.get("Type") != "DoubleSlim":
all_double_slim = False
break
#모든 BORDER 태그의 Type 속성이 'DoubleSlim'
if all_double_slim:
user_answer["all_double_slim"] = True
# 하나 이상의 BORDER 태그가 'DoubleSlim'이 아님
else:
user_answer["all_double_slim"] = False
self.evaluate_answer(scoring, user_answer, right_answer, points, method="equal")
onePersonResult['score_results'].append(scoring)
print(f'scoring: {scoring}')