lib: try a single filter again to speed up -V; simplify a bit (#999)
There was no speedup, in fact.
This commit is contained in:
parent
76b933641d
commit
168edb910e
@ -105,7 +105,7 @@ module Hledger.Data.Amount (
|
|||||||
isZeroMixedAmount,
|
isZeroMixedAmount,
|
||||||
isReallyZeroMixedAmount,
|
isReallyZeroMixedAmount,
|
||||||
isReallyZeroMixedAmountCost,
|
isReallyZeroMixedAmountCost,
|
||||||
mixedAmountValue,
|
-- mixedAmountValue,
|
||||||
mixedAmountTotalPriceToUnitPrice,
|
mixedAmountTotalPriceToUnitPrice,
|
||||||
-- ** rendering
|
-- ** rendering
|
||||||
styleMixedAmount,
|
styleMixedAmount,
|
||||||
@ -446,35 +446,32 @@ canonicaliseAmount styles a@Amount{acommodity=c, astyle=s} = a{astyle=s'}
|
|||||||
|
|
||||||
-- | Find the market value of this amount on the given date, in it's
|
-- | Find the market value of this amount on the given date, in it's
|
||||||
-- default valuation commodity, using the given market prices which
|
-- default valuation commodity, using the given market prices which
|
||||||
-- should be in date then parse order.
|
-- are expected to be in parse order.
|
||||||
-- If no default valuation commodity can be found, the amount is left
|
-- If no default valuation commodity can be found, the amount is left
|
||||||
-- unchanged.
|
-- unchanged.
|
||||||
amountValue :: MarketPricesDateAndParseOrdered -> Day -> Amount -> Amount
|
amountValue :: [MarketPrice] -> Day -> Amount -> Amount
|
||||||
amountValue ps d a@Amount{acommodity=c} =
|
amountValue ps d a@Amount{acommodity=c} =
|
||||||
let ps' = filter ((c==).mpcommodity) ps
|
case commodityValue ps d c of
|
||||||
in
|
Just v -> v{aquantity=aquantity v * aquantity a}
|
||||||
case commodityValue ps' d c of
|
Nothing -> a
|
||||||
Just v -> v{aquantity=aquantity v * aquantity a}
|
|
||||||
Nothing -> a
|
|
||||||
|
|
||||||
-- (This is here not in Commodity.hs to use the Amount Show instance above for debugging.)
|
-- (This is here not in Commodity.hs to use the Amount Show instance above for debugging.)
|
||||||
--
|
--
|
||||||
-- | Find the market value, if known, of one unit of the given
|
-- | Find the market value, if known, of one unit of the given
|
||||||
-- commodity (A), on the given valuation date, in the commodity (B)
|
-- commodity (A), on the given valuation date, in the commodity (B)
|
||||||
-- mentioned in the latest applicable market price.
|
-- mentioned in the latest applicable market price.
|
||||||
--
|
|
||||||
-- The applicable price is obtained from the given market prices,
|
-- The applicable price is obtained from the given market prices,
|
||||||
-- which should be for commodity A only, and in date then parse order.
|
-- which are expected to be in parse order.
|
||||||
-- It is the price with the latest date on or before the valuation
|
-- It is the price with the latest date on or before the valuation
|
||||||
-- date; or if there are multiple prices on that date, the last one
|
-- date, or if there are multiple prices on that date, the last one
|
||||||
-- parsed.
|
-- parsed.
|
||||||
--
|
commodityValue :: [MarketPrice] -> Day -> CommoditySymbol -> Maybe Amount
|
||||||
commodityValue :: CommodityPricesDateAndParseOrdered -> Day -> CommoditySymbol -> Maybe Amount
|
|
||||||
commodityValue ps valuationdate c =
|
commodityValue ps valuationdate c =
|
||||||
case filter ((<=valuationdate).mpdate) ps of
|
case ps' of
|
||||||
[] -> dbg Nothing
|
[] -> dbg Nothing
|
||||||
ps' -> dbg $ Just $ mpamount $ last ps'
|
ps'' -> dbg $ Just $ mpamount $ head ps''
|
||||||
where
|
where
|
||||||
|
ps' = filter (\MarketPrice{..} -> mpcommodity==c && mpdate<=valuationdate) ps
|
||||||
dbg = dbg8 ("using market price for "++T.unpack c)
|
dbg = dbg8 ("using market price for "++T.unpack c)
|
||||||
|
|
||||||
|
|
||||||
@ -731,8 +728,8 @@ cshowMixedAmountOneLineWithoutPrice m = intercalate ", " $ map cshowAmountWithou
|
|||||||
canonicaliseMixedAmount :: M.Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount
|
canonicaliseMixedAmount :: M.Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount
|
||||||
canonicaliseMixedAmount styles (Mixed as) = Mixed $ map (canonicaliseAmount styles) as
|
canonicaliseMixedAmount styles (Mixed as) = Mixed $ map (canonicaliseAmount styles) as
|
||||||
|
|
||||||
mixedAmountValue :: MarketPricesDateAndParseOrdered -> Day -> MixedAmount -> MixedAmount
|
-- mixedAmountValue :: MarketPricesDateAndParseOrdered -> Day -> MixedAmount -> MixedAmount
|
||||||
mixedAmountValue ps d (Mixed as) = Mixed $ map (amountValue ps d) as
|
-- mixedAmountValue ps d (Mixed as) = Mixed $ map (amountValue ps d) as
|
||||||
|
|
||||||
-- | Replace each component amount's TotalPrice, if it has one, with an equivalent UnitPrice.
|
-- | Replace each component amount's TotalPrice, if it has one, with an equivalent UnitPrice.
|
||||||
-- Has no effect on amounts without one.
|
-- Has no effect on amounts without one.
|
||||||
|
|||||||
@ -428,15 +428,6 @@ data MarketPrice = MarketPrice {
|
|||||||
|
|
||||||
instance NFData MarketPrice
|
instance NFData MarketPrice
|
||||||
|
|
||||||
-- | Market prices in the order they were declared in the parse stream.
|
|
||||||
type MarketPricesParseOrdered = [MarketPrice]
|
|
||||||
|
|
||||||
-- | Market prices in date then parse order.
|
|
||||||
type MarketPricesDateAndParseOrdered = [MarketPrice]
|
|
||||||
|
|
||||||
-- | Market prices for a single commodity, in date then parse order.
|
|
||||||
type CommodityPricesDateAndParseOrdered = [MarketPrice]
|
|
||||||
|
|
||||||
-- | A Journal, containing transactions and various other things.
|
-- | A Journal, containing transactions and various other things.
|
||||||
-- The basic data model for hledger.
|
-- The basic data model for hledger.
|
||||||
--
|
--
|
||||||
@ -461,8 +452,8 @@ data Journal = Journal {
|
|||||||
,jdeclaredaccounttypes :: M.Map AccountType [AccountName] -- ^ Accounts whose type has been declared in account directives (usually 5 top-level accounts)
|
,jdeclaredaccounttypes :: M.Map AccountType [AccountName] -- ^ Accounts whose type has been declared in account directives (usually 5 top-level accounts)
|
||||||
,jcommodities :: M.Map CommoditySymbol Commodity -- ^ commodities and formats declared by commodity directives
|
,jcommodities :: M.Map CommoditySymbol Commodity -- ^ commodities and formats declared by commodity directives
|
||||||
,jinferredcommodities :: M.Map CommoditySymbol AmountStyle -- ^ commodities and formats inferred from journal amounts TODO misnamed - jusedstyles
|
,jinferredcommodities :: M.Map CommoditySymbol AmountStyle -- ^ commodities and formats inferred from journal amounts TODO misnamed - jusedstyles
|
||||||
,jmarketprices :: MarketPricesParseOrdered -- ^ All market prices declared by P directives, in parse order (after journal finalisation).
|
,jmarketprices :: [MarketPrice] -- ^ All market prices declared by P directives. After journal finalisation,
|
||||||
-- Note, not yet in date order because concatenating journals could mess that up.
|
-- these will be in parse order (not yet date-sorted, to allow concatenating Journals).
|
||||||
,jtxnmodifiers :: [TransactionModifier]
|
,jtxnmodifiers :: [TransactionModifier]
|
||||||
,jperiodictxns :: [PeriodicTransaction]
|
,jperiodictxns :: [PeriodicTransaction]
|
||||||
,jtxns :: [Transaction]
|
,jtxns :: [Transaction]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user