Created
March 9, 2019 14:08
-
-
Save ijgnd/c6e80793a9f346d5091eceb305fa6d24 to your computer and use it in GitHub Desktop.
Reset_review_Stats_in_ Anki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#minimal modification of Reset review Stats in Anki, https://ankiweb.net/shared/info/1040127450 | |
#copyright unknown | |
#License: AGPLv3 | |
# | |
#USE IT AT YOUR OWN RISK!!! This modification is done to experiment and learn by a beginner. | |
#made by request, https://www.reddit.com/r/Anki/comments/93tcek/reset_review_stats_from_a_year_to_a_certain_date/ | |
####################USERCONFIG######################### | |
#Dates must be in format YYYY-MM-DD. Input is not validated so be careful | |
#everything from Date2 to Date1 will be removed | |
Date1="2018-05-30" #keep reviews younger than this | |
Date2="2018-01-01" #keep reviews older than this | |
#######Don't change anything below this line########### | |
# import the main window object (mw) from ankiqt | |
from aqt import mw | |
# import the "show info" tool from utils.py | |
from aqt.utils import showInfo | |
# import all of the Qt GUI library | |
from aqt.qt import * | |
from time import mktime,time | |
from datetime import datetime | |
def testFunction(): | |
# get the number of cards in the current collection, which is stored in | |
# the main window | |
cardCount = mw.col.cardCount() | |
# show a message box | |
showInfo("Card count: %d" % cardCount) | |
def epochTodayMidnight(): | |
n = datetime.now() | |
midnight = datetime(n.year, n.month, n.day) | |
return mktime(midnight.timetuple()) | |
def epochCustomDateMidnight(mydate): | |
n = datetime.strptime(mydate, '%Y-%m-%d') | |
midnight = datetime(n.year, n.month, n.day) | |
return mktime(midnight.timetuple()) | |
def deleteRevlog(timeinfo): | |
# showInfo("TIME: %d %d" % (timeinfo * 1000, time() * 1000)) | |
mw.col.db.execute("delete from revlog where id > ?", timeinfo * 1000) | |
def resetCustomTime(): | |
mw.col.db.execute("delete from revlog where (id < ? and id > ? ) ", epochCustomDateMidnight(Date1) * 1000, epochCustomDateMidnight(Date2) * 1000) | |
def resetYearAgo(): | |
deleteRevlog(epochTodayMidnight() - DAY*365) | |
def resetMonthAgo(): | |
deleteRevlog(epochTodayMidnight() - DAY*30) | |
def resetThreeWeeksAgo(): | |
deleteRevlog(epochTodayMidnight() - DAY*21) | |
def resetTwoWeeksAgo(): | |
deleteRevlog(epochTodayMidnight() - DAY*14) | |
def resetOneWeekAgo(): | |
deleteRevlog(epochTodayMidnight() - DAY*7) | |
def resetYesterday(): | |
deleteRevlog(epochTodayMidnight() - DAY) | |
def resetToday(): | |
deleteRevlog(epochTodayMidnight()) | |
def resetLastHour(): | |
deleteRevlog(time() - HOUR) | |
# Day in seconds | |
DAY = 86400 | |
# Hour in seconds | |
HOUR = 3600 | |
# Create menu Reset Study | |
resetStudy = mw.form.menuTools.addMenu("Reset Study") | |
resetLastHourAction = resetStudy.addAction("Last hour") | |
resetTodayAction = resetStudy.addAction("Today") | |
resetYesterdayAction = resetStudy.addAction("Yesterday") | |
resetOneWeekAction = resetStudy.addAction("One Week") | |
resetTwoWeeksAction = resetStudy.addAction("Two Weeks") | |
resetThreeWeeksAction = resetStudy.addAction("Three Weeks") | |
resetMonthAction = resetStudy.addAction("A month ago") | |
resetYearAction = resetStudy.addAction("A year ago") | |
resetCustomTimeAction = resetStudy.addAction("Custom Time (see source code for config)") | |
# Connect actions to functions | |
mw.connect(resetLastHourAction, SIGNAL("triggered()"), resetLastHour) | |
mw.connect(resetTodayAction, SIGNAL("triggered()"), resetToday) | |
mw.connect(resetYesterdayAction, SIGNAL("triggered()"), resetYesterday) | |
mw.connect(resetOneWeekAction, SIGNAL("triggered()"), resetOneWeekAgo) | |
mw.connect(resetTwoWeeksAction, SIGNAL("triggered()"), resetTwoWeeksAgo) | |
mw.connect(resetThreeWeeksAction, SIGNAL("triggered()"), resetThreeWeeksAgo) | |
mw.connect(resetMonthAction, SIGNAL("triggered()"), resetMonthAgo) | |
mw.connect(resetYearAction, SIGNAL("triggered()"), resetYearAgo) | |
mw.connect(resetCustomTimeAction, SIGNAL("triggered()"), resetCustomTime) | |
# create a new menu item, "test" | |
#action = QAction("test", mw) | |
# set it to call testFunction when it's clicked | |
#mw.connect(action, SIGNAL("triggered()"), testFunction) | |
# and add it to the tools menu | |
#mw.form.menuTools.addAction(action) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment