diff --git a/.gitignore b/.gitignore index 0bb7d61..b622d60 100644 --- a/.gitignore +++ b/.gitignore @@ -15,8 +15,10 @@ old/ data/cache/ data/electron/ data/nucleon/ -!data/nucleon/test* +data/global/ +!data/nucleon/TEST* data/orbital/ +config/config_dev.toml AGENTS.md # Byte-compiled / optimized / DLL files diff --git a/config/config.toml b/config/config.toml index fc60ff8..a24b7a0 100644 --- a/config/config.toml +++ b/config/config.toml @@ -19,6 +19,9 @@ timezone_offset = +28800 # 中国标准时间 (UTC+8) [interface.memorizor] autovoice = true # 自动语音播放, 仅限于 recognition 组件 +[algorithm] +default = "SM-2" # 主要算法; 可选项: SM-2, SM-15M, FSRS + [puzzles] # 谜题默认配置 [puzzles.mcq] @@ -30,6 +33,7 @@ min_denominator = 3 [paths] # 相对于配置文件的 ".." (即工作目录) 而言 或绝对路径 nucleon_dir = "./data/nucleon" electron_dir = "./data/electron" +global_dir = "./data/global" # 全局数据路径, SM-15 等算法需要 orbital_dir = "./data/orbital" cache_dir = "./data/cache" template_dir = "./data/template" diff --git a/src/heurams/context.py b/src/heurams/context.py index abf29d1..80f7feb 100644 --- a/src/heurams/context.py +++ b/src/heurams/context.py @@ -32,7 +32,11 @@ try: except Exception as e: print("未能加载自定义用户配置") logger.warning("未能加载自定义用户配置, 错误: %s", e) - +if pathlib.Path(rootdir / "default" / "config" / "config_dev.toml").exists(): + logger.debug("使用开发设置") + config_var: ContextVar[ConfigFile] = ContextVar( + "config_var", default=ConfigFile(workdir / "config" / "config_dev.toml") +) # runtime_var: ContextVar = ContextVar('runtime_var', default=dict()) # 运行时共享数据 diff --git a/src/heurams/default/config/config_dev.toml b/src/heurams/default/config/config_dev.toml new file mode 100644 index 0000000..e69de29 diff --git a/src/heurams/kernel/algorithms/sm15m.py b/src/heurams/kernel/algorithms/sm15m.py index de79bd7..95e210e 100644 --- a/src/heurams/kernel/algorithms/sm15m.py +++ b/src/heurams/kernel/algorithms/sm15m.py @@ -11,13 +11,14 @@ import datetime import json import os from typing import TypedDict - +import pathlib +from heurams.context import config_var from heurams.kernel.algorithms.sm15m_calc import (MAX_AF, MIN_AF, NOTCH_AF, RANGE_AF, RANGE_REPETITION, SM, THRESHOLD_RECALL, Item) # 全局状态文件路径 -_GLOBAL_STATE_FILE = os.path.expanduser("~/.sm15_global_state.json") +_GLOBAL_STATE_FILE = os.path.expanduser(pathlib.Path(config_var.get()['paths']['global_dir']) / 'sm15m_global_state.json') def _get_global_sm(): diff --git a/src/heurams/kernel/particles/electron.py b/src/heurams/kernel/particles/electron.py index 6afb128..cb7cf54 100644 --- a/src/heurams/kernel/particles/electron.py +++ b/src/heurams/kernel/particles/electron.py @@ -9,7 +9,7 @@ logger = get_logger(__name__) class Electron: """电子: 记忆分析元数据及算法""" - def __init__(self, ident: str, algodata: dict = {}, algo_name: str = "SM-2"): + def __init__(self, ident: str, algodata: dict = {}, algo_name: str = ""): """初始化电子对象 (记忆数据) Args: @@ -17,6 +17,8 @@ class Electron: algodata: 算法数据字典, 包含算法的各项参数和设置 algo: 使用的算法模块标识 """ + if algo_name == "": + algo_name = config_var.get()['algorithm']['default'] logger.debug( "创建 Electron 实例, ident: '%s', algo_name: '%s', algodata: %s", ident, algo_name, algodata )