all repos

clerk @ 5e60b81

missing tooling for ledger/hledger

clerk/internal/analyzer/analyzer.go (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
analyzer: build payee templates lazily, 1 month ago
1
package analyzer
2
3
import (
4
	"olexsmir.xyz/clerk/journal"
5
	"olexsmir.xyz/clerk/journal/ast"
6
)
7
8
type Analysis struct {
9
	Files []*journal.ParsedFile
10
11
	Transactions          []*ast.Transaction
12
	PeriodicTransactions  []*ast.PeriodicTransaction
13
	AutomatedTransactions []*ast.AutomatedTransaction
14
	Directives            []ast.Entry // account, commodity, payee, etc
15
16
	Accounts    map[string]*AccountInfo
17
	Commodities map[string]*CommodityInfo
18
	Payees      map[string]*PayeeInfo
19
20
	AccountAliases  map[string]string     // maps alias names to the account they resovle to
21
	AliasDirectives []*ast.AliasDirective // holds every top-level "alias A = B" directive in entry order
22
23
	AccountNames     []string            // sorted for binary search
24
	PayeeNames       []string            // sorted, all payee names from directives + usage
25
	AccountsByPrefix map[string][]string // "expenses:" -> ["expenses:food", "expenses:taxi"]
26
27
	Tags      map[string]*TagInfo
28
	TagNames  []string // unique tag names, sorted
29
	TagValues []string // unique non-empty tag values across all tags, sorted
30
31
	Dates       []ast.Date // unique transaction dates, sorted
32
	DateStrings []string   // same order as Dates, rendered as written
33
34
	TransactionsCountByDate map[string]int                // counts transactions per date, keyed by [Date.String]
35
	TransactionsByKey       map[string][]*ast.Transaction // groups transactions by [TxDuplicateKey] signature
36
}
37
38
type AccountInfo struct {
39
	Directives []*ast.AccountDirective
40
	Usages     []AccountUsage
41
	UsedCount  int
42
	LastUsed   ast.Date
43
}
44
45
type AccountUsage struct {
46
	FileIndex int
47
	Posting   *ast.Posting
48
}
49
50
type CommodityInfo struct {
51
	Directives []*ast.CommodityDirective
52
	Usages     []CommodityUsage
53
	UsedCount  int
54
	LastUsed   ast.Date
55
}
56
57
type CommodityUsage struct {
58
	FileIndex int
59
	Amount    *ast.Amount
60
}
61
62
type PayeeInfo struct {
63
	Directives []*ast.PayeeDirective
64
	Usage      []PayeeUsage
65
	UsedCount  int
66
	LastUsed   ast.Date
67
}
68
69
type PayeeUsage struct {
70
	FileIndex int
71
	Payee     *ast.Payee
72
}
73
74
type TagInfo struct {
75
	Directives []*ast.TagDirective
76
	Usage      []TagUsage
77
	UsedCount  int
78
	LastUsed   ast.Date
79
	Values     []string // unique non-empty values from comment usages, sorted
80
}
81
82
type TagUsage struct {
83
	FileIndex int
84
	Tag       *ast.Tag
85
}
86
87
type PostingTemplate struct {
88
	Account    string
89
	Amount     string
90
	Commodity  string
91
	IsInferred bool // true if the amount was inferred (auto-balanced)
92
}