Skip to content

Commit 57cd6b2

Browse files
solzipclaude
andcommitted
fix: stats 프로젝트별 세션 카운트 버그 수정 + 막대 정렬
프로젝트별 세션 수가 전체 세션 수로 동일하게 집계되던 버그를 수정하고, 프로젝트명 길이에 따라 막대 시작 위치가 어긋나던 정렬 문제를 해결 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7f391c5 commit 57cd6b2

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/claude_diary/cli/stats.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def cmd_stats(args):
5252

5353
total_sessions += sessions
5454
daily_sessions[day] = sessions
55-
for p in stats["projects"]:
56-
all_projects[p] += sessions
55+
for p, count in stats.get("project_sessions", {}).items():
56+
all_projects[p] += count
5757
for c in stats.get("categories", []):
5858
all_categories[c] += 1
5959
total_files_created += len(stats["files_created"])
@@ -72,10 +72,11 @@ def cmd_stats(args):
7272
if all_projects:
7373
print(" Projects:")
7474
max_count = max(all_projects.values()) if all_projects else 1
75+
max_name_len = max(len(p) for p in all_projects) + 1
7576
for proj, count in all_projects.most_common(10):
7677
bar_len = int(count / max_count * 16)
7778
bar = "█" * bar_len + "░" * (16 - bar_len)
78-
print(" %-20s %s %d" % (proj, bar, count))
79+
print(" %-*s %s %d" % (max_name_len, proj, bar, count))
7980
print()
8081

8182
if all_categories:

src/claude_diary/lib/stats.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ def parse_daily_file(filepath):
3535
project_matches = re.findall(r'📁 `([^`]+)`', content)
3636
stats["projects"] = set(project_matches)
3737

38+
# Per-project session counts
39+
project_counter = Counter(project_matches)
40+
stats["project_sessions"] = dict(project_counter)
41+
3842
# Files created (KO/EN)
3943
created_matches = re.findall(
4044
r'(?:생성된 파일|Files Created).*?\n((?:\s+- `[^`]+`\n?)+)', content

tests/test_cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ def test_stats_with_projects_and_categories(self, mock_config, mock_parse, base_
694694
mock_config.return_value = base_config
695695
mock_parse.return_value = {
696696
"sessions": 5, "projects": {"my-app"},
697+
"project_sessions": {"my-app": 5},
697698
"files_created": ["a.py"], "files_modified": ["b.py"],
698699
"tasks": [], "categories": ["feature", "bugfix"],
699700
}

0 commit comments

Comments
 (0)