all repos

clerk @ 1f3a17349e37c8189adb11b8d956acbf3b2080d1

missing tooling for ledger/hledger

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

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
improve analyzer, 1 day 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
	TagNames []string // unique, from tag directives
28
29
	Dates       []ast.Date // unique transaction dats in sorted order
30
	DateStrings []string   // same order as Dates, "YYYY-MM-DD"
31
32
	// CommodityDecimalMarks decimal mark per commodity, detected from D/amounts.
33
	CommodityDecimalMarks map[string]byte
34
35
	// TransactionsByKey groups transactions by [TxDuplicateKey] signature.
36
	TransactionsByKey map[string][]*ast.Transaction
37
}
38
39
type AccountInfo struct {
40
	Directives []*ast.AccountDirective
41
	Usages     []AccountUsage
42
	UsedCount  int
43
	LastUsed   ast.Date
44
}
45
46
type AccountUsage struct {
47
	FileIndex int
48
	Posting   *ast.Posting
49
}
50
51
type CommodityInfo struct {
52
	Directives []*ast.CommodityDirective
53
	Usages     []CommodityUsage
54
	UsedCount  int
55
	LastUsed   ast.Date
56
}
57
58
type CommodityUsage struct {
59
	FileIndex int
60
	Amount    *ast.Amount
61
}
62
63
type PayeeInfo struct {
64
	Directives []*ast.Payee
65
	Usage      []PayeeUsage
66
	UsedCount  int
67
	LastUsed   ast.Date
68
}
69
70
type PayeeUsage struct {
71
	FileIndex int
72
	Payee     *ast.Payee
73
}
74
75
type PostingTemplate struct {
76
	Account    string
77
	Amount     string
78
	Commodity  string
79
	IsInferred bool // true if the amount was inferred (auto-balanced)
80
}