Add getIntervals function

This commit is contained in:
David Bailey 2017-08-09 18:40:09 +01:00
parent 9298f867f6
commit 1a2c559ca2
2 changed files with 55 additions and 0 deletions

View File

@ -409,6 +409,16 @@ class AnkiBridge:
return False return False
def getIntervals(self, cards, complete=False):
intervals = []
for card in cards:
interval = self.window().col.db.list('select ivl from revlog where cid = ?', card)
if not complete:
interval = interval[-1]
intervals.append(interval)
return intervals
def startEditing(self): def startEditing(self):
self.window().requireReset() self.window().requireReset()
@ -728,6 +738,11 @@ class AnkiConnect:
return self.anki.isSuspended(card) return self.anki.isSuspended(card)
@webApi
def getIntervals(self, cards, complete=False):
return self.anki.getIntervals(cards, complete)
@webApi @webApi
def upgrade(self): def upgrade(self):
response = QMessageBox.question( response = QMessageBox.question(

View File

@ -404,6 +404,46 @@ Below is a list of currently supported actions. Requests with invalid actions or
false false
``` ```
* **getIntervals**
Returns an array of the most recent intervals for each given card ID, or a 2-dimensional array of all the intervals
for each given card ID when `complete` is `true`. (Negative intervals are in seconds and positive intervals in days.)
*Sample request 1*:
```
{
"action": "getIntervals",
"params": {
"cards": [1502298033753, 1502298036657]
}
}
```
*Sample response 1*:
```
[-14400, 3]
```
*Sample request 2*:
```
{
"action": "getIntervals",
"params": {
"cards": [1502298033753, 1502298036657],
"complete": true
}
}
```
*Sample response 2*:
```
[
[-120, -180, -240, -300, -360, -14400],
[-120, -180, -240, -300, -360, -14400, 1, 3]
]
```
* **findNotes** * **findNotes**
Returns an array of note IDs for a given query (same query syntax as **guiBrowse**). Returns an array of note IDs for a given query (same query syntax as **guiBrowse**).