diff --git a/norms/wsocket.py b/norms/wsocket.py index b339bbe..ad37930 100644 --- a/norms/wsocket.py +++ b/norms/wsocket.py @@ -14,5 +14,6 @@ async def main(): async with serve(echo, "localhost", 8765): await asyncio.Future() # run forever + if __name__ == "__main__": asyncio.run(main()) diff --git a/src/social_norms_trees/atomic_mutations.py b/src/social_norms_trees/atomic_mutations.py index 8a9b744..3b014b9 100644 --- a/src/social_norms_trees/atomic_mutations.py +++ b/src/social_norms_trees/atomic_mutations.py @@ -190,10 +190,8 @@ def exchange( --> A """ - node0_parent, node0_index = node0.parent, node0.parent.children.index( - node0) - node1_parent, node1_index = node1.parent, node1.parent.children.index( - node1) + node0_parent, node0_index = node0.parent, node0.parent.children.index(node0) + node1_parent, node1_index = node1.parent, node1.parent.children.index(node1) move(node0, (node1_parent, node1_index)) move(node1, (node0_parent, node0_index)) @@ -527,7 +525,7 @@ def prompt_identify_composite( tree: py_trees.behaviour.Behaviour, message: str = "Which composite node?", display_nodes: bool = True, - skip_label: str = "_" + skip_label: str = "_", ) -> Tuple[py_trees.composites.Composite, int]: """ Example: @@ -655,8 +653,7 @@ def format_library_with_indices(library: List[py_trees.behaviour.Behaviour]): # Wrapper functions for the atomic operations which give them a UI. -MutationResult = namedtuple( - "MutationResult", ["result", "tree", "function", "kwargs"]) +MutationResult = namedtuple("MutationResult", ["result", "tree", "function", "kwargs"]) def mutate_chooser(*fs: Union[Callable], message="Which action?"): @@ -723,14 +720,12 @@ def prompt_get_mutate_arguments(annotation: GenericAlias, tree, library): return node elif annotation_ == str(CompositeIndex): _logger.debug("in CompositeIndex") - composite_node = prompt_identify_composite( - tree, message="Which parent?") + composite_node = prompt_identify_composite(tree, message="Which parent?") index = prompt_identify_child_index(composite_node) return composite_node, index elif annotation_ == str(NewNode): _logger.debug("in NewNode") - new_node = prompt_identify_library_node( - library, "Which node from the library?") + new_node = prompt_identify_library_node(library, "Which node from the library?") return new_node else: _logger.debug("in 'else'") diff --git a/src/social_norms_trees/ui_wrapper.py b/src/social_norms_trees/ui_wrapper.py index de1f3ba..88c9e88 100644 --- a/src/social_norms_trees/ui_wrapper.py +++ b/src/social_norms_trees/ui_wrapper.py @@ -45,8 +45,7 @@ def experiment_setup(db, origin_tree): print("\n") participant_id = participant_login() - experiment_id = initialize_experiment_record( - db, participant_id, origin_tree) + experiment_id = initialize_experiment_record(db, participant_id, origin_tree) print("\nSetup Complete.\n") @@ -61,8 +60,7 @@ def participant_login(): def load_resources(file_path): try: - print( - f"\nLoading behavior tree and behavior library from {file_path}...\n") + print(f"\nLoading behavior tree and behavior library from {file_path}...\n") with open(file_path, "r") as file: resources = json.load(file) @@ -137,8 +135,7 @@ def run_experiment(db, origin_tree, experiment_id, behavior_library): db[experiment_id]["action_history"].append(action_log) elif action == 4: - origin_tree, action_log = add_node( - origin_tree, behavior_library) + origin_tree, action_log = add_node(origin_tree, behavior_library) db[experiment_id]["action_history"].append(action_log) else: @@ -167,9 +164,16 @@ def run_experiment(db, origin_tree, experiment_id, behavior_library): @app.command() def main( - resources_file: Annotated[pathlib.Path, typer.Argument(help="file with the experimental context, behavior tree, and behavior library")], - db_file: Annotated[pathlib.Path, typer.Option( - help="file where the experimental results will be written")] = "db.json", + resources_file: Annotated[ + pathlib.Path, + typer.Argument( + help="file with the experimental context, behavior tree, and behavior library" + ), + ], + db_file: Annotated[ + pathlib.Path, + typer.Option(help="file where the experimental results will be written"), + ] = "db.json", ): print("AIT Prototype #1 Simulator") @@ -179,8 +183,7 @@ def main( # load tree to run experiment on, and behavior library - original_tree, behavior_library, context_paragraph = load_resources( - resources_file) + original_tree, behavior_library, context_paragraph = load_resources(resources_file) print(f"\nContext of this experiment: {context_paragraph}") participant_id, experiment_id = experiment_setup(db, original_tree)