implement analyzer.go:Analyzer:LargestTransaction to return the first largest transaction in slice

main
bel 2023-10-15 11:39:31 -06:00
parent 18d5e14813
commit e771a40901
3 changed files with 57 additions and 7 deletions

View File

@ -1,7 +1,5 @@
package analyzer
import "errors"
// Analyzer processes Transactions and generates reports.
type Analyzer struct {
// The list of Transactions available to analyze.
@ -28,11 +26,19 @@ func (anz *Analyzer) TransactionsAmount() Amount {
// the absolute value of the transaction amount. Returns an error if there
// are no transactions.
//
// - Note: Large negative transactions are still large--it just means the
// money moved the other direction.
// - Note: Large negative transactions are still large--it just means the
// money moved the other direction.
func (anz *Analyzer) LargestTransaction() (Transaction, error) {
// TODO: Not implemented.
return Transaction{}, errors.New("not implemented")
if anz == nil || len(anz.transactions) == 0 {
return Transaction{}, ErrNoTransactionsToAnalyze
}
largestIdx := 0
for i := 1; i < len(anz.transactions); i++ {
if anz.transactions[largestIdx].Amount.AbsoluteValue() < anz.transactions[i].Amount.AbsoluteValue() {
largestIdx = i
}
}
return anz.transactions[largestIdx], nil
}
// ByCategory groups the transactions by category and returns a map of

View File

@ -0,0 +1,7 @@
package analyzer
import "errors"
var (
ErrNoTransactionsToAnalyze = errors.New("no transactions to analyze")
)

View File

@ -2,7 +2,6 @@ todo:
- review readme tail to finish // answer 3 questions, gofmt
- todo: go test
subtasks:
- TestAnalyzer_LargestTransaction
- TestAnalyzer_DuplicatesExcluded
- TestAnalyzer_GroupByCategory
- TestAnalyzer_BigSpendersReport
@ -16,6 +15,8 @@ todo:
not be changed, or even what currency Amount is
- transaction.go:Transaction:Sum again doesnt care about Amount currency or vendor/vendee
drift
- analyzer.go:Analyzer:LargestTransaction doesn't specify how to break ties; stable
or latest?
scheduled: []
done:
- todo: hello world
@ -451,3 +452,39 @@ done:
- transaction.go:Transaction:Sum again doesnt care about Amount currency or vendor/vendee
drift
ts: Sun Oct 15 11:36:45 MDT 2023
- todo: go test
subtasks:
- TestAnalyzer_LargestTransaction
- TestAnalyzer_DuplicatesExcluded
- TestAnalyzer_GroupByCategory
- TestAnalyzer_BigSpendersReport
- TestAnalyzer_TransactionsFromURLs
- TestAnalyzer_TransactionsFromURLsConcurrent
- amount.go:Rounded probably does NOT handle float precision well... it is float64
tho...
- my `go mod tidy` actually cleared `go.mod` file, probably weird localhost backwards
compatilble stuff
- transaction.go:Transaction:String not clear if FormatUSD or amount currency should
not be changed, or even what currency Amount is
- transaction.go:Transaction:Sum again doesnt care about Amount currency or vendor/vendee
drift
ts: Sun Oct 15 11:38:22 MDT 2023
- todo: go test
subtasks:
- TestAnalyzer_LargestTransaction
- TestAnalyzer_DuplicatesExcluded
- TestAnalyzer_GroupByCategory
- TestAnalyzer_BigSpendersReport
- TestAnalyzer_TransactionsFromURLs
- TestAnalyzer_TransactionsFromURLsConcurrent
- amount.go:Rounded probably does NOT handle float precision well... it is float64
tho...
- my `go mod tidy` actually cleared `go.mod` file, probably weird localhost backwards
compatilble stuff
- transaction.go:Transaction:String not clear if FormatUSD or amount currency should
not be changed, or even what currency Amount is
- transaction.go:Transaction:Sum again doesnt care about Amount currency or vendor/vendee
drift
- analyzer.go:Analyzer:LargestTransaction doesn't specify how to break ties; stable
or latest?
ts: Sun Oct 15 11:38:46 MDT 2023