openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

added Yearly Reading Goals to /stats page

Open kevinc16 opened this issue 9 months ago • 0 comments

Closes #7352

Added summary and total_yearly_reading_goals functions to bookshelves_events.py. Added unit test for total_yearly_reading_goals function. Added Yearly Reading Goals row in openlibrary/templates/admin/index.html.

Let me know if there are things we want to change!

Technical

There are a few things to note:

  1. First, during testing, I found that for some reason the key in the storage object (noted by @scottbarnes in https://github.com/internetarchive/openlibrary/pull/7560#discussion_r1153914826, Scott is also right that the other functions are documented incorrectly - they return Storage objects not ints) in the unit test is different from when the application is run (that is the reason in the HTML file the key is 'count' while in the unit test it is 'count(*)')

Application log:

web-1           | total_yearly_reading_goals (<Storage {'count': 1}>,)
web-1           | total_yearly_reading_goals (<Storage {'count': 1}>,)
web-1           | total_yearly_reading_goals (<Storage {'count': 1}>,)

But when I use the key 'count' in the unit tests:

====================================================================================== FAILURES ======================================================================================
_______________________________________________________________ TestYearlyReadingGoals.test_total_yearly_reading_goals _______________________________________________________________
self = <core.test_db.TestYearlyReadingGoals object at 0x7f8426bf9dc0>

    def test_total_yearly_reading_goals(self):
>       assert BookshelvesEvents.total_yearly_reading_goals()['count'] == 3
E       KeyError: 'count'

openlibrary/tests/core/test_db.py:523: KeyError
-------------------------------------------------------------------------------- Captured stdout call --------------------------------------------------------------------------------
total_yearly_reading_goals (<Storage {'count(*)': 3}>,)
  1. The second is that I noticed the other stat functions (e.g., total_books_logged in openlibrary/core/bookshelves.py) don't have unit tests - is there a specific reason for that?

Testing

UI changes and docker compose run --rm home make test.

Screenshot

1

Stakeholders

@jimchamp

kevinc16 avatar May 20 '24 02:05 kevinc16