diwScoring.py 문제1 적용완료
This commit is contained in:
@@ -139,6 +139,10 @@ class XMLScorer:
|
||||
is_correct = abs(user_answer - right_answer) <= tolerance
|
||||
elif method == "in":
|
||||
is_correct = user_answer in right_answer
|
||||
elif method == "partial_score":
|
||||
# 부분 점수 계산
|
||||
is_correct = isinstance(user_answer, (int, float)) and user_answer <= right_answer
|
||||
points = min(points, user_answer)
|
||||
else:
|
||||
raise ValueError(f"Unknown comparison method: {method}")
|
||||
|
||||
@@ -183,7 +187,7 @@ class XMLScorer:
|
||||
for criterion_id, criterion in section.items():
|
||||
id = criterion_id
|
||||
xpath = criterion.get('path', None)
|
||||
xpath2 = criterion.get('path2', None)
|
||||
xpath2 = criterion.get('path2', None)
|
||||
search_value = criterion.get('searchValue', None)
|
||||
right_answer = criterion.get('value', None)
|
||||
points = criterion.get('points', 0)
|
||||
@@ -196,6 +200,7 @@ 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)
|
||||
|
||||
# 문항 별 채점 결과 저장
|
||||
scoring = {
|
||||
@@ -273,6 +278,21 @@ class XMLScorer:
|
||||
if scoring['points'] > 0:
|
||||
break
|
||||
|
||||
elif "ParaShape" in (category or ""):
|
||||
items = root.xpath(xpath)
|
||||
|
||||
for item in items:
|
||||
user_answer = {
|
||||
'Left': float(item.get('Left', 0)) / 200,
|
||||
'Indent': float(item.get('Indent', 0)) / -200,
|
||||
}
|
||||
|
||||
# 정답과 수험자 답안 비교
|
||||
self.evaluate_answer(scoring, user_answer, right_answer, points, method="equal")
|
||||
|
||||
if scoring['points'] > 0:
|
||||
break
|
||||
|
||||
# Boolean 타입 정답인 경우
|
||||
elif "Boolean" in (category or ""):
|
||||
items = root.xpath(xpath)
|
||||
@@ -296,6 +316,7 @@ class XMLScorer:
|
||||
if scoring['points'] > 0:
|
||||
break
|
||||
|
||||
# 문단 첫글자 장식 채점
|
||||
elif "TwoLineSize" in (category or ""):
|
||||
items = root.xpath(xpath)
|
||||
error_range = criterion.get('tolerance', 0)
|
||||
@@ -309,6 +330,7 @@ class XMLScorer:
|
||||
if scoring['points'] > 0:
|
||||
break
|
||||
|
||||
# 폰트명
|
||||
elif "FontName" in (category or ""):
|
||||
charshape_id = root.xpath(xpath)
|
||||
if not charshape_id:
|
||||
@@ -321,6 +343,7 @@ class XMLScorer:
|
||||
|
||||
self.evaluate_answer(scoring, user_answer, right_answer, points, method="equal")
|
||||
|
||||
# 폰트 속성
|
||||
elif "FontAttribute" in (category or ""):
|
||||
charshape = root.xpath(xpath)
|
||||
if not charshape:
|
||||
@@ -330,8 +353,50 @@ class XMLScorer:
|
||||
font_attribute = charshape[0].find(right_answer)
|
||||
if font_attribute is not None:
|
||||
user_answer = font_attribute.tag
|
||||
else:
|
||||
user_answer = None
|
||||
|
||||
self.evaluate_answer(scoring, user_answer, right_answer, points, method="equal")
|
||||
|
||||
# 특수문자 갯수 채점
|
||||
elif "SpecialChar" in (category or ""):
|
||||
ch1 = criterion.get('char1', None)
|
||||
ch2 = criterion.get('char2', None)
|
||||
xpath = xpath.replace('{char1}', ch1)
|
||||
xpath2 = xpath2.replace('{char2}', ch2)
|
||||
char1_ele = root.xpath(xpath)
|
||||
char2_ele = root.xpath(xpath2)
|
||||
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
|
||||
|
||||
# char2 요소에서 특수문자 갯수 세기 (최대 1점)
|
||||
if not char2_ele:
|
||||
user_answer = 0
|
||||
else:
|
||||
count_char2 = char2_ele[0].text.count(ch2)
|
||||
if count_char2 > 1:
|
||||
count_char2 = 1
|
||||
sum_char += count_char2
|
||||
|
||||
user_answer = sum_char
|
||||
|
||||
self.evaluate_answer(scoring, user_answer, right_answer, points, method="partial_score")
|
||||
|
||||
# 줄간격
|
||||
elif "LineSpacing" in (category or ""):
|
||||
|
||||
break
|
||||
|
||||
|
||||
onePersonResult['score_results'].append(scoring)
|
||||
print(f'scoring: {scoring}')
|
||||
|
||||
Reference in New Issue
Block a user