diff options
Diffstat (limited to 'hledger-overview.hs')
-rwxr-xr-x | hledger-overview.hs | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/hledger-overview.hs b/hledger-overview.hs index 5e296cf..431099f 100755 --- a/hledger-overview.hs +++ b/hledger-overview.hs @@ -26,6 +26,7 @@ import qualified Data.Text.IO as IO import Data.Time.Calendar (Day, fromGregorian, toGregorian) import Data.Time.Clock (UTCTime (..), diffTimeToPicoseconds, diffUTCTime, getCurrentTime) import Hledger +import Hledger.Data.Types import Rainbow import System.Environment (getArgs) import qualified System.Process as Process @@ -63,9 +64,9 @@ main = do t <- today let bal = getTotal j t reportopts sec "cash balances" - row " cashap" (cur $ bal "^as:me:cash:cashapp status:! status:*") Nothing + row " cashapp" (cur $ bal "^as:me:cash:cashapp status:! status:*") Nothing row " wallet" (cur $ bal "^as:me:cash:wallet") Nothing - row " cse" (cur $ bal "^as:me:cash:cse") Nothing + row " cse" (cur $ bal "^as:me:cash:cse status:*") Nothing row " disc" (cur $ bal "^li:me:cred:discover status:*") Nothing row " citi" (cur $ bal "^li:me:cred:citi status:*") Nothing @@ -73,6 +74,7 @@ main = do row " ben" (cur $ bal "^li:me:allowance:ben") Nothing row " kate" (cur $ bal "^li:me:allowance:kate") Nothing row " tithe" (cur $ bal "^li:me:church:tithe") Nothing + row "nick rent" (cur $ bal "^li:me:rent:nick") Nothing let (year, month, _) = toGregorian t let expectedLevel = fromJust $ Map.lookup (roundTo 2 $ (fromIntegral year + fromIntegral month / 12) - (1992 + 7 / 12)) $ levelSchedule cur @@ -86,11 +88,11 @@ main = do -- let lastyear = 2020 -- row " in:net" (- getTotal j t (defreportopts {value_ = value_, period_ = YearPeriod 2020}) "^in:me") Nothing -- net cash is limited to USD because that is what I can effectively spend - let netCash = bal "^as:me:cash ^li:me:cred ^li:me:allowance cur:USD" - row " net cash" (Target 0 netCash) $ Just "credit spending minus cash/allowances. keep it positive" + let netCash = bal "^as:me:cash ^li:me:cred cur:USD" + row " net cash" (Target 0 netCash) $ Just "credit spending minus cash. keep it positive" row "month nut" (Limit monthlyNut thisMonth) $ Just $ "avg: " <> (display $ Diff $ monthlyNut - thisMonth) let netWorth = bal "^as ^li" - row " bip" (pr $ roundTo 2 $ trivial * netWorth) Nothing + row " bip" (roundTo 2 $ trivial * netWorth) Nothing -- ideally: ramen 12 mo, runway 4 yrs. let (_, _, runwayMo) = runway j t reportopts row " runway" (Target 12 runwayMo) $ Just "want: 12 months" @@ -250,16 +252,15 @@ levelSchedule' cur = (ages++[70], lvls++[goal]) -- exchange rate, but it changes so much that it would be hard to have a -- concrete plan when dealing in BTC/sats. So I figure 100k is a good price -- target for the next year or so. -usdToBtc usd = usd / 100_000 - -btcToUsd btc = btc * 100_000 +usdBtcExchangeRate = 100_000 +usdToBtc usd = usd / usdBtcExchangeRate +btcToUsd btc = btc * usdBtcExchangeRate +usdToSat usd = btcToSat $ usdToBtc usd +-- These are constants, should never change. btcToSat btc = btc * 100_000_000 - satToBtc sat = sat / 100_000_000 -usdToSat usd = btcToSat $ usdToBtc usd - -- | A trivial decision is one that is 0.01% of the total, or 1 basis point. -- From <https://ofdollarsanddata.com/climbing-the-wealth-ladder/>. trivial :: Quantity @@ -269,7 +270,7 @@ getTotal :: Journal -> Day -> ReportOpts -> String -> Quantity getTotal j t o q = sum . map aquantity $ getTotalAmounts j t o q getTotalAmounts :: Journal -> Day -> ReportOpts -> String -> [Amount] -getTotalAmounts j d opts q = totals +getTotalAmounts j d opts q = Map.elems totals where (_, (Mixed totals)) = balanceReport (ReportSpec opts d query []) j Right (query, _) = parseQuery d $ pack q @@ -296,7 +297,7 @@ targetFund :: Journal -> Day -> ReportOpts -> Quantity targetFund j d opts = 25 * yearlyExpenses where yearlyExpenses = expenses / yearsSinceBeginning d - expenses = sum $ map aquantity $ total + expenses = sum $ map aquantity $ Map.elems total Right (query, _) = parseQuery d $ pack "^ex:me:want ^ex:..:need" (_, (Mixed total)) = balanceReport (ReportSpec opts d query []) j |