Repository navigation
fix(gain): report total savings percentage in by-command table (#3506) - #3977
anujsingh-cse wants to merge 1 commit into
Conversation
📊 Automated PR Analysis
SummaryFixes the Review Checklist
Linked issues: #3506 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
e3b910b to
82d4ee2
Compare
|
Closing as a duplicate of #891, which makes the same change in get_by_command, swapping AVG(savings_pct) for a volume weighted rate over SUM(saved_tokens) and SUM(input_tokens), and renames the same column header. #891 was kept because it already has a green CI run, a maintainer approval and a regression test. Your in-memory test DB is a better fixture than the one there, so it would be welcome as a comment on #891, and please reply here if you were fixing something #891 leaves untouched. |
Closes #3506
Problem
rtk gain's By Command table shows aSavedcolumn (aSUM) next to anAvg%column (aAVGof per-command percentages). The two numbers in a row describe disjoint populations, so a reader naturally combines them ("24% off 478.8M") and gets nonsense — the average percentage is dominated by many tiny commands while the sum is dominated by a few huge ones.Fix
Make the percentage consistent with the sum in the same row by switching the aggregation from
AVG(savings_pct)to a total-based percentage:COALESCEguards the zero-total-input edge case (matching thetotal_input > 0guard already used for the summary's overall percentage). The column header is renamedAvg%→Total%to reflect it now answers a different question than a mean-of-percentages would.Tests
Added
test_get_by_command_uses_total_savings_pct, which records a long-tailed pair (a 90%-savings 1M-token command and a 10%-savings 100-token command under the samertk_cmd) and asserts the reported percentage is the total-based ~89.99% rather than the mean-of-percentages 50%.cargo fmt --checkandcargo clippy --all-targetsclean; 28 tracking tests pass.