Add scoring system with JSON configuration and point calculation logic
This commit is contained in:
65
main.py
65
main.py
@@ -0,0 +1,65 @@
|
||||
from jsonpath_ng.ext import parse
|
||||
import json
|
||||
|
||||
# 파일 경로 설정
|
||||
project_json_path = '/Users/waterdrw/Works/KAIT/Entry-Scoring/sample/제2410회 코딩활용능력 2급 B형 정답/project.json'
|
||||
scoring_json_path = '/Users/waterdrw/Works/KAIT/Entry-Scoring/scoring.json'
|
||||
|
||||
# JSON 파일 읽기
|
||||
def read_json(file_path):
|
||||
with open(file_path, 'r', encoding='utf-8') as file:
|
||||
return json.load(file)
|
||||
|
||||
# 요소 탐색 함수
|
||||
def find_element(project_data, jsonpath_expr):
|
||||
jsonpath_expr = parse(jsonpath_expr)
|
||||
return [match.value for match in jsonpath_expr.find(project_data)]
|
||||
|
||||
# 요소 탐색 함수
|
||||
def find_script_element(project_data, jsonpath_expr):
|
||||
jsonpath_expr = parse(jsonpath_expr)
|
||||
match = jsonpath_expr.find(project_data)
|
||||
|
||||
return match[0].value
|
||||
|
||||
|
||||
|
||||
|
||||
# main 함수
|
||||
def main():
|
||||
project_data = read_json(project_json_path)
|
||||
scoring_data = read_json(scoring_json_path)
|
||||
|
||||
total_points = 0
|
||||
|
||||
for key, value in scoring_data.items():
|
||||
ele = value.get('ele')
|
||||
type = value.get('type')
|
||||
blocks = value.get('blocks')
|
||||
|
||||
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}")
|
||||
|
||||
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'))
|
||||
|
||||
# 블록에 따라 params 값이나 statements 값이 있는 경우 처리 추가 필요
|
||||
|
||||
if block_exists:
|
||||
total_points += block.get('points')
|
||||
# else:
|
||||
# print(f"No elements found for {block.get('ele')}")
|
||||
|
||||
print(f"Total Points: {total_points}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
51
scorer.py
Normal file
51
scorer.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import json
|
||||
|
||||
def load_json(file_path):
|
||||
with open(file_path, 'r', encoding='utf-8') as file:
|
||||
return json.load(file)
|
||||
|
||||
def compare_params(params1, params2):
|
||||
if len(params1) != len(params2):
|
||||
return False
|
||||
for p1, p2 in zip(params1, params2):
|
||||
if p1 != p2:
|
||||
return False
|
||||
return True
|
||||
|
||||
def calculate_points(project_data, scoring_data):
|
||||
total_points = 0
|
||||
for key, criteria in scoring_data.items():
|
||||
ele = criteria['ele']
|
||||
arg = criteria['arg']
|
||||
value = criteria['value']
|
||||
|
||||
|
||||
if ele == "scenes":
|
||||
for scene in project_data['scenes']:
|
||||
if scene.get(arg) == value:
|
||||
points = criteria['points']
|
||||
total_points += points
|
||||
break
|
||||
elif ele == "objects":
|
||||
for obj in project_data['objects']:
|
||||
if obj.get(arg) == value:
|
||||
if 'script' in criteria:
|
||||
for script_criteria in criteria['script']:
|
||||
for script in json.loads(obj['script']):
|
||||
if script['type'] == script_criteria['type']:
|
||||
if 'params' in script_criteria:
|
||||
if compare_params(script['params'], script_criteria['params']):
|
||||
total_points += script_criteria['points']
|
||||
else:
|
||||
total_points += script_criteria['points']
|
||||
return total_points
|
||||
|
||||
def main():
|
||||
project_data = load_json('sample/제2410회 코딩활용능력 2급 B형 정답/project.json')
|
||||
scoring_data = load_json('scoring.json')
|
||||
|
||||
total_points = calculate_points(project_data, scoring_data)
|
||||
print(f"Total Points: {total_points}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
29
scoring.json
Normal file
29
scoring.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"0": {
|
||||
"type": "scene",
|
||||
"ele": "$.scenes[0].name",
|
||||
"value": "장면 1",
|
||||
"points": 10
|
||||
},
|
||||
"1": {
|
||||
"type": "scene",
|
||||
"ele": "$.scenes[1].name",
|
||||
"value": "장면 2",
|
||||
"points": 10
|
||||
},
|
||||
"2": {
|
||||
"type": "script",
|
||||
"ele": "$.objects[?(@.name=='미어캣')].script[*]",
|
||||
"blocks": [
|
||||
{
|
||||
"ele": "$[*][?(@.type=='hide')]",
|
||||
"points": 10
|
||||
},
|
||||
{
|
||||
"ele": "$[*][?(@.type=='set_scale_size')].params[0].params[0]",
|
||||
"points": 10
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
}
|
||||
429
scripts.json
Normal file
429
scripts.json
Normal file
@@ -0,0 +1,429 @@
|
||||
[
|
||||
[
|
||||
{
|
||||
"id": "w44a",
|
||||
"x": 50,
|
||||
"y": 30,
|
||||
"type": "when_run_button_click",
|
||||
"params": [
|
||||
null
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
{
|
||||
"id": "lks0",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "hide",
|
||||
"params": [
|
||||
null
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
{
|
||||
"id": "3wtk",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "set_scale_size",
|
||||
"params": [
|
||||
{
|
||||
"id": "cs1e",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "number",
|
||||
"params": [
|
||||
"60"
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
null
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
{
|
||||
"id": "0ihj",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "repeat_inf",
|
||||
"params": [
|
||||
null,
|
||||
null
|
||||
],
|
||||
"statements": [
|
||||
[
|
||||
{
|
||||
"id": "orn8",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "locate_xy",
|
||||
"params": [
|
||||
{
|
||||
"id": "dmfl",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "calc_rand",
|
||||
"params": [
|
||||
null,
|
||||
{
|
||||
"id": "8u37",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "number",
|
||||
"params": [
|
||||
"-200"
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
null,
|
||||
{
|
||||
"id": "ouuv",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "number",
|
||||
"params": [
|
||||
"200"
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
null
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
{
|
||||
"id": "8j47",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "calc_rand",
|
||||
"params": [
|
||||
null,
|
||||
{
|
||||
"id": "669m",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "number",
|
||||
"params": [
|
||||
"-100"
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
null,
|
||||
{
|
||||
"id": "kaq0",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "number",
|
||||
"params": [
|
||||
"100"
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
null
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
null
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
{
|
||||
"id": "ro4n",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "wait_second",
|
||||
"params": [
|
||||
{
|
||||
"id": "6xf0",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "number",
|
||||
"params": [
|
||||
"1"
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
null
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
{
|
||||
"id": "r39u",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "show",
|
||||
"params": [
|
||||
null
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
{
|
||||
"id": "kkqk",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "wait_second",
|
||||
"params": [
|
||||
{
|
||||
"id": "167c",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "number",
|
||||
"params": [
|
||||
"1"
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
null
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
{
|
||||
"id": "0qng",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "hide",
|
||||
"params": [
|
||||
null
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
}
|
||||
]
|
||||
],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"id": "knwd",
|
||||
"x": 53,
|
||||
"y": 343,
|
||||
"type": "when_message_cast",
|
||||
"params": [
|
||||
null,
|
||||
"m0l6"
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
{
|
||||
"id": "40hi",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "_if",
|
||||
"params": [
|
||||
{
|
||||
"id": "sbmy",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "reach_something",
|
||||
"params": [
|
||||
null,
|
||||
"xskt",
|
||||
null
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
null
|
||||
],
|
||||
"statements": [
|
||||
[
|
||||
{
|
||||
"id": "jy0j",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "hide",
|
||||
"params": [
|
||||
null
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
{
|
||||
"id": "w887",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "change_variable",
|
||||
"params": [
|
||||
"v94h",
|
||||
{
|
||||
"id": "grbn",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"type": "text",
|
||||
"params": [
|
||||
"-10"
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
},
|
||||
null
|
||||
],
|
||||
"statements": [],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
}
|
||||
]
|
||||
],
|
||||
"movable": null,
|
||||
"deletable": 1,
|
||||
"emphasized": false,
|
||||
"readOnly": null,
|
||||
"copyable": true,
|
||||
"assemble": true,
|
||||
"extensions": []
|
||||
}
|
||||
]
|
||||
]
|
||||
Reference in New Issue
Block a user