mirror of
https://github.com/ankitects/anki.git
synced 2026-01-13 14:03:55 -05:00
Add anki_helpers module with activity.py
This commit is contained in:
parent
2c45175cec
commit
8af9eb07c6
1 changed files with 30 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
||||||
|
import time
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
def analyze_activity(col, days=30):
|
||||||
|
day_cutoff = col.sched.day_cutoff
|
||||||
|
start_time = day_cutoff - days * 86400
|
||||||
|
start_ts = start_time * 1000 # ms
|
||||||
|
|
||||||
|
rows = col.db.all(
|
||||||
|
"""
|
||||||
|
SELECT id FROM revlog
|
||||||
|
WHERE id > ?
|
||||||
|
""",
|
||||||
|
start_ts,
|
||||||
|
)
|
||||||
|
|
||||||
|
days_dict = defaultdict(int)
|
||||||
|
for (id,) in rows:
|
||||||
|
day = int((id / 1000) // 86400)
|
||||||
|
days_dict[day] += 1
|
||||||
|
|
||||||
|
total_days = len(days_dict)
|
||||||
|
average_per_day = sum(days_dict.values()) / days
|
||||||
|
low_days = sum(1 for v in days_dict.values() if v < 10) # z. B. Schwelle
|
||||||
|
|
||||||
|
return {
|
||||||
|
"active_days": total_days,
|
||||||
|
"average_per_day": round(average_per_day, 2),
|
||||||
|
"low_days": low_days,
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue