2021-04-13 10:45:05 +02:00
|
|
|
# Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2019-12-25 05:18:34 +01:00
|
|
|
import os
|
2019-12-25 22:00:10 +01:00
|
|
|
import tempfile
|
2019-12-25 05:18:34 +01:00
|
|
|
|
2021-10-14 11:22:47 +02:00
|
|
|
from anki.collection import CardStats
|
2019-12-25 22:36:26 +01:00
|
|
|
from tests.shared import getEmptyCol
|
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
|
|
|
|
def test_stats():
|
2020-07-17 05:21:12 +02:00
|
|
|
col = getEmptyCol()
|
|
|
|
note = col.newNote()
|
2020-07-17 05:18:09 +02:00
|
|
|
note["Front"] = "foo"
|
2020-07-17 05:21:12 +02:00
|
|
|
col.addNote(note)
|
2020-07-17 05:18:09 +02:00
|
|
|
c = note.cards()[0]
|
2012-12-21 08:51:59 +01:00
|
|
|
# card stats
|
2022-01-21 12:32:39 +01:00
|
|
|
card_stats = col.card_stats_data(c.id)
|
2021-10-14 11:22:47 +02:00
|
|
|
assert card_stats.note_id == note.id
|
2020-07-17 05:21:12 +02:00
|
|
|
c = col.sched.getCard()
|
|
|
|
col.sched.answerCard(c, 3)
|
|
|
|
col.sched.answerCard(c, 2)
|
2022-01-21 12:32:39 +01:00
|
|
|
card_stats = col.card_stats_data(c.id)
|
2021-10-14 11:22:47 +02:00
|
|
|
assert len(card_stats.revlog) == 2
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2019-12-25 05:18:34 +01:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
def test_graphs_empty():
|
2020-07-17 05:21:12 +02:00
|
|
|
col = getEmptyCol()
|
|
|
|
assert col.stats().report()
|
2012-12-21 08:51:59 +01:00
|
|
|
|
2019-12-25 05:18:34 +01:00
|
|
|
|
2012-12-21 08:51:59 +01:00
|
|
|
def test_graphs():
|
2019-12-25 22:00:10 +01:00
|
|
|
dir = tempfile.gettempdir()
|
2020-07-17 05:21:12 +02:00
|
|
|
col = getEmptyCol()
|
|
|
|
g = col.stats()
|
2012-12-21 08:51:59 +01:00
|
|
|
rep = g.report()
|
2020-07-17 05:18:09 +02:00
|
|
|
with open(os.path.join(dir, "test.html"), "w", encoding="UTF-8") as note:
|
|
|
|
note.write(rep)
|
2012-12-21 08:51:59 +01:00
|
|
|
return
|