fix: 改进
This commit is contained in:
@@ -22,7 +22,6 @@ tts_text = "eval:nucleon['content'].replace('/', '')"
|
|||||||
# 我们称 "Recognition" 为 recognition 谜题的 alia
|
# 我们称 "Recognition" 为 recognition 谜题的 alia
|
||||||
"Recognition" = { __origin__ = "recognition", __hint__ = "", primary = "eval:nucleon['content']", secondary = ["eval:nucleon['keyword_note']", "eval:nucleon['note']"], top_dim = ["eval:nucleon['translation']"] }
|
"Recognition" = { __origin__ = "recognition", __hint__ = "", primary = "eval:nucleon['content']", secondary = ["eval:nucleon['keyword_note']", "eval:nucleon['note']"], top_dim = ["eval:nucleon['translation']"] }
|
||||||
"SelectMeaning" = { __origin__ = "mcq", __hint__ = "eval:nucleon['content']", primary = "eval:nucleon['content']", mapping = "eval:nucleon['keyword_note']", jammer = "eval:list(nucleon['keyword_note'].values())", max_riddles_num = "eval:default['mcq']['max_riddles_num']", prefix = "选择正确项: " }
|
"SelectMeaning" = { __origin__ = "mcq", __hint__ = "eval:nucleon['content']", primary = "eval:nucleon['content']", mapping = "eval:nucleon['keyword_note']", jammer = "eval:list(nucleon['keyword_note'].values())", max_riddles_num = "eval:default['mcq']['max_riddles_num']", prefix = "选择正确项: " }
|
||||||
#"FillBlank" = { __origin__ = "mcq", __hint__ = "eval:nucleon['content']", primary = "eval:nucleon['content']", mapping = "eval:nucleon['keyword_note']", jammer = "eval:list(nucleon['keyword_note'].values())", max_riddles_num = "eval:default['mcq']['max_riddles_num']", prefix = "选择正确项: " }
|
|
||||||
"FillBlank" = { __origin__ = "cloze", __hint__ = "", text = "eval:nucleon['content']", delimiter = "eval:metadata['formation']['delimiter']", min_denominator = "eval:default['cloze']['min_denominator']"}
|
"FillBlank" = { __origin__ = "cloze", __hint__ = "", text = "eval:nucleon['content']", delimiter = "eval:metadata['formation']['delimiter']", min_denominator = "eval:default['cloze']['min_denominator']"}
|
||||||
|
|
||||||
#debug
|
#debug
|
||||||
|
|||||||
@@ -18,9 +18,11 @@ import heurams.services.version as version
|
|||||||
import heurams.services.timer as timer
|
import heurams.services.timer as timer
|
||||||
from .preparation import PreparationScreen
|
from .preparation import PreparationScreen
|
||||||
from .about import AboutScreen
|
from .about import AboutScreen
|
||||||
|
from heurams.services.logger import get_logger
|
||||||
|
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
class DashboardScreen(Screen):
|
class DashboardScreen(Screen):
|
||||||
|
|
||||||
@@ -53,6 +55,9 @@ class DashboardScreen(Screen):
|
|||||||
electron_file_path = pathlib.Path(config_var.get()["paths"]["electron_dir"]) / (
|
electron_file_path = pathlib.Path(config_var.get()["paths"]["electron_dir"]) / (
|
||||||
filestem + ".json"
|
filestem + ".json"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
logger.debug(f"电子文件路径: {electron_file_path}")
|
||||||
|
|
||||||
if electron_file_path.exists(): # 未找到则创建电子文件 (json)
|
if electron_file_path.exists(): # 未找到则创建电子文件 (json)
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@@ -60,6 +65,7 @@ class DashboardScreen(Screen):
|
|||||||
with open(electron_file_path, "w") as f:
|
with open(electron_file_path, "w") as f:
|
||||||
f.write("{}")
|
f.write("{}")
|
||||||
electron_dict = load_electron(path=electron_file_path) # TODO: 取消硬编码扩展名
|
electron_dict = load_electron(path=electron_file_path) # TODO: 取消硬编码扩展名
|
||||||
|
logger.debug(electron_dict)
|
||||||
is_due = 0
|
is_due = 0
|
||||||
is_activated = 0
|
is_activated = 0
|
||||||
nextdate = 0x3F3F3F3F
|
nextdate = 0x3F3F3F3F
|
||||||
|
|||||||
@@ -113,6 +113,9 @@ class MemScreen(Screen):
|
|||||||
self.procession = self.phaser.current_procession() # type: ignore
|
self.procession = self.phaser.current_procession() # type: ignore
|
||||||
if self.procession == 0:
|
if self.procession == 0:
|
||||||
logger.debug(f"记忆进程结束")
|
logger.debug(f"记忆进程结束")
|
||||||
|
for i in self.atoms:
|
||||||
|
i: pt.Atom
|
||||||
|
i.persist("electron")
|
||||||
self.load_finished_widget()
|
self.load_finished_widget()
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -143,12 +143,18 @@ class Atom:
|
|||||||
logger.debug("持久化路径: %s, 格式: %s", path, self.registry[key + "_fmt"])
|
logger.debug("持久化路径: %s, 格式: %s", path, self.registry[key + "_fmt"])
|
||||||
path.parent.mkdir(parents=True, exist_ok=True)
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
if self.registry[key + "_fmt"] == "toml":
|
if self.registry[key + "_fmt"] == "toml":
|
||||||
with open(path, "w") as f:
|
with open(path, "r+") as f:
|
||||||
|
f.seek(0)
|
||||||
|
f.truncate()
|
||||||
toml.dump(self.registry[key], f)
|
toml.dump(self.registry[key], f)
|
||||||
logger.debug("TOML 数据已保存到: %s", path)
|
logger.debug("TOML 数据已保存到: %s", path)
|
||||||
elif self.registry[key + "_fmt"] == "json":
|
elif self.registry[key + "_fmt"] == "json":
|
||||||
with open(path, "w") as f:
|
with open(path, "r+") as f:
|
||||||
json.dump(self.registry[key], f)
|
origin = json.load(f)
|
||||||
|
f.seek(0)
|
||||||
|
f.truncate()
|
||||||
|
origin[self.ident] = self.registry[key].algodata
|
||||||
|
json.dump(origin, f, indent=2, ensure_ascii=False)
|
||||||
logger.debug("JSON 数据已保存到: %s", path)
|
logger.debug("JSON 数据已保存到: %s", path)
|
||||||
else:
|
else:
|
||||||
logger.error("不受支持的持久化格式: %s", self.registry[key + "_fmt"])
|
logger.error("不受支持的持久化格式: %s", self.registry[key + "_fmt"])
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ class Electron:
|
|||||||
logger.debug("使用的算法类: %s", self.algo.__name__)
|
logger.debug("使用的算法类: %s", self.algo.__name__)
|
||||||
|
|
||||||
if self.algo not in self.algodata.keys():
|
if self.algo not in self.algodata.keys():
|
||||||
self.algodata[self.algo] = {}
|
self.algodata[self.algo.algo_name] = {}
|
||||||
logger.debug("算法键 '%s' 不存在,已创建空字典", self.algo)
|
logger.debug("算法键 '%s' 不存在,已创建空字典", self.algo)
|
||||||
if not self.algodata[self.algo]:
|
if not self.algodata[self.algo.algo_name]:
|
||||||
logger.debug("算法数据为空,使用默认值初始化")
|
logger.debug("算法数据为空,使用默认值初始化")
|
||||||
self._default_init(self.algo.defaults)
|
self._default_init(self.algo.defaults)
|
||||||
else:
|
else:
|
||||||
@@ -36,21 +36,21 @@ class Electron:
|
|||||||
def _default_init(self, defaults: dict):
|
def _default_init(self, defaults: dict):
|
||||||
"""默认初始化包装"""
|
"""默认初始化包装"""
|
||||||
logger.debug("Electron._default_init: 使用默认值,keys: %s", list(defaults.keys()))
|
logger.debug("Electron._default_init: 使用默认值,keys: %s", list(defaults.keys()))
|
||||||
self.algodata[self.algo] = defaults.copy()
|
self.algodata[self.algo.algo_name] = defaults.copy()
|
||||||
|
|
||||||
def activate(self):
|
def activate(self):
|
||||||
"""激活此电子"""
|
"""激活此电子"""
|
||||||
logger.debug("Electron.activate: 激活 ident='%s'", self.ident)
|
logger.debug("Electron.activate: 激活 ident='%s'", self.ident)
|
||||||
self.algodata[self.algo]["is_activated"] = 1
|
self.algodata[self.algo.algo_name]["is_activated"] = 1
|
||||||
self.algodata[self.algo]["last_modify"] = timer.get_timestamp()
|
self.algodata[self.algo.algo_name]["last_modify"] = timer.get_timestamp()
|
||||||
logger.debug("电子已激活,is_activated=1")
|
logger.debug("电子已激活,is_activated=1")
|
||||||
|
|
||||||
def modify(self, var: str, value):
|
def modify(self, var: str, value):
|
||||||
"""修改 algodata[algo] 中子字典数据"""
|
"""修改 algodata[algo] 中子字典数据"""
|
||||||
logger.debug("Electron.modify: var='%s', value=%s", var, value)
|
logger.debug("Electron.modify: var='%s', value=%s", var, value)
|
||||||
if var in self.algodata[self.algo]:
|
if var in self.algodata[self.algo.algo_name]:
|
||||||
self.algodata[self.algo][var] = value
|
self.algodata[self.algo.algo_name][var] = value
|
||||||
self.algodata[self.algo]["last_modify"] = timer.get_timestamp()
|
self.algodata[self.algo.algo_name]["last_modify"] = timer.get_timestamp()
|
||||||
logger.debug("变量 '%s' 已修改,更新 last_modify", var)
|
logger.debug("变量 '%s' 已修改,更新 last_modify", var)
|
||||||
else:
|
else:
|
||||||
logger.warning("'%s' 非已知元数据字段", var)
|
logger.warning("'%s' 非已知元数据字段", var)
|
||||||
@@ -64,7 +64,7 @@ class Electron:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def is_activated(self):
|
def is_activated(self):
|
||||||
result = self.algodata[self.algo]["is_activated"]
|
result = self.algodata[self.algo.algo_name]["is_activated"]
|
||||||
logger.debug("Electron.is_activated: ident='%s', 结果: %d", self.ident, result)
|
logger.debug("Electron.is_activated: ident='%s', 结果: %d", self.ident, result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -98,10 +98,10 @@ class Electron:
|
|||||||
f"记忆单元预览 \n"
|
f"记忆单元预览 \n"
|
||||||
f"标识符: '{self.ident}' \n"
|
f"标识符: '{self.ident}' \n"
|
||||||
f"算法: {self.algo} \n"
|
f"算法: {self.algo} \n"
|
||||||
f"易度系数: {self.algodata[self.algo]['efactor']:.2f} \n"
|
f"易度系数: {self.algodata[self.algo.algo_name]['efactor']:.2f} \n"
|
||||||
f"已经重复的次数: {self.algodata[self.algo]['rept']} \n"
|
f"已经重复的次数: {self.algodata[self.algo.algo_name]['rept']} \n"
|
||||||
f"下次间隔: {self.algodata[self.algo]['interval']} 天 \n"
|
f"下次间隔: {self.algodata[self.algo.algo_name]['interval']} 天 \n"
|
||||||
f"下次复习日期时间戳: {self.algodata[self.algo]['next_date']}"
|
f"下次复习日期时间戳: {self.algodata[self.algo.algo_name]['next_date']}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
@@ -115,20 +115,20 @@ class Electron:
|
|||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
if key == "ident":
|
if key == "ident":
|
||||||
return self.ident
|
return self.ident
|
||||||
if key in self.algodata[self.algo]:
|
if key in self.algodata[self.algo.algo_name]:
|
||||||
return self.algodata[self.algo][key]
|
return self.algodata[self.algo.algo_name][key]
|
||||||
else:
|
else:
|
||||||
raise KeyError(f"键 '{key}' 未在 algodata[self.algo] 中")
|
raise KeyError(f"键 '{key}' 未在 algodata[self.algo] 中")
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
if key == "ident":
|
if key == "ident":
|
||||||
raise AttributeError("ident 应为只读")
|
raise AttributeError("ident 应为只读")
|
||||||
self.algodata[self.algo][key] = value
|
self.algodata[self.algo.algo_name][key] = value
|
||||||
self.algodata[self.algo]["last_modify"] = timer.get_timestamp()
|
self.algodata[self.algo.algo_name]["last_modify"] = timer.get_timestamp()
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
"""仅返回当前算法的配置数量"""
|
"""仅返回当前算法的配置数量"""
|
||||||
return len(self.algodata[self.algo])
|
return len(self.algodata[self.algo.algo_name])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def placeholder():
|
def placeholder():
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ def load_nucleon(path: pathlib.Path, fmt="toml"):
|
|||||||
lst.append(
|
lst.append(
|
||||||
(
|
(
|
||||||
Nucleon(
|
Nucleon(
|
||||||
hasher.hash(item), attr, deepcopy(nested_data["__metadata__"])
|
item, attr, deepcopy(nested_data["__metadata__"])
|
||||||
),
|
),
|
||||||
deepcopy(nested_data["__metadata__"]["orbital"]),
|
deepcopy(nested_data["__metadata__"]["orbital"]),
|
||||||
)
|
)
|
||||||
@@ -68,6 +68,6 @@ def load_electron(path: pathlib.Path, fmt="json") -> dict:
|
|||||||
dic = dict()
|
dic = dict()
|
||||||
for item, attr in dictdata.items():
|
for item, attr in dictdata.items():
|
||||||
logger.debug("处理电子项目: %s", item)
|
logger.debug("处理电子项目: %s", item)
|
||||||
dic[item] = Electron(hasher.hash(item), attr)
|
dic[item] = Electron(item, attr)
|
||||||
logger.debug("load_electron 完成,加载了 %d 个 Electron 对象", len(dic))
|
logger.debug("load_electron 完成,加载了 %d 个 Electron 对象", len(dic))
|
||||||
return dic
|
return dic
|
||||||
|
|||||||
Reference in New Issue
Block a user