Skip to content
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

Display monthly statistics for the range of months where the project was active #885

Merged
merged 2 commits into from Jan 18, 2022

Conversation

zorun
Copy link
Collaborator

@zorun zorun commented Oct 20, 2021

Currently, we display a hard-coded "one year" range of monthly statistics
starting from today. This generally is not the intended behaviour: for
instance, on an archived project, the bills might all be older than one
year, so the table only displays months without any operation.

Instead, display all months between the first and last bills. There might
be empty months in the middle, but that's intended, because we want all
months to be consecutive.

If there are no bills, simply display an empty table.

@almet
Copy link
Member

almet commented Oct 20, 2021

I'm not sure : should we get a test for this?

@zorun
Copy link
Collaborator Author

zorun commented Oct 21, 2021

Hmm, yes, it could be useful

ihatemoney/models.py Outdated Show resolved Hide resolved
ihatemoney/web.py Outdated Show resolved Hide resolved
ihatemoney/web.py Outdated Show resolved Hide resolved
ihatemoney/web.py Outdated Show resolved Hide resolved
@almet
Copy link
Member

almet commented Nov 21, 2021

Hey @zorun, here's a gentle ping on this so we can merge it before it rots (if you have the time, of course!).

@zorun
Copy link
Collaborator Author

zorun commented Nov 21, 2021

I don't have time to add tests for this anytime soon. You decide if it can be merged without tests or not :)

@almet
Copy link
Member

almet commented Nov 28, 2021

Rebased.

@zorun
Copy link
Collaborator Author

zorun commented Dec 9, 2021

I'm currently adding a test, and it is catching a corner case I had overlooked, so it was definitely a good suggestion, thanks @almet 👍

@zorun zorun changed the title Display monthly statistics for the range of months where the project … Display monthly statistics for the range of months where the project was active Dec 9, 2021
@zorun zorun force-pushed the fix_statistics_by_month branch 2 times, most recently from b5d5f7a to 6c2cb73 Compare December 9, 2021 21:52
@zorun
Copy link
Collaborator Author

zorun commented Dec 9, 2021

@almet I took into account your remarks, fixed the corner cases, and added a test. A second quick review would be appreciated, thanks!

Copy link
Member

@almet almet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, here's a quick review. Overall, I think we're good and I'm okay merging it as-is. That being said, if you want to polish things a bit more I've left a few comments. Don't hesitate to ignore them if you feel I'm too picky.

ihatemoney/models.py Show resolved Hide resolved
ihatemoney/tests/budget_test.py Outdated Show resolved Hide resolved
months_fmt = [
r"<tr>\s*<td>{}</td>\s*<td>{}</td>\s*</tr>".format(month, amount)
for month, amount in months
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I find it kinda weird to check the output of the HTML like this, because it means that if we change the format of the table we also need to change the tests, even though we're not changing the actual behavior of the code.

I wonder if we might instead create a model function, and test that it works properly with python-related tests (more unit tests than functional tests, though). We might also want to have this information on the /api endpoint.

What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must admit that I'm not completely happy with this regexp magic ;) and when the test fails, it's really hard to know why, you just get a big blob of HTML soup and you have to figure out what's wrong in it.

I hadn't thought of testing the function itself, but now that you mention it, it's obviously a good idea... I guess I just continued what the existing test was doing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As explained below, I just implement this new testing approach!

For the API, I'm not sure. The client could just request the list of bills and compute any statistics itself.

Baptiste Jonglez added 2 commits January 14, 2022 22:10
This makes it easier to use datetime.date later.
…was active

Currently, we display a hard-coded "one year" range of monthly statistics
starting from today.  This generally is not the intended behaviour: for
instance, on an archived project, the bills might all be older than one
year, so the table only displays months without any operation.

Instead, display all months between the first and last bills.  There might
be empty months in the middle, but that's intended, because we want all
months to be consecutive.

If there are no bills, simply display an empty table.
@zorun
Copy link
Collaborator Author

zorun commented Jan 14, 2022

I have changed the approach a bit:

  • move the logic (that computes active months) as a method in the model, because it makes it easier to test
  • change the tests to use that new method instead of checking the HTML output
  • I am still checking the HTML table once (the empty one) to make sure it's displayed

@almet I guess another review is in order :)

@almet
Copy link
Member

almet commented Jan 18, 2022

It's far better this way, thanks!

@almet almet merged commit c8cbe43 into spiral-project:master Jan 18, 2022
TomRoussel pushed a commit to TomRoussel/ihatemoney that referenced this pull request Mar 2, 2024
…was active (spiral-project#885)

* Change the way we import datetime

This makes it easier to use datetime.date later.

* Display monthly statistics for the range of months where the project was active

Currently, we display a hard-coded "one year" range of monthly statistics
starting from today.  This generally is not the intended behaviour: for
instance, on an archived project, the bills might all be older than one
year, so the table only displays months without any operation.

Instead, display all months between the first and last bills.  There might
be empty months in the middle, but that's intended, because we want all
months to be consecutive.

If there are no bills, simply display an empty table.

Co-authored-by: Baptiste Jonglez <git@bitsofnetworks.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants