1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-04 21:15:19 +02:00

Add the ability to "rollup" values in a time series (#554)

* Clean up time series models

* Add value group rollup class for summarizing hierarchical data

* Integrate new classes

* Update UI to use new patterns

* Update D3 charts to expect new data format

* Clean up account model

* More cleanup

* Money improvements

* Use new money fields

* Remove invalid fixture data to avoid orphaned accountables

* Update time series to work better with collections

* Fix tests and UI bugs
This commit is contained in:
Zach Gollwitzer 2024-03-19 09:10:40 -04:00 committed by GitHub
parent 0a8518506c
commit f904d9d062
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 687 additions and 391 deletions

View file

@ -23,10 +23,12 @@ class Family < ApplicationRecord
query = query.where("account_balances.date BETWEEN ? AND ?", period.date_range.begin, period.date_range.end) if period.date_range
result = query.to_a
{
asset_series: MoneySeries.new(query, { trend_type: :asset, amount_accessor: "assets" }),
liability_series: MoneySeries.new(query, { trend_type: :liability, amount_accessor: "liabilities" }),
net_worth_series: MoneySeries.new(query, { trend_type: :asset, amount_accessor: "net_worth" })
asset_series: TimeSeries.new(result.map { |r| { date: r.date, value: Money.new(r.assets, r.currency) } }),
liability_series: TimeSeries.new(result.map { |r| { date: r.date, value: Money.new(r.liabilities, r.currency) } }),
net_worth_series: TimeSeries.new(result.map { |r| { date: r.date, value: Money.new(r.net_worth, r.currency) } })
}
end
@ -35,7 +37,7 @@ class Family < ApplicationRecord
end
def net_worth
accounts.active.sum("CASE WHEN classification = 'asset' THEN balance ELSE -balance END")
Money.new(accounts.active.sum("CASE WHEN classification = 'asset' THEN balance ELSE -balance END"), currency)
end
def assets
@ -43,6 +45,6 @@ class Family < ApplicationRecord
end
def liabilities
accounts.active.liabilities.sum(:balance)
Money.new(accounts.active.liabilities.sum(:balance), currency)
end
end