forked from kristaller486/RuQualBench
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender_debug.py
More file actions
69 lines (50 loc) · 2.19 KB
/
render_debug.py
File metadata and controls
69 lines (50 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import argparse
import json
import base64
from pathlib import Path
from jinja2 import Environment, FileSystemLoader
def load_benchmark_log(log_path: str) -> dict:
"""Загружает лог бенчмарка из JSON файла"""
with open(log_path, 'r', encoding='utf-8') as f:
return json.load(f)
def generate_html(log_data: dict, filename: str) -> str:
"""Генерирует HTML для отладки используя Jinja2 шаблон"""
env = Environment(loader=FileSystemLoader('templates'))
template = env.get_template('debug.html')
config = log_data['config']
results = log_data['results']
summary = log_data['summary']
# Подготавливаем данные для шаблона
results_json = json.dumps(results, ensure_ascii=False)
results_b64 = base64.b64encode(results_json.encode("utf-8")).decode("ascii")
# Рендерим шаблон
html = template.render(
config=config,
results=results,
summary=summary,
results_json=results_json,
results_b64=results_b64,
filename=filename
)
return html
def main():
parser = argparse.ArgumentParser(description='Генерация HTML для отладки логов бенчмарка')
parser.add_argument('log_file', type=str, help='Путь к JSON логу бенчмарка')
args = parser.parse_args()
log_path = Path(args.log_file)
if not log_path.exists():
print(f"Ошибка: файл {args.log_file} не найден")
return
print(f"Загрузка лога: {log_path}")
log_data = load_benchmark_log(args.log_file)
print("Генерация HTML...")
html_content = generate_html(log_data, log_path.name)
# Сохраняем HTML рядом с логом
output_path = log_path.with_suffix('.html')
with open(output_path, 'w', encoding='utf-8') as f:
f.write(html_content)
print(f"HTML сохранен в: {output_path}")
print(f"\nОткройте файл в браузере для просмотра:")
print(f" {output_path.absolute()}")
if __name__ == "__main__":
main()