Skip to content

Commit

Permalink
Follow stat (#9368)
Browse files Browse the repository at this point in the history
* Added Followers count to /stats
* Updates .pot
---------
Co-authored-by: anrawool <anrawool@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Spedi authored Jun 3, 2024
1 parent c0daab0 commit de61a01
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 43 deletions.
20 changes: 20 additions & 0 deletions openlibrary/core/follows.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from typing import cast
from openlibrary.core.bookshelves import Bookshelves
from openlibrary.utils.dateutil import DATE_ONE_MONTH_AGO, DATE_ONE_WEEK_AGO

from . import db

Expand Down Expand Up @@ -130,6 +131,25 @@ def count_followers(cls, publisher):
)
return cast(tuple[int], count)[0].get('count', 0)

@classmethod
def total_followers(cls, since=None) -> int:
oldb = db.get_db()
query = f"SELECT count(DISTINCT subscriber) from {cls.TABLENAME}"
if since:
query += " WHERE created >= $since"
results = oldb.query(query, vars={'since': since})
return results[0]['count'] if results else 0

@classmethod
def summary(cls):
return {
"total_following_count": {
"total": cls.total_followers(),
"month": cls.total_followers(since=DATE_ONE_MONTH_AGO),
"week": cls.total_followers(since=DATE_ONE_WEEK_AGO),
}
}

@classmethod
def count_total_subscribers(cls):
oldb = db.get_db()
Expand Down
88 changes: 46 additions & 42 deletions openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -839,47 +839,6 @@ msgstr[1] ""
msgid "BARF! Search engine ERROR!"
msgstr ""

#: work_search.html
msgid "Zoom In"
msgstr ""

#: work_search.html
msgid "Focus your results using these <a href=\"/search/howto\">filters</a>"
msgstr ""

#: work_search.html
msgid "Merge duplicate authors from this search"
msgstr ""

#: type/work/editions.html work_search.html
msgid "Merge duplicates"
msgstr ""

#: work_search.html
msgid "yes"
msgstr ""

#: work_search.html
msgid "no"
msgstr ""

#: work_search.html
msgid "Filter results for ebook availability"
msgstr ""

#: work_search.html
#, python-format
msgid "Filter results for %(facet)s"
msgstr ""

#: work_search.html
msgid "more"
msgstr ""

#: work_search.html
msgid "less"
msgstr ""

#: about/index.html
msgid "The Open Library Team"
msgstr ""
Expand Down Expand Up @@ -1887,6 +1846,10 @@ msgstr ""
msgid "Users Reviewing"
msgstr ""

#: admin/index.html
msgid "Patrons Following"
msgstr ""

#: admin/index.html
msgid "Notes Created"
msgstr ""
Expand Down Expand Up @@ -2600,7 +2563,7 @@ msgstr ""
msgid "Not in Library"
msgstr ""

#: books/custom_carousel.html
#: books/custom_carousel.html search/work_search_facets.html
msgid "Loading..."
msgstr ""

Expand Down Expand Up @@ -5096,6 +5059,47 @@ msgstr ""
msgid "work"
msgstr ""

#: search/work_search_facets.html
msgid "Merge duplicate authors from this search"
msgstr ""

#: search/work_search_facets.html type/work/editions.html
msgid "Merge duplicates"
msgstr ""

#: search/work_search_facets.html
msgid "more"
msgstr ""

#: search/work_search_facets.html
msgid "less"
msgstr ""

#: search/work_search_facets.html
#, python-format
msgid "Filter results for %(facet)s"
msgstr ""

#: search/work_search_facets.html
msgid "Filter results for ebook availability"
msgstr ""

#: search/work_search_facets.html
msgid "yes"
msgstr ""

#: search/work_search_facets.html
msgid "no"
msgstr ""

#: search/work_search_facets.html
msgid "Zoom In"
msgstr ""

#: search/work_search_facets.html
msgid "Focus your results using these <a href=\"/search/howto\">filters</a>"
msgstr ""

#: site/around_the_library.html
msgid "View all recent changes"
msgstr ""
Expand Down
8 changes: 7 additions & 1 deletion openlibrary/templates/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,13 @@ <h2>$_("Members")</h2>
<td></td>
<td class="amount">$commify(counts.reading_log['total_reviewers']['total'])</td>
</tr>

<tr class="major even">
<td>$_("Patrons Following")</td>
<td class="amount">$commify(counts.reading_log['total_following_count']['week'])</td>
<td class="amount">$commify(counts.reading_log['total_following_count']['month'])</td>
<td></td>
<td class="amount">$commify(counts.reading_log['total_following_count']['total'])</td>
</tr>
<tr class="major">
<td>$_("Notes Created")</td>
<td class="amount">$commify(counts.reading_log['total_notes_created']['week'])</td>
Expand Down
2 changes: 2 additions & 0 deletions openlibrary/views/loanstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ..core import cache
from ..core.observations import Observations
from ..core.booknotes import Booknotes
from ..core.follows import PubSub
from ..core.bookshelves import Bookshelves
from ..core.ratings import Ratings
from ..plugins.admin.code import get_counts
Expand Down Expand Up @@ -38,6 +39,7 @@ def reading_log_summary():
stats.update(Ratings.summary())
stats.update(Observations.summary())
stats.update(Booknotes.summary())
stats.update(PubSub.summary())
return stats


Expand Down

0 comments on commit de61a01

Please sign in to comment.