Skip to content

Commit

Permalink
Feat/filter out cards with specific flags (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-M-Sherlock authored Aug 6, 2023
1 parent 5843a20 commit bda6925
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "FSRS-Optimizer"
version = "4.6.0"
version = "4.7.0"
readme = "README.md"
dependencies = [
"matplotlib>=3.7.0",
Expand Down
7 changes: 6 additions & 1 deletion src/fsrs_optimizer/fsrs_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class Optimizer:
def __init__(self) -> None:
tqdm.pandas()

def anki_extract(self, filename: str, filter_out_suspended_cards: bool = False):
def anki_extract(self, filename: str, filter_out_suspended_cards: bool = False, filter_out_flags: List[int] = []):
"""Step 1"""
# Extract the collection file or deck file to get the .anki21 database.
with zipfile.ZipFile(f'{filename}', 'r') as zip_ref:
Expand All @@ -334,6 +334,10 @@ def anki_extract(self, filename: str, filter_out_suspended_cards: bool = False):
else:
raise Exception("Collection not exist!")
cur = con.cursor()

def flags2str(flags: List[int]) -> str:
return f"({','.join(map(str, flags))})"

res = cur.execute(f"""
SELECT *
FROM revlog
Expand All @@ -342,6 +346,7 @@ def anki_extract(self, filename: str, filter_out_suspended_cards: bool = False):
FROM cards
WHERE queue != 0
{"AND queue != -1" if filter_out_suspended_cards else ""}
{"AND flags NOT IN %s" % flags2str(filter_out_flags) if len(filter_out_flags) > 0 else ""}
)
"""
)
Expand Down

0 comments on commit bda6925

Please sign in to comment.