Add: filter relevant transactions by account
This commit is contained in:
		
							parent
							
								
									30dee8cc7d
								
							
						
					
					
						commit
						20b243a3a3
					
				| @ -46,13 +46,8 @@ getTransaction l args = do | |||||||
|             (Just $ showDate today) |             (Just $ showDate today) | ||||||
|             (Just $ \s -> null s ||  |             (Just $ \s -> null s ||  | ||||||
|              isRight (parse (smartdate >> many spacenonewline >> eof) "" $ lowercase s)) |              isRight (parse (smartdate >> many spacenonewline >> eof) "" $ lowercase s)) | ||||||
|   description <- if null args  |   description <- askFor "description" Nothing (Just $ not . null)  | ||||||
|                   then askFor "description" Nothing (Just $ not . null)  |   let historymatches = transactionsSimilarTo l args description | ||||||
|                   else do |  | ||||||
|                          let description = unwords args |  | ||||||
|                          hPutStrLn stderr $ "description: " ++ description |  | ||||||
|                          return description |  | ||||||
|   let historymatches = transactionsSimilarTo l description |  | ||||||
|       bestmatch | null historymatches = Nothing |       bestmatch | null historymatches = Nothing | ||||||
|                 | otherwise = Just $ snd $ head historymatches |                 | otherwise = Just $ snd $ head historymatches | ||||||
|       bestmatchpostings = maybe Nothing (Just . tpostings) bestmatch |       bestmatchpostings = maybe Nothing (Just . tpostings) bestmatch | ||||||
| @ -177,18 +172,19 @@ wordLetterPairs = concatMap letterPairs . words | |||||||
| letterPairs (a:b:rest) = [a,b] : letterPairs (b:rest) | letterPairs (a:b:rest) = [a,b] : letterPairs (b:rest) | ||||||
| letterPairs _ = [] | letterPairs _ = [] | ||||||
| 
 | 
 | ||||||
|  | compareLedgerDescriptions :: [Char] -> [Char] -> Double | ||||||
| compareLedgerDescriptions s t = compareStrings s' t' | compareLedgerDescriptions s t = compareStrings s' t' | ||||||
|     where s' = simplify s |     where s' = simplify s | ||||||
|           t' = simplify t |           t' = simplify t | ||||||
|           simplify = filter (not . (`elem` "0123456789")) |           simplify = filter (not . (`elem` "0123456789")) | ||||||
| 
 | 
 | ||||||
| transactionsSimilarTo :: Ledger -> String -> [(Double,Transaction)] | transactionsSimilarTo :: Ledger -> String -> [(Double,LedgerTransaction)] | ||||||
| transactionsSimilarTo l s = | transactionsSimilarTo l s = | ||||||
|     sortBy compareRelevanceAndRecency |     sortBy compareRelevanceAndRecency | ||||||
|                $ filter ((> threshold).fst) |                $ filter ((> threshold).fst) | ||||||
|                [(compareLedgerDescriptions s $ tdescription t, t) | t <- ts] |                [(compareLedgerDescriptions s $ tdescription t, t) | t <- ts] | ||||||
|     where |     where | ||||||
|       compareRelevanceAndRecency (n1,t1) (n2,t2) = compare (n2,tdate t2) (n1,tdate t1) |       compareRelevanceAndRecency (n1,t1) (n2,t2) = compare (n2,ltdate t2) (n1,ltdate t1) | ||||||
|       ts = jtxns $ journal l |       ts = ledger_txns $ rawledger l | ||||||
|       threshold = 0 |       threshold = 0 | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user