Skip to content

Commit

Permalink
Merge pull request #14 from crcresearch/Danny-search-and-rescue
Browse files Browse the repository at this point in the history
Danny search and rescue
  • Loading branch information
chowington authored Nov 25, 2024
2 parents 89adcdd + 1ca7cfc commit 0dcf80a
Show file tree
Hide file tree
Showing 2 changed files with 265 additions and 140 deletions.
59 changes: 59 additions & 0 deletions print_all_sim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
import json
import re
import sys

def get_unique_conversations(simulation_name):
sim_folder = os.path.join("environment", "frontend_server", "storage")

regex_name = re.compile(re.escape(simulation_name + '-'))
for file_name in os.listdir(sim_folder):
step=0
output = []
if regex_name.search(file_name):
step_folder = os.path.join(sim_folder, file_name, "movement")
for filename in os.listdir(step_folder):
filepath = os.path.join(step_folder, filename)
output.append(f"Step {str(step)}:")
try:
with open(filepath, "r") as file:
data = json.load(file)
for k, v in data.items():
output.append(k)
if k == 'persona':
for key, value in v.items():
output.append(f' {key}')
for attribute, val in value.items():
if attribute != 'chat' or (attribute == 'chat' and val is None):
output.append(f' {attribute}: {val}')
else:
output.append(f' {attribute}:')
for convo in val:
output.append(f' {convo[0]}: {convo[1]}')
else:
for key, value in v.items():
output.append(f' {key}: {value}')
output.append('\n')
except json.JSONDecodeError:
continue
except Exception as e:
print(f"Error processing file {filename}: {e}")
continue
step+=1

output_filename = os.path.join(sim_folder, file_name, f"output_0-{file_name.split('-')[5]}.txt", )
with open(output_filename, "w") as output_file:
output_file.write('\n'.join(output))


if __name__ == "__main__":
if len(sys.argv) < 2:
print("Please provide the simulation name as a command line argument.")
sys.exit(1)

simulation_name = sys.argv[1]
'''
unique_conversations = get_unique_conversations(simulation_name)
print(json.dumps(unique_conversations, indent=2))
'''
get_unique_conversations(simulation_name)
Loading

0 comments on commit 0dcf80a

Please sign in to comment.