Merge pull request #350 from Aquafina-water-bottle/get_reviews_of_card

Added getReviewsOfCards
This commit is contained in:
Alexei Yatskov 2022-09-20 17:53:03 -07:00 committed by GitHub
commit 82ca4b847d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 92 additions and 0 deletions

View File

@ -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** * **getLatestReviewID**
Returns the unix time of the latest review for the given deck. 0 if no review has ever been made for the deck. Returns the unix time of the latest review for the given deck. 0 if no review has ever been made for the deck.

View File

@ -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() @util.api()
def reloadCollection(self): def reloadCollection(self):
self.collection().reset() self.collection().reset()

View File

@ -29,3 +29,18 @@ class TestReviews:
assert len(ac.cardReviews(deck="test_deck", startID=0)) == 2 assert len(ac.cardReviews(deck="test_deck", startID=0)) == 2
assert ac.getLatestReviewID(deck="test_deck") == 789 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,
}
]
}