Skip to content
Snippets Groups Projects
Commit 6a671b9e authored by Florian Schröder's avatar Florian Schröder
Browse files

Refactor recorder and hooks setup in config files

This commit refactors the setup of recorders and hooks in several configuration files. It simplifies the YAML structure, renames "extra_setup_functions" to "hook_callbacks", and replaces "log_path" with "record_path". This makes the configurations cleaner and more intuitive. The update also removes the "func" and "kwargs" in the extra setup functions. Now only hooks are registered. This change should not affect functionality, because until now only hooks were registered as extra setup functions.
parent 0ddb9e04
No related branches found
No related tags found
1 merge request!77Resolve "Remove repitition of Hook callback class in env config"
Pipeline #48290 passed
Showing with 379 additions and 485 deletions
......@@ -323,7 +323,7 @@ player_config:
effect_manager: # fire effect
...
extra_setup_functions: # scores, recording, msgs, etc.
hook_callbacks: # scores, recording, msgs, etc.
...
```
......
......@@ -98,114 +98,96 @@ effect_manager:
fire_burns_ingredients_and_meals: true
extra_setup_functions:
hook_callbacks:
# # --------------- Scoring ---------------
orders:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ completed_order ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 20
score_on_specific_kwarg: meal_name
score_map:
Burger: 15
OnionSoup: 10
Salad: 5
TomatoSoup: 10
hooks: [ completed_order ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 20
score_on_specific_kwarg: meal_name
score_map:
Burger: 15
OnionSoup: 10
Salad: 5
TomatoSoup: 10
not_ordered_meals:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ serve_not_ordered_meal ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 2
hooks: [ serve_not_ordered_meal ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 2
trashcan_usages:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ trashcan_usage ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -5
hooks: [ trashcan_usage ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -5
expired_orders:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ order_expired ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -10
# # --------------- Recording ---------------
hooks: [ order_expired ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -10
# --------------- Recording ---------------
# json_states:
# func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
# kwargs:
# hooks: [ json_state ]
# callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
# callback_class_kwargs:
# log_path: USER_LOG_DIR/ENV_NAME/json_states.jsonl
# hooks: [ json_state ]
# callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
# callback_class_kwargs:
# record_path: USER_LOG_DIR/ENV_NAME/json_states.jsonl
actions:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ pre_perform_action ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
hooks: [ pre_perform_action ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
random_env_events:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ order_duration_sample, plate_out_of_kitchen_time ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
hooks: [ order_duration_sample, plate_out_of_kitchen_time ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
env_configs:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ env_initialized, item_info_config ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
hooks: [ env_initialized, item_info_config ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
# Game event recording
game_events:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks:
- post_counter_pick_up
- post_counter_drop_off
- post_dispenser_pick_up
- cutting_board_100
- player_start_interaction
- player_end_interact
- post_serving
- no_serving
- dirty_plate_arrives
- trashcan_usage
- plate_cleaned
- added_plate_to_sink
- drop_on_sink_addon
- pick_up_from_sink_addon
- serve_not_ordered_meal
- serve_without_plate
- completed_order
- new_orders
- order_expired
- action_on_not_reachable_counter
- new_fire
- fire_spreading
- drop_off_on_cooking_equipment
- players_collide
- post_plate_dispenser_pick_up
- post_plate_dispenser_drop_off
- on_item_transition
- progress_started
- progress_finished
- content_ready
hooks:
- post_counter_pick_up
- post_counter_drop_off
- post_dispenser_pick_up
- cutting_board_100
- player_start_interaction
- player_end_interact
- post_serving
- no_serving
- dirty_plate_arrives
- trashcan_usage
- plate_cleaned
- added_plate_to_sink
- drop_on_sink_addon
- pick_up_from_sink_addon
- serve_not_ordered_meal
- serve_without_plate
- completed_order
- new_orders
- order_expired
- action_on_not_reachable_counter
- new_fire
- fire_spreading
- drop_off_on_cooking_equipment
- players_collide
- post_plate_dispenser_pick_up
- post_plate_dispenser_drop_off
- on_item_transition
- progress_started
- progress_finished
- content_ready
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
# info_msg:
......
......@@ -98,127 +98,105 @@ effect_manager:
fire_burns_ingredients_and_meals: true
extra_setup_functions:
hook_callbacks:
# # --------------- Scoring ---------------
orders:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ completed_order ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 20
score_on_specific_kwarg: meal_name
score_map:
Burger: 15
OnionSoup: 10
Salad: 5
TomatoSoup: 10
hooks: [ completed_order ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 20
score_on_specific_kwarg: meal_name
score_map:
Burger: 15
OnionSoup: 10
Salad: 5
TomatoSoup: 10
not_ordered_meals:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ serve_not_ordered_meal ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 2
hooks: [ serve_not_ordered_meal ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 2
trashcan_usages:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ trashcan_usage ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -5
hooks: [ trashcan_usage ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -5
expired_orders:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ order_expired ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -10
hooks: [ order_expired ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -10
# # --------------- Recording ---------------
# json_states:
# func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
# kwargs:
# hooks: [ json_state ]
# callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
# callback_class_kwargs:
# log_path: USER_LOG_DIR/ENV_NAME/json_states.jsonl
# hooks: [ json_state ]
# callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
# callback_class_kwargs:
# record_path: USER_LOG_DIR/ENV_NAME/json_states.jsonl
# Game event recording
game_events:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks:
- post_counter_pick_up
- post_counter_drop_off
- post_dispenser_pick_up
- cutting_board_100
- player_start_interaction
- player_end_interact
- post_serving
- no_serving
- dirty_plate_arrives
- trashcan_usage
- plate_cleaned
- added_plate_to_sink
- drop_on_sink_addon
- pick_up_from_sink_addon
- serve_not_ordered_meal
- serve_without_plate
- completed_order
- new_orders
- order_expired
- action_on_not_reachable_counter
- new_fire
- fire_spreading
- drop_off_on_cooking_equipment
- players_collide
- post_plate_dispenser_pick_up
- post_plate_dispenser_drop_off
- on_item_transition
- progress_started
- progress_finished
- content_ready
hooks:
- post_counter_pick_up
- post_counter_drop_off
- post_dispenser_pick_up
- cutting_board_100
- player_start_interaction
- player_end_interact
- post_serving
- no_serving
- dirty_plate_arrives
- trashcan_usage
- plate_cleaned
- added_plate_to_sink
- drop_on_sink_addon
- pick_up_from_sink_addon
- serve_not_ordered_meal
- serve_without_plate
- completed_order
- new_orders
- order_expired
- action_on_not_reachable_counter
- new_fire
- fire_spreading
- drop_off_on_cooking_equipment
- players_collide
- post_plate_dispenser_pick_up
- post_plate_dispenser_drop_off
- on_item_transition
- progress_started
- progress_finished
- content_ready
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
actions:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ pre_perform_action ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
hooks: [ pre_perform_action ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
random_env_events:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ order_duration_sample, plate_out_of_kitchen_time ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
hooks: [ order_duration_sample, plate_out_of_kitchen_time ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
env_configs:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ env_initialized, item_info_config ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
hooks: [ env_initialized, item_info_config ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
# info_msg:
# func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
# kwargs:
# hooks: [ cutting_board_100 ]
# log_class: !!python/name:cooperative_cuisine.info_msg.InfoMsgManager ''
# log_class_kwargs:
# msg: Glückwunsch du hast was geschnitten!
# hooks: [ cutting_board_100 ]
# record_class: !!python/name:cooperative_cuisine.info_msg.InfoMsgManager ''
# record_class_kwargs:
# msg: Glückwunsch du hast was geschnitten!
# fire_msg:
# func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
# kwargs:
# hooks: [ new_fire ]
# log_class: !!python/name:cooperative_cuisine.info_msg.InfoMsgManager ''
# log_class_kwargs:
# msg: Feuer, Feuer, Feuer
# level: Warning
# hooks: [ new_fire ]
# record_class: !!python/name:cooperative_cuisine.info_msg.InfoMsgManager ''
# record_class_kwargs:
# msg: Feuer, Feuer, Feuer
# level: Warning
......@@ -97,127 +97,105 @@ effect_manager:
fire_burns_ingredients_and_meals: true
extra_setup_functions:
hook_callbacks:
# # --------------- Scoring ---------------
orders:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ completed_order ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 20
score_on_specific_kwarg: meal_name
score_map:
Burger: 15
OnionSoup: 10
Salad: 5
TomatoSoup: 10
hooks: [ completed_order ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 20
score_on_specific_kwarg: meal_name
score_map:
Burger: 15
OnionSoup: 10
Salad: 5
TomatoSoup: 10
not_ordered_meals:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ serve_not_ordered_meal ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 2
hooks: [ serve_not_ordered_meal ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 2
trashcan_usages:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ trashcan_usage ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -5
hooks: [ trashcan_usage ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -5
expired_orders:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ order_expired ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -10
hooks: [ order_expired ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -10
# # --------------- Recording ---------------
# json_states:
# func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
# kwargs:
# hooks: [ json_state ]
# callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
# callback_class_kwargs:
# log_path: USER_LOG_DIR/ENV_NAME/json_states.jsonl
# hooks: [ json_state ]
# callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
# callback_class_kwargs:
# record_path: USER_LOG_DIR/ENV_NAME/json_states.jsonl
actions:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ pre_perform_action ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
hooks: [ pre_perform_action ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
random_env_events:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ order_duration_sample, plate_out_of_kitchen_time ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
hooks: [ order_duration_sample, plate_out_of_kitchen_time ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
env_configs:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ env_initialized, item_info_config ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
hooks: [ env_initialized, item_info_config ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
# Game event recording
game_events:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks:
- post_counter_pick_up
- post_counter_drop_off
- post_dispenser_pick_up
- cutting_board_100
- player_start_interaction
- player_end_interact
- post_serving
- no_serving
- dirty_plate_arrives
- trashcan_usage
- plate_cleaned
- added_plate_to_sink
- drop_on_sink_addon
- pick_up_from_sink_addon
- serve_not_ordered_meal
- serve_without_plate
- completed_order
- new_orders
- order_expired
- action_on_not_reachable_counter
- new_fire
- fire_spreading
- drop_off_on_cooking_equipment
- players_collide
- post_plate_dispenser_pick_up
- post_plate_dispenser_drop_off
- on_item_transition
- progress_started
- progress_finished
- content_ready
hooks:
- post_counter_pick_up
- post_counter_drop_off
- post_dispenser_pick_up
- cutting_board_100
- player_start_interaction
- player_end_interact
- post_serving
- no_serving
- dirty_plate_arrives
- trashcan_usage
- plate_cleaned
- added_plate_to_sink
- drop_on_sink_addon
- pick_up_from_sink_addon
- serve_not_ordered_meal
- serve_without_plate
- completed_order
- new_orders
- order_expired
- action_on_not_reachable_counter
- new_fire
- fire_spreading
- drop_off_on_cooking_equipment
- players_collide
- post_plate_dispenser_pick_up
- post_plate_dispenser_drop_off
- on_item_transition
- progress_started
- progress_finished
- content_ready
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
# info_msg:
# func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
# kwargs:
# hooks: [ cutting_board_100 ]
# log_class: !!python/name:cooperative_cuisine.info_msg.InfoMsgManager ''
# log_class_kwargs:
# msg: Glückwunsch du hast was geschnitten!
# hooks: [ cutting_board_100 ]
# record_class: !!python/name:cooperative_cuisine.info_msg.InfoMsgManager ''
# record_class_kwargs:
# msg: Glückwunsch du hast was geschnitten!
# fire_msg:
# func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
# kwargs:
# hooks: [ new_fire ]
# log_class: !!python/name:cooperative_cuisine.info_msg.InfoMsgManager ''
# log_class_kwargs:
# msg: Feuer, Feuer, Feuer
# level: Warning
# hooks: [ new_fire ]
# record_class: !!python/name:cooperative_cuisine.info_msg.InfoMsgManager ''
# record_class_kwargs:
# msg: Feuer, Feuer, Feuer
# level: Warning
......@@ -94,4 +94,4 @@ effect_manager:
fire_burns_ingredients_and_meals: true
extra_setup_functions:
\ No newline at end of file
hook_callbacks:
\ No newline at end of file
......@@ -51,6 +51,7 @@ from cooperative_cuisine.hooks import (
ACTION_INTERACT_START,
ITEM_INFO_CONFIG,
POST_STEP,
hooks_via_callback_class,
)
from cooperative_cuisine.items import (
ItemInfo,
......@@ -90,8 +91,8 @@ class EnvironmentConfig(TypedDict):
"""Configuration about the player characters."""
layout_chars: dict[str, str]
"""Definition of which characters in the layout file correspond to which kitchen counter."""
extra_setup_functions: dict[str, dict]
"""Configuration of extra setup functions, for example hook behavior."""
hook_callbacks: dict[str, dict]
"""Configuration of callbacks via HookCallbackClass."""
effect_manager: dict
"""Config of different effects in the environment, which control for example fire behavior."""
......@@ -184,7 +185,7 @@ class Environment:
"player_config"
].view_range
self.extra_setup_functions()
self.hook_callbacks()
self.layout_config: str = layout_config
"""The layout config for the environment"""
......@@ -570,16 +571,14 @@ class Environment:
"""
self.hook.register_callback(hook_ref, callback)
def extra_setup_functions(self):
def hook_callbacks(self):
"""Executes extra setup functions specified in the environment configuration."""
if self.environment_config["extra_setup_functions"]:
for function_name, function_def in self.environment_config[
"extra_setup_functions"
if self.environment_config["hook_callbacks"]:
for callback_name, setup_kwargs in self.environment_config[
"hook_callbacks"
].items():
log.info(f"Setup function {function_name}")
function_def["func"](
name=function_name, env=self, **function_def["kwargs"]
)
log.info(f"Setup hook callback {callback_name}")
hooks_via_callback_class(name=callback_name, env=self, **setup_kwargs)
def increment_score(self, score: int | float, info: str = ""):
"""Add a value to the current score and log it."""
......
......@@ -2,7 +2,7 @@
You can add callbacks at specific points in the environment.
This "hook" mechanism is defined here.
You can add hooks via the `environment_config` under `extra_setup_functions` and the here defined
You can add hooks via the `environment_config` under `hook_callbacks` and the here defined
`hooks_via_callback_class` function.
Each hook get different kwargs. But `env` with the environment object and `hook_ref` with the name of the hook are
......@@ -229,7 +229,7 @@ def hooks_via_callback_class(
callback_class: Type[HookCallbackClass],
callback_class_kwargs: dict[str, Any],
):
"""Function to reference in the `environment_config.yml` to add functionality via hooks and a configured callback class.
"""Setup hook callback class.
Args:
name: A string representing the name of the callback class instance.
......
"""Based on hooks, text-based info msgs can be displayed.
```yaml
extra_setup_functions:
hook_callbacks:
info_msg:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ cutting_board_100 ]
callback_class: !!python/name:cooperative_cuisine.info_msg.InfoMsgManager ''
callback_class_kwargs:
msg: Glückwunsch du hast was geschnitten!
fire_msg:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ new_fire ]
callback_class: !!python/name:cooperative_cuisine.info_msg.InfoMsgManager ''
callback_class_kwargs:
msg: Feuer, Feuer, Feuer
level: Warning
hooks: [ cutting_board_100 ]
callback_class: !!python/name:cooperative_cuisine.info_msg.InfoMsgManager ''
callback_class_kwargs:
msg: Glückwunsch du hast was geschnitten!
fire_msg:
hooks: [ new_fire ]
callback_class: !!python/name:cooperative_cuisine.info_msg.InfoMsgManager ''
callback_class_kwargs:
msg: Feuer, Feuer, Feuer
level: Warning
```
"""
......
......@@ -72,14 +72,14 @@ def simulate(
You can record the relevant files via hooks in the environment_config:
```yaml
extra_setup_functions
hook_callbacks
env_configs:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ env_initialized, item_info_config ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
actions:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
......@@ -87,7 +87,7 @@ def simulate(
hooks: [ pre_perform_action ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
```
You can call simulation function via the command line. For example by replacing the ENVIRONMENT_ID (Linux system) or the complete path:
......@@ -219,7 +219,7 @@ def from_json_states(
hooks: [ json_state ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/json_states.jsonl
record_path: USER_LOG_DIR/ENV_NAME/json_states.jsonl
```
You can call this function via the command line:
......
......@@ -7,42 +7,35 @@ https://pypi.org/project/platformdirs/) -> `user_log_dir`.
- `ENV_NAME` to the name of the environment.
```yaml
extra_setup_functions:
hook_callbacks:
json_states:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ json_state ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/json_states.jsonl
hooks: [ json_state ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
record_path: USER_LOG_DIR/ENV_NAME/json_states.jsonl
actions:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ pre_perform_action ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
hooks: [ pre_perform_action ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
random_env_events:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ order_duration_sample, plate_out_of_kitchen_time ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
hooks: [ order_duration_sample, plate_out_of_kitchen_time ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
env_configs:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ env_initialized, item_info_config ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
hooks: [ env_initialized, item_info_config ]
callback_class: !!python/name:cooperative_cuisine.recording.FileRecorder ''
callback_class_kwargs:
record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
add_hook_ref: true
```
"""
import json
import logging
import os
import sys
import traceback
from pathlib import Path
from string import Template
......@@ -68,7 +61,7 @@ class FileRecorder(HookCallbackClass):
self,
name: str,
env: Environment,
log_path: str = "USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl",
record_path: str = "USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl",
add_hook_ref: bool = False,
**kwargs,
):
......@@ -77,19 +70,19 @@ class FileRecorder(HookCallbackClass):
Args:
name (str): The name of the recorder. This name is used to replace the placeholder "LOG_RECORD_NAME" in the default log file path.
env (Environment): The environment in which the recorder is being used.
log_path (str, optional): The path to the log file. Defaults to "USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl".
record_path (str, optional): The path to the log file. Defaults to "USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl".
add_hook_ref (bool, optional): Indicates whether to add a hook reference to the recorded data. Defaults to False.
**kwargs: Additional keyword arguments.
"""
super().__init__(name, env, **kwargs)
self.add_hook_ref: bool = add_hook_ref
"""Indicates whether to add a hook reference to the recorded data. Default value is False."""
log_path = log_path.replace("LOG_RECORD_NAME", name)
log_path = Path(expand_path(log_path, env_name=env.env_name))
self.log_path: Path = log_path
record_path = record_path.replace("LOG_RECORD_NAME", name)
record_path = Path(expand_path(record_path, env_name=env.env_name))
self.record_path: Path = record_path
"""The path to the log file. Default value is "USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl"."""
log.info(f"Recorder record for {name} in file://{log_path}")
os.makedirs(log_path.parent, exist_ok=True)
log.info(f"Recorder record for {name} in file://{record_path}")
os.makedirs(record_path.parent, exist_ok=True)
def __call__(self, hook_ref: str, env: Environment, **kwargs):
for key, item in kwargs.items():
......@@ -134,8 +127,8 @@ class FileRecorder(HookCallbackClass):
)
+ "\n"
)
with open(self.log_path, "a") as log_file:
log_file.write(record)
with open(self.record_path, "a") as record_file:
record_file.write(record)
except TypeError as e:
traceback.print_exception(e)
log.info(
......@@ -151,7 +144,7 @@ def print_recorded_events_human_readable(jsonl_path: Path):
"""
def stringify_item(item_):
def stringify_item(item_) -> str | None:
if isinstance(item_, float):
return str(item_)
if isinstance(item_, str):
......@@ -226,7 +219,5 @@ def print_recorded_events_human_readable(jsonl_path: Path):
if __name__ == "__main__":
json_lines_path: Path = Path(
"/home/fabian/.local/state/cooperative_cuisine/log/fcb095915c454446b9ee2905ff534610/game_events.jsonl"
)
json_lines_path: Path = Path(sys.argv[0])
print_recorded_events_human_readable(json_lines_path)
......@@ -98,86 +98,64 @@ effect_manager: { }
# fire_burns_ingredients_and_meals: true
extra_setup_functions:
hook_callbacks:
# # --------------- Scoring ---------------
orders:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ completed_order ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 0.95
hooks: [ completed_order ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 0.95
serve_not_ordered_meals:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ serve_not_ordered_meal ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 0.95
hooks: [ serve_not_ordered_meal ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 0.95
trashcan_usages:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ trashcan_usage ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -0.2
hooks: [ trashcan_usage ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -0.2
item_cut:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ cutting_board_100 ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 0.1
hooks: [ cutting_board_100 ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 0.1
stepped:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ post_step ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -0.01
hooks: [ post_step ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -0.01
combine:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ drop_off_on_cooking_equipment ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 0.01
hooks: [ drop_off_on_cooking_equipment ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 0.01
start_interact:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ player_start_interaction ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 0.01
# json_states:
# func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
# kwargs:
# hooks: [ json_state ]
# log_class: !!python/name:cooperative_cuisine.recording.LogRecorder ''
# log_class_kwargs:
# log_path: USER_LOG_DIR/ENV_NAME/json_states.jsonl
hooks: [ player_start_interaction ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 0.01
# json_states:
# hooks: [ json_state ]
# record_class: !!python/name:cooperative_cuisine.recording.LogRecorder ''
# record_class_kwargs:
# record_path: USER_LOG_DIR/ENV_NAME/json_states.jsonl
# actions:
# func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
# kwargs:
# hooks: [ pre_perform_action ]
# log_class: !!python/name:cooperative_cuisine.recording.LogRecorder ''
# log_class_kwargs:
# log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
# hooks: [ pre_perform_action ]
# record_class: !!python/name:cooperative_cuisine.recording.LogRecorder ''
# record_class_kwargs:
# record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
# random_env_events:
# func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
# kwargs:
# hooks: [ order_duration_sample, plate_out_of_kitchen_time ]
# log_class: !!python/name:cooperative_cuisine.recording.LogRecorder ''
# log_class_kwargs:
# log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
# add_hook_ref: true
# hooks: [ order_duration_sample, plate_out_of_kitchen_time ]
# record_class: !!python/name:cooperative_cuisine.recording.LogRecorder ''
# record_class_kwargs:
# record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
# add_hook_ref: true
# env_configs:
# func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
# kwargs:
# hooks: [ env_initialized, item_info_config ]
# log_class: !!python/name:cooperative_cuisine.recording.LogRecorder ''
# log_class_kwargs:
# log_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
# add_hook_ref: true
# hooks: [ env_initialized, item_info_config ]
# record_class: !!python/name:cooperative_cuisine.recording.LogRecorder ''
# record_class_kwargs:
# record_path: USER_LOG_DIR/ENV_NAME/LOG_RECORD_NAME.jsonl
# add_hook_ref: true
"""
Scores are managed via hooks. You can add them in the `environment_config` under `extra_setup_functions`.
Scores are managed via hooks. You can add them in the `environment_config` under `hook_callbacks`.
The here defined `ScoreViaHooks` is a `HookCallbackClass`. It allows you to define how the score is effected by
specific hook events.
......@@ -12,41 +12,33 @@ You can:
You can filter the events via `kwarg_filter`.
```yaml
extra_setup_functions:
hook_callbacks:
orders:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ completed_order ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 20
score_on_specific_kwarg: meal_name
score_map:
Burger: 15
OnionSoup: 10
Salad: 5
TomatoSoup: 10
hooks: [ completed_order ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 20
score_on_specific_kwarg: meal_name
score_map:
Burger: 15
OnionSoup: 10
Salad: 5
TomatoSoup: 10
not_ordered_meals:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ serve_not_ordered_meal ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 2
hooks: [ serve_not_ordered_meal ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: 2
trashcan_usages:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ trashcan_usage ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -5
hooks: [ trashcan_usage ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -5
expired_orders:
func: !!python/name:cooperative_cuisine.hooks.hooks_via_callback_class ''
kwargs:
hooks: [ order_expired ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -10
hooks: [ order_expired ]
callback_class: !!python/name:cooperative_cuisine.scores.ScoreViaHooks ''
callback_class_kwargs:
static_score: -10
```
......
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