엔트리 채점 기능 수정 및 채점표 작성
This commit is contained in:
88
main.py
88
main.py
@@ -1,8 +1,9 @@
|
||||
from jsonpath_ng.ext import parse
|
||||
import json
|
||||
from itertools import chain
|
||||
|
||||
# 파일 경로 설정
|
||||
project_json_path = './sample/제2410회 코딩활용능력 2급 B형 정답/project.json'
|
||||
project_json_path = './sample/제2502회 코딩활용능력 2급 B형 정답/project.json'
|
||||
scoring_json_path = './scoring.json'
|
||||
|
||||
# JSON 파일 읽기
|
||||
@@ -20,8 +21,21 @@ def find_script_element(project_data, jsonpath_expr):
|
||||
jsonpath_expr = parse(jsonpath_expr)
|
||||
match = jsonpath_expr.find(project_data)
|
||||
|
||||
if not match:
|
||||
return None
|
||||
|
||||
return match[0].value
|
||||
|
||||
# jsonpath_expr_list 로 넘어온 jsonpath들을 하나씩 parse 해주고 결과를 result 리스트로 반환
|
||||
def find_list_element(data, jsonpath_expr_list):
|
||||
result = []
|
||||
|
||||
for jsonpath_expr in jsonpath_expr_list:
|
||||
jsonpath_expr = parse(jsonpath_expr)
|
||||
result.append([match.value for match in jsonpath_expr.find(data)])
|
||||
|
||||
return result
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -30,33 +44,77 @@ def main():
|
||||
project_data = read_json(project_json_path)
|
||||
scoring_data = read_json(scoring_json_path)
|
||||
|
||||
total_points = 0
|
||||
total_points = 0
|
||||
|
||||
for key, value in scoring_data.items():
|
||||
ele = value.get('ele')
|
||||
type = value.get('type')
|
||||
blocks = value.get('blocks')
|
||||
# 정답
|
||||
answer = value.get('answer')
|
||||
|
||||
print(f"example: {key}")
|
||||
if type == "scene":
|
||||
exists = find_element(project_data, ele)
|
||||
if exists:
|
||||
# print(f"No elements found for {ele}")
|
||||
total_points += value.get('points')
|
||||
# else:
|
||||
# print(f"Element '{ele}' exists in project.json: {exists}")
|
||||
print(f"elements found for {ele}")
|
||||
if exists == answer:
|
||||
total_points += value.get('points')
|
||||
elif exists and answer == None:
|
||||
total_points += value.get('points')
|
||||
print(f"{ele} found ");
|
||||
else :
|
||||
print(f"{exists} not found");
|
||||
else:
|
||||
print(f"Element '{ele}' exists in project.json: {exists}")
|
||||
|
||||
if type == "script":
|
||||
exists = find_script_element(project_data, ele)
|
||||
temp = json.loads(exists)
|
||||
for block in blocks:
|
||||
block_exists = find_element(temp, block.get('ele'))
|
||||
exists = find_script_element(project_data, ele)
|
||||
|
||||
# 블록에 따라 params 값이나 statements 값이 있는 경우 처리 추가 필요
|
||||
if exists == None:
|
||||
temp = None
|
||||
else:
|
||||
temp = json.loads(exists)
|
||||
|
||||
if block_exists:
|
||||
total_points += block.get('points')
|
||||
# else:
|
||||
# print(f"No elements found for {block.get('ele')}")
|
||||
innerKey= 1;
|
||||
for block in blocks:
|
||||
innerType = block.get('type')
|
||||
|
||||
if temp == None:
|
||||
print(f"{key}-{innerKey}: Script Not exist")
|
||||
innerKey = innerKey + 1
|
||||
continue
|
||||
|
||||
if innerType == "list":
|
||||
block_exists = find_list_element(temp, block.get('ele'))
|
||||
|
||||
else:
|
||||
block_exists = find_element(temp, block.get('ele'))
|
||||
|
||||
# 정답
|
||||
answer = block.get('answer', None)
|
||||
|
||||
if isinstance(answer, list):
|
||||
flat_matches = list(chain.from_iterable(block_exists))
|
||||
|
||||
else:
|
||||
flat_matches = block_exists[0]
|
||||
|
||||
|
||||
# 블록에 따라 params 값이나 statements 값이 있는 경우 처리 추가 필요
|
||||
if block_exists:
|
||||
if answer is not None and answer != flat_matches:
|
||||
print(f"{key}-{innerKey}: {answer} != {flat_matches}")
|
||||
elif answer is not None and answer == flat_matches:
|
||||
print(f"{key}-{innerKey}: {answer} == {flat_matches}")
|
||||
total_points += block.get('points')
|
||||
elif answer is None and block_exists:
|
||||
total_points += block.get('points')
|
||||
print(f"{key}-{innerKey}: exist ele: {block_exists}")
|
||||
else:
|
||||
print(f"No elements found for {block.get('ele')}")
|
||||
|
||||
innerKey = innerKey + 1
|
||||
|
||||
print(f"Total Points: {total_points}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user