diff --git a/cooperative_cuisine/configs/human_readable_print_templates.yaml b/cooperative_cuisine/configs/human_readable_print_templates.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0e1bec2cddac67bac7ce25dad95188e7c0e36d9a --- /dev/null +++ b/cooperative_cuisine/configs/human_readable_print_templates.yaml @@ -0,0 +1,27 @@ +post_dispenser_pick_up: "Player $player picked up $return_this from the $counter." +post_counter_pick_up: "Player $player picked $return_this up from $counter." +post_counter_drop_off: "Player $player dropped $item off on $counter." +cutting_board_100: "Player $player_name finished chopping at $counter." +player_start_interaction: "Player $player started interacting with $counter." +player_end_interact: "Player $player stopped interacting with $counter." +post_serving: "Item $item was served at $counter." +dirty_plate_arrives: "A plate returned to $counter." +trashcan_usage: "Player $player threw $item in $counter." +plate_cleaned: "Player $player_name cleaned a plate at $counter." +added_plate_to_sink: "Player $player put $item in $counter." +drop_on_sink_addon: "Player $player put $item on $counter." +pick_up_from_sink_addon: "Player $player picked up $occupied_by from $counter." +serve_not_ordered_meal: "Meal $meal was served but it was not ordered." +completed_order: "Order $order was completed." +new_orders: "Orders $new_orders were ordered." +order_expired: "Order $order expired." +action_on_not_reachable_counter: "Action $action was performed yet nearest counter $counter was not reachable." +new_fire: "A fire broke out at $target." +fire_spreading: "A fire spread to target." +drop_off_on_cooking_equipment: "Player $player put $item in/on $equipment at $counter." +post_plate_dispenser_pick_up: "Player $player picked up $returned_item from $counter." +post_plate_dispenser_drop_off: "Player $player dropped $item on $counter." +on_item_transition: "$item became $result." +progress_started: "Item $item started progressing." +progress_finished: "Item $item finished its progress." +content_ready: "Meal $result was created on $before." diff --git a/cooperative_cuisine/recording.py b/cooperative_cuisine/recording.py index 8d19009df42f4eaac6d5c0c45c10579c46dfd892..c46f4190d75bf7bb1c20893ee9286fd2a9baaf9e 100644 --- a/cooperative_cuisine/recording.py +++ b/cooperative_cuisine/recording.py @@ -47,6 +47,9 @@ import traceback from pathlib import Path from string import Template +import yaml + +from cooperative_cuisine import ROOT_DIR from cooperative_cuisine.counters import Counter from cooperative_cuisine.environment import Environment from cooperative_cuisine.hooks import HookCallbackClass @@ -162,8 +165,9 @@ def print_recorded_events_human_readable(jsonl_path: Path): else: return None - seen_keys = [] - print() + with open(ROOT_DIR / "configs" / "human_readable_print_templates.yaml", "r") as f: + string_templates = yaml.safe_load(f) + column_size = 20 with open(jsonl_path, "r") as jsonl_file: for line in jsonl_file: @@ -200,110 +204,17 @@ def print_recorded_events_human_readable(jsonl_path: Path): except KeyError as e: pass - # print(hook) - match hook: - case "post_dispenser_pick_up": - n = Template( - "Player $player picked up $return_this from the $counter." - ) - print(n.substitute(**dict(record.items()))) - case "post_counter_pick_up": - n = Template("Player $player picked $return_this up from $counter.") - print(n.substitute(**dict(record.items()))) - case "post_counter_drop_off": - n = Template("Player $player dropped $item off on $counter.") - print(n.substitute(**dict(record.items()))) - case "cutting_board_100": - n = Template("Player $player_name finished chopping at $counter.") - print(n.substitute(**dict(record.items()))) - case "player_start_interaction": - n = Template("Player $player started interacting with $counter.") - print(n.substitute(**dict(record.items()))) - case "player_end_interact": - n = Template("Player $player stopped interacting with $counter.") - print(n.substitute(**dict(record.items()))) - case "post_serving": - n = Template("Item $item was served at $counter.") - print(n.substitute(**dict(record.items()))) - # case "no_serving": - # pass - case "dirty_plate_arrives": - n = Template("A plate returned to $counter.") - print(n.substitute(**dict(record.items()))) - case "trashcan_usage": - n = Template("Player $player threw $item in $counter.") - print(n.substitute(**dict(record.items()))) - case "plate_cleaned": - n = Template("Player $player_name cleaned a plate at $counter.") - print(n.substitute(**dict(record.items()))) - case "added_plate_to_sink": - n = Template("Player $player put $item in $counter.") - print(n.substitute(**dict(record.items()))) - case "drop_on_sink_addon": - n = Template("Player $player put $item on $counter.") - print(n.substitute(**dict(record.items()))) - case "pick_up_from_sink_addon": - n = Template("Player $player picked up $occupied_by from $counter.") - print(n.substitute(**dict(record.items()))) - case "serve_not_ordered_meal": - n = Template("Meal $meal was served but it was not ordered.") - print(n.substitute(**dict(record.items()))) - # case "serve_without_plate": - # pass - case "completed_order": - n = Template("Order $order was completed.") - print(n.substitute(**dict(record.items()))) - case "new_orders": - n = Template("Orders $new_orders were ordered.") - print(n.substitute(**dict(record.items()))) - case "order_expired": - n = Template("Order $order expired.") - print(n.substitute(**dict(record.items()))) - case "action_on_not_reachable_counter": - n = Template("Action $action was performed yet nearest counter $counter was not reachable.") - print(n.substitute(**dict(record.items()))) - case "new_fire": - n = Template("A fire broke out at $target.") - print(n.substitute(**dict(record.items()))) - case "fire_spreading": - n = Template("A fire spread to target.") - print(n.substitute(**dict(record.items()))) - case "drop_off_on_cooking_equipment": - n = Template( - "Player $player put $item in/on $equipment at $counter." - ) - print(n.substitute(**dict(record.items()))) - # case "players_collide": - # pass - case "post_plate_dispenser_pick_up": - n = Template( - "Player $player picked up $returned_item from $counter." - ) - print(n.substitute(**dict(record.items()))) - case "post_plate_dispenser_drop_off": - n = Template("Player $player dropped $item on $counter.") - print(n.substitute(**dict(record.items()))) - case "on_item_transition": - n = Template("$item became $result.") - print(n.substitute(**dict(record.items()))) - case "progress_started": - n = Template("Item $item started progressing.") - print(n.substitute(**dict(record.items()))) - case "progress_finished": - n = Template("Item $item finished its progress.") - print(n.substitute(**dict(record.items()))) - case "content_ready": - n = Template("Meal $result was created on $before.") - print(n.substitute(**dict(record.items()))) - case other: - print() - print(hook) - for key, item in record.items(): - print(f" - {(key+':').ljust(column_size)}{item}") + if hook in string_templates.keys(): + string_template = Template(string_templates[hook]) + print(string_template.substitute(**dict(record.items()))) + else: + print(hook) + for key, item in record.items(): + print(f" - {(key+':').ljust(column_size)}{item}") if __name__ == "__main__": jsonl_path: Path = Path( - "/home/fabian/.local/state/cooperative_cuisine/log/9dac74d0af424115a70932c51db9023d/game_events.jsonl" + "/Users/fheinrich/Library/Logs/cooperative_cuisine/e8b0551442934324bd3204c46379ebe5/game_events.jsonl" ) print_recorded_events_human_readable(jsonl_path)