-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(accumulative balance chart): Add accumulative balance chart for account #33
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VladislavSokov
changed the title
feat(accumulative balance chart): Add accumulative balance chart for …
feat(accumulative balance chart): Add accumulative balance chart for account
Aug 28, 2023
ka8725
reviewed
Aug 28, 2023
@@ -31,4 +31,8 @@ class Account < ApplicationRecord | |||
def transactions | |||
Transaction.where(to_account: self).or(Transaction.where(from_account: self)) | |||
end | |||
|
|||
def accumulative_balance_data | |||
transactions.group_by_day(:created_at).sum(:amount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VladislavSokov it doesn't produce accumulative balance:
- Sum by date does sum only for the date and nothing more, it doesn't "remember" the sum of the previous date. But the task is supposed to produce the accumulative sum
- Seems the gem won't help here
Here is the SQL that produces correct result:
with trs as (select id, created_at::date as date, case when to_account_id = 1 then amount else -amount end as amount from transactions where to_account_id = 1 or from_account_id = 1 order by created_at::date) select date, sum(amount) over (order by date) from trs order by date;
This is the result I got on my account:
date | sum
------------+---------
2021-10-22 | 135.00
2021-10-22 | 135.00
2021-10-22 | 135.00
2021-10-22 | 135.00
2021-10-24 | 100.00
2021-10-29 | 110.00
2021-10-29 | 110.00
2021-11-05 | 134.00
2021-11-05 | 134.00
2021-11-06 | 90.00
2021-11-12 | 125.00
2021-11-19 | 160.00
2021-11-20 | -25.00
2021-11-26 | 10.00
2021-12-03 | 45.00
2021-12-04 | 0.00
2021-12-10 | 35.00
2021-12-17 | 70.00
2021-12-24 | 105.00
2021-12-31 | 140.00
2022-01-07 | 175.00
2022-01-08 | 70.00
2022-01-14 | 105.00
2022-01-15 | 25.00
2022-01-21 | 60.00
2022-01-24 | 65.00
2022-01-28 | 100.00
2022-02-04 | 135.00
2022-02-06 | 105.00
2022-02-09 | 95.00
2022-02-10 | 105.00
2022-02-11 | 140.00
2022-02-18 | 175.00
2022-02-22 | 160.00
2022-02-25 | 120.00
2022-02-25 | 120.00
2022-02-25 | 120.00
2022-03-01 | 0.00
2022-03-04 | 35.00
2022-03-11 | 70.00
2022-03-18 | 105.00
2022-03-19 | 55.00
2022-03-20 | 50.00
2022-03-25 | 85.00
2022-03-29 | 15.00
2022-04-01 | 50.00
2022-04-04 | 5.00
2022-04-06 | 0.50
2022-04-08 | 35.50
2022-04-12 | 15.50
2022-04-12 | 15.50
2022-04-15 | 35.50
2022-04-15 | 35.50
2022-04-22 | -4.50
2022-04-22 | -4.50
2022-04-29 | 30.50
2022-05-06 | 40.50
2022-05-06 | 40.50
2022-05-12 | 15.50
2022-05-13 | 25.50
2022-05-13 | 25.50
2022-05-17 | 0.50
2022-05-20 | 5.50
2022-05-20 | 5.50
2022-05-27 | 40.50
2022-05-29 | 40.70
2022-06-03 | 75.70
2022-06-10 | 110.70
2022-06-15 | 160.70
2022-06-17 | 195.70
2022-06-18 | 19.05
2022-06-19 | -5.00
2022-06-19 | -5.00
2022-06-19 | -5.00
2022-06-20 | -15.00
2022-06-20 | -15.00
2022-06-24 | 20.00
2022-06-26 | 6.00
2022-07-01 | 41.00
2022-07-04 | 16.00
2022-07-08 | 51.00
2022-07-09 | 21.00
2022-07-15 | 31.00
2022-07-15 | 31.00
2022-07-16 | 6.00
2022-07-18 | 16.00
2022-07-19 | 26.00
2022-07-20 | 22.00
2022-07-20 | 22.00
2022-07-22 | 62.00
2022-07-22 | 62.00
2022-07-23 | 12.00
2022-07-26 | 14.00
2022-07-29 | 49.00
2022-07-30 | -4.00
2022-07-30 | -4.00
2022-08-05 | -4.00
2022-08-05 | -4.00
2022-08-10 | 1.00
2022-08-12 | -4.00
2022-08-12 | -4.00
2022-08-15 | 6.00
2022-08-19 | 41.00
2022-08-22 | 6.00
2022-08-24 | -4.00
2022-08-24 | -4.00
2022-08-26 | 23.00
2022-08-26 | 23.00
2022-08-26 | 23.00
2022-09-02 | 63.00
2022-09-02 | 63.00
2022-09-08 | 38.00
2022-09-09 | 73.00
2022-09-14 | 78.00
2022-09-16 | 113.00
2022-09-23 | 63.00
2022-09-23 | 63.00
2022-09-23 | 63.00
2022-09-30 | 98.00
2022-10-07 | 133.00
2022-10-14 | 168.00
2022-10-21 | 203.00
2022-10-28 | 98.00
2022-10-28 | 98.00
2022-11-01 | 62.00
2022-11-02 | 2.00
2022-11-03 | 6.00
2022-11-03 | 6.00
2022-11-03 | 6.00
2022-11-04 | 41.00
2022-11-05 | 11.00
2022-11-11 | 46.00
2022-11-18 | 18.00
2022-11-18 | 18.00
2022-11-25 | 53.00
2022-11-26 | 10.00
2022-12-02 | 45.00
2022-12-03 | 0.00
2022-12-09 | 35.00
2022-12-16 | 70.00
2022-12-18 | -105.00
2022-12-18 | -105.00
2022-12-20 | 35.00
2022-12-23 | 53.00
2022-12-23 | 53.00
2022-12-30 | 88.00
2023-01-06 | 123.00
2023-01-07 | -27.00
2023-01-13 | 8.00
2023-01-20 | 43.00
2023-01-21 | 53.00
2023-01-27 | 88.00
2023-02-03 | 123.00
2023-02-10 | 158.00
2023-02-17 | 193.00
2023-02-19 | 103.00
2023-02-24 | 138.00
2023-02-25 | -12.00
2023-02-25 | -12.00
2023-02-25 | -12.00
2023-03-01 | -17.00
2023-03-03 | 18.00
2023-03-07 | 30.00
2023-03-10 | 15.00
2023-03-10 | 15.00
2023-03-17 | 50.00
2023-03-18 | 0.00
2023-03-24 | 35.00
2023-03-31 | 35.00
2023-03-31 | 35.00
2023-04-07 | 70.00
2023-04-11 | -7.00
2023-04-14 | 28.00
2023-04-21 | 44.00
2023-04-21 | 44.00
2023-04-24 | 5.00
2023-04-25 | -135.00
2023-04-28 | -100.00
2023-05-05 | -65.00
2023-05-12 | -30.00
2023-05-19 | 5.00
2023-05-26 | 40.00
2023-05-29 | 10.00
2023-06-11 | 80.00
2023-06-16 | 115.00
2023-06-23 | 150.00
2023-06-27 | 20.00
2023-06-30 | 55.00
2023-07-07 | 90.00
2023-07-14 | 125.00
2023-07-15 | 15.00
2023-07-21 | 50.00
2023-07-25 | 0.00
2023-07-28 | 35.00
2023-08-02 | 0.00
2023-08-04 | 35.00
2023-08-10 | 16.00
2023-08-11 | 51.00
2023-08-15 | 16.00
2023-08-17 | -9.00
2023-08-18 | 26.00
2023-08-25 | 61.00
(202 rows)
This is not even close to what the current implementation does:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.