Skip to content

Commit 11fc437

Browse files
authored
Merge pull request #59 from apauley/reports
Use the correct years available for each owner in reports
2 parents f88588d + 243b56a commit 11fc437

File tree

8 files changed

+76
-17
lines changed

8 files changed

+76
-17
lines changed

CONTRIBUTING.org

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ username) to the list below, and include it in a new or existing pull request.
2222

2323
Hledger Flow is brought to you by:
2424
- [[https://github.com/apauley][Andreas Pauley]]
25-
- [[https://github.com/jecaro][Jean-Charles Quillet]]
25+
26+
Miscellaneous contributors:
27+
- [[https://github.com/jecaro][Jean-Charles Quillet]] (improved command-line parameters)
2628

2729
* Contributing
2830
:PROPERTIES:

ChangeLog.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog for [hledger-flow](https://github.com/apauley/hledger-flow)
22

3+
## 0.12.2
4+
5+
Slightly smarter reporting.
6+
7+
- Get the available report years for each individual owner. Only generate reports for those years.
8+
- Create uniform output directories.
9+
- Add system info to version output
10+
311
## 0.12.1
412

513
Generate some reports per owner.

bin/time-check

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
BASEDIRS="$@"
4+
5+
date
6+
echo -e "A simple script to get a rough idea of execution time."
7+
echo -e "Each script argument is a base directory.\n"
8+
9+
hledger-flow --version|head -n 1
10+
echo
11+
12+
for bd in ${BASEDIRS}
13+
do
14+
DIRNAME=$(basename ${bd})
15+
echo "$(date) BEGIN: ${DIRNAME}"
16+
for subcommand in $(echo "import report")
17+
do
18+
/usr/bin/time --format="${DIRNAME} ${subcommand} sequential real %es" hledger-flow --sequential ${subcommand} ${bd} 2>&1 | grep 'Generated.*reports\|Imported.*journals\|real'
19+
echo
20+
/usr/bin/time --format="${DIRNAME} ${subcommand} parallel real %es" hledger-flow ${subcommand} ${bd} 2>&1 | grep 'Generated.*reports\|Imported.*journals\|real'
21+
echo
22+
done
23+
echo -e "$(date) END: ${DIRNAME}\n"
24+
done
25+
26+
echo "***"

package.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: hledger-flow
2-
version: 0.12.1.99
2+
version: 0.12.2.0
33
synopsis: An hledger workflow focusing on automated statement import and classification.
44
category: Finance, Console
55
license: GPL-3

src/Hledger/Flow/CSVImport.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ importCSVs' opts ch = do
4747
do
4848
channelOutLn ch $ format ("Found "%d%" input files in "%s%". Proceeding with import...") fileCount (repr diff)
4949
let actions = map (extractAndImport opts ch) inputFiles :: [IO FilePath]
50-
importedJournals <- if (sequential opts) then sequence actions else single . shellToList $ parallel actions
50+
importedJournals <- parAwareActions opts actions
5151
sh $ writeIncludesUpTo opts ch "import" importedJournals
5252
return importedJournals
5353

src/Hledger/Flow/Common.hs

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ versionInfo :: NE.NonEmpty Line
3535
versionInfo = textToLines versionInfo'
3636

3737
versionInfo' :: Text
38-
versionInfo' = T.pack ("hledger-flow " ++ Version.showVersion version)
38+
versionInfo' = T.pack ("hledger-flow " ++ Version.showVersion version ++ " " ++
39+
os systemInfo ++ " " ++ arch systemInfo ++ " " ++
40+
compilerName systemInfo ++ " " ++
41+
Version.showVersion (compilerVersion systemInfo))
3942

4043
systemInfo :: SystemInfo
4144
systemInfo = SystemInfo { os = Sys.os
@@ -181,6 +184,11 @@ procWithEmptyOutput cmd args stdinput = do
181184
parAwareProc :: HasSequential o => o -> ProcFun
182185
parAwareProc opts = if (sequential opts) then procWithEmptyOutput else procStrictWithErr
183186

187+
parAwareActions :: HasSequential o => o -> [IO a] -> IO [a]
188+
parAwareActions opts = parAwareFun opts
189+
where
190+
parAwareFun op = if (sequential op) then sequence else single . shellToList . parallel
191+
184192
inprocWithErrFun :: (Text -> IO ()) -> ProcInput -> Shell Line
185193
inprocWithErrFun errFun (cmd, args, standardInput) = do
186194
result <- inprocWithErr cmd args standardInput

src/Hledger/Flow/Reports.hs

+27-12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import qualified Data.Text as T
1515
import qualified Hledger.Flow.Types as FlowTypes
1616
import qualified Data.List as List
1717

18+
data ReportParams = ReportParams { ledgerFile :: FilePath
19+
, reportYears :: [Integer]
20+
, outputDir :: FilePath
21+
}
22+
deriving (Show)
23+
1824
generateReports :: ReportOptions -> IO ()
1925
generateReports opts = sh (
2026
do
@@ -38,15 +44,16 @@ generateReports' opts ch = do
3844
channelOutLn ch wipMsg
3945
owners <- single $ shellToList $ listOwners opts
4046
let baseJournal = journalFile opts []
41-
let baseReportDir = outputDir opts ["all"]
42-
years <- includeYears ch baseJournal
43-
let baseParams = if length owners > 1 then [(baseJournal, baseReportDir)] else []
44-
let reportParams = baseParams ++ map (ownerParams opts) owners
45-
let actions = List.concat $ fmap (generateReports'' opts ch years) reportParams
46-
if (sequential opts) then sequence actions else single $ shellToList $ parallel actions
47+
let baseReportDir = outputReportDir opts ["all"]
48+
baseYears <- includeYears ch baseJournal
49+
let baseParams = if length owners > 1 then [(ReportParams baseJournal baseYears baseReportDir)] else []
50+
ownerParams <- ownerParameters opts ch owners
51+
let reportParams = baseParams ++ ownerParams
52+
let actions = List.concat $ fmap (generateReports'' opts ch) reportParams
53+
parAwareActions opts actions
4754

48-
generateReports'' :: ReportOptions -> TChan FlowTypes.LogMessage -> [Integer] -> (FilePath, FilePath) -> [IO (Either FilePath FilePath)]
49-
generateReports'' opts ch years (journal, reportsDir) = do
55+
generateReports'' :: ReportOptions -> TChan FlowTypes.LogMessage -> ReportParams -> [IO (Either FilePath FilePath)]
56+
generateReports'' opts ch (ReportParams journal years reportsDir) = do
5057
y <- years
5158
let actions = map (\r -> r opts ch journal reportsDir y) [accountList, incomeStatement]
5259
map (fmap fst) actions
@@ -87,8 +94,16 @@ generateReport opts ch journal baseOutDir year fileName args = do
8794
journalFile :: ReportOptions -> [FilePath] -> FilePath
8895
journalFile opts dirs = (foldl (</>) (baseDir opts) dirs) </> "all-years" <.> "journal"
8996

90-
outputDir :: ReportOptions -> [FilePath] -> FilePath
91-
outputDir opts dirs = foldl (</>) (baseDir opts) ("reports":dirs)
97+
outputReportDir :: ReportOptions -> [FilePath] -> FilePath
98+
outputReportDir opts dirs = foldl (</>) (baseDir opts) ("reports":dirs)
99+
100+
ownerParameters :: ReportOptions -> TChan FlowTypes.LogMessage -> [FilePath] -> IO [ReportParams]
101+
ownerParameters opts ch owners = do
102+
let actions = map (ownerParameters' opts ch) owners
103+
parAwareActions opts actions
92104

93-
ownerParams :: ReportOptions -> FilePath -> (FilePath, FilePath)
94-
ownerParams opts owner = (journalFile opts ["import", owner], outputDir opts [owner])
105+
ownerParameters' :: ReportOptions -> TChan FlowTypes.LogMessage -> FilePath -> IO ReportParams
106+
ownerParameters' opts ch owner = do
107+
let ownerJournal = journalFile opts ["import", owner]
108+
years <- includeYears ch ownerJournal
109+
return $ ReportParams ownerJournal years (outputReportDir opts [owner])

stack.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919
# resolver: ./custom-snapshot.yaml
2020
# resolver: https://example.com/snapshots/2018-01-01.yaml
21-
resolver: lts-13.20
21+
resolver: nightly-2019-05-16
2222

2323
# User packages to be built.
2424
# Various formats can be used as shown in the example below.

0 commit comments

Comments
 (0)