Files
git-insights-cli/src/formatters/dashboard.py
7000pctAUTO 1f925437cc
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
CI / release (push) Has been cancelled
Initial upload: git-insights-cli with CI/CD workflow
2026-01-30 20:35:29 +00:00

113 lines
4.7 KiB
Python

from typing import Any
from rich.console import Console
from rich.panel import Panel
from rich.table import Table
from rich.text import Text
from rich.columns import Columns
from rich.box import ROUNDED
class DashboardFormatter:
"""Rich console dashboard formatter."""
@staticmethod
def display(data: Any) -> None:
"""Display data as a Rich dashboard."""
console = Console()
title = Text("Git Insights - Productivity Dashboard", style="bold green", justify="center")
console.print(Panel(title, box=ROUNDED, style="green"))
console.print()
if hasattr(data, "commit_analysis") and data.commit_analysis:
DashboardFormatter._print_commit_stats(console, data.commit_analysis)
if hasattr(data, "velocity_analysis") and data.velocity_analysis:
DashboardFormatter._print_velocity(console, data.velocity_analysis)
if hasattr(data, "code_churn_analysis") and data.code_churn_analysis:
DashboardFormatter._print_churn(console, data.code_churn_analysis)
if hasattr(data, "risky_commit_analysis") and data.risky_commit_analysis:
DashboardFormatter._print_risky(console, data.risky_commit_analysis)
@staticmethod
def _print_commit_stats(console: Console, ca: Any) -> None:
"""Print commit statistics."""
table = Table(title="[bold]Commit Overview[/bold]", box=ROUNDED)
table.add_column("Metric", style="cyan")
table.add_column("Value", style="magenta")
table.add_row("Total Commits", str(ca.total_commits))
table.add_row("Unique Authors", str(ca.unique_authors))
table.add_row("Avg Commits/Day", f"{ca.average_commits_per_day:.1f}")
console.print(Panel(table, title="[bold yellow]Commits[/bold yellow]", box=ROUNDED))
console.print()
if ca.top_authors:
author_table = Table(title="[bold]Top Contributors[/bold]", box=ROUNDED)
author_table.add_column("Author", style="green")
author_table.add_column("Commits", justify="right", style="blue")
for author in ca.top_authors[:5]:
author_table.add_row(author.name, str(author.commit_count))
console.print(Panel(author_table, box=ROUNDED))
console.print()
@staticmethod
def _print_velocity(console: Console, va: Any) -> None:
"""Print velocity metrics."""
table = Table(box=ROUNDED)
table.add_column("Metric", style="cyan")
table.add_column("Value", style="magenta")
trend_style = "green" if va.velocity_trend == "increasing" else "orange" if va.velocity_trend == "decreasing" else "blue"
table.add_row("Commits/Day", f"{va.commits_per_day:.1f}")
table.add_row("Commits/Week", f"{va.commits_per_week:.1f}")
table.add_row("Velocity Trend", f"[{trend_style}]{va.velocity_trend}[/{trend_style}]")
table.add_row("Most Active Day", va.most_active_day)
table.add_row("Most Active Hour", va.most_active_hour)
console.print(Panel(table, title="[bold yellow]Velocity[/bold yellow]", box=ROUNDED))
console.print()
@staticmethod
def _print_churn(console: Console, cc: Any) -> None:
"""Print code churn metrics."""
table = Table(box=ROUNDED)
table.add_column("Metric", style="cyan")
table.add_column("Value", style="magenta")
net_color = "green" if cc.net_change >= 0 else "red"
table.add_row("Lines Added", f"[green]+{cc.total_lines_added:,}[/green]")
table.add_row("Lines Deleted", f"[red]-{cc.total_lines_deleted:,}[/red]")
table.add_row("Net Change", f"[{net_color}]{cc.net_change:+,}[/{net_color}]")
table.add_row("Avg Churn/Commit", f"{cc.average_churn_per_commit:.1f}")
table.add_row("High Churn Commits", str(len(cc.high_churn_commits)))
console.print(Panel(table, title="[bold yellow]Code Churn[/bold yellow]", box=ROUNDED))
console.print()
@staticmethod
def _print_risky(console: Console, ra: Any) -> None:
"""Print risky commit metrics."""
table = Table(box=ROUNDED)
table.add_column("Metric", style="cyan")
table.add_column("Value", style="magenta")
risk_color = "red" if ra.risk_score > 20 else "orange" if ra.risk_score > 10 else "green"
table.add_row("Total Risky Commits", str(ra.total_risky_commits))
table.add_row("Risk Score", f"[{risk_color}]{ra.risk_score:.1f}%[/]")
table.add_row("Large Changes", str(len(ra.large_change_commits)))
table.add_row("Merge Commits", str(len(ra.merge_commits)))
table.add_row("Reverts", str(len(ra.revert_commits)))
console.print(Panel(table, title="[bold yellow]Risky Commits[/bold yellow]", box=ROUNDED))
console.print()