From 19d0e32b6fb04296672318bd21516791386ca328 Mon Sep 17 00:00:00 2001 From: david-ajax Date: Sun, 14 Sep 2025 01:54:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=94=A8=E6=88=B7=E7=95=8C?= =?UTF-8?q?=E9=9D=A2,=20=E4=BF=AE=E5=A4=8D=E6=80=BB=E5=A4=8D=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NOTE.md | 2 +- config.toml | 4 +-- electron/E-朝天子·咏喇叭.toml | 0 electron/E-贺新郎·国脉微如缕.toml | 0 electron/赤壁赋.toml | 0 llmplugin.py | 1 + main.py | 4 +-- metadata.py | 3 +- particles.py | 48 +++++++++++-------------------- reactor.py | 31 ++++++++++++++++++++ reactor_k.py | 1 + screens.py | 48 ++++++++++++++++++++++++------- 12 files changed, 93 insertions(+), 49 deletions(-) delete mode 100644 electron/E-朝天子·咏喇叭.toml delete mode 100644 electron/E-贺新郎·国脉微如缕.toml delete mode 100644 electron/赤壁赋.toml diff --git a/NOTE.md b/NOTE.md index ff3713c..7fe39bc 100644 --- a/NOTE.md +++ b/NOTE.md @@ -3,7 +3,7 @@ ## 用于数据组织的 prompt ```` markdown -1. 我先给你应该一个文件范例 +1. 我应该先给你一个文件范例 ``` # 散列表的键翻译 ["keydata"] diff --git a/config.toml b/config.toml index 4b35721..04232bd 100644 --- a/config.toml +++ b/config.toml @@ -1,8 +1,8 @@ # [调试] 将更改保存到文件 save = 1 -# [调试] 覆写时间 +# [调试] 覆写时间, 设为 -1 以禁用 time_override = -1 # [调试] 一键通过 quick_pass = 0 # 对于每个项目的新记忆核子数量 -tasked_number = 6 \ No newline at end of file +tasked_number = 6 diff --git a/electron/E-朝天子·咏喇叭.toml b/electron/E-朝天子·咏喇叭.toml deleted file mode 100644 index e69de29..0000000 diff --git a/electron/E-贺新郎·国脉微如缕.toml b/electron/E-贺新郎·国脉微如缕.toml deleted file mode 100644 index e69de29..0000000 diff --git a/electron/赤壁赋.toml b/electron/赤壁赋.toml deleted file mode 100644 index e69de29..0000000 diff --git a/llmplugin.py b/llmplugin.py index e69de29..c567f85 100644 --- a/llmplugin.py +++ b/llmplugin.py @@ -0,0 +1 @@ +# 语言模型接入 \ No newline at end of file diff --git a/main.py b/main.py index a9200f5..551062c 100644 --- a/main.py +++ b/main.py @@ -6,11 +6,11 @@ class AppLauncher(App): TITLE = "潜进 - 辅助记忆程序" BINDINGS = [("escape", "quit", "退出"), ("d", "toggle_dark", "改变色调")] SCREENS = { - "file_selection_screen": screens.FileSelectorScreen, + "dashboard": screens.DashboardScreen, } def on_mount(self) -> None: - self.push_screen("file_selection_screen") + self.push_screen("dashboard") if __name__ == "__main__": diff --git a/metadata.py b/metadata.py index b2eb58e..c6c69d9 100644 --- a/metadata.py +++ b/metadata.py @@ -1 +1,2 @@ -ver = "0.3.3" \ No newline at end of file +ver = "0.3.4" +stage = "prototype" \ No newline at end of file diff --git a/particles.py b/particles.py index d31195d..919ce12 100644 --- a/particles.py +++ b/particles.py @@ -155,7 +155,7 @@ class Nucleon: return Nucleon("核子对象样例内容", {}) -class NucleonUnion: +class NucleonUnion(): """ 替代原有 NucleonFile 类, 支持复杂逻辑 @@ -171,7 +171,7 @@ class NucleonUnion: path (Path): 包含核子数据的文件路径。 """ - def __init__(self, path): + def __init__(self, path: pathlib.Path): self.path = path self.name = path.name.replace(path.suffix, "") with open(path, 'r') as f: @@ -190,6 +190,12 @@ class NucleonUnion: def __len__(self): return len(self.nucleons) + + def linked_electron_union(self): + if (self.path.parent / '..' / 'electron' / self.path.name).exists(): + return ElectronUnion(self.path.parent / '..' / 'electron' / self.path.name) + else: + return 0 def save(self): with open(self.path, 'w') as f: @@ -199,9 +205,9 @@ class NucleonUnion: class ElectronUnion: """取代原有 ElectronFile 类, 以支持复杂逻辑""" - def __init__(self, path): self.path = path + print(path) self.name = path.name.replace(path.suffix, "") with open(path, 'r') as f: all = toml.load(f) @@ -214,8 +220,14 @@ class ElectronUnion: self.electrons_dict = {i.content: i for i in lst} def sync(self): - """同步 electrons_dict 中新增对到 electrons 中""" + """同步 electrons_dict 中新增对到 electrons 中, 仅用于缺省初始化不存在映射时调用""" self.electrons = self.electrons_dict.values() + + def __len__(self): + return len(self.electrons) + + def linked_nucleon_union(self): + return NucleonUnion(self.path.parent / '..' / 'nucleon' / self.path.name) def save(self): # print(1) @@ -227,34 +239,6 @@ class ElectronUnion: toml.dump(tmp, f) -""" -class AtomicFile(): - def __init__(self, path, type_="unknown"): - self.path = path - self.type_ = type_ - if type_ == "nucleon": - self.name, self.datalist = Nucleon.import_from_file(pathlib.Path(path)) - if type_ == "electron": - self.name, self.datalist = Electron.import_from_file(pathlib.Path(path)) - def save(self): - dictobj = {i.content: i.export_data() for i in self.datalist} - print(dictobj) - if self.type_ == "nucleon": - Nucleon.save_to_file(dictobj, self.path) - if self.type_ == "electron": - Electron.save_to_file(dictobj, self.path) - def get_full_content(self): - if self.type_ == "nucleon": - text = "" - for i in self.datalist: - text += i.content - return text - return "" - def get_len(self): - return len(self.datalist) -""" - - class Atom: @staticmethod def placeholder(): diff --git a/reactor.py b/reactor.py index d3ef6b6..da25a27 100644 --- a/reactor.py +++ b/reactor.py @@ -5,6 +5,33 @@ import auxiliary as aux import compositions as comps import random #from pprint import pprint as print # debug + +class Glimpse(): + """轻量级只读, 用于状态指示""" + def __init__(self, nucleon_union: pt.NucleonUnion): + self.name = nucleon_union.name + self.nuc_u = nucleon_union + self.elt_u = self.nuc_u.linked_electron_union() + self.lastest_date = -1 + self.next_date = -1 + self.avg_efactor = 0 + self.total_num = 0 + self.activated_num = 0 + self.is_initialized = 0 + if self.elt_u != 0: + self.is_initialized = 1 + self.total_num = len(self.elt_u.electrons) + for i in self.elt_u.electrons: + self.next_date = max(self.next_date, i['next_date']) + self.lastest_date = max(self.lastest_date, i['last_date']) + if i['is_activated']: + self.avg_efactor += i['efactor'] + self.activated_num += 1 + if self.activated_num == 0: + return + self.avg_efactor = round(self.avg_efactor / self.activated_num, 2) + return + class Apparatus(): """反应器对象, 决策一个原子的不同记忆方式, 并反馈到布局""" def __init__(self, screen, reactor, atom): @@ -44,6 +71,7 @@ class Reactor(): self.screen = screen self.electron_dict = electron_file.electrons_dict self.quality_dict = {} + def electron_dict_get_fallback(key) -> pt.Electron: value = self.electron_dict.get(key) # 如果值不存在,则设置默认值 @@ -101,6 +129,9 @@ class Reactor(): if stage == 1 and len(processions[1]) == 0: stage = 2 ret = 2 + if stage == 1 and len(processions[2]) == 0: + stage = 3 + ret = 3 self.set_round(title=titles[stage], procession=processions[stage]) return ret diff --git a/reactor_k.py b/reactor_k.py index 2f3d792..c329be5 100644 --- a/reactor_k.py +++ b/reactor_k.py @@ -1,3 +1,4 @@ +# reactor.py 设计改进型 尚未完成功能重构 import particles as pt import auxiliary as aux import time diff --git a/screens.py b/screens.py index d64f7b8..e4a6589 100644 --- a/screens.py +++ b/screens.py @@ -7,6 +7,7 @@ from textual.widgets import ( DirectoryTree, ListItem, Label, + Markdown, Static, Button, ) @@ -17,7 +18,7 @@ import threading import edge_tts as tts from playsound import playsound import particles as pt -from reactor import Reactor, Apparatus +from reactor import Reactor, Apparatus, Glimpse import auxiliary as aux import compositions as compo import builtins @@ -45,7 +46,13 @@ class MemScreen(Screen): self.reactor = Reactor(nucleon_file, electron_file, self, tasked_num) self.stage = 1 self.stage += self.reactor.set_round_templated(self.stage) - self.reactor.forward() + first_forward = self.reactor.forward() + print(first_forward) + if first_forward == -1: + self.stage = 3 + self.reactor.set_round_templated(3) + print(self.reactor.forward()) + #self._forward_judge(first_forward) self.compo = next(self.reactor.current_appar) def compose(self) -> ComposeResult: @@ -184,28 +191,47 @@ class PreparationScreen(Screen): ) self.app.push_screen(newscr) - -class FileSelectorScreen(Screen): - +class DashboardScreen(Screen): def compose(self) -> ComposeResult: yield Header(show_clock=True) yield Container( - Label(f'欢迎使用 "潜进" 辅助记忆软件, 版本 {metadata.ver}', classes="title-label"), - Label("选择要学习的文件:", classes="title-label"), + Label(f'欢迎使用 "潜进" 启发式辅助记忆调度器, 版本 {metadata.ver}', classes="title-label"), + Label(f"当前的 UNIX 日时间戳: {aux.get_daystamp()}"), + Label("选择待学习的记忆单元:", classes="title-label"), ListView(id="file-list", classes="file-list-view"), + Label(f"\"潜进\" 开放源代码软件项目 | 版本 {metadata.ver} {metadata.stage.capitalize()} | Wang Zhiyu 2025"), ) yield Footer() + + def item_desc_generator(self, path) -> dict: + gmp = Glimpse(pt.NucleonUnion(path)) + res = dict() + res[0] = f"{gmp.name}.toml\0" + res[1] = f"" + if gmp.is_initialized: + res[1] += f" 已激活单元: {gmp.activated_num}/{gmp.total_num}\n" + res[1] += f" 下一次复习: {gmp.next_date} (最后复习于 {gmp.lastest_date})\n" + res[1] += f" 系数均值: {gmp.avg_efactor}" + else: + res[1] = " 尚未激活" + return res def on_mount(self) -> None: file_list_widget = self.query_one("#file-list", ListView) nucleon_path = pathlib.Path("./nucleon") nucleon_files = sorted( - [f.name for f in nucleon_path.iterdir() if f.suffix == ".toml"] + [f for f in nucleon_path.iterdir() if f.suffix == ".toml"], + key=lambda f: Glimpse(pt.NucleonUnion(f)).next_date, + reverse=True ) if nucleon_files: - for filename in nucleon_files: - file_list_widget.append(ListItem(Label(filename))) + for file in nucleon_files: + text = self.item_desc_generator(pathlib.Path(file)) + file_list_widget.append(ListItem( + Label(text[0]), + Label(text[1]), + )) else: file_list_widget.append( ListItem(Static("在 ./nucleon/ 中未找到任何核子文件. 请放置文件后重启应用.")) @@ -220,7 +246,7 @@ class FileSelectorScreen(Screen): if "未找到任何 .toml 文件" in str(selected_label.renderable): return - selected_filename = str(selected_label.renderable) + selected_filename = str(selected_label.renderable).partition('\0')[0].replace('*', "") nucleon_file = pt.NucleonUnion( pathlib.Path("./nucleon") / selected_filename )