implement analyzer.go:Analyzer:LargestTransaction to return the first largest transaction in slice
parent
18d5e14813
commit
e771a40901
|
|
@ -1,7 +1,5 @@
|
||||||
package analyzer
|
package analyzer
|
||||||
|
|
||||||
import "errors"
|
|
||||||
|
|
||||||
// Analyzer processes Transactions and generates reports.
|
// Analyzer processes Transactions and generates reports.
|
||||||
type Analyzer struct {
|
type Analyzer struct {
|
||||||
// The list of Transactions available to analyze.
|
// The list of Transactions available to analyze.
|
||||||
|
|
@ -31,8 +29,16 @@ func (anz *Analyzer) TransactionsAmount() Amount {
|
||||||
// - Note: Large negative transactions are still large--it just means the
|
// - Note: Large negative transactions are still large--it just means the
|
||||||
// money moved the other direction.
|
// money moved the other direction.
|
||||||
func (anz *Analyzer) LargestTransaction() (Transaction, error) {
|
func (anz *Analyzer) LargestTransaction() (Transaction, error) {
|
||||||
// TODO: Not implemented.
|
if anz == nil || len(anz.transactions) == 0 {
|
||||||
return Transaction{}, errors.New("not implemented")
|
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
|
// ByCategory groups the transactions by category and returns a map of
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package analyzer
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrNoTransactionsToAnalyze = errors.New("no transactions to analyze")
|
||||||
|
)
|
||||||
39
todo.yaml
39
todo.yaml
|
|
@ -2,7 +2,6 @@ todo:
|
||||||
- review readme tail to finish // answer 3 questions, gofmt
|
- review readme tail to finish // answer 3 questions, gofmt
|
||||||
- todo: go test
|
- todo: go test
|
||||||
subtasks:
|
subtasks:
|
||||||
- TestAnalyzer_LargestTransaction
|
|
||||||
- TestAnalyzer_DuplicatesExcluded
|
- TestAnalyzer_DuplicatesExcluded
|
||||||
- TestAnalyzer_GroupByCategory
|
- TestAnalyzer_GroupByCategory
|
||||||
- TestAnalyzer_BigSpendersReport
|
- TestAnalyzer_BigSpendersReport
|
||||||
|
|
@ -16,6 +15,8 @@ todo:
|
||||||
not be changed, or even what currency Amount is
|
not be changed, or even what currency Amount is
|
||||||
- transaction.go:Transaction:Sum again doesnt care about Amount currency or vendor/vendee
|
- transaction.go:Transaction:Sum again doesnt care about Amount currency or vendor/vendee
|
||||||
drift
|
drift
|
||||||
|
- analyzer.go:Analyzer:LargestTransaction doesn't specify how to break ties; stable
|
||||||
|
or latest?
|
||||||
scheduled: []
|
scheduled: []
|
||||||
done:
|
done:
|
||||||
- todo: hello world
|
- todo: hello world
|
||||||
|
|
@ -451,3 +452,39 @@ done:
|
||||||
- transaction.go:Transaction:Sum again doesnt care about Amount currency or vendor/vendee
|
- transaction.go:Transaction:Sum again doesnt care about Amount currency or vendor/vendee
|
||||||
drift
|
drift
|
||||||
ts: Sun Oct 15 11:36:45 MDT 2023
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue