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

Add income and spending insight cards to dashboard (#668)

* Generate time series for rolling 30 day sum of income and spending

* Highlight accounts with most income and spending in the last 30 days

* Aggregate chips after 3 top accounts in insight card

* Refactor aggregation filter

I think this is easier to read and understand whats happening at a
glance

* Refactor and tidy

* Use family currency for insight cards

* Further reduce risk of sql injection

* Fix lint

* Refactor rolling total queries

* Add test for transaction snapshot
This commit is contained in:
Josh Brown 2024-04-24 13:34:50 +01:00 committed by GitHub
parent 1f6e83ee91
commit 461fa672ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 207 additions and 64 deletions

View file

@ -16,7 +16,9 @@ class FamilyTest < ActiveSupport::TestCase
"date" => (Date.current + row["date_offset"].to_i.days).to_date,
"net_worth" => row["net_worth"],
"assets" => row["assets"],
"liabilities" => row["liabilities"]
"liabilities" => row["liabilities"],
"rolling_spend" => row["rolling_spend"],
"rolling_income" => row["rolling_income"]
}
end
end
@ -83,6 +85,22 @@ class FamilyTest < ActiveSupport::TestCase
end
end
test "should calculate transaction snapshot correctly" do
spending_series = @family.snapshot_transactions[:spending_series]
income_series = @family.snapshot_transactions[:income_series]
assert_equal @expected_snapshots.count, spending_series.values.count
assert_equal @expected_snapshots.count, income_series.values.count
@expected_snapshots.each_with_index do |row, index|
expected_spending = TimeSeries::Value.new(date: row["date"], value: Money.new(row["rolling_spend"].to_d))
expected_income = TimeSeries::Value.new(date: row["date"], value: Money.new(row["rolling_income"].to_d))
assert_in_delta expected_spending.value.amount, Money.new(spending_series.values[index].value).amount, 0.01
assert_in_delta expected_income.value.amount, Money.new(income_series.values[index].value).amount, 0.01
end
end
test "should exclude disabled accounts from calculations" do
assets_before = @family.assets
liabilities_before = @family.liabilities