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

Add Yearly Reading Goals to /stats #7352

Open
mekarpeles opened this issue Jan 1, 2023 · 8 comments · May be fixed by #9301
Open

Add Yearly Reading Goals to /stats #7352

mekarpeles opened this issue Jan 1, 2023 · 8 comments · May be fixed by #9301
Assignees
Labels
Lead: @jimchamp Issues overseen by Jim (Front-end Lead, BookNotes) [managed] Needs: Help Issues, typically substantial ones, that need a dedicated developer to take them on. [managed] Priority: 3 Issues that we can consider at our leisure. [managed] Theme: Analytics Regarding metrics, stats, and analytics Theme: Yearly Reading Goals Type: Feature Request Issue describes a feature or enhancement we'd like to implement. [managed]

Comments

@mekarpeles
Copy link
Member

mekarpeles commented Jan 1, 2023

Describe the problem that you'd like solved

Adding Yearly Reading Goals to /stats

select count(*) from yearly_reading_goals

See:

def get_admin_stats():
def f(dates):
keys = ["/admin/stats/" + date.isoformat() for date in dates]
docs = web.ctx.site.get_many(keys)
return g(docs)
def has_doc(date):
return bool(web.ctx.site.get('/admin/stats/' + date.isoformat()))
def g(docs):
return {
'edits': {
'human': sum(doc['edits']['human'] for doc in docs),
'bot': sum(doc['edits']['bot'] for doc in docs),
'total': sum(doc['edits']['total'] for doc in docs),
},
'members': sum(doc['members'] for doc in docs),
}
date = datetime.datetime.utcnow().date()
if has_doc(date):
today = f([date])
else:
today = g([stats().get_stats(date.isoformat())])
yesterday = f(daterange(date, -1, 0, 1))
thisweek = f(daterange(date, 0, -7, -1))
thismonth = f(daterange(date, 0, -30, -1))
xstats = {
'edits': {
'today': today['edits'],
'yesterday': yesterday['edits'],
'thisweek': thisweek['edits'],
'thismonth': thismonth['edits'],
},
'members': {
'today': today['members'],
'yesterday': yesterday['members'],
'thisweek': thisweek['members'],
'thismonth': thismonth['members'],
},
}
return storify(xstats)

class stats:
def GET(self, today):
json = web.ctx.site._conn.request(
web.ctx.site.name, '/get', 'GET', {'key': '/admin/stats/' + today}
)
return delegate.RawText(json)
def POST(self, today):
"""Update stats for today."""
doc = self.get_stats(today)
doc._save()
raise web.seeother(web.ctx.path)
def get_stats(self, today):
stats = web.ctx.site._request("/stats/" + today)
key = '/admin/stats/' + today
doc = web.ctx.site.new(key, {'key': key, 'type': {'key': '/type/object'}})
doc.edits = {
'human': stats.edits - stats.edits_by_bots,
'bot': stats.edits_by_bots,
'total': stats.edits,
}
doc.members = stats.new_accounts
return doc

class stats(app.view):
path = "/stats"
def GET(self):
counts = get_counts()
counts.reading_log = cached_reading_log_summary()
return app.render_template("admin/index", counts)

A function needs to be added to https://github.com/internetarchive/openlibrary/blob/3b1d509a8a9b4b5c22095664e169950a34cea8b6/openlibrary/core/bookshelves_events.py (Correction: https://github.com/internetarchive/openlibrary/blob/master/openlibrary/core/yearly_reading_goals.py) to allow for reading_log_counts similar to

@classmethod
def total_books_logged(
cls, shelf_ids: list[str] | None = None, since: date | None = None
) -> int:
"""Returns (int) number of books logged across all Reading Log shelves (e.g. those
specified in PRESET_BOOKSHELVES). One may alternatively specify a
`list` of `shelf_ids` to isolate or span multiple
shelves. `since` may be used to limit the result to those
books logged since a specific date. Any python datetime.date
type should work.
:param shelf_ids: one or more bookshelf_id values, see also the default values
specified in PRESET_BOOKSHELVES
:param since: returns all logged books after date
"""
oldb = db.get_db()
query = "SELECT count(*) from bookshelves_books"
if shelf_ids:
query += " WHERE bookshelf_id IN ($shelf_ids)"
if since:
query += " AND created >= $since"
elif since:
query += " WHERE created >= $since"
results = cast(
tuple[int],
oldb.query(query, vars={'since': since, 'shelf_ids': shelf_ids}),
)
return results[0]
.

openlibrary org_stats (3)

Proposal & Constraints

Additional context

Stakeholders

@mekarpeles mekarpeles added Type: Feature Request Issue describes a feature or enhancement we'd like to implement. [managed] Priority: 3 Issues that we can consider at our leisure. [managed] Good First Issue Easy issue. Good for newcomers. [managed] Needs: Help Issues, typically substantial ones, that need a dedicated developer to take them on. [managed] Theme: Analytics Regarding metrics, stats, and analytics Lead: @jimchamp Issues overseen by Jim (Front-end Lead, BookNotes) [managed] Theme: Yearly Reading Goals labels Jan 1, 2023
@Blueclaus13
Copy link

Do you still need help with this? Could I collaborate on it?

@scottbarnes
Copy link
Collaborator

Hi, @Blueclaus13. I am just another volunteer, but I can see you have been looking hard for an issue. This one seems pretty self-contained, it hasn't been done yet, and it doesn't appear as if anyone else is working on it. If you haven't selected another issue, this might be a good one to work on.

If you decide to give it a go, just mention it here and even if it's not assigned to you immediately, it's unlikely anyone else will work on it. Please also ask any questions you have and we'll do our best to help.

@SamWilson22
Copy link

Hey @Blueclaus13 and @scottbarnes. I apologize for jumping in taking a look at this issue without discussing it with you first. Let me know if you'd like to collaborate on it going forward.

@Reykox123
Copy link

Reykox123 commented Feb 21, 2023 via email

@Blueclaus13
Copy link

Don't worry, I hadn't started this issue because I had other assigned.

@rd713
Copy link

rd713 commented Mar 27, 2023

I want to to work on this issue and request to be assigned with this issue

@mekarpeles mekarpeles added this to the Sprint 2023-04 milestone Mar 29, 2023
@mekarpeles mekarpeles removed this from the Sprint 2023-06 milestone May 30, 2023
@mekarpeles mekarpeles removed the Good First Issue Easy issue. Good for newcomers. [managed] label Oct 19, 2023
@kevinc16
Copy link

Hey, I am new to the repo but I would like to work on this!

@github-actions github-actions bot added the Needs: Response Issues which require feedback from lead label May 11, 2024
@jimchamp
Copy link
Collaborator

Thanks @kevinc16! The links in the original post have been updated as they were out-of-date. Let me know if you have any questions.

@jimchamp jimchamp removed the Needs: Response Issues which require feedback from lead label May 13, 2024
@kevinc16 kevinc16 linked a pull request May 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Lead: @jimchamp Issues overseen by Jim (Front-end Lead, BookNotes) [managed] Needs: Help Issues, typically substantial ones, that need a dedicated developer to take them on. [managed] Priority: 3 Issues that we can consider at our leisure. [managed] Theme: Analytics Regarding metrics, stats, and analytics Theme: Yearly Reading Goals Type: Feature Request Issue describes a feature or enhancement we'd like to implement. [managed]
Projects
None yet
8 participants