Add average cost per transaction to top expense categories

Display the average spend per transaction for each category on the
dashboard's top expense categories table. This helps users understand
spending patterns beyond just total amounts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
AJ
2025-10-12 10:11:17 -04:00
parent 98df8b6240
commit b2fa1d47a8
2 changed files with 5 additions and 1 deletions

View File

@@ -71,6 +71,7 @@
<tr> <tr>
<th>Category</th> <th>Category</th>
<th class="text-end">Total Spend</th> <th class="text-end">Total Spend</th>
<th class="text-end">Avg Per Txn</th>
<th class="text-end">% of Total</th> <th class="text-end">% of Total</th>
<th class="text-end">Txns</th> <th class="text-end">Txns</th>
</tr> </tr>
@@ -85,6 +86,7 @@
</a> </a>
</td> </td>
<td class="text-end">@c.TotalSpend.ToString("C")</td> <td class="text-end">@c.TotalSpend.ToString("C")</td>
<td class="text-end text-muted">@c.AveragePerTransaction.ToString("C")</td>
<td class="text-end"> <td class="text-end">
<span class="badge bg-secondary">@c.PercentageOfTotal.ToString("F1")%</span> <span class="badge bg-secondary">@c.PercentageOfTotal.ToString("F1")%</span>
</td> </td>

View File

@@ -45,6 +45,7 @@ namespace MoneyMap.Pages
public decimal TotalSpend { get; set; } public decimal TotalSpend { get; set; }
public int Count { get; set; } public int Count { get; set; }
public decimal PercentageOfTotal { get; set; } public decimal PercentageOfTotal { get; set; }
public decimal AveragePerTransaction { get; set; }
} }
public class RecentTxnRow public class RecentTxnRow
@@ -194,7 +195,8 @@ namespace MoneyMap.Pages
Category = g.Key, Category = g.Key,
TotalSpend = g.Sum(x => -x.Amount), TotalSpend = g.Sum(x => -x.Amount),
Count = g.Count(), Count = g.Count(),
PercentageOfTotal = totalSpend > 0 ? (g.Sum(x => -x.Amount) / totalSpend) * 100 : 0 PercentageOfTotal = totalSpend > 0 ? (g.Sum(x => -x.Amount) / totalSpend) * 100 : 0,
AveragePerTransaction = g.Count() > 0 ? g.Sum(x => -x.Amount) / g.Count() : 0
}) })
.OrderByDescending(x => x.TotalSpend) .OrderByDescending(x => x.TotalSpend)
.Take(count) .Take(count)