Skip to content

Commit

Permalink
fix: summary (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feudalman authored Sep 19, 2024
1 parent 64b2003 commit aaaeeeb
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions swanboard/controller/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import ujson
import shutil
from fastapi import Request
from urllib.parse import quote
from swanboard.utils import check_desc_format, get_swanlog_dir, COLOR_LIST, swanlog
import yaml
from typing import List
Expand Down Expand Up @@ -124,12 +123,11 @@ def get_project_summary(project_id: int = DEFAULT_PROJECT_ID) -> dict:
"id": experiment.id,
"name": experiment.name,
"run_id": experiment.run_id,
"tags": [tag["name"] for tag in __to_list(experiment.tags)],
"tags": [{"name": tag["name"], "sort": tag["sort"]} for tag in __to_list(experiment.tags)],
}
for experiment in experiments
]
ids = [item["id"] for item in exprs]

# 根据 id 列表找到所有的 tag,提出不含重复 tag 名的元组
# tags = Tag.filter(Tag.experiment_id.in_(ids)).order_by(Tag.experiment_id)
tags = (
Expand All @@ -151,12 +149,13 @@ def get_project_summary(project_id: int = DEFAULT_PROJECT_ID) -> dict:
data = {}
# 第一层循环对应实验层,每次探寻一个实验
for expr in exprs:
# 第二层为 tag 层,在实验目录下遍历所有 tag,若存在则获取最后一个次提交的值
# 第二层为 tag 层,在实验目录下遍历所有 tag,若存在则获取最后一次提交的值
experiment_summaries = {}
for tag in expr["tags"]:
tag_path = get_tag_dir(expr["run_id"], quote(tag, safe=""))
# tag 结构:{ name: tag_name, sort: tag_sort },其中 sort 同时为 tag 文件夹名
tag_path = get_tag_dir(expr["run_id"], str(tag["sort"]))
if not os.path.exists(tag_path):
experiment_summaries[tag] = "TypeError"
experiment_summaries[tag["name"]] = "TypeError"
continue
# 获取所有 tag 文件
logs = get_tag_files(tag_path, exclude=LOGS_CONFIGS)
Expand All @@ -165,9 +164,9 @@ def get_project_summary(project_id: int = DEFAULT_PROJECT_ID) -> dict:
try:
lines = f.readlines()
tag_data = ujson.loads(lines[-1])
experiment_summaries[tag] = tag_data["data"]
experiment_summaries[tag["name"]] = tag_data["data"]
except Exception as e:
swanlog.error(f"[expr: {expr['name']} - {tag}] --- {e}")
swanlog.error(f"[expr: {expr['name']} - {tag["name"]}] --- {e}")
continue

data[expr["name"]] = experiment_summaries
Expand Down

0 comments on commit aaaeeeb

Please # to comment.