Skip to content

Commit

Permalink
quicker stats
Browse files Browse the repository at this point in the history
  • Loading branch information
howeyc committed Oct 4, 2024
1 parent 50ec18f commit b159e9d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ledger/cmd/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,25 @@ func printStats(generalLedger []*ledger.Transaction) {
endDate := generalLedger[len(generalLedger)-1].Date

payees := make(map[string]struct{})
cipayees := make(map[string]struct{})
accounts := make(map[string]struct{})

var postings int64
for _, trans := range generalLedger {
payees[strings.ToLower(strings.TrimSpace(trans.Payee))] = struct{}{}
payees[trans.Payee] = struct{}{}
for _, account := range trans.AccountChanges {
postings++
accounts[account.Name] = struct{}{}
}
}
for p := range payees {
cipayees[strings.ToLower(strings.TrimSpace(p))] = struct{}{}
}

days := math.Floor(endDate.Sub(startDate).Hours() / 24)

fmt.Printf("%-25s : %s to %s (%s)\n", "Time period", startDate.Format(time.DateOnly), endDate.Format(time.DateOnly), durafmt.Parse(endDate.Sub(startDate)).String())
fmt.Printf("%-25s : %d\n", "Unique payees", len(payees))
fmt.Printf("%-25s : %d\n", "Unique payees", len(cipayees))
fmt.Printf("%-25s : %d\n", "Unique accounts", len(accounts))
fmt.Printf("%-25s : %d (%.1f per day)\n", "Number of transactions", len(generalLedger), float64(len(generalLedger))/days)
fmt.Printf("%-25s : %d (%.1f per day)\n", "Number of postings", postings, float64(postings)/days)
Expand Down

0 comments on commit b159e9d

Please sign in to comment.