diff --git a/actions/statistics.md b/actions/statistics.md index 0ff29b0..c02dad5 100644 --- a/actions/statistics.md +++ b/actions/statistics.md @@ -20,6 +20,29 @@ } ``` +* **getNumCardsReviewedByDay** + + Gets the number of cards reviewed as a list of pairs of `(dateString, number)` + + *Sample request*: + ```json + { + "action": "getNumCardsReviewedByDay", + "version": 6, + } + ``` + + *Sample result*: + ```json + { + "result": [ + ["2021-02-28", 124], + ["2021-02-27", 261] + ], + "error": null + } + ``` + * **getCollectionStatsHTML** Gets the collection statistics report diff --git a/plugin/__init__.py b/plugin/__init__.py index 0da6d44..5a4bac9 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -351,6 +351,11 @@ class AnkiConnect: def getNumCardsReviewedToday(self): return self.database().scalar('select count() from revlog where id > ?', (self.scheduler().dayCutoff - 86400) * 1000) + @util.api() + def getNumCardsReviewedByDay(self): + return self.database().all('select date(id/1000 - ?, "unixepoch", "localtime") as day, count() from revlog group by day order by day desc', + int(time.strftime("%H", time.localtime(self.scheduler().dayCutoff))) * 3600) + @util.api() def getCollectionStatsHTML(self, wholeCollection=True): diff --git a/tests/test_stats.py b/tests/test_stats.py index 0aa1475..3b80ac7 100755 --- a/tests/test_stats.py +++ b/tests/test_stats.py @@ -28,6 +28,10 @@ class TestStats(unittest.TestCase): result = util.invoke('getNumCardsReviewedToday') self.assertIsInstance(result, int) + # getNumCardsReviewedByDay + result = util.invoke('getNumCardsReviewedByDay') + self.assertIsInstance(result, list) + # collectionStats result = util.invoke('getCollectionStatsHTML') self.assertIsInstance(result, str)