clerk/internal/analyzer/analyzer.go (view raw)
| 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 | PayeeTemplates map[string][]PostingTemplate // holds the last transaction's postings per payee name |
| 26 | AccountsByPrefix map[string][]string // "expenses:" -> ["expenses:food", "expenses:taxi"] |
| 27 | |
| 28 | Tags map[string]*TagInfo |
| 29 | TagNames []string // unique tag names, sorted |
| 30 | TagValues []string // unique non-empty tag values across all tags, sorted |
| 31 | |
| 32 | Dates []ast.Date // unique transaction dates, sorted |
| 33 | DateStrings []string // same order as Dates, rendered as written |
| 34 | |
| 35 | TransactionsCountByDate map[string]int // counts transactions per date, keyed by [Date.String] |
| 36 | TransactionsByKey map[string][]*ast.Transaction // groups transactions by [TxDuplicateKey] signature |
| 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.PayeeDirective |
| 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 TagInfo struct { |
| 76 | Directives []*ast.TagDirective |
| 77 | Usage []TagUsage |
| 78 | UsedCount int |
| 79 | LastUsed ast.Date |
| 80 | Values []string // unique non-empty values from comment usages, sorted |
| 81 | } |
| 82 | |
| 83 | type TagUsage struct { |
| 84 | FileIndex int |
| 85 | Tag *ast.Tag |
| 86 | } |
| 87 | |
| 88 | type PostingTemplate struct { |
| 89 | Account string |
| 90 | Amount string |
| 91 | Commodity string |
| 92 | IsInferred bool // true if the amount was inferred (auto-balanced) |
| 93 | } |