From f43c7e41d1d1ab83d775f4ca8f431aaf1ac1ae27 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 10 Nov 2020 08:01:31 -0800 Subject: [PATCH] csv, journal: debug output The prolific "assignment" output is now at level 9. --- hledger-lib/Hledger/Data/Journal.hs | 14 +++++++------- hledger-lib/Hledger/Read/CsvReader.hs | 12 +++++++----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index a408151e6..6b7866e5e 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -566,7 +566,7 @@ journalReverse j = ,jtxns = reverse $ jtxns j ,jtxnmodifiers = reverse $ jtxnmodifiers j ,jperiodictxns = reverse $ jperiodictxns j - ,jpricedirectives = reverse $ jpricedirectives j + ,jpricedirectives = reverse $ jpricedirectives j } -- | Set this journal's last read time, ie when its files were last read. @@ -982,14 +982,12 @@ journalCommodityStyles j = -- "the format of the first amount, adjusted to the highest precision of all amounts". -- Can return an error message eg if inconsistent number formats are found. journalInferCommodityStyles :: Journal -> Either String Journal -journalInferCommodityStyles j = +journalInferCommodityStyles j = case - commodityStylesFromAmounts $ - dbg7 "journalInferCommodityStyles using amounts" $ - journalStyleInfluencingAmounts j + commodityStylesFromAmounts $ journalStyleInfluencingAmounts j of Left e -> Left e - Right cs -> Right j{jinferredcommodities = cs} + Right cs -> Right j{jinferredcommodities = dbg7 "journalInferCommodityStyles" cs} -- | Given a list of amounts, in parse order (roughly speaking; see journalStyleInfluencingAmounts), -- build a map from their commodity names to standard commodity @@ -1119,7 +1117,9 @@ journalToCost j@Journal{jtxns=ts} = j{jtxns=map (transactionToCost styles) ts} -- Transaction price amounts (posting amounts' aprice field) are not included. -- journalStyleInfluencingAmounts :: Journal -> [Amount] -journalStyleInfluencingAmounts j = catMaybes $ concat [ +journalStyleInfluencingAmounts j = + dbg7 "journalStyleInfluencingAmounts" $ + catMaybes $ concat [ [mdefaultcommodityamt] ,map (Just . pdamount) $ jpricedirectives j ,map Just $ concatMap amounts $ map pamount $ journalPostings j diff --git a/hledger-lib/Hledger/Read/CsvReader.hs b/hledger-lib/Hledger/Read/CsvReader.hs index 3d78aff29..4b24aa734 100644 --- a/hledger-lib/Hledger/Read/CsvReader.hs +++ b/hledger-lib/Hledger/Read/CsvReader.hs @@ -712,7 +712,7 @@ readJournalFromCsv mrulesfile csvfile csvdata = else return $ defaultRulesText rulesfile rules <- either throwerr return $ parseAndValidateCsvRules rulesfile rulestext - dbg6IO "rules" rules + dbg6IO "csv rules" rules -- parse the skip directive's value, if any let skiplines = case getDirective "skip" rules of @@ -745,7 +745,7 @@ readJournalFromCsv mrulesfile csvfile csvdata = let -- convert CSV records to transactions - txns = snd $ mapAccumL + txns = dbg7 "csv txns" $ snd $ mapAccumL (\pos r -> let SourcePos name line col = pos @@ -762,7 +762,9 @@ readJournalFromCsv mrulesfile csvfile csvdata = -- than one date and the first date is more recent than the last): -- reverse them to get same-date transactions ordered chronologically. txns' = - (if newestfirst || mdataseemsnewestfirst == Just True then reverse else id) txns + (if newestfirst || mdataseemsnewestfirst == Just True + then dbg7 "reversed csv txns" . reverse else id) + txns where newestfirst = dbg6 "newestfirst" $ isJust $ getDirective "newest-first" rules mdataseemsnewestfirst = dbg6 "mdataseemsnewestfirst" $ @@ -770,7 +772,7 @@ readJournalFromCsv mrulesfile csvfile csvdata = ds | length ds > 1 -> Just $ head ds > last ds _ -> Nothing -- Second, sort by date. - txns'' = sortBy (comparing tdate) txns' + txns'' = dbg7 "date-sorted csv txns" $ sortBy (comparing tdate) txns' when (not rulesfileexists) $ do dbg1IO "creating conversion rules file" rulesfile @@ -1190,7 +1192,7 @@ getEffectiveAssignment :: CsvRules -> CsvRecord -> HledgerFieldName -> Maybe Fie getEffectiveAssignment rules record f = lastMay $ map snd $ assignments where -- all active assignments to field f, in order - assignments = dbg7 "assignments" $ filter ((==f).fst) $ toplevelassignments ++ conditionalassignments + assignments = dbg9 "csv assignments" $ filter ((==f).fst) $ toplevelassignments ++ conditionalassignments where -- all top level field assignments toplevelassignments = rassignments rules