diff --git a/README.md b/README.md index 7cf79ff..7516ac7 100644 --- a/README.md +++ b/README.md @@ -2764,6 +2764,69 @@ corresponding to when the API was available for use. } ``` +* **getReviewsOfCards** + + Requests all card reviews for each card ID. + Returns a dictionary mapping each card ID to a list of dictionaries of the format: + ``` + { + "id": reviewTime, + "usn": usn, + "ease": buttonPressed, + "ivl": newInterval, + "lastIvl": previousInterval, + "factor": newFactor, + "time": reviewDuration, + "type": reviewType, + } + ``` + The reason why these key values are used instead of the more descriptive counterparts + is because these are the exact key values used in Anki's database. + + *Sample request*: + ```json + { + "action": "getReviewsOfCards", + "version": 6, + "params": { + "cards": [ + "1653613948202" + ] + } + } + ``` + + *Sample result*: + ```json + { + "result": { + "1653613948202": [ + { + "id": 1653772912146, + "usn": 1750, + "ease": 1, + "ivl": -20, + "lastIvl": -20, + "factor": 0, + "time": 38192, + "type": 0 + }, + { + "id": 1653772965429, + "usn": 1750, + "ease": 3, + "ivl": -45, + "lastIvl": -20, + "factor": 0, + "time": 15337, + "type": 0 + } + ] + }, + "error": null + } + ``` + * **getLatestReviewID** Returns the unix time of the latest review for the given deck. 0 if no review has ever been made for the deck. diff --git a/plugin/__init__.py b/plugin/__init__.py index f057412..056ca01 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -1373,6 +1373,20 @@ class AnkiConnect: ) + @util.api() + def getReviewsOfCards(self, cards): + COLUMNS = ['id', 'usn', 'ease', 'ivl', 'lastIvl', 'factor', 'time', 'type'] + QUERY = 'select {} from revlog where cid = ?'.format(', '.join(COLUMNS)) + + result = {} + for card in cards: + query_result = self.database().all(QUERY, card) + result[card] = [dict(zip(COLUMNS, row)) for row in query_result] + + return result + + + @util.api() def reloadCollection(self): self.collection().reset() diff --git a/tests/test_stats.py b/tests/test_stats.py index a412ca1..6cf16df 100755 --- a/tests/test_stats.py +++ b/tests/test_stats.py @@ -29,3 +29,18 @@ class TestReviews: assert len(ac.cardReviews(deck="test_deck", startID=0)) == 2 assert ac.getLatestReviewID(deck="test_deck") == 789 + assert ac.getReviewsOfCards(cards=[setup.card_ids[0]]) == \ + { + setup.card_ids[0]: [ + { + "id": 456, + "usn": -1, + "ease": 3, + "ivl": 4, + "lastIvl": -60, + "factor": 2500, + "time": 6157, + "type": 0, + } + ] + }