Skip to content
Snippets Groups Projects
Commit 0d7d34bc authored by Fabian Heinrich's avatar Fabian Heinrich
Browse files

String templates in yaml file

parent dee3714c
No related branches found
No related tags found
1 merge request!75Resolve "record relevent game events with hooks"
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."
...@@ -47,6 +47,9 @@ import traceback ...@@ -47,6 +47,9 @@ import traceback
from pathlib import Path from pathlib import Path
from string import Template from string import Template
import yaml
from cooperative_cuisine import ROOT_DIR
from cooperative_cuisine.counters import Counter from cooperative_cuisine.counters import Counter
from cooperative_cuisine.environment import Environment from cooperative_cuisine.environment import Environment
from cooperative_cuisine.hooks import HookCallbackClass from cooperative_cuisine.hooks import HookCallbackClass
...@@ -162,8 +165,9 @@ def print_recorded_events_human_readable(jsonl_path: Path): ...@@ -162,8 +165,9 @@ def print_recorded_events_human_readable(jsonl_path: Path):
else: else:
return None return None
seen_keys = [] with open(ROOT_DIR / "configs" / "human_readable_print_templates.yaml", "r") as f:
print() string_templates = yaml.safe_load(f)
column_size = 20 column_size = 20
with open(jsonl_path, "r") as jsonl_file: with open(jsonl_path, "r") as jsonl_file:
for line in jsonl_file: for line in jsonl_file:
...@@ -200,110 +204,17 @@ def print_recorded_events_human_readable(jsonl_path: Path): ...@@ -200,110 +204,17 @@ def print_recorded_events_human_readable(jsonl_path: Path):
except KeyError as e: except KeyError as e:
pass pass
# print(hook) if hook in string_templates.keys():
match hook: string_template = Template(string_templates[hook])
case "post_dispenser_pick_up": print(string_template.substitute(**dict(record.items())))
n = Template( else:
"Player $player picked up $return_this from the $counter." print(hook)
) for key, item in record.items():
print(n.substitute(**dict(record.items()))) print(f" - {(key+':').ljust(column_size)}{item}")
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 __name__ == "__main__": if __name__ == "__main__":
jsonl_path: Path = Path( 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) print_recorded_events_human_readable(jsonl_path)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment