You've already forked HeurAMS-Classic
fix: 改进与日志简化
This commit is contained in:
@@ -44,38 +44,21 @@ class BaseAlgorithm:
|
||||
cls, algodata: dict, feedback: int = 5, is_new_activation: bool = False
|
||||
) -> None:
|
||||
"""迭代记忆数据"""
|
||||
logger.debug(
|
||||
"BaseAlgorithm.revisor 被调用, algodata keys: %s, feedback: %d, is_new_activation: %s",
|
||||
list(algodata.keys()) if algodata else [],
|
||||
feedback,
|
||||
is_new_activation,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def is_due(cls, algodata) -> int:
|
||||
"""是否应该复习"""
|
||||
logger.debug(
|
||||
"BaseAlgorithm.is_due 被调用, algodata keys: %s",
|
||||
list(algodata.keys()) if algodata else [],
|
||||
)
|
||||
return 1
|
||||
|
||||
@classmethod
|
||||
def get_rating(cls, algodata) -> str:
|
||||
"""获取评分信息"""
|
||||
logger.debug(
|
||||
"BaseAlgorithm.rate 被调用, algodata keys: %s",
|
||||
list(algodata.keys()) if algodata else [],
|
||||
)
|
||||
|
||||
return ""
|
||||
|
||||
@classmethod
|
||||
def nextdate(cls, algodata) -> int:
|
||||
"""获取下一次记忆时间戳"""
|
||||
logger.debug(
|
||||
"BaseAlgorithm.nextdate 被调用, algodata keys: %s",
|
||||
list(algodata.keys()) if algodata else [],
|
||||
)
|
||||
return -1
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -33,7 +33,7 @@ def _get_global_scheduler():
|
||||
with open(_SCHEDULER_STATE_FILE, "r", encoding="utf-8") as f:
|
||||
return Scheduler.from_json(f.read())
|
||||
except Exception:
|
||||
logger.warning("FSRS Scheduler 状态文件加载失败, 创建新实例")
|
||||
logger.warning("No former FSRS Scheduler file founded, creating new instance")
|
||||
return Scheduler()
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ def _save_global_scheduler(scheduler):
|
||||
with open(_SCHEDULER_STATE_FILE, "w", encoding="utf-8") as f:
|
||||
f.write(data)
|
||||
except Exception:
|
||||
logger.exception("FSRS Scheduler 状态保存失败")
|
||||
logger.error("Failed to persist FSRS Scheduler state")
|
||||
|
||||
|
||||
def _feedback_to_rating(feedback: int) -> Rating:
|
||||
@@ -176,14 +176,9 @@ class FSRSAlgorithm(BaseAlgorithm):
|
||||
feedback (int): 0-5 的记忆保留率量化参数
|
||||
is_new_activation: 是否为全新激活(重置为初始状态)
|
||||
"""
|
||||
logger.debug(
|
||||
"FSRS.revisor 开始, feedback: %d, is_new_activation: %s",
|
||||
feedback,
|
||||
is_new_activation,
|
||||
)
|
||||
|
||||
if feedback == -1:
|
||||
logger.debug("feedback 为 -1, 跳过更新")
|
||||
logger.debug("feedback = -1, update skipped")
|
||||
return
|
||||
|
||||
scheduler = _get_global_scheduler()
|
||||
@@ -191,7 +186,7 @@ class FSRSAlgorithm(BaseAlgorithm):
|
||||
|
||||
if is_new_activation:
|
||||
card = Card()
|
||||
logger.debug("新激活, 创建新 Card")
|
||||
logger.debug("New activation, create new Card")
|
||||
else:
|
||||
card = cls._algodata_to_card(algodata)
|
||||
|
||||
@@ -206,7 +201,7 @@ class FSRSAlgorithm(BaseAlgorithm):
|
||||
algodata[cls.algo_name]["rept"] += 1
|
||||
|
||||
logger.debug(
|
||||
"FSRS.revisor 完成: stability=%s, difficulty=%s, state=%s, " "next_date=%d",
|
||||
"FSRS.revisor finished: stability=%s, difficulty=%s, state=%s, " "next_date=%d",
|
||||
card.stability,
|
||||
card.difficulty,
|
||||
card.state,
|
||||
|
||||
@@ -51,7 +51,7 @@ class NSP0Algorithm(BaseAlgorithm):
|
||||
)
|
||||
|
||||
if feedback == -1:
|
||||
logger.debug("feedback 为 -1, 跳过更新")
|
||||
logger.debug("feedback = -1, update skipped")
|
||||
return
|
||||
algodata[cls.algo_name]["interval"] = 1 if feedback <= 3 else float("inf")
|
||||
if not algodata[cls.algo_name]["important"]:
|
||||
@@ -65,7 +65,7 @@ class NSP0Algorithm(BaseAlgorithm):
|
||||
algodata[cls.algo_name]["last_modify"] = timer.get_timestamp()
|
||||
|
||||
logger.debug(
|
||||
"更新日期: last_date=%d, next_date=%d, last_modify=%f",
|
||||
"Update date: last_date=%d, next_date=%d, last_modify=%f",
|
||||
algodata[cls.algo_name]["last_date"],
|
||||
algodata[cls.algo_name]["next_date"],
|
||||
algodata[cls.algo_name]["last_modify"],
|
||||
|
||||
@@ -614,7 +614,7 @@ def _get_global_sm():
|
||||
with open(_GLOBAL_STATE_FILE, "r", encoding="utf-8") as f:
|
||||
return SM.load(json.load(f))
|
||||
except Exception:
|
||||
logger.warning("SM-15M 全局状态文件加载失败, 创建新实例")
|
||||
logger.warning("Failed to load SM-15M global state file, creating new instance")
|
||||
sm = SM()
|
||||
_save_global_sm(sm)
|
||||
return sm
|
||||
@@ -626,7 +626,7 @@ def _save_global_sm(sm):
|
||||
with open(_GLOBAL_STATE_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump(sm.data(), f, indent=2)
|
||||
except Exception:
|
||||
logger.exception("SM-15M 全局状态保存失败")
|
||||
logger.error("Failed to save SM-15M global state")
|
||||
|
||||
|
||||
# ============================================================================
|
||||
@@ -758,7 +758,7 @@ class SM15MAlgorithm(BaseAlgorithm):
|
||||
cls, algodata: dict, feedback: int = 5, is_new_activation: bool = False
|
||||
):
|
||||
logger.debug(
|
||||
"SM-15M.revisor 开始, feedback=%d, is_new_activation=%s",
|
||||
"SM-15M.revisor, feedback=%d, is_new_activation=%s",
|
||||
feedback,
|
||||
is_new_activation,
|
||||
)
|
||||
@@ -788,7 +788,7 @@ class SM15MAlgorithm(BaseAlgorithm):
|
||||
algodata[cls.algo_name]["rept"] += 1
|
||||
|
||||
logger.debug(
|
||||
"SM-15M.revisor 完成: repetition=%d, of=%.4f, next_date=%d",
|
||||
"SM-15M.revisor: repetition=%d, of=%.4f, next_date=%d",
|
||||
item.repetition,
|
||||
item.of,
|
||||
algodata[cls.algo_name]["next_date"],
|
||||
|
||||
@@ -45,13 +45,13 @@ class SM2Algorithm(BaseAlgorithm):
|
||||
quality (int): 记忆保留率量化参数
|
||||
"""
|
||||
logger.debug(
|
||||
"SM2.revisor 开始, feedback: %d, is_new_activation: %s",
|
||||
"SM2.revisor, feedback: %d, is_new_activation: %s",
|
||||
feedback,
|
||||
is_new_activation,
|
||||
)
|
||||
|
||||
if feedback == -1:
|
||||
logger.debug("feedback 为 -1, 跳过更新")
|
||||
logger.debug("feedback = -1, update skipped")
|
||||
return
|
||||
|
||||
algodata[cls.algo_name]["efactor"] = algodata[cls.algo_name]["efactor"] + (
|
||||
@@ -60,7 +60,7 @@ class SM2Algorithm(BaseAlgorithm):
|
||||
algodata[cls.algo_name]["efactor"] = max(
|
||||
1.3, algodata[cls.algo_name]["efactor"]
|
||||
)
|
||||
logger.debug("更新 efactor: %f", algodata[cls.algo_name]["efactor"])
|
||||
logger.debug("Update efactor: %f", algodata[cls.algo_name]["efactor"])
|
||||
|
||||
if feedback < 3:
|
||||
algodata[cls.algo_name]["rept"] = 0
|
||||
@@ -68,28 +68,28 @@ class SM2Algorithm(BaseAlgorithm):
|
||||
logger.debug("feedback < 3, 重置 rept 和 interval")
|
||||
else:
|
||||
algodata[cls.algo_name]["rept"] += 1
|
||||
logger.debug("递增 rept: %d", algodata[cls.algo_name]["rept"])
|
||||
logger.debug("Increase rept: %d", algodata[cls.algo_name]["rept"])
|
||||
|
||||
algodata[cls.algo_name]["real_rept"] += 1
|
||||
logger.debug("递增 real_rept: %d", algodata[cls.algo_name]["real_rept"])
|
||||
logger.debug("Increase real_rept: %d", algodata[cls.algo_name]["real_rept"])
|
||||
|
||||
if is_new_activation:
|
||||
algodata[cls.algo_name]["rept"] = 0
|
||||
algodata[cls.algo_name]["efactor"] = 2.5
|
||||
logger.debug("新激活, 重置 rept 和 efactor")
|
||||
logger.debug("New activation, reset rept and efactor")
|
||||
|
||||
if algodata[cls.algo_name]["rept"] == 0:
|
||||
algodata[cls.algo_name]["interval"] = 1
|
||||
logger.debug("rept=0, 设置 interval=1")
|
||||
logger.debug("rept=0, set interval=1")
|
||||
elif algodata[cls.algo_name]["rept"] == 1:
|
||||
algodata[cls.algo_name]["interval"] = 6
|
||||
logger.debug("rept=1, 设置 interval=6")
|
||||
logger.debug("rept=1, set interval=6")
|
||||
else:
|
||||
algodata[cls.algo_name]["interval"] = round(
|
||||
algodata[cls.algo_name]["interval"] * algodata[cls.algo_name]["efactor"]
|
||||
)
|
||||
logger.debug(
|
||||
"rept>1, 计算 interval: %d", algodata[cls.algo_name]["interval"]
|
||||
"rept>1, providing interval: %d", algodata[cls.algo_name]["interval"]
|
||||
)
|
||||
|
||||
algodata[cls.algo_name]["last_date"] = timer.get_daystamp()
|
||||
@@ -99,7 +99,7 @@ class SM2Algorithm(BaseAlgorithm):
|
||||
algodata[cls.algo_name]["last_modify"] = timer.get_timestamp()
|
||||
|
||||
logger.debug(
|
||||
"更新日期: last_date=%d, next_date=%d, last_modify=%f",
|
||||
"Update date: last_date=%d, next_date=%d, last_modify=%f",
|
||||
algodata[cls.algo_name]["last_date"],
|
||||
algodata[cls.algo_name]["next_date"],
|
||||
algodata[cls.algo_name]["last_modify"],
|
||||
|
||||
Reference in New Issue
Block a user