mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-17 15:35:21 +02:00
Merge branch 'minecraft' of github.com:geekan/MetaGPT into minecraft
This commit is contained in:
commit
e81339f0b0
9 changed files with 65 additions and 35 deletions
|
|
@ -9,7 +9,7 @@ def extract_logs(filename, start_time=None, end_time=None):
|
|||
with open(filename, 'r') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
if start_time is None or end_time is None:
|
||||
if start_time is None :
|
||||
# 如果没有提供时间参数,则返回所有日志
|
||||
return lines
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ def extract_logs(filename, start_time=None, end_time=None):
|
|||
capture = True
|
||||
if capture:
|
||||
logs_block.append(line)
|
||||
if end_time in line:
|
||||
if end_time and end_time in line:
|
||||
capture = False
|
||||
break
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ def extract_time_from_last_round_zero(log_filename):
|
|||
|
||||
# 倒序遍历文件的每一行
|
||||
for line in reversed(lines):
|
||||
if "check msg round :0" in line:
|
||||
if "Config loading done" in line:
|
||||
# 正则表达式匹配年月日 小时:分钟的格式
|
||||
match = re.search(r'(\d{4}-\d{2}-\d{2} \d{2}:\d{2})', line)
|
||||
if match:
|
||||
|
|
@ -44,43 +44,57 @@ def analyze_log_block(logs_block):
|
|||
rounds: list[int] = []
|
||||
items_collected :list[int] = []
|
||||
total_items = 0
|
||||
positions:list[(int,int,int)] = []
|
||||
|
||||
check_for_info = False # 用于检查是否应在下几行中查找 Inventory 的标志
|
||||
line_after_message = 0 # 从 "Critic Agent human message" 开始计数的行数
|
||||
positions:list[(int, int, int)] = []
|
||||
completed_tasks: list[int] = []
|
||||
failed_tasks: list[int] = []
|
||||
|
||||
round_start = False
|
||||
check_for_info = False # 用于检查是否应在下几行中查找Position Inventory 的标志
|
||||
line_after_message = 0 # 从 "Curriculum Agent human message" 开始计数的行数
|
||||
|
||||
for line in logs_block:
|
||||
if "check msg round :" in line:
|
||||
n = int(re.search(r'check msg round :(\d+)', line).group(1))
|
||||
if "round_id:" in line:
|
||||
n = int(re.search(r'round_id:(\d+)', line).group(1))
|
||||
if n not in rounds:
|
||||
rounds.append(n)
|
||||
items_collected.append(total_items) # add previous total before updating
|
||||
if "Critic Agent human message" in line:
|
||||
check_for_info = True
|
||||
line_after_message = 0
|
||||
continue
|
||||
round_start = True
|
||||
check_for_info = True
|
||||
|
||||
if check_for_info:
|
||||
line_after_message += 1
|
||||
if round_start:
|
||||
if "Curriculum Agent human message" in line:
|
||||
line_after_message = 0
|
||||
continue
|
||||
|
||||
if line_after_message <= 20:
|
||||
if "Position: x=" in line:
|
||||
match = re.search(r'Position: x=([\d.-]+), y=([\d.-]+), z=([\d.-]+)', line)
|
||||
if match:
|
||||
if check_for_info:
|
||||
line_after_message += 1
|
||||
|
||||
if line_after_message <= 20:
|
||||
if "Position: x=" in line:
|
||||
match = re.search(r'Position: x=([\d.-]+), y=([\d.-]+), z=([\d.-]+)', line)
|
||||
x, y, z = float(match.group(1)), float(match.group(2)), float(match.group(3))
|
||||
positions.append((x, y, z))
|
||||
|
||||
if "Inventory (" in line:
|
||||
if ": Empty" in line:
|
||||
check_for_info = False
|
||||
continue
|
||||
items = re.search(r'Inventory \(\d+/36\): ({.*?})', line).group(1)
|
||||
items_dict = eval(items)
|
||||
total_items = sum(items_dict.values())
|
||||
check_for_info = False
|
||||
if "Inventory (" in line:
|
||||
if ": Empty" in line:
|
||||
items_collected.append(0)
|
||||
else:
|
||||
items = re.search(r'Inventory \(\d+/36\): ({.*?})', line).group(1)
|
||||
items_dict = eval(items)
|
||||
total_items = sum(items_dict.values())
|
||||
items_collected.append(total_items)
|
||||
|
||||
return rounds, items_collected,positions
|
||||
if "Completed tasks so far:" in line:
|
||||
tasks = line.replace("Completed tasks so far:", "").strip().split(", ")
|
||||
completed_tasks.append(0 if tasks == ['None'] else len(tasks))
|
||||
|
||||
if "Failed tasks that are too hard:" in line:
|
||||
tasks = line.replace("Failed tasks that are too hard:", "").strip().split(", ")
|
||||
failed_tasks.append(0 if tasks == ['None'] else len(tasks))
|
||||
check_for_info = False
|
||||
round_start = False
|
||||
|
||||
min_len: int = min(len(rounds), len(items_collected), len(positions), len(completed_tasks), len(failed_tasks))
|
||||
return rounds[:min_len], items_collected[:min_len], positions[:min_len], completed_tasks[:min_len], failed_tasks[:min_len]
|
||||
|
||||
def save_item_results_png(rounds, items_collected, start_time, path_prefix):
|
||||
# item png
|
||||
|
|
@ -88,7 +102,9 @@ def save_item_results_png(rounds, items_collected, start_time, path_prefix):
|
|||
plt.xlabel("Round")
|
||||
plt.ylabel("Total Items Collected")
|
||||
plt.title("Items Collected Over Rounds")
|
||||
plt.grid(True)
|
||||
plt.savefig(f'{path_prefix}/{start_time}_items_collected_over_rounds.png', dpi=300)
|
||||
plt.close()
|
||||
|
||||
def save_path_results_png(positions, start_time, path_prefix):
|
||||
|
||||
|
|
@ -115,7 +131,19 @@ def save_path_results_png(positions, start_time, path_prefix):
|
|||
ax.set_zlabel("Z Coordinate")
|
||||
ax.text(min(x_coords), max(y_coords), max(z_coords), f"Total Distance: {total_distance:.2f} units", fontsize=15, color='red')
|
||||
plt.savefig(f'{path_prefix}/{start_time}_bot_movement_3D_path.png', dpi=300)
|
||||
plt.close()
|
||||
|
||||
def save_task_results_png(rounds , completed, failed, start_time, path_prefix):
|
||||
plt.plot(rounds, completed, label='Completed Tasks', marker='o')
|
||||
plt.plot(rounds, failed, label='Failed Tasks', marker='x')
|
||||
|
||||
plt.xlabel("Rounds")
|
||||
plt.ylabel("Number of Tasks")
|
||||
plt.title("Completed vs Failed Tasks per Round")
|
||||
plt.grid(True)
|
||||
plt.legend()
|
||||
plt.savefig(f'{path_prefix}/{start_time}_task_results.png', dpi=300)
|
||||
plt.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Analyze game log file between a start and end time.")
|
||||
|
|
@ -124,7 +152,6 @@ if __name__ == "__main__":
|
|||
parser.add_argument('--end_time', type=str, default=None, nargs='?', help="End time for analysis in the log file.")
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
current_script_path = os.path.dirname(os.path.abspath(__file__))
|
||||
filename = f"{current_script_path}/logs/log.txt"
|
||||
|
||||
|
|
@ -137,7 +164,8 @@ if __name__ == "__main__":
|
|||
start_time = extract_time_from_last_round_zero(filename)
|
||||
logs_block = extract_logs(filename, start_time)
|
||||
|
||||
rounds, items_collected, positions = analyze_log_block(logs_block)
|
||||
rounds, items_collected, positions, completed_tasks, failed_tasks= analyze_log_block(logs_block)
|
||||
#save png
|
||||
save_item_results_png(rounds, items_collected, args.start_time if args.start_time else start_time, current_script_path+"/results_pic")
|
||||
save_path_results_png(positions, args.start_time if args.start_time else start_time, current_script_path+"/results_pic")
|
||||
save_path_results_png(positions, args.start_time if args.start_time else start_time, current_script_path+"/results_pic")
|
||||
save_task_results_png(rounds, completed_tasks, failed_tasks, args.start_time if args.start_time else start_time, current_script_path+"/results_pic" )
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
javascript
|
||||
requests
|
||||
psutil
|
||||
chromadb==0.3.29
|
||||
chromadb==0.3.29
|
||||
minecraft_launcher_lib
|
||||
|
|
@ -30,7 +30,8 @@
|
|||
"dependencies": {
|
||||
"mineflayer": "^4.0.0",
|
||||
"mineflayer-pathfinder": "^2.1.1",
|
||||
"mineflayer-tool": "^1.1.0"
|
||||
"mineflayer-tool": "^1.1.0",
|
||||
"npm": "^10.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.6.4",
|
||||
|
|
|
|||
|
|
@ -310,7 +310,7 @@ class CurriculumDesigner(Base):
|
|||
context = self.game_memory.context
|
||||
elif inventoryUsed >= 33:
|
||||
context = self.generate_context_if_inventory_full(
|
||||
self, events=events, chest_observation=chest_observation
|
||||
events=events, chest_observation=chest_observation
|
||||
)
|
||||
else:
|
||||
logger.info(self.game_memory.qa_cache_questions_vectordb._collection.count())
|
||||
|
|
|
|||
BIN
results_pic/2023-10-10 17:02_bot_movement_3D_path.png
Normal file
BIN
results_pic/2023-10-10 17:02_bot_movement_3D_path.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 682 KiB |
BIN
results_pic/2023-10-10 17:02_items_collected_over_rounds.png
Normal file
BIN
results_pic/2023-10-10 17:02_items_collected_over_rounds.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 83 KiB |
BIN
results_pic/2023-10-10 17:02_task_results.png
Normal file
BIN
results_pic/2023-10-10 17:02_task_results.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 129 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 786 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 79 KiB |
Loading…
Add table
Add a link
Reference in a new issue