Skip to content

Conversation

@jonathanpberger
Copy link

@jonathanpberger jonathanpberger commented Nov 7, 2025

Summary

This PR enhances the monthly and daily table views with:

  • Custom date formatting via --date-format flag
  • Token count abbreviation via --abbreviate-tokens flag
  • Tufte-style dot sparklines for visual comparison
  • Improved model name display

Features

1. Date Formatting (--date-format flag)

  • Accepts strftime format strings for custom date display
  • Monthly view: Formats first day of month (e.g., 01 Nov - Fri)
  • Daily view: Formats dates with custom format
  • Reduced date column width from 20 to 12 chars for better fit

2. Token Abbreviation (--abbreviate-tokens flag)

  • Shows token counts with 'k' suffix (e.g., 273k, 48,875k)
  • Consistent formatting (no mixing k/mm)
  • Values < 1000 remain unchanged

3. Tufte-Style Dot Sparklines

  • Replaced filled bar sparklines with dot position sparklines
  • Universal scale (max_total_tokens) for all columns
  • Enables comparison across rows AND columns
  • Format: 273k\n─────────●───

4. Model Name Display

  • Uses normalized display names (e.g., "Claude 3 Opus")
  • No truncation, removes duplicates
  • Cleaner presentation

Usage Examples

# Monthly view with weekday and abbreviated tokens
python -m claude_monitor --view monthly --date-format "%d %b - %a" --abbreviate-tokens

# Daily view with custom format
python -m claude_monitor --view daily --date-format "%d %b - %a" --abbreviate-tokens

Testing

  • ✅ All 33 tests passing
  • ✅ Tests updated for new model name formatting
  • ✅ Added tests for dot sparkline functionality
  • ✅ Added tests for token abbreviation

Files Changed

  • src/claude_monitor/core/settings.py - Added date_format and abbreviate_tokens fields
  • src/claude_monitor/ui/table_views.py - Updated table creation with formatting and sparklines
  • src/claude_monitor/ui/progress_bars.py - Added create_dot_sparkline() function
  • src/claude_monitor/utils/formatting.py - Added format_number_abbreviated() function
  • src/claude_monitor/cli/main.py - Pass new flags to display controller
  • src/tests/test_table_views.py - Updated and added tests
  • src/tests/test_formatting.py - Added tests for abbreviation function

Design Principles

This implementation follows Edward Tufte's visualization principles:

  • Universal Scale: All sparklines use the same scale for meaningful comparison
  • Data-Ink Ratio: Dot sparklines maximize information density
  • Small Multiples: Consistent formatting across all rows and columns

Summary by CodeRabbit

  • New Features

    • Added sparkline visualizations for token usage metrics in tables for better at-a-glance insights
    • Added customizable date formatting for period displays across all views
    • Added token abbreviation support for compact number notation (e.g., "1k" for thousands)
    • Improved model name display formatting in summary panels
  • Chores

    • Enhanced VS Code settings with custom theming and syntax highlighting

- Add --date-format flag for custom strftime formatting (e.g., '%d %b - %a')
- Add --abbreviate-tokens flag to show token counts with 'k' suffix
- Reduce date column width from 20 to 12 chars for better fit
- Format numbers consistently: 273k, 48,875k (no mixing k/mm)
- Add format_number_abbreviated() utility function
- Update all table views to support new formatting options
- Add comprehensive tests for new formatting features
- Replace filled bar sparklines with dot position sparklines
- Use universal scale (max_total_tokens) for all columns (Tufte principle)
- Enables comparison across rows AND columns with same scale
- Fix model name display to use normalized display names (no truncation)
- Add create_dot_sparkline() function for table visualizations
- Update tests to reflect new model name formatting
- All 33 tests passing
@coderabbitai
Copy link

coderabbitai bot commented Nov 7, 2025

Walkthrough

Adds date formatting, token abbreviation, and sparkline visualization features to the Claude Code Usage Monitor. New settings fields enable custom date formats and abbreviated token display. Sparkline utilities render visual bar charts in table cells. Table view controller propagates these parameters through aggregation workflows to display enhanced monitoring tables.

Changes

