-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80affaf
commit d615f6e
Showing
5 changed files
with
156 additions
and
149 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: ["master"] | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["master"] | ||
branches: ["main"] | ||
jobs: | ||
test: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
python-version: [3.5, 3.6, 3.7, 3.8, 3.9] | ||
python-version: [3.7, 3.8, 3.9, 3.10, 3.11, 3.12] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v3 | ||
- name: Setup Python | ||
uses: actions/setup-python@v2 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Generate coverage report | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
pytest | ||
upload_coverage: | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v3 | ||
- name: Setup Python | ||
uses: actions/setup-python@v2 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.9' | ||
python-version: '3.10' | ||
- name: Generate coverage report | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest-cov | ||
pytest --cov=supermemo2 --cov-report=xml | ||
- name: "Upload coverage to Codecov" | ||
uses: codecov/codecov-action@v1 | ||
uses: codecov/codecov-action@v4 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pytest-cov==2.10.1 | ||
|
||
freezegun==1.5.1 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,53 @@ | ||
from math import ceil | ||
from datetime import date, datetime, timedelta | ||
from datetime import datetime, timedelta | ||
from typing import Optional, Union, Dict | ||
|
||
import attr | ||
|
||
def review( | ||
quality: int, | ||
easiness: float, | ||
interval: int, | ||
repetitions: int, | ||
review_datetime: Optional[Union[datetime, str]] = None, | ||
) -> Dict: | ||
if not review_datetime: | ||
review_datetime = datetime.utcnow().isoformat(sep=" ", timespec="seconds") | ||
|
||
if isinstance(review_datetime, str): | ||
review_datetime = datetime.fromisoformat(review_datetime).replace(microsecond=0) | ||
|
||
if quality < 3: | ||
interval = 1 | ||
repetitions = 0 | ||
else: | ||
if repetitions == 0: | ||
interval = 1 | ||
elif repetitions == 1: | ||
interval = 6 | ||
else: | ||
interval = ceil(interval * easiness) | ||
|
||
year_mon_day = "%Y-%m-%d" | ||
mon_day_year = "%m-%d-%Y" | ||
day_mon_year = "%d-%m-%Y" | ||
|
||
|
||
@attr.s | ||
class SMTwo: | ||
easiness = attr.ib(validator=attr.validators.instance_of(float)) | ||
interval = attr.ib(validator=attr.validators.instance_of(int)) | ||
repetitions = attr.ib(validator=attr.validators.instance_of(int)) | ||
review_date = attr.ib(init=False) | ||
|
||
@staticmethod | ||
def first_review( | ||
quality: int, | ||
review_date: Optional[Union[date, str]] = None, | ||
date_fmt: Optional[str] = None, | ||
) -> "SMTwo": | ||
if not review_date: | ||
review_date = date.today() | ||
|
||
if not date_fmt: | ||
date_fmt = year_mon_day | ||
|
||
return SMTwo(2.5, 0, 0).review(quality, review_date, date_fmt) | ||
|
||
def review( | ||
self, | ||
quality: int, | ||
review_date: Optional[Union[date, str]] = None, | ||
date_fmt: Optional[str] = None, | ||
) -> "SMTwo": | ||
if not review_date: | ||
review_date = date.today() | ||
|
||
if not date_fmt: | ||
date_fmt = year_mon_day | ||
repetitions += 1 | ||
|
||
if isinstance(review_date, str): | ||
review_date = datetime.strptime(review_date, date_fmt).date() | ||
easiness += 0.1 - (5 - quality) * (0.08 + (5 - quality) * 0.02) | ||
if easiness < 1.3: | ||
easiness = 1.3 | ||
|
||
if quality < 3: | ||
self.interval = 1 | ||
self.repetitions = 0 | ||
else: | ||
if self.repetitions == 0: | ||
self.interval = 1 | ||
elif self.repetitions == 1: | ||
self.interval = 6 | ||
else: | ||
self.interval = ceil(self.interval * self.easiness) | ||
review_datetime += timedelta(days=interval) | ||
|
||
self.repetitions = self.repetitions + 1 | ||
return { | ||
"easiness": easiness, | ||
"interval": interval, | ||
"repetitions": repetitions, | ||
"review_date": str(review_datetime), | ||
} | ||
|
||
self.easiness += 0.1 - (5 - quality) * (0.08 + (5 - quality) * 0.02) | ||
if self.easiness < 1.3: | ||
self.easiness = 1.3 | ||
|
||
review_date += timedelta(days=self.interval) | ||
self.review_date = review_date | ||
def first_review( | ||
quality: int, | ||
review_datetime: Optional[Union[datetime, str]] = None, | ||
) -> Dict: | ||
if not review_datetime: | ||
review_datetime = datetime.utcnow() | ||
|
||
return self | ||
return review(quality, 2.5, 0, 0, review_datetime) |
Oops, something went wrong.