2009-04-03 14:58:05 +04:00
|
|
|
{-|
|
|
|
|
|
2012-05-14 22:52:22 +04:00
|
|
|
A 'Posting' represents a change (by some 'MixedAmount') of the balance in
|
|
|
|
some 'Account'. Each 'Transaction' contains two or more postings which
|
|
|
|
should add up to 0. Postings reference their parent transaction, so we can
|
|
|
|
look up the date or description there.
|
2009-04-03 14:58:05 +04:00
|
|
|
|
|
|
|
-}
|
|
|
|
|
lib: textification begins! account names
The first of several conversions from String to (strict) Text, hopefully
reducing space and time usage.
This one shows a small improvement, with GHC 7.10.3 and text-1.2.2.1:
hledger -f data/100x100x10.journal stats
string: <<ghc: 39471064 bytes, 77 GCs, 198421/275048 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.020 elapsed), 0.010 GC (0.014 elapsed) :ghc>>
text: <<ghc: 39268024 bytes, 77 GCs, 197018/270840 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.002 elapsed), 0.016 MUT (0.022 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
hledger -f data/1000x100x10.journal stats
string: <<ghc: 318555920 bytes, 617 GCs, 2178997/7134472 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.001 elapsed), 0.129 MUT (0.136 elapsed), 0.067 GC (0.077 elapsed) :ghc>>
text: <<ghc: 314248496 bytes, 612 GCs, 2074045/6617960 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.003 elapsed), 0.137 MUT (0.145 elapsed), 0.067 GC (0.079 elapsed) :ghc>>
hledger -f data/10000x100x10.journal stats
string: <<ghc: 3114763608 bytes, 6026 GCs, 18858950/75552024 avg/max bytes residency (11 samples), 201M in use, 0.000 INIT (0.000 elapsed), 1.331 MUT (1.372 elapsed), 0.699 GC (0.812 elapsed) :ghc>>
text: <<ghc: 3071468920 bytes, 5968 GCs, 14120344/62951360 avg/max bytes residency (9 samples), 124M in use, 0.000 INIT (0.003 elapsed), 1.272 MUT (1.349 elapsed), 0.513 GC (0.578 elapsed) :ghc>>
hledger -f data/100000x100x10.journal stats
string: <<ghc: 31186579432 bytes, 60278 GCs, 135332581/740228992 avg/max bytes residency (13 samples), 1697M in use, 0.000 INIT (0.008 elapsed), 14.677 MUT (15.508 elapsed), 7.081 GC (8.074 elapsed) :ghc>>
text: <<ghc: 30753427672 bytes, 59763 GCs, 117595958/666457240 avg/max bytes residency (14 samples), 1588M in use, 0.000 INIT (0.008 elapsed), 13.713 MUT (13.966 elapsed), 6.220 GC (7.108 elapsed) :ghc>>
2016-05-24 04:16:21 +03:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2018-03-25 01:51:56 +03:00
|
|
|
{-# LANGUAGE CPP #-}
|
lib: textification begins! account names
The first of several conversions from String to (strict) Text, hopefully
reducing space and time usage.
This one shows a small improvement, with GHC 7.10.3 and text-1.2.2.1:
hledger -f data/100x100x10.journal stats
string: <<ghc: 39471064 bytes, 77 GCs, 198421/275048 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.020 elapsed), 0.010 GC (0.014 elapsed) :ghc>>
text: <<ghc: 39268024 bytes, 77 GCs, 197018/270840 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.002 elapsed), 0.016 MUT (0.022 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
hledger -f data/1000x100x10.journal stats
string: <<ghc: 318555920 bytes, 617 GCs, 2178997/7134472 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.001 elapsed), 0.129 MUT (0.136 elapsed), 0.067 GC (0.077 elapsed) :ghc>>
text: <<ghc: 314248496 bytes, 612 GCs, 2074045/6617960 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.003 elapsed), 0.137 MUT (0.145 elapsed), 0.067 GC (0.079 elapsed) :ghc>>
hledger -f data/10000x100x10.journal stats
string: <<ghc: 3114763608 bytes, 6026 GCs, 18858950/75552024 avg/max bytes residency (11 samples), 201M in use, 0.000 INIT (0.000 elapsed), 1.331 MUT (1.372 elapsed), 0.699 GC (0.812 elapsed) :ghc>>
text: <<ghc: 3071468920 bytes, 5968 GCs, 14120344/62951360 avg/max bytes residency (9 samples), 124M in use, 0.000 INIT (0.003 elapsed), 1.272 MUT (1.349 elapsed), 0.513 GC (0.578 elapsed) :ghc>>
hledger -f data/100000x100x10.journal stats
string: <<ghc: 31186579432 bytes, 60278 GCs, 135332581/740228992 avg/max bytes residency (13 samples), 1697M in use, 0.000 INIT (0.008 elapsed), 14.677 MUT (15.508 elapsed), 7.081 GC (8.074 elapsed) :ghc>>
text: <<ghc: 30753427672 bytes, 59763 GCs, 117595958/666457240 avg/max bytes residency (14 samples), 1588M in use, 0.000 INIT (0.008 elapsed), 13.713 MUT (13.966 elapsed), 6.220 GC (7.108 elapsed) :ghc>>
2016-05-24 04:16:21 +03:00
|
|
|
|
2012-05-07 18:36:40 +04:00
|
|
|
module Hledger.Data.Posting (
|
|
|
|
-- * Posting
|
|
|
|
nullposting,
|
2012-12-06 04:03:07 +04:00
|
|
|
posting,
|
|
|
|
post,
|
2012-05-07 18:36:40 +04:00
|
|
|
-- * operations
|
2017-01-13 18:25:44 +03:00
|
|
|
originalPosting,
|
2015-05-16 21:51:35 +03:00
|
|
|
postingStatus,
|
2012-05-07 18:36:40 +04:00
|
|
|
isReal,
|
|
|
|
isVirtual,
|
|
|
|
isBalancedVirtual,
|
|
|
|
isEmptyPosting,
|
2016-12-10 18:04:48 +03:00
|
|
|
isAssignment,
|
2012-05-07 18:36:40 +04:00
|
|
|
hasAmount,
|
2012-05-28 04:27:55 +04:00
|
|
|
postingAllTags,
|
|
|
|
transactionAllTags,
|
2012-12-22 04:24:38 +04:00
|
|
|
relatedPostings,
|
2016-12-10 18:04:48 +03:00
|
|
|
removePrices,
|
2012-05-07 18:36:40 +04:00
|
|
|
-- * date operations
|
|
|
|
postingDate,
|
2012-12-06 08:43:41 +04:00
|
|
|
postingDate2,
|
2012-05-07 18:36:40 +04:00
|
|
|
isPostingInDateSpan,
|
2014-04-14 01:57:40 +04:00
|
|
|
isPostingInDateSpan',
|
2012-05-07 18:36:40 +04:00
|
|
|
postingsDateSpan,
|
2014-04-14 02:14:07 +04:00
|
|
|
postingsDateSpan',
|
2012-05-14 22:52:22 +04:00
|
|
|
-- * account name operations
|
2012-05-07 18:36:40 +04:00
|
|
|
accountNamesFromPostings,
|
|
|
|
accountNamePostingType,
|
|
|
|
accountNameWithoutPostingType,
|
|
|
|
accountNameWithPostingType,
|
|
|
|
joinAccountNames,
|
|
|
|
concatAccountNames,
|
|
|
|
accountNameApplyAliases,
|
2015-09-27 04:54:46 +03:00
|
|
|
accountNameApplyAliasesMemo,
|
2017-01-13 13:07:26 +03:00
|
|
|
-- * transaction description operations
|
|
|
|
transactionPayee,
|
|
|
|
transactionNote,
|
|
|
|
payeeAndNoteFromDescription,
|
2012-05-07 18:36:40 +04:00
|
|
|
-- * arithmetic
|
|
|
|
sumPostings,
|
|
|
|
-- * rendering
|
|
|
|
showPosting,
|
|
|
|
-- * misc.
|
2012-05-14 22:52:22 +04:00
|
|
|
showComment,
|
2012-05-07 18:36:40 +04:00
|
|
|
tests_Hledger_Data_Posting
|
|
|
|
)
|
2009-04-03 14:58:05 +04:00
|
|
|
where
|
2011-05-28 08:11:44 +04:00
|
|
|
import Data.List
|
2012-12-06 04:03:07 +04:00
|
|
|
import Data.Maybe
|
2015-09-27 04:45:44 +03:00
|
|
|
import Data.MemoUgly (memo)
|
2018-03-25 01:51:56 +03:00
|
|
|
#if !(MIN_VERSION_base(4,11,0))
|
lib: textification begins! account names
The first of several conversions from String to (strict) Text, hopefully
reducing space and time usage.
This one shows a small improvement, with GHC 7.10.3 and text-1.2.2.1:
hledger -f data/100x100x10.journal stats
string: <<ghc: 39471064 bytes, 77 GCs, 198421/275048 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.020 elapsed), 0.010 GC (0.014 elapsed) :ghc>>
text: <<ghc: 39268024 bytes, 77 GCs, 197018/270840 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.002 elapsed), 0.016 MUT (0.022 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
hledger -f data/1000x100x10.journal stats
string: <<ghc: 318555920 bytes, 617 GCs, 2178997/7134472 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.001 elapsed), 0.129 MUT (0.136 elapsed), 0.067 GC (0.077 elapsed) :ghc>>
text: <<ghc: 314248496 bytes, 612 GCs, 2074045/6617960 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.003 elapsed), 0.137 MUT (0.145 elapsed), 0.067 GC (0.079 elapsed) :ghc>>
hledger -f data/10000x100x10.journal stats
string: <<ghc: 3114763608 bytes, 6026 GCs, 18858950/75552024 avg/max bytes residency (11 samples), 201M in use, 0.000 INIT (0.000 elapsed), 1.331 MUT (1.372 elapsed), 0.699 GC (0.812 elapsed) :ghc>>
text: <<ghc: 3071468920 bytes, 5968 GCs, 14120344/62951360 avg/max bytes residency (9 samples), 124M in use, 0.000 INIT (0.003 elapsed), 1.272 MUT (1.349 elapsed), 0.513 GC (0.578 elapsed) :ghc>>
hledger -f data/100000x100x10.journal stats
string: <<ghc: 31186579432 bytes, 60278 GCs, 135332581/740228992 avg/max bytes residency (13 samples), 1697M in use, 0.000 INIT (0.008 elapsed), 14.677 MUT (15.508 elapsed), 7.081 GC (8.074 elapsed) :ghc>>
text: <<ghc: 30753427672 bytes, 59763 GCs, 117595958/666457240 avg/max bytes residency (14 samples), 1588M in use, 0.000 INIT (0.008 elapsed), 13.713 MUT (13.966 elapsed), 6.220 GC (7.108 elapsed) :ghc>>
2016-05-24 04:16:21 +03:00
|
|
|
import Data.Monoid
|
2018-03-25 01:51:56 +03:00
|
|
|
#endif
|
2011-05-28 08:11:44 +04:00
|
|
|
import Data.Ord
|
lib: textification: comments and tags
No change.
hledger -f data/100x100x10.journal stats
<<ghc: 42859576 bytes, 84 GCs, 193781/269984 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.016 MUT (0.020 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
<<ghc: 42859576 bytes, 84 GCs, 193781/269984 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.018 elapsed), 0.009 GC (0.013 elapsed) :ghc>>
hledger -f data/1000x1000x10.journal stats
<<ghc: 349576344 bytes, 681 GCs, 1407388/4091680 avg/max bytes residency (7 samples), 11M in use, 0.000 INIT (0.000 elapsed), 0.124 MUT (0.130 elapsed), 0.047 GC (0.055 elapsed) :ghc>>
<<ghc: 349576280 bytes, 681 GCs, 1407388/4091680 avg/max bytes residency (7 samples), 11M in use, 0.000 INIT (0.000 elapsed), 0.126 MUT (0.132 elapsed), 0.049 GC (0.058 elapsed) :ghc>>
hledger -f data/10000x1000x10.journal stats
<<ghc: 3424030664 bytes, 6658 GCs, 11403359/41071624 avg/max bytes residency (11 samples), 111M in use, 0.000 INIT (0.000 elapsed), 1.207 MUT (1.228 elapsed), 0.473 GC (0.528 elapsed) :ghc>>
<<ghc: 3424030760 bytes, 6658 GCs, 11403874/41077288 avg/max bytes residency (11 samples), 111M in use, 0.000 INIT (0.002 elapsed), 1.234 MUT (1.256 elapsed), 0.470 GC (0.520 elapsed) :ghc>>
hledger -f data/100000x1000x10.journal stats
<<ghc: 34306547448 bytes, 66727 GCs, 76805504/414629288 avg/max bytes residency (14 samples), 1009M in use, 0.000 INIT (0.003 elapsed), 12.615 MUT (12.813 elapsed), 4.656 GC (5.291 elapsed) :ghc>>
<<ghc: 34306547320 bytes, 66727 GCs, 76805504/414629288 avg/max bytes residency (14 samples), 1009M in use, 0.000 INIT (0.009 elapsed), 12.802 MUT (13.065 elapsed), 4.774 GC (5.441 elapsed) :ghc>>
2016-05-25 03:09:20 +03:00
|
|
|
import Data.Text (Text)
|
lib: textification begins! account names
The first of several conversions from String to (strict) Text, hopefully
reducing space and time usage.
This one shows a small improvement, with GHC 7.10.3 and text-1.2.2.1:
hledger -f data/100x100x10.journal stats
string: <<ghc: 39471064 bytes, 77 GCs, 198421/275048 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.020 elapsed), 0.010 GC (0.014 elapsed) :ghc>>
text: <<ghc: 39268024 bytes, 77 GCs, 197018/270840 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.002 elapsed), 0.016 MUT (0.022 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
hledger -f data/1000x100x10.journal stats
string: <<ghc: 318555920 bytes, 617 GCs, 2178997/7134472 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.001 elapsed), 0.129 MUT (0.136 elapsed), 0.067 GC (0.077 elapsed) :ghc>>
text: <<ghc: 314248496 bytes, 612 GCs, 2074045/6617960 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.003 elapsed), 0.137 MUT (0.145 elapsed), 0.067 GC (0.079 elapsed) :ghc>>
hledger -f data/10000x100x10.journal stats
string: <<ghc: 3114763608 bytes, 6026 GCs, 18858950/75552024 avg/max bytes residency (11 samples), 201M in use, 0.000 INIT (0.000 elapsed), 1.331 MUT (1.372 elapsed), 0.699 GC (0.812 elapsed) :ghc>>
text: <<ghc: 3071468920 bytes, 5968 GCs, 14120344/62951360 avg/max bytes residency (9 samples), 124M in use, 0.000 INIT (0.003 elapsed), 1.272 MUT (1.349 elapsed), 0.513 GC (0.578 elapsed) :ghc>>
hledger -f data/100000x100x10.journal stats
string: <<ghc: 31186579432 bytes, 60278 GCs, 135332581/740228992 avg/max bytes residency (13 samples), 1697M in use, 0.000 INIT (0.008 elapsed), 14.677 MUT (15.508 elapsed), 7.081 GC (8.074 elapsed) :ghc>>
text: <<ghc: 30753427672 bytes, 59763 GCs, 117595958/666457240 avg/max bytes residency (14 samples), 1588M in use, 0.000 INIT (0.008 elapsed), 13.713 MUT (13.966 elapsed), 6.220 GC (7.108 elapsed) :ghc>>
2016-05-24 04:16:21 +03:00
|
|
|
import qualified Data.Text as T
|
2011-05-28 08:11:44 +04:00
|
|
|
import Data.Time.Calendar
|
2011-08-03 03:29:13 +04:00
|
|
|
import Safe
|
2011-05-28 08:11:44 +04:00
|
|
|
|
|
|
|
import Hledger.Utils
|
2010-05-20 03:08:53 +04:00
|
|
|
import Hledger.Data.Types
|
|
|
|
import Hledger.Data.Amount
|
|
|
|
import Hledger.Data.AccountName
|
2010-07-11 22:56:36 +04:00
|
|
|
import Hledger.Data.Dates (nulldate, spanContainsDate)
|
2009-04-03 14:58:05 +04:00
|
|
|
|
|
|
|
|
|
|
|
instance Show Posting where show = showPosting
|
|
|
|
|
2012-12-06 04:03:07 +04:00
|
|
|
nullposting, posting :: Posting
|
|
|
|
nullposting = Posting
|
2012-12-06 04:28:23 +04:00
|
|
|
{pdate=Nothing
|
2012-12-06 06:41:37 +04:00
|
|
|
,pdate2=Nothing
|
2017-06-16 02:25:37 +03:00
|
|
|
,pstatus=Unmarked
|
2012-12-06 04:03:07 +04:00
|
|
|
,paccount=""
|
|
|
|
,pamount=nullmixedamt
|
|
|
|
,pcomment=""
|
|
|
|
,ptype=RegularPosting
|
|
|
|
,ptags=[]
|
2013-05-29 03:18:15 +04:00
|
|
|
,pbalanceassertion=Nothing
|
2012-12-06 04:03:07 +04:00
|
|
|
,ptransaction=Nothing
|
2017-01-13 18:25:44 +03:00
|
|
|
,porigin=Nothing
|
2012-12-06 04:03:07 +04:00
|
|
|
}
|
|
|
|
posting = nullposting
|
|
|
|
|
|
|
|
post :: AccountName -> Amount -> Posting
|
2014-07-28 17:32:09 +04:00
|
|
|
post acct amt = posting {paccount=acct, pamount=Mixed [amt]}
|
2009-04-03 14:58:05 +04:00
|
|
|
|
2017-05-30 23:39:53 +03:00
|
|
|
-- Get the original posting, if any.
|
2017-01-13 18:25:44 +03:00
|
|
|
originalPosting :: Posting -> Posting
|
|
|
|
originalPosting p = fromMaybe p $ porigin p
|
|
|
|
|
2014-05-07 08:35:38 +04:00
|
|
|
-- XXX once rendered user output, but just for debugging now; clean up
|
2009-04-03 14:58:05 +04:00
|
|
|
showPosting :: Posting -> String
|
2012-05-14 22:52:22 +04:00
|
|
|
showPosting p@Posting{paccount=a,pamount=amt,ptype=t} =
|
2014-05-07 08:35:38 +04:00
|
|
|
unlines $ [concatTopPadded [show (postingDate p) ++ " ", showaccountname a ++ " ", showamount amt, showComment (pcomment p)]]
|
2009-04-03 14:58:05 +04:00
|
|
|
where
|
2009-11-25 09:13:35 +03:00
|
|
|
ledger3ishlayout = False
|
|
|
|
acctnamewidth = if ledger3ishlayout then 25 else 22
|
lib: textification begins! account names
The first of several conversions from String to (strict) Text, hopefully
reducing space and time usage.
This one shows a small improvement, with GHC 7.10.3 and text-1.2.2.1:
hledger -f data/100x100x10.journal stats
string: <<ghc: 39471064 bytes, 77 GCs, 198421/275048 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.020 elapsed), 0.010 GC (0.014 elapsed) :ghc>>
text: <<ghc: 39268024 bytes, 77 GCs, 197018/270840 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.002 elapsed), 0.016 MUT (0.022 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
hledger -f data/1000x100x10.journal stats
string: <<ghc: 318555920 bytes, 617 GCs, 2178997/7134472 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.001 elapsed), 0.129 MUT (0.136 elapsed), 0.067 GC (0.077 elapsed) :ghc>>
text: <<ghc: 314248496 bytes, 612 GCs, 2074045/6617960 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.003 elapsed), 0.137 MUT (0.145 elapsed), 0.067 GC (0.079 elapsed) :ghc>>
hledger -f data/10000x100x10.journal stats
string: <<ghc: 3114763608 bytes, 6026 GCs, 18858950/75552024 avg/max bytes residency (11 samples), 201M in use, 0.000 INIT (0.000 elapsed), 1.331 MUT (1.372 elapsed), 0.699 GC (0.812 elapsed) :ghc>>
text: <<ghc: 3071468920 bytes, 5968 GCs, 14120344/62951360 avg/max bytes residency (9 samples), 124M in use, 0.000 INIT (0.003 elapsed), 1.272 MUT (1.349 elapsed), 0.513 GC (0.578 elapsed) :ghc>>
hledger -f data/100000x100x10.journal stats
string: <<ghc: 31186579432 bytes, 60278 GCs, 135332581/740228992 avg/max bytes residency (13 samples), 1697M in use, 0.000 INIT (0.008 elapsed), 14.677 MUT (15.508 elapsed), 7.081 GC (8.074 elapsed) :ghc>>
text: <<ghc: 30753427672 bytes, 59763 GCs, 117595958/666457240 avg/max bytes residency (14 samples), 1588M in use, 0.000 INIT (0.008 elapsed), 13.713 MUT (13.966 elapsed), 6.220 GC (7.108 elapsed) :ghc>>
2016-05-24 04:16:21 +03:00
|
|
|
showaccountname = fitString (Just acctnamewidth) Nothing False False . bracket . T.unpack . elideAccountName width
|
2009-12-19 06:44:52 +03:00
|
|
|
(bracket,width) = case t of
|
2009-11-25 09:13:35 +03:00
|
|
|
BalancedVirtualPosting -> (\s -> "["++s++"]", acctnamewidth-2)
|
|
|
|
VirtualPosting -> (\s -> "("++s++")", acctnamewidth-2)
|
|
|
|
_ -> (id,acctnamewidth)
|
2015-10-10 21:53:28 +03:00
|
|
|
showamount = padLeftWide 12 . showMixedAmount
|
2012-05-14 22:52:22 +04:00
|
|
|
|
|
|
|
|
lib: textification: comments and tags
No change.
hledger -f data/100x100x10.journal stats
<<ghc: 42859576 bytes, 84 GCs, 193781/269984 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.016 MUT (0.020 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
<<ghc: 42859576 bytes, 84 GCs, 193781/269984 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.018 elapsed), 0.009 GC (0.013 elapsed) :ghc>>
hledger -f data/1000x1000x10.journal stats
<<ghc: 349576344 bytes, 681 GCs, 1407388/4091680 avg/max bytes residency (7 samples), 11M in use, 0.000 INIT (0.000 elapsed), 0.124 MUT (0.130 elapsed), 0.047 GC (0.055 elapsed) :ghc>>
<<ghc: 349576280 bytes, 681 GCs, 1407388/4091680 avg/max bytes residency (7 samples), 11M in use, 0.000 INIT (0.000 elapsed), 0.126 MUT (0.132 elapsed), 0.049 GC (0.058 elapsed) :ghc>>
hledger -f data/10000x1000x10.journal stats
<<ghc: 3424030664 bytes, 6658 GCs, 11403359/41071624 avg/max bytes residency (11 samples), 111M in use, 0.000 INIT (0.000 elapsed), 1.207 MUT (1.228 elapsed), 0.473 GC (0.528 elapsed) :ghc>>
<<ghc: 3424030760 bytes, 6658 GCs, 11403874/41077288 avg/max bytes residency (11 samples), 111M in use, 0.000 INIT (0.002 elapsed), 1.234 MUT (1.256 elapsed), 0.470 GC (0.520 elapsed) :ghc>>
hledger -f data/100000x1000x10.journal stats
<<ghc: 34306547448 bytes, 66727 GCs, 76805504/414629288 avg/max bytes residency (14 samples), 1009M in use, 0.000 INIT (0.003 elapsed), 12.615 MUT (12.813 elapsed), 4.656 GC (5.291 elapsed) :ghc>>
<<ghc: 34306547320 bytes, 66727 GCs, 76805504/414629288 avg/max bytes residency (14 samples), 1009M in use, 0.000 INIT (0.009 elapsed), 12.802 MUT (13.065 elapsed), 4.774 GC (5.441 elapsed) :ghc>>
2016-05-25 03:09:20 +03:00
|
|
|
showComment :: Text -> String
|
|
|
|
showComment t = if T.null t then "" else " ;" ++ T.unpack t
|
2012-05-14 22:52:22 +04:00
|
|
|
|
2009-04-03 14:58:05 +04:00
|
|
|
isReal :: Posting -> Bool
|
|
|
|
isReal p = ptype p == RegularPosting
|
|
|
|
|
2009-05-17 03:12:42 +04:00
|
|
|
isVirtual :: Posting -> Bool
|
|
|
|
isVirtual p = ptype p == VirtualPosting
|
|
|
|
|
|
|
|
isBalancedVirtual :: Posting -> Bool
|
|
|
|
isBalancedVirtual p = ptype p == BalancedVirtualPosting
|
|
|
|
|
2009-04-03 14:58:05 +04:00
|
|
|
hasAmount :: Posting -> Bool
|
2012-05-27 22:14:20 +04:00
|
|
|
hasAmount = (/= missingmixedamt) . pamount
|
2009-05-25 21:28:41 +04:00
|
|
|
|
2016-12-10 18:04:48 +03:00
|
|
|
isAssignment :: Posting -> Bool
|
|
|
|
isAssignment p = not (hasAmount p) && isJust (pbalanceassertion p)
|
|
|
|
|
2017-12-29 23:16:46 +03:00
|
|
|
-- | Sorted unique account names referenced by these postings.
|
2009-12-19 08:57:54 +03:00
|
|
|
accountNamesFromPostings :: [Posting] -> [AccountName]
|
2017-12-29 23:16:46 +03:00
|
|
|
accountNamesFromPostings = nub . sort . map paccount
|
2009-12-19 08:57:54 +03:00
|
|
|
|
|
|
|
sumPostings :: [Posting] -> MixedAmount
|
2017-01-13 03:24:53 +03:00
|
|
|
sumPostings = sumStrict . map pamount
|
2009-12-19 08:57:54 +03:00
|
|
|
|
2016-12-10 18:04:48 +03:00
|
|
|
-- | Remove all prices of a posting
|
|
|
|
removePrices :: Posting -> Posting
|
|
|
|
removePrices p = p{ pamount = Mixed $ remove <$> amounts (pamount p) }
|
|
|
|
where remove a = a { aprice = NoPrice }
|
|
|
|
|
2012-12-06 06:41:37 +04:00
|
|
|
-- | Get a posting's (primary) date - it's own primary date if specified,
|
|
|
|
-- otherwise the parent transaction's primary date, or the null date if
|
|
|
|
-- there is no parent transaction.
|
2009-12-19 08:57:54 +03:00
|
|
|
postingDate :: Posting -> Day
|
2012-12-06 04:28:23 +04:00
|
|
|
postingDate p = fromMaybe txndate $ pdate p
|
2014-09-11 00:07:53 +04:00
|
|
|
where
|
2012-12-06 04:28:23 +04:00
|
|
|
txndate = maybe nulldate tdate $ ptransaction p
|
2009-12-19 08:57:54 +03:00
|
|
|
|
2012-12-06 08:43:41 +04:00
|
|
|
-- | Get a posting's secondary (secondary) date, which is the first of:
|
2012-12-06 06:41:37 +04:00
|
|
|
-- posting's secondary date, transaction's secondary date, posting's
|
|
|
|
-- primary date, transaction's primary date, or the null date if there is
|
|
|
|
-- no parent transaction.
|
2012-12-06 08:43:41 +04:00
|
|
|
postingDate2 :: Posting -> Day
|
|
|
|
postingDate2 p = headDef nulldate $ catMaybes dates
|
2012-12-06 06:41:37 +04:00
|
|
|
where dates = [pdate2 p
|
2012-12-06 08:43:41 +04:00
|
|
|
,maybe Nothing tdate2 $ ptransaction p
|
2012-12-06 06:41:37 +04:00
|
|
|
,pdate p
|
|
|
|
,maybe Nothing (Just . tdate) $ ptransaction p
|
|
|
|
]
|
2012-12-06 05:10:15 +04:00
|
|
|
|
2017-06-16 02:25:37 +03:00
|
|
|
-- | Get a posting's status. This is cleared or pending if those are
|
|
|
|
-- explicitly set on the posting, otherwise the status of its parent
|
|
|
|
-- transaction, or unmarked if there is no parent transaction. (Note
|
|
|
|
-- the ambiguity, unmarked can mean "posting and transaction are both
|
|
|
|
-- unmarked" or "posting is unmarked and don't know about the transaction".
|
2017-06-16 02:54:34 +03:00
|
|
|
postingStatus :: Posting -> Status
|
2015-05-16 21:51:35 +03:00
|
|
|
postingStatus Posting{pstatus=s, ptransaction=mt}
|
2017-06-16 02:25:37 +03:00
|
|
|
| s == Unmarked = case mt of Just t -> tstatus t
|
|
|
|
Nothing -> Unmarked
|
2015-05-16 21:51:35 +03:00
|
|
|
| otherwise = s
|
|
|
|
|
2017-01-13 13:07:26 +03:00
|
|
|
transactionPayee :: Transaction -> Text
|
|
|
|
transactionPayee = fst . payeeAndNoteFromDescription . tdescription
|
|
|
|
|
|
|
|
transactionNote :: Transaction -> Text
|
2017-08-31 00:21:01 +03:00
|
|
|
transactionNote = snd . payeeAndNoteFromDescription . tdescription
|
2017-01-13 13:07:26 +03:00
|
|
|
|
|
|
|
-- | Parse a transaction's description into payee and note (aka narration) fields,
|
|
|
|
-- assuming a convention of separating these with | (like Beancount).
|
|
|
|
-- Ie, everything up to the first | is the payee, everything after it is the note.
|
|
|
|
-- When there's no |, payee == note == description.
|
|
|
|
payeeAndNoteFromDescription :: Text -> (Text,Text)
|
2017-08-31 00:21:01 +03:00
|
|
|
payeeAndNoteFromDescription t
|
|
|
|
| T.null n = (t, t)
|
|
|
|
| otherwise = (textstrip p, textstrip $ T.drop 1 n)
|
2017-01-13 13:07:26 +03:00
|
|
|
where
|
2017-08-31 00:21:01 +03:00
|
|
|
(p, n) = T.span (/= '|') t
|
2017-01-13 13:07:26 +03:00
|
|
|
|
2012-05-28 04:27:55 +04:00
|
|
|
-- | Tags for this posting including any inherited from its parent transaction.
|
|
|
|
postingAllTags :: Posting -> [Tag]
|
2014-03-06 02:43:58 +04:00
|
|
|
postingAllTags p = ptags p ++ maybe [] ttags (ptransaction p)
|
2012-05-28 04:27:55 +04:00
|
|
|
|
2014-03-02 05:42:13 +04:00
|
|
|
-- | Tags for this transaction including any from its postings.
|
2012-05-28 04:27:55 +04:00
|
|
|
transactionAllTags :: Transaction -> [Tag]
|
2014-03-02 05:42:13 +04:00
|
|
|
transactionAllTags t = ttags t ++ concatMap ptags (tpostings t)
|
2012-05-28 04:27:55 +04:00
|
|
|
|
2012-12-22 04:24:38 +04:00
|
|
|
-- Get the other postings from this posting's transaction.
|
|
|
|
relatedPostings :: Posting -> [Posting]
|
|
|
|
relatedPostings p@Posting{ptransaction=Just t} = filter (/= p) $ tpostings t
|
|
|
|
relatedPostings _ = []
|
|
|
|
|
2009-12-19 08:57:54 +03:00
|
|
|
-- | Does this posting fall within the given date span ?
|
|
|
|
isPostingInDateSpan :: DateSpan -> Posting -> Bool
|
2010-07-11 22:56:36 +04:00
|
|
|
isPostingInDateSpan s = spanContainsDate s . postingDate
|
2009-12-21 08:23:07 +03:00
|
|
|
|
2014-04-14 01:57:40 +04:00
|
|
|
-- --date2-sensitive version, separate for now to avoid disturbing multiBalanceReport.
|
|
|
|
isPostingInDateSpan' :: WhichDate -> DateSpan -> Posting -> Bool
|
|
|
|
isPostingInDateSpan' PrimaryDate s = spanContainsDate s . postingDate
|
|
|
|
isPostingInDateSpan' SecondaryDate s = spanContainsDate s . postingDate2
|
|
|
|
|
2009-12-21 08:23:07 +03:00
|
|
|
isEmptyPosting :: Posting -> Bool
|
|
|
|
isEmptyPosting = isZeroMixedAmount . pamount
|
|
|
|
|
2012-05-14 22:52:22 +04:00
|
|
|
-- | Get the minimal date span which contains all the postings, or the
|
|
|
|
-- null date span if there are none.
|
2009-12-21 09:03:34 +03:00
|
|
|
postingsDateSpan :: [Posting] -> DateSpan
|
|
|
|
postingsDateSpan [] = DateSpan Nothing Nothing
|
|
|
|
postingsDateSpan ps = DateSpan (Just $ postingDate $ head ps') (Just $ addDays 1 $ postingDate $ last ps')
|
|
|
|
where ps' = sortBy (comparing postingDate) ps
|
|
|
|
|
2014-04-14 02:14:07 +04:00
|
|
|
-- --date2-sensitive version, as above.
|
|
|
|
postingsDateSpan' :: WhichDate -> [Posting] -> DateSpan
|
2014-04-14 19:31:11 +04:00
|
|
|
postingsDateSpan' _ [] = DateSpan Nothing Nothing
|
2014-04-14 02:14:07 +04:00
|
|
|
postingsDateSpan' wd ps = DateSpan (Just $ postingdate $ head ps') (Just $ addDays 1 $ postingdate $ last ps')
|
|
|
|
where
|
|
|
|
ps' = sortBy (comparing postingdate) ps
|
|
|
|
postingdate = if wd == PrimaryDate then postingDate else postingDate2
|
|
|
|
|
2011-08-05 04:05:39 +04:00
|
|
|
-- AccountName stuff that depends on PostingType
|
2011-08-03 03:29:13 +04:00
|
|
|
|
|
|
|
accountNamePostingType :: AccountName -> PostingType
|
|
|
|
accountNamePostingType a
|
lib: textification begins! account names
The first of several conversions from String to (strict) Text, hopefully
reducing space and time usage.
This one shows a small improvement, with GHC 7.10.3 and text-1.2.2.1:
hledger -f data/100x100x10.journal stats
string: <<ghc: 39471064 bytes, 77 GCs, 198421/275048 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.020 elapsed), 0.010 GC (0.014 elapsed) :ghc>>
text: <<ghc: 39268024 bytes, 77 GCs, 197018/270840 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.002 elapsed), 0.016 MUT (0.022 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
hledger -f data/1000x100x10.journal stats
string: <<ghc: 318555920 bytes, 617 GCs, 2178997/7134472 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.001 elapsed), 0.129 MUT (0.136 elapsed), 0.067 GC (0.077 elapsed) :ghc>>
text: <<ghc: 314248496 bytes, 612 GCs, 2074045/6617960 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.003 elapsed), 0.137 MUT (0.145 elapsed), 0.067 GC (0.079 elapsed) :ghc>>
hledger -f data/10000x100x10.journal stats
string: <<ghc: 3114763608 bytes, 6026 GCs, 18858950/75552024 avg/max bytes residency (11 samples), 201M in use, 0.000 INIT (0.000 elapsed), 1.331 MUT (1.372 elapsed), 0.699 GC (0.812 elapsed) :ghc>>
text: <<ghc: 3071468920 bytes, 5968 GCs, 14120344/62951360 avg/max bytes residency (9 samples), 124M in use, 0.000 INIT (0.003 elapsed), 1.272 MUT (1.349 elapsed), 0.513 GC (0.578 elapsed) :ghc>>
hledger -f data/100000x100x10.journal stats
string: <<ghc: 31186579432 bytes, 60278 GCs, 135332581/740228992 avg/max bytes residency (13 samples), 1697M in use, 0.000 INIT (0.008 elapsed), 14.677 MUT (15.508 elapsed), 7.081 GC (8.074 elapsed) :ghc>>
text: <<ghc: 30753427672 bytes, 59763 GCs, 117595958/666457240 avg/max bytes residency (14 samples), 1588M in use, 0.000 INIT (0.008 elapsed), 13.713 MUT (13.966 elapsed), 6.220 GC (7.108 elapsed) :ghc>>
2016-05-24 04:16:21 +03:00
|
|
|
| T.null a = RegularPosting
|
|
|
|
| T.head a == '[' && T.last a == ']' = BalancedVirtualPosting
|
|
|
|
| T.head a == '(' && T.last a == ')' = VirtualPosting
|
2011-08-03 03:29:13 +04:00
|
|
|
| otherwise = RegularPosting
|
|
|
|
|
|
|
|
accountNameWithoutPostingType :: AccountName -> AccountName
|
|
|
|
accountNameWithoutPostingType a = case accountNamePostingType a of
|
lib: textification begins! account names
The first of several conversions from String to (strict) Text, hopefully
reducing space and time usage.
This one shows a small improvement, with GHC 7.10.3 and text-1.2.2.1:
hledger -f data/100x100x10.journal stats
string: <<ghc: 39471064 bytes, 77 GCs, 198421/275048 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.020 elapsed), 0.010 GC (0.014 elapsed) :ghc>>
text: <<ghc: 39268024 bytes, 77 GCs, 197018/270840 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.002 elapsed), 0.016 MUT (0.022 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
hledger -f data/1000x100x10.journal stats
string: <<ghc: 318555920 bytes, 617 GCs, 2178997/7134472 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.001 elapsed), 0.129 MUT (0.136 elapsed), 0.067 GC (0.077 elapsed) :ghc>>
text: <<ghc: 314248496 bytes, 612 GCs, 2074045/6617960 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.003 elapsed), 0.137 MUT (0.145 elapsed), 0.067 GC (0.079 elapsed) :ghc>>
hledger -f data/10000x100x10.journal stats
string: <<ghc: 3114763608 bytes, 6026 GCs, 18858950/75552024 avg/max bytes residency (11 samples), 201M in use, 0.000 INIT (0.000 elapsed), 1.331 MUT (1.372 elapsed), 0.699 GC (0.812 elapsed) :ghc>>
text: <<ghc: 3071468920 bytes, 5968 GCs, 14120344/62951360 avg/max bytes residency (9 samples), 124M in use, 0.000 INIT (0.003 elapsed), 1.272 MUT (1.349 elapsed), 0.513 GC (0.578 elapsed) :ghc>>
hledger -f data/100000x100x10.journal stats
string: <<ghc: 31186579432 bytes, 60278 GCs, 135332581/740228992 avg/max bytes residency (13 samples), 1697M in use, 0.000 INIT (0.008 elapsed), 14.677 MUT (15.508 elapsed), 7.081 GC (8.074 elapsed) :ghc>>
text: <<ghc: 30753427672 bytes, 59763 GCs, 117595958/666457240 avg/max bytes residency (14 samples), 1588M in use, 0.000 INIT (0.008 elapsed), 13.713 MUT (13.966 elapsed), 6.220 GC (7.108 elapsed) :ghc>>
2016-05-24 04:16:21 +03:00
|
|
|
BalancedVirtualPosting -> T.init $ T.tail a
|
|
|
|
VirtualPosting -> T.init $ T.tail a
|
2011-08-03 03:29:13 +04:00
|
|
|
RegularPosting -> a
|
|
|
|
|
|
|
|
accountNameWithPostingType :: PostingType -> AccountName -> AccountName
|
lib: textification begins! account names
The first of several conversions from String to (strict) Text, hopefully
reducing space and time usage.
This one shows a small improvement, with GHC 7.10.3 and text-1.2.2.1:
hledger -f data/100x100x10.journal stats
string: <<ghc: 39471064 bytes, 77 GCs, 198421/275048 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.020 elapsed), 0.010 GC (0.014 elapsed) :ghc>>
text: <<ghc: 39268024 bytes, 77 GCs, 197018/270840 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.002 elapsed), 0.016 MUT (0.022 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
hledger -f data/1000x100x10.journal stats
string: <<ghc: 318555920 bytes, 617 GCs, 2178997/7134472 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.001 elapsed), 0.129 MUT (0.136 elapsed), 0.067 GC (0.077 elapsed) :ghc>>
text: <<ghc: 314248496 bytes, 612 GCs, 2074045/6617960 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.003 elapsed), 0.137 MUT (0.145 elapsed), 0.067 GC (0.079 elapsed) :ghc>>
hledger -f data/10000x100x10.journal stats
string: <<ghc: 3114763608 bytes, 6026 GCs, 18858950/75552024 avg/max bytes residency (11 samples), 201M in use, 0.000 INIT (0.000 elapsed), 1.331 MUT (1.372 elapsed), 0.699 GC (0.812 elapsed) :ghc>>
text: <<ghc: 3071468920 bytes, 5968 GCs, 14120344/62951360 avg/max bytes residency (9 samples), 124M in use, 0.000 INIT (0.003 elapsed), 1.272 MUT (1.349 elapsed), 0.513 GC (0.578 elapsed) :ghc>>
hledger -f data/100000x100x10.journal stats
string: <<ghc: 31186579432 bytes, 60278 GCs, 135332581/740228992 avg/max bytes residency (13 samples), 1697M in use, 0.000 INIT (0.008 elapsed), 14.677 MUT (15.508 elapsed), 7.081 GC (8.074 elapsed) :ghc>>
text: <<ghc: 30753427672 bytes, 59763 GCs, 117595958/666457240 avg/max bytes residency (14 samples), 1588M in use, 0.000 INIT (0.008 elapsed), 13.713 MUT (13.966 elapsed), 6.220 GC (7.108 elapsed) :ghc>>
2016-05-24 04:16:21 +03:00
|
|
|
accountNameWithPostingType BalancedVirtualPosting a = "["<>accountNameWithoutPostingType a<>"]"
|
|
|
|
accountNameWithPostingType VirtualPosting a = "("<>accountNameWithoutPostingType a<>")"
|
2011-08-03 03:29:13 +04:00
|
|
|
accountNameWithPostingType RegularPosting a = accountNameWithoutPostingType a
|
|
|
|
|
|
|
|
-- | Prefix one account name to another, preserving posting type
|
|
|
|
-- indicators like concatAccountNames.
|
|
|
|
joinAccountNames :: AccountName -> AccountName -> AccountName
|
lib: textification begins! account names
The first of several conversions from String to (strict) Text, hopefully
reducing space and time usage.
This one shows a small improvement, with GHC 7.10.3 and text-1.2.2.1:
hledger -f data/100x100x10.journal stats
string: <<ghc: 39471064 bytes, 77 GCs, 198421/275048 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.020 elapsed), 0.010 GC (0.014 elapsed) :ghc>>
text: <<ghc: 39268024 bytes, 77 GCs, 197018/270840 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.002 elapsed), 0.016 MUT (0.022 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
hledger -f data/1000x100x10.journal stats
string: <<ghc: 318555920 bytes, 617 GCs, 2178997/7134472 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.001 elapsed), 0.129 MUT (0.136 elapsed), 0.067 GC (0.077 elapsed) :ghc>>
text: <<ghc: 314248496 bytes, 612 GCs, 2074045/6617960 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.003 elapsed), 0.137 MUT (0.145 elapsed), 0.067 GC (0.079 elapsed) :ghc>>
hledger -f data/10000x100x10.journal stats
string: <<ghc: 3114763608 bytes, 6026 GCs, 18858950/75552024 avg/max bytes residency (11 samples), 201M in use, 0.000 INIT (0.000 elapsed), 1.331 MUT (1.372 elapsed), 0.699 GC (0.812 elapsed) :ghc>>
text: <<ghc: 3071468920 bytes, 5968 GCs, 14120344/62951360 avg/max bytes residency (9 samples), 124M in use, 0.000 INIT (0.003 elapsed), 1.272 MUT (1.349 elapsed), 0.513 GC (0.578 elapsed) :ghc>>
hledger -f data/100000x100x10.journal stats
string: <<ghc: 31186579432 bytes, 60278 GCs, 135332581/740228992 avg/max bytes residency (13 samples), 1697M in use, 0.000 INIT (0.008 elapsed), 14.677 MUT (15.508 elapsed), 7.081 GC (8.074 elapsed) :ghc>>
text: <<ghc: 30753427672 bytes, 59763 GCs, 117595958/666457240 avg/max bytes residency (14 samples), 1588M in use, 0.000 INIT (0.008 elapsed), 13.713 MUT (13.966 elapsed), 6.220 GC (7.108 elapsed) :ghc>>
2016-05-24 04:16:21 +03:00
|
|
|
joinAccountNames a b = concatAccountNames $ filter (not . T.null) [a,b]
|
2011-08-03 03:29:13 +04:00
|
|
|
|
|
|
|
-- | Join account names into one. If any of them has () or [] posting type
|
|
|
|
-- indicators, these (the first type encountered) will also be applied to
|
|
|
|
-- the resulting account name.
|
|
|
|
concatAccountNames :: [AccountName] -> AccountName
|
lib: textification begins! account names
The first of several conversions from String to (strict) Text, hopefully
reducing space and time usage.
This one shows a small improvement, with GHC 7.10.3 and text-1.2.2.1:
hledger -f data/100x100x10.journal stats
string: <<ghc: 39471064 bytes, 77 GCs, 198421/275048 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.020 elapsed), 0.010 GC (0.014 elapsed) :ghc>>
text: <<ghc: 39268024 bytes, 77 GCs, 197018/270840 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.002 elapsed), 0.016 MUT (0.022 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
hledger -f data/1000x100x10.journal stats
string: <<ghc: 318555920 bytes, 617 GCs, 2178997/7134472 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.001 elapsed), 0.129 MUT (0.136 elapsed), 0.067 GC (0.077 elapsed) :ghc>>
text: <<ghc: 314248496 bytes, 612 GCs, 2074045/6617960 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.003 elapsed), 0.137 MUT (0.145 elapsed), 0.067 GC (0.079 elapsed) :ghc>>
hledger -f data/10000x100x10.journal stats
string: <<ghc: 3114763608 bytes, 6026 GCs, 18858950/75552024 avg/max bytes residency (11 samples), 201M in use, 0.000 INIT (0.000 elapsed), 1.331 MUT (1.372 elapsed), 0.699 GC (0.812 elapsed) :ghc>>
text: <<ghc: 3071468920 bytes, 5968 GCs, 14120344/62951360 avg/max bytes residency (9 samples), 124M in use, 0.000 INIT (0.003 elapsed), 1.272 MUT (1.349 elapsed), 0.513 GC (0.578 elapsed) :ghc>>
hledger -f data/100000x100x10.journal stats
string: <<ghc: 31186579432 bytes, 60278 GCs, 135332581/740228992 avg/max bytes residency (13 samples), 1697M in use, 0.000 INIT (0.008 elapsed), 14.677 MUT (15.508 elapsed), 7.081 GC (8.074 elapsed) :ghc>>
text: <<ghc: 30753427672 bytes, 59763 GCs, 117595958/666457240 avg/max bytes residency (14 samples), 1588M in use, 0.000 INIT (0.008 elapsed), 13.713 MUT (13.966 elapsed), 6.220 GC (7.108 elapsed) :ghc>>
2016-05-24 04:16:21 +03:00
|
|
|
concatAccountNames as = accountNameWithPostingType t $ T.intercalate ":" $ map accountNameWithoutPostingType as
|
2011-08-03 03:29:13 +04:00
|
|
|
where t = headDef RegularPosting $ filter (/= RegularPosting) $ map accountNamePostingType as
|
|
|
|
|
2015-05-14 22:50:32 +03:00
|
|
|
-- | Rewrite an account name using all matching aliases from the given list, in sequence.
|
|
|
|
-- Each alias sees the result of applying the previous aliases.
|
2014-10-25 02:05:10 +04:00
|
|
|
accountNameApplyAliases :: [AccountAlias] -> AccountName -> AccountName
|
|
|
|
accountNameApplyAliases aliases a = accountNameWithPostingType atype aname'
|
|
|
|
where
|
|
|
|
(aname,atype) = (accountNameWithoutPostingType a, accountNamePostingType a)
|
2015-05-14 22:50:32 +03:00
|
|
|
aname' = foldl
|
2015-05-28 20:39:12 +03:00
|
|
|
(\acct alias -> dbg6 "result" $ aliasReplace (dbg6 "alias" alias) (dbg6 "account" acct))
|
2015-05-14 22:50:32 +03:00
|
|
|
aname
|
|
|
|
aliases
|
|
|
|
|
2015-09-27 04:54:46 +03:00
|
|
|
-- | Memoising version of accountNameApplyAliases, maybe overkill.
|
|
|
|
accountNameApplyAliasesMemo :: [AccountAlias] -> AccountName -> AccountName
|
|
|
|
accountNameApplyAliasesMemo aliases = memo (accountNameApplyAliases aliases)
|
|
|
|
|
2015-05-14 22:50:32 +03:00
|
|
|
-- aliasMatches :: AccountAlias -> AccountName -> Bool
|
|
|
|
-- aliasMatches (BasicAlias old _) a = old `isAccountNamePrefixOf` a
|
|
|
|
-- aliasMatches (RegexAlias re _) a = regexMatchesCI re a
|
|
|
|
|
|
|
|
aliasReplace :: AccountAlias -> AccountName -> AccountName
|
2015-05-28 20:39:12 +03:00
|
|
|
aliasReplace (BasicAlias old new) a
|
lib: textification begins! account names
The first of several conversions from String to (strict) Text, hopefully
reducing space and time usage.
This one shows a small improvement, with GHC 7.10.3 and text-1.2.2.1:
hledger -f data/100x100x10.journal stats
string: <<ghc: 39471064 bytes, 77 GCs, 198421/275048 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.020 elapsed), 0.010 GC (0.014 elapsed) :ghc>>
text: <<ghc: 39268024 bytes, 77 GCs, 197018/270840 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.002 elapsed), 0.016 MUT (0.022 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
hledger -f data/1000x100x10.journal stats
string: <<ghc: 318555920 bytes, 617 GCs, 2178997/7134472 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.001 elapsed), 0.129 MUT (0.136 elapsed), 0.067 GC (0.077 elapsed) :ghc>>
text: <<ghc: 314248496 bytes, 612 GCs, 2074045/6617960 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.003 elapsed), 0.137 MUT (0.145 elapsed), 0.067 GC (0.079 elapsed) :ghc>>
hledger -f data/10000x100x10.journal stats
string: <<ghc: 3114763608 bytes, 6026 GCs, 18858950/75552024 avg/max bytes residency (11 samples), 201M in use, 0.000 INIT (0.000 elapsed), 1.331 MUT (1.372 elapsed), 0.699 GC (0.812 elapsed) :ghc>>
text: <<ghc: 3071468920 bytes, 5968 GCs, 14120344/62951360 avg/max bytes residency (9 samples), 124M in use, 0.000 INIT (0.003 elapsed), 1.272 MUT (1.349 elapsed), 0.513 GC (0.578 elapsed) :ghc>>
hledger -f data/100000x100x10.journal stats
string: <<ghc: 31186579432 bytes, 60278 GCs, 135332581/740228992 avg/max bytes residency (13 samples), 1697M in use, 0.000 INIT (0.008 elapsed), 14.677 MUT (15.508 elapsed), 7.081 GC (8.074 elapsed) :ghc>>
text: <<ghc: 30753427672 bytes, 59763 GCs, 117595958/666457240 avg/max bytes residency (14 samples), 1588M in use, 0.000 INIT (0.008 elapsed), 13.713 MUT (13.966 elapsed), 6.220 GC (7.108 elapsed) :ghc>>
2016-05-24 04:16:21 +03:00
|
|
|
| old `isAccountNamePrefixOf` a || old == a = new <> T.drop (T.length old) a
|
2015-05-28 20:39:12 +03:00
|
|
|
| otherwise = a
|
lib: textification begins! account names
The first of several conversions from String to (strict) Text, hopefully
reducing space and time usage.
This one shows a small improvement, with GHC 7.10.3 and text-1.2.2.1:
hledger -f data/100x100x10.journal stats
string: <<ghc: 39471064 bytes, 77 GCs, 198421/275048 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.020 elapsed), 0.010 GC (0.014 elapsed) :ghc>>
text: <<ghc: 39268024 bytes, 77 GCs, 197018/270840 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.002 elapsed), 0.016 MUT (0.022 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
hledger -f data/1000x100x10.journal stats
string: <<ghc: 318555920 bytes, 617 GCs, 2178997/7134472 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.001 elapsed), 0.129 MUT (0.136 elapsed), 0.067 GC (0.077 elapsed) :ghc>>
text: <<ghc: 314248496 bytes, 612 GCs, 2074045/6617960 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.003 elapsed), 0.137 MUT (0.145 elapsed), 0.067 GC (0.079 elapsed) :ghc>>
hledger -f data/10000x100x10.journal stats
string: <<ghc: 3114763608 bytes, 6026 GCs, 18858950/75552024 avg/max bytes residency (11 samples), 201M in use, 0.000 INIT (0.000 elapsed), 1.331 MUT (1.372 elapsed), 0.699 GC (0.812 elapsed) :ghc>>
text: <<ghc: 3071468920 bytes, 5968 GCs, 14120344/62951360 avg/max bytes residency (9 samples), 124M in use, 0.000 INIT (0.003 elapsed), 1.272 MUT (1.349 elapsed), 0.513 GC (0.578 elapsed) :ghc>>
hledger -f data/100000x100x10.journal stats
string: <<ghc: 31186579432 bytes, 60278 GCs, 135332581/740228992 avg/max bytes residency (13 samples), 1697M in use, 0.000 INIT (0.008 elapsed), 14.677 MUT (15.508 elapsed), 7.081 GC (8.074 elapsed) :ghc>>
text: <<ghc: 30753427672 bytes, 59763 GCs, 117595958/666457240 avg/max bytes residency (14 samples), 1588M in use, 0.000 INIT (0.008 elapsed), 13.713 MUT (13.966 elapsed), 6.220 GC (7.108 elapsed) :ghc>>
2016-05-24 04:16:21 +03:00
|
|
|
aliasReplace (RegexAlias re repl) a = T.pack $ regexReplaceCIMemo re repl $ T.unpack a -- XXX
|
2014-10-29 18:20:27 +03:00
|
|
|
|
2011-08-05 04:05:39 +04:00
|
|
|
|
2010-12-27 23:26:22 +03:00
|
|
|
tests_Hledger_Data_Posting = TestList [
|
2011-08-03 03:29:13 +04:00
|
|
|
|
|
|
|
"accountNamePostingType" ~: do
|
|
|
|
accountNamePostingType "a" `is` RegularPosting
|
|
|
|
accountNamePostingType "(a)" `is` VirtualPosting
|
|
|
|
accountNamePostingType "[a]" `is` BalancedVirtualPosting
|
|
|
|
|
|
|
|
,"accountNameWithoutPostingType" ~: do
|
|
|
|
accountNameWithoutPostingType "(a)" `is` "a"
|
|
|
|
|
|
|
|
,"accountNameWithPostingType" ~: do
|
|
|
|
accountNameWithPostingType VirtualPosting "[a]" `is` "(a)"
|
|
|
|
|
|
|
|
,"joinAccountNames" ~: do
|
|
|
|
"a" `joinAccountNames` "b:c" `is` "a:b:c"
|
|
|
|
"a" `joinAccountNames` "(b:c)" `is` "(a:b:c)"
|
|
|
|
"[a]" `joinAccountNames` "(b:c)" `is` "[a:b:c]"
|
|
|
|
"" `joinAccountNames` "a" `is` "a"
|
|
|
|
|
|
|
|
,"concatAccountNames" ~: do
|
|
|
|
concatAccountNames [] `is` ""
|
|
|
|
concatAccountNames ["a","(b)","[c:d]"] `is` "(a:b:c:d)"
|
|
|
|
|
2010-12-27 23:26:22 +03:00
|
|
|
]
|
2014-09-11 00:07:53 +04:00
|
|
|
|