채점상세내역 시트 열인덱스 추가
This commit is contained in:
18
score5.py
18
score5.py
@@ -52,7 +52,6 @@ class XMLScorer:
|
||||
|
||||
elif second_xpath is not None:
|
||||
try:
|
||||
# result = root.xpath(first_xpath)
|
||||
result1 = root.xpath(first_xpath)
|
||||
result2 = root.xpath(second_xpath)
|
||||
if (type(result1) is list and len(result1) == 0) and (type(result2) is list and len(result2) == 0):
|
||||
@@ -430,28 +429,39 @@ class XMLScorer:
|
||||
|
||||
section_num = None
|
||||
partial_idx = 0
|
||||
row_index = []
|
||||
for i, score_result in enumerate(result['score_results']):
|
||||
current_section = int(score_result['id'].split('-')[0])
|
||||
|
||||
if section_num is None:
|
||||
section_num = current_section
|
||||
|
||||
# 다음 섹션(페이지)로 넘어갔을 경우
|
||||
if current_section != section_num:
|
||||
# 이전 섹션의 부분합을 출력
|
||||
detail_row[f'[{section_num}]합계'] = result['partial_scores'][partial_idx]['score']
|
||||
detail_row[f'문제{section_num}'] = result['partial_scores'][partial_idx]['score']
|
||||
row_index.append(f'문제{section_num}')
|
||||
partial_idx += 1
|
||||
section_num = current_section
|
||||
|
||||
detail_row[f'{i+1}'] = score_result['points']
|
||||
row_index.append(score_result['id'])
|
||||
|
||||
# 마지막 섹션의 부분합을 출력
|
||||
if section_num is not None and partial_idx < len(result['partial_scores']):
|
||||
detail_row[f'[{section_num}]합계'] = result['partial_scores'][partial_idx]['score']
|
||||
detail_row[f'문제{section_num}'] = result['partial_scores'][partial_idx]['score']
|
||||
row_index.append(f'문제{section_num}')
|
||||
|
||||
detail_row['총점'] = result.get('total_score', 0)
|
||||
row_index.append('총점')
|
||||
detail_data.append(detail_row)
|
||||
|
||||
summary_df = pd.DataFrame(summary_data)
|
||||
detail_df = pd.DataFrame(detail_data).transpose()
|
||||
detail_df.columns = detail_df.iloc[0]
|
||||
detail_df = detail_df[1:]
|
||||
|
||||
detail_df.index = row_index
|
||||
# detail_df = pd.DataFrame(detail_data)
|
||||
|
||||
for temp in results:
|
||||
@@ -464,7 +474,7 @@ class XMLScorer:
|
||||
# ExcelWriter 객체 생성
|
||||
with pd.ExcelWriter(output_path, engine='openpyxl') as writer:
|
||||
summary_df.to_excel(writer, sheet_name='채점결과요약', index=False)
|
||||
detail_df.to_excel(writer, sheet_name='채점상세내역', index=False)
|
||||
detail_df.to_excel(writer, sheet_name='채점상세내역', index=True)
|
||||
typo_df.to_excel(writer, sheet_name='오타내역', index=False)
|
||||
|
||||
# 열 너비 자동 조정
|
||||
|
||||
Reference in New Issue
Block a user