Cohort / File(s) Change Summary
VS Code Configuration
.vscode/settings.json
Adds comprehensive workbench color customizations for UI theming and editor.tokenColorCustomizations for syntax highlighting, plus a custom window title string.
Core Settings
src/claude_monitor/core/settings.py
Introduces date_format: Optional[str] and abbreviate_tokens: bool fields; adds corresponding mappings in to_namespace method for public namespace propagation.
UI Sparkline Utilities
src/claude_monitor/ui/progress_bars.py
Adds two new public functions: create_sparkline (filled/empty bar proportional to value/max) and create_dot_sparkline (line with dot at value position).
CLI Integration
src/claude_monitor/cli/main.py
Updates _run_table_view to pass date_format and abbreviate_tokens parameters from CLI args to TableViewsController.display_aggregated_view.
Number Formatting Utility
src/claude_monitor/utils/formatting.py
Adds format_number_abbreviated function to format integers with 'k' suffix for thousands (e.g., "1,234k").
Table View Controller
src/claude_monitor/ui/table_views.py
Major enhancements: new methods _format_period_value for timezone-aware date formatting; updates to _add_data_rows, _add_totals_row, and table creation methods to support date formatting and abbreviated tokens; adds sparkline visuals to token columns; improves model display via get_model_display_name integration; extends method signatures throughout to propagate date_format and abbreviate_tokens.
Test Suites
src/tests/test_formatting.py, src/tests/test_table_views.py
Adds tests for format_number_abbreviated; introduces error-handling test suites for formatting functions; adds tests for period formatting, date_format parameter integration in tables, and sparkline rendering with edge cases; expands table structure and data validation tests.

Sequence Diagram

sequenceDiagram
    participant CLI as CLI (_run_table_view)
    participant Args as args namespace
    participant Settings as Settings
    participant TVC as TableViewsController
    participant Table as Table Display

    CLI->>Args: getattr(args, "date_format", None)<br/>getattr(args, "abbreviate_tokens", False)
    Args->>TVC: display_aggregated_view(..., date_format, abbreviate_tokens)
    
    TVC->>TVC: create_aggregate_table(..., date_format, abbreviate_tokens)
    alt Daily/Monthly Path
        TVC->>TVC: create_daily_table(..., date_format, abbreviate_tokens)
        TVC->>TVC: _add_data_rows(..., date_format, abbreviate_tokens)
        TVC->>TVC: _format_period_value(period_value, date_format, timezone)
    end
    
    TVC->>TVC: compute max_total_tokens<br/>for sparkline scaling
    TVC->>TVC: create_dot_sparkline(value, max_total)
    
    TVC->>TVC: _add_totals_row(..., abbreviate_tokens)
    TVC->>TVC: format_number_abbreviated(value)
    
    TVC->>Table: Render table with sparklines<br/>& formatted dates/abbreviations
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • table_views.py: High logic density with timezone-aware date formatting, sparkline integration, model display improvements, and parameter propagation through multiple method signatures require careful review.
  • Edge cases: Period formatting, timezone handling, zero/very-small value sparklines, and format_number_abbreviated boundary conditions.
  • Method signature changes: Verify consistent propagation of date_format and abbreviate_tokens through the call chain (CLI → Settings → controller methods).
  • Integration: Ensure abbreviated token formatting and sparklines render correctly with various view types and data ranges.

Possibly related PRs

  • Daily monthly token stats #107: Introduces the foundational settings, CLI, and table-view infrastructure that this PR extends with date_format/abbreviate_tokens plumbing and sparkline helpers.
  • Add: Daily and monthly token usage views #99: Directly extends the same TableViewsController, Settings, and formatting utilities; shares the same code-level modifications for feature integration.

Poem

🐰 Sparkles dance in columns bright,
Dates now shine with formatted light,
Tokens hide in abbreviated grace—
"k" marks thousands in every place!
Charts and bars in table's row,
Let the usage data flow!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main changes: date formatting, token abbreviation, and Tufte-style sparklines for table views.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/claude_monitor/core/settings.py (1)

27-53: Add date_format and abbreviate_tokens to last used params persistence.

The new settings fields date_format and abbreviate_tokens are not saved to last_used.json, meaning user preferences won't persist across sessions. Users will need to specify these flags every time.

Apply this diff to persist the new settings:

             params = {
                 "theme": settings.theme,
                 "timezone": settings.timezone,
                 "time_format": settings.time_format,
                 "refresh_rate": settings.refresh_rate,
                 "reset_hour": settings.reset_hour,
                 "view": settings.view,
+                "date_format": settings.date_format,
+                "abbreviate_tokens": settings.abbreviate_tokens,
                 "timestamp": datetime.now().isoformat(),
             }
🧹 Nitpick comments (2)
.vscode/settings.json (1)

1-312: Developer environment configuration file—scope check needed.

