From c023f5bbfc1cfc036541b2a562f4edd8826873bd Mon Sep 17 00:00:00 2001 From: bel Date: Sun, 15 Oct 2023 11:44:46 -0600 Subject: [PATCH] implement O(n**2) analyzer.go:Analyzer:Add mvp --- digits-work-sample-go.d/analyzer.go | 12 +++++++++++- todo.yaml | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/digits-work-sample-go.d/analyzer.go b/digits-work-sample-go.d/analyzer.go index ad14b95..d71481d 100644 --- a/digits-work-sample-go.d/analyzer.go +++ b/digits-work-sample-go.d/analyzer.go @@ -8,7 +8,17 @@ type Analyzer struct { // Add adds unique transactions to Analyzer. func (anz *Analyzer) Add(transactions Transactions) int { - anz.transactions = append(anz.transactions, transactions...) + for i := range transactions { + dupe := false + for j := range anz.transactions { + if transactions[i] == anz.transactions[j] { + dupe = true + } + } + if !dupe { + anz.transactions = append(anz.transactions, transactions[i]) + } + } return len(transactions) } diff --git a/todo.yaml b/todo.yaml index edc6cb4..0903e10 100755 --- a/todo.yaml +++ b/todo.yaml @@ -19,6 +19,11 @@ todo: or latest? - analyzer.go:Analyzer:Add should dedupe transactions added, but transactions.go:FromFile will load duplicate transactions from json file so hmmmm + - analyzer.go:Analzyer:Add dedupes each transaction, which is O(n**2) to compare + each input with each existing entry + - analyzer.go:Analyzer:Add dedupes but what is a duplicate transaction? Transactions + can be pending and then later disappear to have their date updated OR be like + pre-charges on credit cards that later disappear scheduled: [] done: - todo: hello world @@ -508,3 +513,23 @@ done: - analyzer.go:Analyzer:LargestTransaction doesn't specify how to break ties; stable or latest? ts: Sun Oct 15 11:40:52 MDT 2023 +- todo: go test + subtasks: + - 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? + - analyzer.go:Analyzer:Add should dedupe transactions added, but transactions.go:FromFile + will load duplicate transactions from json file so hmmmm + ts: Sun Oct 15 11:44:18 MDT 2023