Add scoring system with JSON configuration and point calculation logic
This commit is contained in:
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()
|
||||
Reference in New Issue
Block a user