Files

82 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""Forge Log Analyzer - extracts key metrics from forge output files."""
import sys
from pathlib import Path
from datetime import datetime
import re
def analyze_forge_log(filepath):
"""Analyze a forge log file and return key metrics."""
content = Path(filepath).read_text()
# Extract duration from filename
filename = Path(filepath).name
duration_match = re.match(r'forge-(\d{4}-\d{2}-\d{2}-\d{6})\.txt', filename)
metrics = {
'file': str(filepath),
'lines': 0,
'words': 0,
'chars': 0,
'session_time': None,
'first_line': None,
'analysis': datetime.now().isoformat()
}
lines = content.split('\n')
metrics['lines'] = len(lines)
metrics['words'] = len(content.split())
metrics['chars'] = len(content)
if lines:
metrics['first_line'] = lines[0][:100] if len(lines[0]) > 100 else lines[0]
if duration_match:
ts_str = duration_match.group(1)
try:
dt = datetime.strptime(ts_str, '%Y-%m-%d-%H%M%S')
metrics['session_time'] = dt.strftime('%Y-%m-%d %H:%M:%S')
except:
pass
return metrics
def main():
outputs_dir = Path('/root/.hermes/wizard-outputs')
forge_logs = sorted(outputs_dir.glob('forge-*.txt'))
if not forge_logs:
print("No forge logs found")
return 1
print("Forge Log Analyzer Report")
print("=" * 60)
total_lines = 0
total_chars = 0
max_chars = 0
min_chars = float('inf')
for log in forge_logs[:10]:
m = analyze_forge_log(log)
total_lines += m['lines']
total_chars += m['chars']
max_chars = max(max_chars, m['chars'])
min_chars = min(min_chars, m['chars'])
print(f"\n{log.name}:")
print(f" Lines: {m['lines']}, Words: {m['words']}, Chars: {m['chars']}")
if m['session_time']:
print(f" Session: {m['session_time']}")
print("\n" + "=" * 60)
print(f"Total analyzed: {len(forge_logs[:10])} files")
print(f"Total lines: {total_lines}")
print(f"Total characters: {total_chars}")
if forge_logs:
print(f"Avg file size: {total_chars / len(forge_logs[:10]):.0f} chars")
print(f"Size range: {min_chars} - {max_chars} chars")
return 0
if __name__ == '__main__':
sys.exit(main())