This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 664
/
calc_algo.d2
150 lines (123 loc) · 3.31 KB
/
calc_algo.d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
cTrnDao: CalcTrnDao {
q: Query {
ByTime
ByCategory
ByAccount
ByPurpose
}
sql: "SQL: O(trns.count) time | O(trns.notDel.count) space" {
"SELECT amount, currency, type FROM transactions WHERE ..."
}
trns: "List<CalcTrn>" {
CalcTrn {
shape: class
amount: Double
currency: String
type: TransactionType
}
}
q -> sql -> trns
}
rawStatsFlow: RawStatsFlow {
in: Input {
shape: class
trns: List<CalcTrn>
}
p: "Process: O(trns.count) time | O(currs.unique.count) space" {
"trns.forEach { aggregate incomes, expense by currencies + count them }"
}
out: RawStats {
shape: class
incomes: Map<CurrencyCode, Double>
expenses: Map<CurrencyCode, Double>
incomesCount: Int
expensesCount: Int
}
in -> p -> out
}
cTrndao.trns -> rawStatsFlow.in.trns
# RatesFlow
ratesDao: RatesDao {
sql: "SQL: O(rates.count) time | O(rates.baseCurr.count) space" {
"SELECT rate, currency FROM exchange_rates WHERE baseCurrency = ?"
}
out: "List<Rate>" {
Rate {
shape: class
rate: Double
currency: String
}
}
sql -> out
}
ratesOverrideDao: RateOverrideDao {
sql: "SQL: O(rates.override.count) time | O(rates.override.baseCurr.count) space" {
"SELECT rate, currency FROM exchange_rates_override WHERE baseCurrency = ? AND sync != $DELETING"
}
out: "List<Rate>" {
Rate {
shape: class
rate: Double
currency: String
}
}
sql -> out
}
ratesFlow: RatesFlow {
deps: Dependencies {
ratesDao
ratesOverrideDao
baseCurrencyFlow
}
p: "Process: O(rates.override.count) time | O(1) space" {
1: "baseCurrency.flatMapLatest {}"
2: "combine(rateDao.findByBaseCurr(), ratesOverridedao.findByBaseCurr())"
3: "Override rate with the manual set ones"
1 -> 2 -> 3
}
out: "RatesData" {
shape: class
baseCurrency: String
rates: Map<CurrencyCode, Double>
}
deps.ratesDao -> p: Reacts
deps.ratesOverrideDao -> p: Reacts
deps.baseCurrencyFlow -> p: Reacts
p -> out
}
ratesDao -> ratesFlow.deps
ratesOverrideDao -> ratesFlow.deps
# ExchangeStatsFlow
exFlow: ExchangeStatsFlow {
deps: Dependencies {
ratesFlow: "rates: RatesFlow"
}
in: Input {
shape: class
rawStats: RawStats
outputCurrency: String
}
p: "Process: O(curr.unique.count) space-time" {
incs_loop: "rawStats.incomes.forEach {}"
incs_exchange: "exchange to output currency"
incs_sum: "sum & count"
incs_loop -> incs_exchange -> incs_sum
exps_loop: "rawStats.expenses.forEach {}"
exps_exchange: "exchange to output currency"
exps_sum: "sum & count"
exps_loop -> exps_exchange -> exps_sum
}
out: Stats {
shape: class
income: Value
expense: Value
incomesCount: Int
expensesCount: Int
}
deps.ratesFlow -> p: Reacts to rates changes
in.rawStats -> p
p.incs_sum -> out
p.exps_sum -> out
}
ratesFlow.out -> exFlow.deps.ratesFlow: Reacts
rawStatsFlow.out -> exFlow.in.rawStats