MCPcopy Create free account
hub / github.com/internetarchive/openlibrary / get_admin_stats

Function get_admin_stats

openlibrary/plugins/admin/code.py:542–585  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

540
541
542def get_admin_stats():
543 def f(dates):
544 keys = ["/admin/stats/" + date.isoformat() for date in dates]
545 docs = web.ctx.site.get_many(keys)
546 return g(docs)
547
548 def has_doc(date):
549 return bool(web.ctx.site.get("/admin/stats/" + date.isoformat()))
550
551 def g(docs):
552 return {
553 "edits": {
554 "human": sum(doc["edits"]["human"] for doc in docs),
555 "bot": sum(doc["edits"]["bot"] for doc in docs),
556 "total": sum(doc["edits"]["total"] for doc in docs),
557 },
558 "members": sum(doc["members"] for doc in docs),
559 }
560
561 current_date = date.today()
562
563 if has_doc(current_date):
564 today = f([current_date])
565 else:
566 today = g([stats().get_stats(current_date.isoformat())])
567 yesterday = f(daterange(current_date, -1, 0, 1))
568 thisweek = f(daterange(current_date, 0, -7, -1))
569 thismonth = f(daterange(current_date, 0, -30, -1))
570
571 xstats = {
572 "edits": {
573 "today": today["edits"],
574 "yesterday": yesterday["edits"],
575 "thisweek": thisweek["edits"],
576 "thismonth": thismonth["edits"],
577 },
578 "members": {
579 "today": today["members"],
580 "yesterday": yesterday["members"],
581 "thisweek": thisweek["members"],
582 "thismonth": thismonth["members"],
583 },
584 }
585 return storify(xstats)
586
587
588from openlibrary.plugins.upstream import borrow # noqa: F401 side effects may be needed

Callers

nothing calls this directly

Calls 7

has_docFunction · 0.85
daterangeFunction · 0.85
storifyFunction · 0.85
get_statsMethod · 0.80
fFunction · 0.70
gFunction · 0.70
statsClass · 0.70

Tested by

no test coverage detected