Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/store specific dates for easy days #416

Merged
merged 2 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"load_balance": false,
"easy_days": [],
"easy_dates": [],
"easy_days_review_ratio": 0,
"days_to_reschedule": 7,
"auto_reschedule_after_sync": false,
Expand Down
12 changes: 11 additions & 1 deletion configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

LOAD_BALANCE = "load_balance"
EASY_DAYS = "easy_days"
EASY_DATES = "easy_dates"
EASY_DAYS_REVIEW_RATIO = "easy_days_review_ratio"
DAYS_TO_RESCHEDULE = "days_to_reschedule"
AUTO_RESCHEDULE_AFTER_SYNC = "auto_reschedule_after_sync"
Expand Down Expand Up @@ -47,7 +48,7 @@ def load_balance(self, value):
self.save()

@property
def easy_days(self):
def easy_days(self) -> list[int]:
return self.data[EASY_DAYS]

@easy_days.setter
Expand All @@ -60,6 +61,15 @@ def easy_days(self, day_enable):
self.data[EASY_DAYS].remove(day)
self.save()

@property
def easy_dates(self) -> list[str]:
return self.data[EASY_DATES]

@easy_dates.setter
def easy_dates(self, value):
self.data[EASY_DATES] = value
self.save()

@property
def easy_days_review_ratio(self):
return max(0, min(self.data[EASY_DAYS_REVIEW_RATIO], 0.9))
Expand Down
24 changes: 23 additions & 1 deletion schedule/easy_days.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,21 @@ class EasySpecificDateManagerWidget(QWidget):
def __init__(self):
super().__init__()
self.initUi()
self.specific_dates = []
self.config = Config()
self.config.load()
current_date = sched_current_date()
self.config.easy_dates = [
date
for date in self.config.easy_dates
if datetime.strptime(date, "%Y-%m-%d").date() >= current_date
]
self.specific_dates = [
datetime.strptime(date, "%Y-%m-%d").date()
for date in self.config.easy_dates
]
for specific_date in self.specific_dates:
deckWidget = DateLabelWidget(specific_date, self)
self.layout.insertWidget(self.layout.count() - 2, deckWidget)

def initUi(self):
self.layout = QVBoxLayout()
Expand Down Expand Up @@ -113,6 +127,9 @@ def addEventFunc(self):
tooltip("Easy days can't be applied on past dates.")
return
self.specific_dates.append(specific_date)
self.config.easy_dates = [
date.strftime("%Y-%m-%d") for date in self.specific_dates
]
deckWidget = DateLabelWidget(specific_date, self)
self.layout.insertWidget(self.layout.count() - 2, deckWidget)
mw.deckBrowser.refresh()
Expand Down Expand Up @@ -179,6 +196,11 @@ def __init__(self, date, manager):
layout.addWidget(self.deleteButton)

def deleteEvent(self):
config = Config()
config.load()
config.easy_dates = list(
filter(lambda x: x != self.date.strftime("%Y-%m-%d"), config.easy_dates)
)
self.manager.specific_dates.remove(self.date)
self.setParent(None)
mw.deckBrowser.refresh()
Expand Down
10 changes: 10 additions & 0 deletions schedule/reschedule.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Set
from aqt import QAction, browser

from .disperse_siblings import disperse_siblings
Expand Down Expand Up @@ -212,6 +213,15 @@ def reschedule_background(
len(fsrs.easy_days), fsrs.easy_days_review_ratio
)
fsrs.easy_specific_due_dates = easy_specific_due_dates

current_date = sched_current_date()
today = mw.col.sched.today
for easy_date_str in config.easy_dates:
easy_date = datetime.strptime(easy_date_str, "%Y-%m-%d").date()
specific_due = today + (easy_date - current_date).days
if specific_due not in fsrs.easy_specific_due_dates:
fsrs.easy_specific_due_dates.append(specific_due)

fsrs.p_obey_specific_due_dates = obey_specific_due_dates(
len(fsrs.easy_specific_due_dates), fsrs.easy_days_review_ratio
)
Expand Down
Loading