2507회 채점자료 추가
This commit is contained in:
37
main.py
37
main.py
@@ -6,6 +6,11 @@ import pandas as pd # 추가된 import
|
||||
import unicodedata # 상단에 import 추가
|
||||
import re # 상단에 추가
|
||||
from datetime import datetime
|
||||
import logging
|
||||
from logging_config import setup_logging # logging 설정을 위한 import
|
||||
import traceback
|
||||
|
||||
setup_logging() # logging 설정 호출
|
||||
|
||||
# JSON 파일 읽기
|
||||
def read_json(file_path):
|
||||
@@ -262,14 +267,11 @@ def process_project(project_data, scoring_data):
|
||||
script_data_1 = json.loads(script_raw) if script_raw else None
|
||||
script_data = swap_script(script_data_1) if script_data_1 else None
|
||||
|
||||
if script_data != script_data_1:
|
||||
print(f"⬜ Script data 순서 변경 ")
|
||||
|
||||
block_index = 1
|
||||
for block in block_list:
|
||||
block_type = block.get('type')
|
||||
block_path = block.get('ele')
|
||||
block_expected_answer = block.get('answer', None)
|
||||
block_answer = block.get('answer', None)
|
||||
block_points = block.get('points')
|
||||
|
||||
if script_data is None:
|
||||
@@ -285,23 +287,23 @@ def process_project(project_data, scoring_data):
|
||||
block_elements = find_element(script_data, block_path)
|
||||
|
||||
# 결과값 정리
|
||||
if block_elements and isinstance(block_expected_answer, list):
|
||||
if block_elements and isinstance(block_answer, list):
|
||||
found_values = [convert_to_str(x) for x in chain.from_iterable(block_elements)]
|
||||
else:
|
||||
found_values = convert_to_str(block_elements[0]) if block_elements else None
|
||||
|
||||
expected_str = convert_to_str(block_expected_answer) if block_expected_answer is not None else None
|
||||
expected_str = convert_to_str(block_answer) if block_answer is not None else None
|
||||
|
||||
# 비교 및 점수 처리
|
||||
if block_elements:
|
||||
if block_expected_answer is not None and expected_str != found_values:
|
||||
if block_answer is not None and expected_str != found_values:
|
||||
print(f"{question_key}-{block_index}: ❌ {expected_str} != {found_values}")
|
||||
score_list.append(0)
|
||||
elif block_expected_answer is not None and expected_str == found_values:
|
||||
elif block_answer is not None and expected_str == found_values:
|
||||
print(f"{question_key}-{block_index}: ✅ {expected_str} == {found_values}")
|
||||
total_points += block_points
|
||||
score_list.append(block_points)
|
||||
elif block_expected_answer is None:
|
||||
elif block_answer is None:
|
||||
total_points += block_points
|
||||
score_list.append(block_points)
|
||||
print(f"{question_key}-{block_index}: Element Exists")
|
||||
@@ -311,6 +313,7 @@ def process_project(project_data, scoring_data):
|
||||
|
||||
block_index += 1
|
||||
|
||||
# total_points = round(total_points, ndigits=0) # 총점 반올림
|
||||
score_list.append(total_points)
|
||||
return score_list
|
||||
|
||||
@@ -321,9 +324,9 @@ def normalize_path(path):
|
||||
|
||||
def main():
|
||||
# 파일 경로 설정
|
||||
# project_json_path = './output/2506_CAS_2_A/'
|
||||
project_json_path = './output/00_test/'
|
||||
scoring_json_path = './correct/2506_CAS_2_A.json'
|
||||
project_json_path = './output/2507_CAT_3_A/'
|
||||
# project_json_path = './output/00_test/'
|
||||
scoring_json_path = './correct/2507_CAT_3_A.json'
|
||||
|
||||
scoring_data = read_json(scoring_json_path)
|
||||
student_score_list = []
|
||||
@@ -363,9 +366,14 @@ def main():
|
||||
# 디렉토리 패스 내에 학생 이름만 뽑아서 엑셀 컬럼 명으로 추가
|
||||
# output/cas-000040-이지원/temp/project.json
|
||||
# student_id = normalize_path(full_path.split('/')[3])
|
||||
match = re.search(r'(\d{6}-[^\\/]+)[\\/]', full_path)
|
||||
match = re.search(r'(\d{6}[-_][^\\/]+)[\\/]', full_path)
|
||||
if match:
|
||||
student_id = match.group(1)
|
||||
else:
|
||||
if '정답' in full_path:
|
||||
student_id = '정답'
|
||||
else:
|
||||
student_id = '000000'
|
||||
|
||||
# project.json 파일 내용
|
||||
project_data = read_json(full_path)
|
||||
@@ -374,7 +382,8 @@ def main():
|
||||
student_score_list.append(points)
|
||||
print(f"Total Points for {points}")
|
||||
except Exception as e:
|
||||
print(f"Error processing {full_path}: {str(e)}")
|
||||
# print(traceback.format_exc())
|
||||
logging.exception(f"🚫Error processing {full_path}: {str(e)}")
|
||||
continue
|
||||
|
||||
# DataFrame 생성 및 엑셀 저장
|
||||
|
||||
Reference in New Issue
Block a user