added getNumCardsReviewedByDay action (#239)

* added getNumCardsReviewedByDay action

* added sample in statistics.md

* fix bad quotes and add basic test
This commit is contained in:
Quentin Harscoët 2021-03-06 18:58:40 +01:00 committed by GitHub
parent b8a7151ed0
commit 27a8678f88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 0 deletions

View File

@ -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** * **getCollectionStatsHTML**
Gets the collection statistics report Gets the collection statistics report

View File

@ -351,6 +351,11 @@ class AnkiConnect:
def getNumCardsReviewedToday(self): def getNumCardsReviewedToday(self):
return self.database().scalar('select count() from revlog where id > ?', (self.scheduler().dayCutoff - 86400) * 1000) 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() @util.api()
def getCollectionStatsHTML(self, wholeCollection=True): def getCollectionStatsHTML(self, wholeCollection=True):

View File

@ -28,6 +28,10 @@ class TestStats(unittest.TestCase):
result = util.invoke('getNumCardsReviewedToday') result = util.invoke('getNumCardsReviewedToday')
self.assertIsInstance(result, int) self.assertIsInstance(result, int)
# getNumCardsReviewedByDay
result = util.invoke('getNumCardsReviewedByDay')
self.assertIsInstance(result, list)
# collectionStats # collectionStats
result = util.invoke('getCollectionStatsHTML') result = util.invoke('getCollectionStatsHTML')
self.assertIsInstance(result, str) self.assertIsInstance(result, str)