diff --git a/.gitignore b/.gitignore index afa589f2a9..5ed4e12626 100644 --- a/.gitignore +++ b/.gitignore @@ -125,4 +125,4 @@ ENV/ # Rope project settings .ropeproject -.history/ +.history/ \ No newline at end of file diff --git a/environment/frontend_server/temp_storage/curr_sim_code.json b/environment/frontend_server/temp_storage/curr_sim_code.json index 310d4314bc..33ad340bc7 100644 --- a/environment/frontend_server/temp_storage/curr_sim_code.json +++ b/environment/frontend_server/temp_storage/curr_sim_code.json @@ -1,3 +1,3 @@ { "sim_code": "33" -} +} \ No newline at end of file diff --git a/print_conversations.py b/print_conversations.py index ff7cf382d3..34de32d23f 100644 --- a/print_conversations.py +++ b/print_conversations.py @@ -1,31 +1,34 @@ +import glob import os import sys import json - def get_unique_conversations(simulation_name): - step_folder = f"environment/frontend_server/storage/{simulation_name}/movement" + step_folder = "environment/frontend_server/storage" + + # Use glob to find all files that start with the simulation_name + search_pattern = os.path.join(step_folder, f"{simulation_name}*/movement/*") + filepaths = glob.glob(search_pattern) observed_conversations = set() file_contents = [] - # Iterate over all files in the simulation folder - for filename in os.listdir(step_folder): - filepath = os.path.join(step_folder, filename) - + # Iterate over all matching files + for filepath in filepaths: with open(filepath, "r") as file: data = json.load(file) - personas = data["persona"] + personas = data.get("persona", {}) # Loop over all personas except one, since conversations are always # between two people for name in list(personas.keys())[:-1]: persona = personas[name] - chat = persona["chat"] + chat = persona.get("chat") if chat: chat_string = str(chat) + # Add unique conversations if chat_string not in observed_conversations: observed_conversations.add(chat_string) file_contents.append(data) @@ -33,6 +36,15 @@ def get_unique_conversations(simulation_name): return file_contents +def write_conversations_to_file(conversations, simulation_name): + output_directory = "logs/conversations" + if not os.path.exists(output_directory): + os.makedirs(output_directory) + output_filename = f"{simulation_name}_highlights.json" + full_path = os.path.join(output_directory, output_filename); + with open(full_path, "w") as file: + for conversation in conversations: + json.dump(conversation, file, indent=4) if __name__ == "__main__": if len(sys.argv) < 2: @@ -41,4 +53,9 @@ def get_unique_conversations(simulation_name): simulation_name = sys.argv[1] unique_conversations = get_unique_conversations(simulation_name) - print(json.dumps(unique_conversations, indent=2)) + + if unique_conversations: + write_conversations_to_file(unique_conversations, simulation_name) + print(f"Unique conversations written to {simulation_name}_highlights.txt") + else: + print("No unique conversations found.") \ No newline at end of file