tools: generatejournal: also generate P records (#999)

This commit is contained in:
Simon Michael 2019-04-19 15:44:25 -07:00
parent 6f4009d589
commit 9dd0b510dd
3 changed files with 36 additions and 24 deletions

View File

@ -1,12 +1,15 @@
2015-01-01 transaction 1 2018-01-01 transaction 1
1 1 1 1 A
1:2 -1 1:2 -1 A
2015-01-02 transaction 2 2018-01-02 transaction 2
1:2:3 1 1:2:3 1 A
1:2:3:4 -1 1:2:3:4 -1 A
2015-01-03 transaction 3 2018-01-03 transaction 3
1:2:3:4:5 1 1:2:3:4:5 1 A
1 -1 1 -1 A
P 2018-01-01 A 0.70 B
P 2018-01-02 A 0.71 B
P 2018-01-03 A 0.72 B

View File

@ -1,12 +1,15 @@
2014-01-01 transaction 1 2018-01-01 transaction 1
㐀 1 㐀 1 A
㐀:㐁 -1 㐀:㐁 -1 A
2014-01-02 transaction 2 2018-01-02 transaction 2
㐀:㐁:㐂 1 㐀:㐁:㐂 1 A
㐀:㐁:㐂:㐃 -1 㐀:㐁:㐂:㐃 -1 A
2014-01-03 transaction 3 2018-01-03 transaction 3
㐀:㐁:㐂:㐃:㐄 1 㐀:㐁:㐂:㐃:㐄 1 A
㐀 -1 㐀 -1 A
P 2018-01-01 A 0.70 B
P 2018-01-02 A 0.71 B
P 2018-01-03 A 0.72 B

View File

@ -2,11 +2,12 @@
{- {-
generatejournal.hs NUMTXNS NUMACCTS ACCTDEPTH [--chinese|--mixed] generatejournal.hs NUMTXNS NUMACCTS ACCTDEPTH [--chinese|--mixed]
Outputs a dummy journal file with the specified number of This generates synthetic journal data for benchmarking & profiling.
transactions, number of accounts, and account tree depth. By default It prints a dummy journal on stdout, with NUMTXNS transactions, one
it uses only ascii characters, with --chinese it uses wide chinese per day, using NUMACCTS account names with depths up to ACCTDEPTH.
characters, or with --mixed it uses both. These files are used for It will also contain NUMACCTS P records, one per day.
testing, benchmarking, profiling, etc. By default it uses only ascii characters, with --chinese it uses wide
chinese characters, or with --mixed it uses both.
-} -}
module Main module Main
@ -30,15 +31,20 @@ main = do
let dates = iterate (addDays 1) d let dates = iterate (addDays 1) d
let accts = pair $ cycle $ take numaccts $ uniqueAccountNames opts acctdepth let accts = pair $ cycle $ take numaccts $ uniqueAccountNames opts acctdepth
mapM_ (\(n,d,(a,b)) -> putStr $ showtxn n d a b) $ take numtxns $ zip3 [1..] dates accts mapM_ (\(n,d,(a,b)) -> putStr $ showtxn n d a b) $ take numtxns $ zip3 [1..] dates accts
let rates = [0.70, 0.71 .. 1.3]
mapM_ (\(d,rate) -> putStr $ showmarketprice d rate) $ take numtxns $ zip dates (cycle $ rates ++ init (tail (reverse rates)))
return () return ()
showtxn :: Int -> Day -> String -> String -> String showtxn :: Int -> Day -> String -> String -> String
showtxn txnno date acct1 acct2 = showtxn txnno date acct1 acct2 =
printf "%s transaction %d\n %-40s %2d\n %-40s %2d\n\n" d txnno acct1 amt acct2 (-amt) printf "%s transaction %d\n %-40s %2d A\n %-40s %2d A\n\n" d txnno acct1 amt acct2 (-amt)
where where
d = show date d = show date
amt = 1::Int amt = 1::Int
showmarketprice :: Day -> Double -> String
showmarketprice date rate = printf "P %s A %.2f B\n" (show date) rate
uniqueAccountNames :: [String] -> Int -> [String] uniqueAccountNames :: [String] -> Int -> [String]
uniqueAccountNames opts depth = uniqueAccountNames opts depth =
mkacctnames uniquenames mkacctnames uniquenames