Skip to content

Commit

Permalink
Include deck names in image filename's (#7)
Browse files Browse the repository at this point in the history
* Added: deck names to image filenames

* Removed .apkg extension from image files

* renamed variables

* save image in a new dir

---------

Co-authored-by: Jarrett Ye <[email protected]>
  • Loading branch information
Luc-Mcgrady and L-M-Sherlock authored Jul 30, 2023
1 parent 3bcfd1d commit e40e3d3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ dmypy.json

# IDE
.idea
.vscode

# Mac
.DS_Store
Expand Down
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.5.1"
version = "4.5.2"
readme = "README.md"
dependencies = [
"matplotlib>=3.7.0",
Expand Down
18 changes: 15 additions & 3 deletions src/fsrs_optimizer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import pytz
import os
from pathlib import Path

def prompt(msg: str, fallback):
default = ""
Expand All @@ -17,7 +18,12 @@ def prompt(msg: str, fallback):
raise Exception("You failed to enter a required parameter")
return response

def process(filename):
def process(filepath):
suffix = filepath.split('/')[-1].replace(".", "_").replace("@", "_")
proj_dir = Path(f'{suffix}')
proj_dir.mkdir(parents=True, exist_ok=True)
os.chdir(proj_dir)

try: # Try and remember the last values inputted.
with open(config_save, "r") as f:
remembered_fallbacks = json.load(f)
Expand Down Expand Up @@ -62,7 +68,7 @@ def remembered_fallback_prompt(key: str, pretty: str = None):

optimizer = fsrs_optimizer.Optimizer()
optimizer.anki_extract(
filename,
f"../{filepath}",
remembered_fallbacks["filter_out_suspended_cards"] == "y"
)
analysis = optimizer.create_time_series(
Expand All @@ -72,6 +78,8 @@ def remembered_fallback_prompt(key: str, pretty: str = None):
)
print(analysis)

filename = os.path.splitext(os.path.basename(filepath))[0]

optimizer.define_model()
figures = optimizer.pretrain(verbose=save_graphs)
for i, f in enumerate(figures):
Expand All @@ -91,7 +99,7 @@ def remembered_fallback_prompt(key: str, pretty: str = None):
profile = \
f"""{{
// Generated, Optimized anki deck settings
"deckName": "{os.path.splitext(os.path.basename(filename))[0]}",// PLEASE CHANGE THIS TO THE DECKS PROPER NAME
"deckName": "{filename}",// PLEASE CHANGE THIS TO THE DECKS PROPER NAME
"w": {optimizer.w},
"requestRetention": {optimizer.optimal_retention},
"maximumInterval": 36500,
Expand Down Expand Up @@ -133,9 +141,13 @@ def remembered_fallback_prompt(key: str, pretty: str = None):
files = [os.path.join(filename, f) for f in files]
for file_path in files:
try:
curdir = os.getcwd()
process(file_path)
os.chdir(curdir)
except Exception as e:
print(e)
print(f"Failed to process {file_path}")
os.chdir(curdir)
continue
else:
process(filename)
Expand Down

0 comments on commit e40e3d3

Please sign in to comment.