更新用户界面, 修复总复习
This commit is contained in:
2
NOTE.md
2
NOTE.md
@@ -3,7 +3,7 @@
|
|||||||
## 用于数据组织的 prompt
|
## 用于数据组织的 prompt
|
||||||
|
|
||||||
```` markdown
|
```` markdown
|
||||||
1. 我先给你应该一个文件范例
|
1. 我应该先给你一个文件范例
|
||||||
```
|
```
|
||||||
# 散列表的键翻译
|
# 散列表的键翻译
|
||||||
["keydata"]
|
["keydata"]
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
# [调试] 将更改保存到文件
|
# [调试] 将更改保存到文件
|
||||||
save = 1
|
save = 1
|
||||||
# [调试] 覆写时间
|
# [调试] 覆写时间, 设为 -1 以禁用
|
||||||
time_override = -1
|
time_override = -1
|
||||||
# [调试] 一键通过
|
# [调试] 一键通过
|
||||||
quick_pass = 0
|
quick_pass = 0
|
||||||
# 对于每个项目的新记忆核子数量
|
# 对于每个项目的新记忆核子数量
|
||||||
tasked_number = 6
|
tasked_number = 6
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
# 语言模型接入
|
4
main.py
4
main.py
@@ -6,11 +6,11 @@ class AppLauncher(App):
|
|||||||
TITLE = "潜进 - 辅助记忆程序"
|
TITLE = "潜进 - 辅助记忆程序"
|
||||||
BINDINGS = [("escape", "quit", "退出"), ("d", "toggle_dark", "改变色调")]
|
BINDINGS = [("escape", "quit", "退出"), ("d", "toggle_dark", "改变色调")]
|
||||||
SCREENS = {
|
SCREENS = {
|
||||||
"file_selection_screen": screens.FileSelectorScreen,
|
"dashboard": screens.DashboardScreen,
|
||||||
}
|
}
|
||||||
|
|
||||||
def on_mount(self) -> None:
|
def on_mount(self) -> None:
|
||||||
self.push_screen("file_selection_screen")
|
self.push_screen("dashboard")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@@ -1 +1,2 @@
|
|||||||
ver = "0.3.3"
|
ver = "0.3.4"
|
||||||
|
stage = "prototype"
|
48
particles.py
48
particles.py
@@ -155,7 +155,7 @@ class Nucleon:
|
|||||||
return Nucleon("核子对象样例内容", {})
|
return Nucleon("核子对象样例内容", {})
|
||||||
|
|
||||||
|
|
||||||
class NucleonUnion:
|
class NucleonUnion():
|
||||||
"""
|
"""
|
||||||
替代原有 NucleonFile 类, 支持复杂逻辑
|
替代原有 NucleonFile 类, 支持复杂逻辑
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ class NucleonUnion:
|
|||||||
path (Path): 包含核子数据的文件路径。
|
path (Path): 包含核子数据的文件路径。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, path):
|
def __init__(self, path: pathlib.Path):
|
||||||
self.path = path
|
self.path = path
|
||||||
self.name = path.name.replace(path.suffix, "")
|
self.name = path.name.replace(path.suffix, "")
|
||||||
with open(path, 'r') as f:
|
with open(path, 'r') as f:
|
||||||
@@ -190,6 +190,12 @@ class NucleonUnion:
|
|||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.nucleons)
|
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):
|
def save(self):
|
||||||
with open(self.path, 'w') as f:
|
with open(self.path, 'w') as f:
|
||||||
@@ -199,9 +205,9 @@ class NucleonUnion:
|
|||||||
|
|
||||||
class ElectronUnion:
|
class ElectronUnion:
|
||||||
"""取代原有 ElectronFile 类, 以支持复杂逻辑"""
|
"""取代原有 ElectronFile 类, 以支持复杂逻辑"""
|
||||||
|
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.path = path
|
self.path = path
|
||||||
|
print(path)
|
||||||
self.name = path.name.replace(path.suffix, "")
|
self.name = path.name.replace(path.suffix, "")
|
||||||
with open(path, 'r') as f:
|
with open(path, 'r') as f:
|
||||||
all = toml.load(f)
|
all = toml.load(f)
|
||||||
@@ -214,8 +220,14 @@ class ElectronUnion:
|
|||||||
self.electrons_dict = {i.content: i for i in lst}
|
self.electrons_dict = {i.content: i for i in lst}
|
||||||
|
|
||||||
def sync(self):
|
def sync(self):
|
||||||
"""同步 electrons_dict 中新增对到 electrons 中"""
|
"""同步 electrons_dict 中新增对到 electrons 中, 仅用于缺省初始化不存在映射时调用"""
|
||||||
self.electrons = self.electrons_dict.values()
|
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):
|
def save(self):
|
||||||
# print(1)
|
# print(1)
|
||||||
@@ -227,34 +239,6 @@ class ElectronUnion:
|
|||||||
toml.dump(tmp, f)
|
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:
|
class Atom:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def placeholder():
|
def placeholder():
|
||||||
|
31
reactor.py
31
reactor.py
@@ -5,6 +5,33 @@ import auxiliary as aux
|
|||||||
import compositions as comps
|
import compositions as comps
|
||||||
import random
|
import random
|
||||||
#from pprint import pprint as print # debug
|
#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():
|
class Apparatus():
|
||||||
"""反应器对象, 决策一个原子的不同记忆方式, 并反馈到布局"""
|
"""反应器对象, 决策一个原子的不同记忆方式, 并反馈到布局"""
|
||||||
def __init__(self, screen, reactor, atom):
|
def __init__(self, screen, reactor, atom):
|
||||||
@@ -44,6 +71,7 @@ class Reactor():
|
|||||||
self.screen = screen
|
self.screen = screen
|
||||||
self.electron_dict = electron_file.electrons_dict
|
self.electron_dict = electron_file.electrons_dict
|
||||||
self.quality_dict = {}
|
self.quality_dict = {}
|
||||||
|
|
||||||
def electron_dict_get_fallback(key) -> pt.Electron:
|
def electron_dict_get_fallback(key) -> pt.Electron:
|
||||||
value = self.electron_dict.get(key)
|
value = self.electron_dict.get(key)
|
||||||
# 如果值不存在,则设置默认值
|
# 如果值不存在,则设置默认值
|
||||||
@@ -101,6 +129,9 @@ class Reactor():
|
|||||||
if stage == 1 and len(processions[1]) == 0:
|
if stage == 1 and len(processions[1]) == 0:
|
||||||
stage = 2
|
stage = 2
|
||||||
ret = 2
|
ret = 2
|
||||||
|
if stage == 1 and len(processions[2]) == 0:
|
||||||
|
stage = 3
|
||||||
|
ret = 3
|
||||||
self.set_round(title=titles[stage], procession=processions[stage])
|
self.set_round(title=titles[stage], procession=processions[stage])
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
# reactor.py 设计改进型 尚未完成功能重构
|
||||||
import particles as pt
|
import particles as pt
|
||||||
import auxiliary as aux
|
import auxiliary as aux
|
||||||
import time
|
import time
|
||||||
|
48
screens.py
48
screens.py
@@ -7,6 +7,7 @@ from textual.widgets import (
|
|||||||
DirectoryTree,
|
DirectoryTree,
|
||||||
ListItem,
|
ListItem,
|
||||||
Label,
|
Label,
|
||||||
|
Markdown,
|
||||||
Static,
|
Static,
|
||||||
Button,
|
Button,
|
||||||
)
|
)
|
||||||
@@ -17,7 +18,7 @@ import threading
|
|||||||
import edge_tts as tts
|
import edge_tts as tts
|
||||||
from playsound import playsound
|
from playsound import playsound
|
||||||
import particles as pt
|
import particles as pt
|
||||||
from reactor import Reactor, Apparatus
|
from reactor import Reactor, Apparatus, Glimpse
|
||||||
import auxiliary as aux
|
import auxiliary as aux
|
||||||
import compositions as compo
|
import compositions as compo
|
||||||
import builtins
|
import builtins
|
||||||
@@ -45,7 +46,13 @@ class MemScreen(Screen):
|
|||||||
self.reactor = Reactor(nucleon_file, electron_file, self, tasked_num)
|
self.reactor = Reactor(nucleon_file, electron_file, self, tasked_num)
|
||||||
self.stage = 1
|
self.stage = 1
|
||||||
self.stage += self.reactor.set_round_templated(self.stage)
|
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)
|
self.compo = next(self.reactor.current_appar)
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
@@ -184,28 +191,47 @@ class PreparationScreen(Screen):
|
|||||||
)
|
)
|
||||||
self.app.push_screen(newscr)
|
self.app.push_screen(newscr)
|
||||||
|
|
||||||
|
class DashboardScreen(Screen):
|
||||||
class FileSelectorScreen(Screen):
|
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
yield Header(show_clock=True)
|
yield Header(show_clock=True)
|
||||||
yield Container(
|
yield Container(
|
||||||
Label(f'欢迎使用 "潜进" 辅助记忆软件, 版本 {metadata.ver}', classes="title-label"),
|
Label(f'欢迎使用 "潜进" 启发式辅助记忆调度器, 版本 {metadata.ver}', classes="title-label"),
|
||||||
Label("选择要学习的文件:", classes="title-label"),
|
Label(f"当前的 UNIX 日时间戳: {aux.get_daystamp()}"),
|
||||||
|
Label("选择待学习的记忆单元:", classes="title-label"),
|
||||||
ListView(id="file-list", classes="file-list-view"),
|
ListView(id="file-list", classes="file-list-view"),
|
||||||
|
Label(f"\"潜进\" 开放源代码软件项目 | 版本 {metadata.ver} {metadata.stage.capitalize()} | Wang Zhiyu 2025"),
|
||||||
)
|
)
|
||||||
yield Footer()
|
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:
|
def on_mount(self) -> None:
|
||||||
file_list_widget = self.query_one("#file-list", ListView)
|
file_list_widget = self.query_one("#file-list", ListView)
|
||||||
nucleon_path = pathlib.Path("./nucleon")
|
nucleon_path = pathlib.Path("./nucleon")
|
||||||
nucleon_files = sorted(
|
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:
|
if nucleon_files:
|
||||||
for filename in nucleon_files:
|
for file in nucleon_files:
|
||||||
file_list_widget.append(ListItem(Label(filename)))
|
text = self.item_desc_generator(pathlib.Path(file))
|
||||||
|
file_list_widget.append(ListItem(
|
||||||
|
Label(text[0]),
|
||||||
|
Label(text[1]),
|
||||||
|
))
|
||||||
else:
|
else:
|
||||||
file_list_widget.append(
|
file_list_widget.append(
|
||||||
ListItem(Static("在 ./nucleon/ 中未找到任何核子文件. 请放置文件后重启应用."))
|
ListItem(Static("在 ./nucleon/ 中未找到任何核子文件. 请放置文件后重启应用."))
|
||||||
@@ -220,7 +246,7 @@ class FileSelectorScreen(Screen):
|
|||||||
if "未找到任何 .toml 文件" in str(selected_label.renderable):
|
if "未找到任何 .toml 文件" in str(selected_label.renderable):
|
||||||
return
|
return
|
||||||
|
|
||||||
selected_filename = str(selected_label.renderable)
|
selected_filename = str(selected_label.renderable).partition('\0')[0].replace('*', "")
|
||||||
nucleon_file = pt.NucleonUnion(
|
nucleon_file = pt.NucleonUnion(
|
||||||
pathlib.Path("./nucleon") / selected_filename
|
pathlib.Path("./nucleon") / selected_filename
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user