Anki/anki_helpers/activity.py
2025-06-16 21:29:31 +02:00

30 lines
759 B
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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,
}