;doc, debug output tweaks (#131)
This commit is contained in:
		
							parent
							
								
									6a62bd6437
								
							
						
					
					
						commit
						dd5afbb6fe
					
				| @ -49,8 +49,6 @@ tests_Prices = tests "Prices" [ | |||||||
| -- Apply a specified valuation to this mixed amount, using the provided | -- Apply a specified valuation to this mixed amount, using the provided | ||||||
| -- prices db, commodity styles, period-end/current dates,  | -- prices db, commodity styles, period-end/current dates,  | ||||||
| -- and whether this is for a multiperiod report or not. | -- and whether this is for a multiperiod report or not. | ||||||
| -- Currently ignores the specified valuation commodity and always uses |  | ||||||
| -- the default valuation commodity. |  | ||||||
| mixedAmountApplyValuation :: [PriceDirective] -> M.Map CommoditySymbol AmountStyle -> Day -> Day -> Bool -> ValuationType -> MixedAmount -> MixedAmount | mixedAmountApplyValuation :: [PriceDirective] -> M.Map CommoditySymbol AmountStyle -> Day -> Day -> Bool -> ValuationType -> MixedAmount -> MixedAmount | ||||||
| mixedAmountApplyValuation prices styles periodend today ismultiperiod v (Mixed as) = | mixedAmountApplyValuation prices styles periodend today ismultiperiod v (Mixed as) = | ||||||
|   Mixed $ map (amountApplyValuation prices styles periodend today ismultiperiod v) as |   Mixed $ map (amountApplyValuation prices styles periodend today ismultiperiod v) as | ||||||
| @ -152,6 +150,7 @@ priceLookup :: [PriceDirective] -> Day -> CommoditySymbol -> Maybe CommoditySymb | |||||||
| priceLookup pricedirectives d from mto = | priceLookup pricedirectives d from mto = | ||||||
|   let |   let | ||||||
|     -- build a graph of the commodity exchange rates in effect on this day |     -- build a graph of the commodity exchange rates in effect on this day | ||||||
|  |     -- XXX should hide these fgl details better | ||||||
|     Prices{prNodemap=m, prDeclaredPrices=g, prWithReversePrices=gr} = pricesAtDate pricedirectives d |     Prices{prNodemap=m, prDeclaredPrices=g, prWithReversePrices=gr} = pricesAtDate pricedirectives d | ||||||
|     fromnode = node m from |     fromnode = node m from | ||||||
|     -- if to is unspecified, try to find a default valuation commodity based on available prices |     -- if to is unspecified, try to find a default valuation commodity based on available prices | ||||||
| @ -167,8 +166,7 @@ priceLookup pricedirectives d from mto = | |||||||
|       Nothing            -> Nothing |       Nothing            -> Nothing | ||||||
|       Just to | to==from -> Nothing |       Just to | to==from -> Nothing | ||||||
|       Just to            -> |       Just to            -> | ||||||
|         -- We have a commodity to convert to. Find the most direct price available, |         -- We have a commodity to convert to. Find the most direct price available. | ||||||
|         -- and return it as an amount. |  | ||||||
|         case |         case | ||||||
|           -- These seem unnecessary, and we can avoid building one of the graphs |           -- These seem unnecessary, and we can avoid building one of the graphs | ||||||
|           -- mdeclaredprice <|> mreverseprice <|> |           -- mdeclaredprice <|> mreverseprice <|> | ||||||
| @ -194,7 +192,7 @@ priceLookup pricedirectives d from mto = | |||||||
|                 where comms = catMaybes $ map (lab g) nodes |                 where comms = catMaybes $ map (lab g) nodes | ||||||
| 
 | 
 | ||||||
|           -- log a message and a Maybe Quantity, hiding Just/Nothing and limiting decimal places |           -- log a message and a Maybe Quantity, hiding Just/Nothing and limiting decimal places | ||||||
|           dbg msg = dbg4With (((msg++": ")++) . maybe "" (show . roundTo 3)) |           dbg msg = dbg4With (((msg++": ")++) . maybe "" (show . roundTo 8)) | ||||||
| 
 | 
 | ||||||
| -- | Convert a list of market price directives in parse order to | -- | Convert a list of market price directives in parse order to | ||||||
| -- a database of market prices in effect on a given day, | -- a database of market prices in effect on a given day, | ||||||
| @ -208,7 +206,7 @@ pricesAtDate pricedirectives d = Prices{ | |||||||
|   where |   where | ||||||
|     -- get the latest (before d) declared price for each commodity pair |     -- get the latest (before d) declared price for each commodity pair | ||||||
|     latestdeclaredprices :: [MarketPrice] = |     latestdeclaredprices :: [MarketPrice] = | ||||||
|       dbg4 "latestdeclaredprices" $ |       dbg5 "latestdeclaredprices" $ | ||||||
|       nubSortBy (compare `on` (\(MarketPrice{..})->(mpfrom,mpto))) $  -- keep only the first (ie newest and latest parsed) price for each pair |       nubSortBy (compare `on` (\(MarketPrice{..})->(mpfrom,mpto))) $  -- keep only the first (ie newest and latest parsed) price for each pair | ||||||
|       map snd $  -- discard the parse order label |       map snd $  -- discard the parse order label | ||||||
|       sortBy (flip compare `on` (\(parseorder,mp)->(mpdate mp,parseorder))) $  -- sort with newest dates and latest parse order first |       sortBy (flip compare `on` (\(parseorder,mp)->(mpdate mp,parseorder))) $  -- sort with newest dates and latest parse order first | ||||||
| @ -241,13 +239,13 @@ marketPriceReverse mp@MarketPrice{..} = mp{mpfrom=mpto, mpto=mpfrom, mprate=1/mp | |||||||
| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------ | ||||||
| -- fgl helpers | -- fgl helpers | ||||||
| 
 | 
 | ||||||
| -- | Look up an existing node by its label in the given NodeMap. | -- | Look up an existing graph node by its label. | ||||||
| -- (If the node does not exist, a new one will be generated, but not | -- (If the node does not exist, a new one will be generated, but not | ||||||
| -- persisted in the nodemap.) | -- persisted in the nodemap.) | ||||||
| node :: Ord a => NodeMap a -> a -> Node | node :: Ord a => NodeMap a -> a -> Node | ||||||
| node m = fst . fst . mkNode m | node m = fst . fst . mkNode m | ||||||
| 
 | 
 | ||||||
| -- | Convert a valid path from the given graph to the corresponding | -- | Convert a valid path within the given graph to the corresponding | ||||||
| -- edge labels. When there are multiple edges between two nodes, the | -- edge labels. When there are multiple edges between two nodes, the | ||||||
| -- lowest-sorting label is used. | -- lowest-sorting label is used. | ||||||
| pathEdgeLabels :: (Show b, Ord b) => Gr a b -> [Node] -> [b] | pathEdgeLabels :: (Show b, Ord b) => Gr a b -> [Node] -> [b] | ||||||
|  | |||||||
| @ -463,9 +463,10 @@ The valuation commodity will be the one referenced in the latest | |||||||
| applicable market price dated on or before the valuation date. | applicable market price dated on or before the valuation date. | ||||||
| If most of your P declarations lead to a single home currency, this will usually be what you want. | If most of your P declarations lead to a single home currency, this will usually be what you want. | ||||||
| 
 | 
 | ||||||
| `-V/--market` is similar to the same flag in Ledger, except | Unlike the similar flag in Ledger, it does not infer market prices | ||||||
| unlike Ledger it does not infer market prices from [transaction prices](/manual.html#transaction-prices). | from [transaction prices](/manual.html#transaction-prices). In | ||||||
| (Mnemonic: in hledger, -B uses transaction prices, -V and -X use market prices.) | hledger, -B uses transaction prices, -V and -X use market prices. | ||||||
|  | 
 | ||||||
| It is equivalent to `--value=now` or `--value=end`. | It is equivalent to `--value=now` or `--value=end`. | ||||||
| 
 | 
 | ||||||
| Here's a quick example: | Here's a quick example: | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user