-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport_formatter.py
More file actions
160 lines (122 loc) · 6.24 KB
/
report_formatter.py
File metadata and controls
160 lines (122 loc) · 6.24 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Dict, List
from datetime import date
from stats_parser import sort_authors_by_activity
class ReportFormatter:
"""Handles formatting and display of git statistics reports."""
def __init__(self, repo_path: str):
"""
Initialize the formatter with repository path.
Args:
repo_path: Absolute path to the repository
"""
self.repo_path = repo_path
def print_header(self, title: str, days: int = None) -> None:
"""
Prints a formatted header for reports.
Args:
title: The main title of the report
days: Number of days (optional)
"""
if days:
full_title = f"{title} for the last {days} day(s)"
else:
full_title = title
print(f"\n--- {full_title} ---")
print(f"Repository: {self.repo_path}")
print("-----------------------------------------------------")
def print_footer(self) -> None:
"""Prints the report footer."""
print("-----------------------------------------------------")
def format_net_change(self, net_change: int) -> str:
"""
Formats net change with appropriate sign.
Args:
net_change: The net change value
Returns:
Formatted string with sign
"""
sign = '+' if net_change >= 0 else ''
return f"{net_change} ({sign}{net_change})"
def print_author_stats(self, author_stats: Dict, days: int) -> None:
"""
Prints author statistics report.
Args:
author_stats: Dictionary of author statistics
days: Number of days the stats cover
"""
self.print_header("Author Git Repository Statistics", days)
if not author_stats:
print("No activity found for the specified period.")
return
sorted_authors = sort_authors_by_activity(author_stats)
for author_email, stats in sorted_authors:
print(f"\nAuthor: {stats['name']} <{author_email}>")
print(f" Commits: {stats['commits_count']}")
print(f" Files changed: {stats['total_files_changed']}")
print(f" Lines added: {stats['added_lines']}")
print(f" Lines deleted: {stats['deleted_lines']}")
net_change = stats['added_lines'] - stats['deleted_lines']
print(f" Net lines change: {self.format_net_change(net_change)}")
total_activity = stats['added_lines'] + stats['deleted_lines']
print(f" Total line activity: {total_activity}")
def print_daily_stats(self, daily_breakdown: List[Dict], days: int) -> None:
"""
Prints daily statistics report.
Args:
daily_breakdown: List of daily statistics
days: Number of days
"""
self.print_header("Daily Git Repository Statistics", days)
for day_data in daily_breakdown:
target_date = day_data['date']
stats = day_data['stats']
print(f"\nDate: {target_date.strftime('%Y-%m-%d')}")
if stats:
print(f" Commits: {stats['commits_count']}")
print(f" Files changed: {stats['total_files_changed']}")
print(f" Lines added: {stats['added_lines']}")
print(f" Lines deleted: {stats['deleted_lines']}")
net_change = stats['added_lines'] - stats['deleted_lines']
print(f" Net lines change: {self.format_net_change(net_change)}")
total_activity = stats['added_lines'] + stats['deleted_lines']
print(f" Total line activity: {total_activity}")
else:
print(" No activity or error fetching stats for this day.")
def print_daily_author_stats(self, daily_author_breakdown: List[Dict], days: int) -> None:
"""
Prints daily statistics with author breakdown.
Args:
daily_author_breakdown: List of daily author statistics
days: Number of days
"""
self.print_header("Daily Git Repository Statistics with Author Breakdown", days)
for day_data in daily_author_breakdown:
target_date = day_data['date']
author_stats = day_data['author_stats']
print(f"\nDate: {target_date.strftime('%Y-%m-%d')}")
if author_stats:
sorted_authors = sort_authors_by_activity(author_stats)
day_totals = {'commits': 0, 'added': 0, 'deleted': 0}
for author_email, stats in sorted_authors:
print(f" {stats['name']} <{author_email}>:")
print(f" Commits: {stats['commits_count']}")
print(f" Files changed: {stats['total_files_changed']}")
print(f" Lines added: {stats['added_lines']}")
print(f" Lines deleted: {stats['deleted_lines']}")
net_change = stats['added_lines'] - stats['deleted_lines']
print(f" Net change: {self.format_net_change(net_change)}")
day_totals['commits'] += stats['commits_count']
day_totals['added'] += stats['added_lines']
day_totals['deleted'] += stats['deleted_lines']
print(f" Day Total:")
print(f" Total commits: {day_totals['commits']}")
print(f" Total lines added: {day_totals['added']}")
print(f" Total lines deleted: {day_totals['deleted']}")
net_total = day_totals['added'] - day_totals['deleted']
print(f" Net change: {self.format_net_change(net_total)}")
total_activity = day_totals['added'] + day_totals['deleted']
print(f" Total activity: {total_activity}")
else:
print(" No activity or error fetching stats for this day.")