This file provides comprehensive VS Code workspace theming with color customizations and syntax highlighting rules. While it creates a cohesive development environment and complements the UI-focused changes in this PR, it is orthogonal to the functional features being added (date formatting, token abbreviation, sparklines).

Consider whether this belongs in the PR addressing feature work, or if it should be a separate, optional developer tooling contribution (e.g., a documented .vscode/settings.example.json or a separate PR). If committed as mandatory workspace settings, all developers cloning this repo will adopt this theme regardless of their preferences.

The JSON structure and color palette are sound; this is a scope consideration rather than a quality issue.

src/claude_monitor/ui/table_views.py (1)

322-323: Consider documenting date_format column width limitation.

The date column width is fixed at 12 characters when date_format is provided. Longer date formats (e.g., "%d %B %Y - %A") will be truncated or wrap. Consider adding a note in the Settings field description that date formats should be kept compact (≤12 chars) for optimal display.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06f0fe1 and 9b0a232.

📒 Files selected for processing (8)
  • .vscode/settings.json (1 hunks)
  • src/claude_monitor/cli/main.py (1 hunks)
  • src/claude_monitor/core/settings.py (2 hunks)
  • src/claude_monitor/ui/progress_bars.py (2 hunks)
  • src/claude_monitor/ui/table_views.py (13 hunks)
  • src/claude_monitor/utils/formatting.py (1 hunks)
  • src/tests/test_formatting.py (2 hunks)
  • src/tests/test_table_views.py (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/tests/test_formatting.py (1)
src/claude_monitor/utils/formatting.py (1)
  • format_number_abbreviated (31-59)
src/tests/test_table_views.py (2)
src/claude_monitor/ui/progress_bars.py (1)
  • create_dot_sparkline (381-420)
src/claude_monitor/ui/table_views.py (4)
  • _format_models (376-411)
  • _format_period_value (95-146)
  • create_monthly_table (301-338)
  • create_daily_table (264-299)
src/claude_monitor/ui/table_views.py (3)
src/claude_monitor/ui/progress_bars.py (1)
  • create_dot_sparkline (381-420)
src/claude_monitor/utils/formatting.py (3)
  • format_currency (62-78)
  • format_number (16-28)
  • format_number_abbreviated (31-59)
src/claude_monitor/utils/model_utils.py (1)
  • get_model_display_name (30-49)
🔇 Additional comments (13)
src/claude_monitor/core/settings.py (1)

164-172: LGTM!

The new settings fields are well-defined with appropriate types, defaults, and descriptive help text.

src/claude_monitor/ui/progress_bars.py (2)

337-379: LGTM!

The create_sparkline function correctly handles edge cases (max_value <= 0, bounds checking) and produces proportional filled bars.


381-420: LGTM!

The create_dot_sparkline function correctly implements Tufte-style visualization with proper position calculation using (width - 1) for 0-indexed positions and handles edge cases appropriately.

src/claude_monitor/cli/main.py (1)

413-414: LGTM!

Correctly passes the new parameters through to the table view controller with appropriate default values.

src/tests/test_formatting.py (1)

334-365: LGTM!

Comprehensive test coverage for format_number_abbreviated including edge cases for small values, thousands, millions, and float inputs.

src/claude_monitor/utils/formatting.py (1)

31-60: LGTM!

The format_number_abbreviated function correctly formats numbers with 'k' suffix, handling both simple thousands and larger values with comma separators.

src/tests/test_table_views.py (2)

484-516: LGTM!

Good test coverage for period value formatting with date_format parameter, including both month and date formats with timezone handling.


567-609: LGTM!

Comprehensive sparkline tests covering edge cases (zero max value, start/middle/end positions, width constraints).

src/claude_monitor/ui/table_views.py (5)

95-147: LGTM!

The _format_period_value method correctly handles date/month parsing, timezone conversion with proper fallback handling, and strftime formatting.


170-180: Universal sparkline scale enables cross-comparison.

The implementation correctly uses max_total_tokens as a universal scale for all sparklines, enabling comparison across both rows and columns per Tufte design principles. This is a conscious design choice where token types with small values relative to the maximum will show dots near the start of the scale.


236-262: LGTM!

The _add_totals_row method consistently applies token abbreviation when enabled while keeping currency formatting unchanged.


376-411: LGTM!

The improved _format_models method correctly handles deduplication, provides clean display names, and formats lists appropriately with bullet points and overflow indicators.


475-547: LGTM!

The display_aggregated_view method correctly propagates the new parameters through the aggregation workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant