Collection stats (#166)
* Add endpoint to retrieve collection stats report * Create separate test for statistics * Add test for collectionStats * Fixed typo * Change endpoint name to use a verb * Change name to getCollectionStatsHTML
This commit is contained in:
parent
457e76e720
commit
faba701251
63
README.md
63
README.md
@ -14,6 +14,7 @@ with the latest stable (2.1.x) releases of Anki; older versions (2.0.x and below
|
|||||||
* [Sample Invocation](#sample-invocation)
|
* [Sample Invocation](#sample-invocation)
|
||||||
* [Supported Actions](#supported-actions)
|
* [Supported Actions](#supported-actions)
|
||||||
* [Miscellaneous](#miscellaneous)
|
* [Miscellaneous](#miscellaneous)
|
||||||
|
* [Statistics](#statistics)
|
||||||
* [Decks](#decks)
|
* [Decks](#decks)
|
||||||
* [Models](#models)
|
* [Models](#models)
|
||||||
* [Notes](#notes)
|
* [Notes](#notes)
|
||||||
@ -297,26 +298,6 @@ guarantee that your application continues to function properly in the future.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
* **getNumCardsReviewedToday**
|
|
||||||
|
|
||||||
Gets the count of cards that have been reviewed in the current day (with day start time as configured by user in anki)
|
|
||||||
|
|
||||||
*Sample request*:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"action": "getNumCardsReviewedToday",
|
|
||||||
"version": 6
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
*Sample result*:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"result": 0,
|
|
||||||
"error": null
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
* **exportPackage**
|
* **exportPackage**
|
||||||
|
|
||||||
Exports a given deck in `.apkg` format. Returns `true` if successful or `false` otherwise. The optional property
|
Exports a given deck in `.apkg` format. Returns `true` if successful or `false` otherwise. The optional property
|
||||||
@ -367,6 +348,48 @@ guarantee that your application continues to function properly in the future.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Statistics
|
||||||
|
|
||||||
|
* **getNumCardsReviewedToday**
|
||||||
|
|
||||||
|
Gets the count of cards that have been reviewed in the current day (with day start time as configured by user in anki)
|
||||||
|
|
||||||
|
*Sample request*:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"action": "getNumCardsReviewedToday",
|
||||||
|
"version": 6
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
*Sample result*:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"result": 0,
|
||||||
|
"error": null
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
* **getCollectionStatsHTML**
|
||||||
|
|
||||||
|
Gets the collection statistics report
|
||||||
|
|
||||||
|
*Sample request*:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"action": "getCollectionStatsHTML",
|
||||||
|
"version": 6
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
*Sample result*:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"error": null,
|
||||||
|
"result": "<center> lots of HTML here </center>",
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#### Decks
|
#### Decks
|
||||||
|
|
||||||
* **deckNames**
|
* **deckNames**
|
||||||
|
@ -298,6 +298,11 @@ class AnkiConnect:
|
|||||||
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 getCollectionStatsHTML(self):
|
||||||
|
return self.collection().stats().report()
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Decks
|
# Decks
|
||||||
#
|
#
|
||||||
|
@ -30,10 +30,6 @@ class TestMisc(unittest.TestCase):
|
|||||||
self.assertIsNone(result['error'])
|
self.assertIsNone(result['error'])
|
||||||
self.assertEqual(result['result'], 6)
|
self.assertEqual(result['result'], 6)
|
||||||
|
|
||||||
# getNumCardsReviewedToday
|
|
||||||
result = util.invoke('getNumCardsReviewedToday')
|
|
||||||
self.assertIsInstance(result, int)
|
|
||||||
|
|
||||||
# exportPackage
|
# exportPackage
|
||||||
fd, newname = tempfile.mkstemp(prefix='testexport', suffix='.apkg')
|
fd, newname = tempfile.mkstemp(prefix='testexport', suffix='.apkg')
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
|
21
tests/test_stats.py
Normal file
21
tests/test_stats.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import os
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
import util
|
||||||
|
|
||||||
|
|
||||||
|
class TestMisc(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
# getNumCardsReviewedToday
|
||||||
|
result = util.invoke('getNumCardsReviewedToday')
|
||||||
|
self.assertIsInstance(result, int)
|
||||||
|
|
||||||
|
# collectionStats
|
||||||
|
result = util.invoke('getCollectionStatsHTML')
|
||||||
|
self.assertIsInstance(result, str)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user