1,2 페이지 채점기준 항목 모두 적용

This commit is contained in:
devdra9
2025-01-10 19:45:08 +09:00
parent 20aba94dff
commit c323779c39
52 changed files with 1411 additions and 51 deletions

View File

@@ -26,6 +26,7 @@ class XMLScorer:
result = root.xpath(query)
if type(result) is list and len(result) == 0:
return None
return result
except ET.XPathEvalError as e:
return None
@@ -95,13 +96,13 @@ class XMLScorer:
if search_value is not None:
simliar_text = self.find_similar_text(root, search_value)
if simliar_text is None:
continue
xpath = xpath.replace('{searchValue}', '')
else:
xpath = xpath.replace('{searchValue}', simliar_text)
# xpath로 실제 작성 답안 찾기
result = self.query_xml(root, xpath)
# [ boolean 타입 ]
# 1. 이텔릭체, 굵게, 밑줄 등 효과가 적용 여부에 따라
# [ITALIC] [BOLD] [UNDERLINE] 태그가 있거나 없을 수 있으므로
@@ -112,6 +113,14 @@ class XMLScorer:
# 1. 부분점수의 합산으로 반환되는 경우 float 타입으로 반환
if type(result) is not list:
actual_answer = result
# 표 같이 여러 조건을 동시에 검사 해야하는 경우우
# elif type(result) is list and len(result) > 1:
# xpath2 = criterion['path2']
# for i in result:
# xpath2 = xpath2.replace('{path_result_list}', str(i))
# print(f"xpath2: {xpath2}")
else:
actual_answer = result[0]
@@ -136,10 +145,13 @@ class XMLScorer:
if right_answer != actual_answer:
scoring['points'] -= points
# 점수 차감 이유 작성 (개발중)
results['score_results'].append(scoring)
total_score += scoring['points']
print(f'scoring: {scoring}')
if scoring['points'] > 0:
print(f'scoring: {scoring}')
results['total_score'] = total_score
return results
@@ -173,7 +185,8 @@ class XMLScorer:
summary_data = []
detail_data = []
header_added = False
for result in results:
# 요약 정보
summary_row = {
@@ -187,22 +200,16 @@ class XMLScorer:
# 상세 정보
if 'score_results' in result:
detail_data.append({'파일명': result['filename']})
for scoring in result['score_results']:
# detail_row = {
# '파일명': result['filename'],
# # '채점분류': scoring['category'],
# # '채점항목': scoring['item'],
# # '채점기준': scoring['right_answer'],
# # '적용답안': scoring['actual_answer'],
# '획득점수': scoring['points'],
# # '감점내역': '; '.join(scoring.get('deductions', []))
# }
# detail_data.append(detail_row)
detail_row = {'파일명': result['filename']}
for i, scoring in enumerate(result['score_results']):
detail_row[f'점수_{i+1}'] = scoring['points']
detail_row['총점'] = result.get('total_score', 0)
detail_data.append(detail_row)
summary_df = pd.DataFrame(summary_data)
detail_df = pd.DataFrame(detail_data)
# detail_df = pd.DataFrame(detail_data)
# ExcelWriter 객체 생성
with pd.ExcelWriter(output_path, engine='openpyxl') as writer:
@@ -210,19 +217,19 @@ class XMLScorer:
detail_df.to_excel(writer, sheet_name='채점상세내역', index=False)
# 열 너비 자동 조정
for sheet_name in writer.sheets:
worksheet = writer.sheets[sheet_name]
for column_cells in worksheet.columns:
max_length = 0
column = column_cells[0].column_letter # 열의 문자
for cell in column_cells:
try:
if cell.value:
max_length = max(max_length, len(str(cell.value)))
except:
pass
adjusted_width = (max_length + 2)
worksheet.column_dimensions[column].width = adjusted_width
# for sheet_name in writer.sheets:
# worksheet = writer.sheets[sheet_name]
# for column_cells in worksheet.columns:
# max_length = 0
# column = column_cells[0].column_letter # 열의 문자
# for cell in column_cells:
# try:
# if cell.value:
# max_length = max(max_length, len(str(cell.value)))
# except:
# pass
# adjusted_width = (max_length + 2)
# worksheet.column_dimensions[column].width = adjusted_width
return output_path