~whereswaldon/ledger

427c2c9231b26fd1bae0b062916985cb2b76d7e2 — Chris Howey 2 years ago bc98784 + 23d1e08
Merge pull request #33 from porjo/import_fix

Fix import account matching
1 files changed, 20 insertions(+), 2 deletions(-)

M ledger/cmd/import.go
M ledger/cmd/import.go => ledger/cmd/import.go +20 -2
@@ 112,9 112,27 @@ var importCmd = &cobra.Command{
			csvDate, _ := time.Parse(csvDateFormat, record[dateColumn])
			if allowMatching || !existingTransaction(generalLedger, csvDate, inputPayeeWords[0]) {
				// Classify into expense account
				_, likely, _ := classifier.LogScores(inputPayeeWords)
				scores, likely, _ := classifier.LogScores(inputPayeeWords)
				if likely >= 0 {
					expenseAccount.Name = string(classifier.Classes[likely])
					matchScore := 0.0
					matchIdx := -1
					for j, score := range scores {
						if j == 0 {
							matchScore = score
						}
						if string(classifier.Classes[j]) == csvAccount.Name {
							continue
						}
						if score > matchScore {
							matchScore = score
							matchIdx = j
						}
					}
					if matchIdx >= 0 {
						expenseAccount.Name = string(classifier.Classes[matchIdx])
					} else {
						expenseAccount.Name = string(classifier.Classes[likely])
					}
				}

				// Parse error, set to zero