all repos

clerk @ cddf442e7f66ba3c73d9f4f9bcb13693d28aa6b1

missing tooling for ledger/hledger

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

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
journal: tags support, 2 months 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
	AccountNames     []string            // sorted for binary search
21
	PayeeNames       []string            // sorted, all payee names from directives + usage
22
	AccountsByPrefix map[string][]string // "expenses:" -> ["expenses:food", "expenses:taxi"]
23
24
	// PayeeTemplates holds the last transaction's postings per payee name.
25
	PayeeTemplates map[string][]PostingTemplate
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 dats in sorted order
32
	DateStrings []string   // same order as Dates, "YYYY-MM-DD"
33
34
	// CommodityDecimalMarks decimal mark per commodity, detected from D/amounts.
35
	CommodityDecimalMarks map[string]byte
36
37
	// TransactionsByKey groups transactions by [TxDuplicateKey] signature.
38
	TransactionsByKey map[string][]*ast.Transaction
39
}
40
41
type AccountInfo struct {
42
	Directives []*ast.AccountDirective
43
	Usages     []AccountUsage
44
	UsedCount  int
45
	LastUsed   ast.Date
46
}
47
48
type AccountUsage struct {
49
	FileIndex int
50
	Posting   *ast.Posting
51
}
52
53
type CommodityInfo struct {
54
	Directives []*ast.CommodityDirective
55
	Usages     []CommodityUsage
56
	UsedCount  int
57
	LastUsed   ast.Date
58
}
59
60
type CommodityUsage struct {
61
	FileIndex int
62
	Amount    *ast.Amount
63
}
64
65
type PayeeInfo struct {
66
	Directives []*ast.Payee
67
	Usage      []PayeeUsage
68
	UsedCount  int
69
	LastUsed   ast.Date
70
}
71
72
type PayeeUsage struct {
73
	FileIndex int
74
	Payee     *ast.Payee
75
}
76
77
type TagInfo struct {
78
	Directives []*ast.TagDirective
79
	Usage      []TagUsage
80
	UsedCount  int
81
	LastUsed   ast.Date
82
	Values     []string // unique non-empty values from comment usages, sorted
83
}
84
85
type TagUsage struct {
86
	FileIndex int
87
	Tag       *ast.Tag
88
}
89
90
type PostingTemplate struct {
91
	Account    string
92
	Amount     string
93
	Commodity  string
94
	IsInferred bool // true if the amount was inferred (auto-balanced)
95
}