You've already forked HeurAMS-legacy
format
This commit is contained in:
@@ -82,5 +82,6 @@ app = HeurAMSApp()
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run()
|
app.run()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
app.run()
|
app.run()
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ from heurams.context import config_var
|
|||||||
class NucleonCreatorScreen(Screen):
|
class NucleonCreatorScreen(Screen):
|
||||||
BINDINGS = [("q", "go_back", "返回")]
|
BINDINGS = [("q", "go_back", "返回")]
|
||||||
SUB_TITLE = "单元集创建向导"
|
SUB_TITLE = "单元集创建向导"
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__(name=None, id=None, classes=None)
|
super().__init__(name=None, id=None, classes=None)
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class PrecachingScreen(Screen):
|
|||||||
nucleons (list): 可选列表, 仅包含 Nucleon 对象
|
nucleons (list): 可选列表, 仅包含 Nucleon 对象
|
||||||
desc (list): 可选字符串, 包含对此次调用的文字描述
|
desc (list): 可选字符串, 包含对此次调用的文字描述
|
||||||
"""
|
"""
|
||||||
|
|
||||||
SUB_TITLE = "缓存管理器"
|
SUB_TITLE = "缓存管理器"
|
||||||
BINDINGS = [("q", "go_back", "返回")]
|
BINDINGS = [("q", "go_back", "返回")]
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class PreparationScreen(Screen):
|
|||||||
("0,1,2,3", "app.push_screen('about')", ""),
|
("0,1,2,3", "app.push_screen('about')", ""),
|
||||||
]
|
]
|
||||||
|
|
||||||
scheduled_num = reactive(config_var.get()['scheduled_num'])
|
scheduled_num = reactive(config_var.get()["scheduled_num"])
|
||||||
|
|
||||||
def __init__(self, nucleon_file: pathlib.Path, electron_file: pathlib.Path) -> None:
|
def __init__(self, nucleon_file: pathlib.Path, electron_file: pathlib.Path) -> None:
|
||||||
super().__init__(name=None, id=None, classes=None)
|
super().__init__(name=None, id=None, classes=None)
|
||||||
@@ -45,8 +45,12 @@ class PreparationScreen(Screen):
|
|||||||
yield Header(show_clock=True)
|
yield Header(show_clock=True)
|
||||||
with ScrollableContainer(id="vice_container"):
|
with ScrollableContainer(id="vice_container"):
|
||||||
yield Label(f"准备就绪: [b]{self.nucleon_file.stem}[/b]\n")
|
yield Label(f"准备就绪: [b]{self.nucleon_file.stem}[/b]\n")
|
||||||
yield Label(f"内容源文件: {config_var.get()['paths']['nucleon_dir']}/[b]{self.nucleon_file.name}[/b]")
|
yield Label(
|
||||||
yield Label(f"元数据文件: {config_var.get()['paths']['electron_dir']}/[b]{self.electron_file.name}[/b]")
|
f"内容源文件: {config_var.get()['paths']['nucleon_dir']}/[b]{self.nucleon_file.name}[/b]"
|
||||||
|
)
|
||||||
|
yield Label(
|
||||||
|
f"元数据文件: {config_var.get()['paths']['electron_dir']}/[b]{self.electron_file.name}[/b]"
|
||||||
|
)
|
||||||
yield Label(f"\n单元数量: {len(self.nucleons_with_orbital)}\n")
|
yield Label(f"\n单元数量: {len(self.nucleons_with_orbital)}\n")
|
||||||
yield Label(f"单次记忆数量: {self.scheduled_num}", id="schnum_label")
|
yield Label(f"单次记忆数量: {self.scheduled_num}", id="schnum_label")
|
||||||
|
|
||||||
@@ -67,7 +71,7 @@ class PreparationScreen(Screen):
|
|||||||
yield Markdown(self._get_full_content().replace("/", ""), classes="full")
|
yield Markdown(self._get_full_content().replace("/", ""), classes="full")
|
||||||
yield Footer()
|
yield Footer()
|
||||||
|
|
||||||
#def watch_scheduled_num(self, old_scheduled_num, new_scheduled_num):
|
# def watch_scheduled_num(self, old_scheduled_num, new_scheduled_num):
|
||||||
# logger.debug("响应", old_scheduled_num, "->", new_scheduled_num)
|
# logger.debug("响应", old_scheduled_num, "->", new_scheduled_num)
|
||||||
# try:
|
# try:
|
||||||
# one = self.query_one("#schnum_label")
|
# one = self.query_one("#schnum_label")
|
||||||
@@ -133,6 +137,7 @@ class PreparationScreen(Screen):
|
|||||||
atoms_to_provide.append(i)
|
atoms_to_provide.append(i)
|
||||||
logger.debug(f"ATP: {atoms_to_provide}")
|
logger.debug(f"ATP: {atoms_to_provide}")
|
||||||
from .memorizor import MemScreen
|
from .memorizor import MemScreen
|
||||||
|
|
||||||
memscreen = MemScreen(atoms_to_provide)
|
memscreen = MemScreen(atoms_to_provide)
|
||||||
self.app.push_screen(memscreen)
|
self.app.push_screen(memscreen)
|
||||||
elif event.button.id == "precache_button":
|
elif event.button.id == "precache_button":
|
||||||
|
|||||||
@@ -158,4 +158,3 @@ class MCQPuzzle(BasePuzzleWidget):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.atom.minimize(rating)
|
self.atom.minimize(rating)
|
||||||
|
|
||||||
@@ -17,6 +17,7 @@ from heurams.services.logger import get_logger
|
|||||||
|
|
||||||
logger = get_logger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class RecognitionConfig(TypedDict):
|
class RecognitionConfig(TypedDict):
|
||||||
__origin__: str
|
__origin__: str
|
||||||
__hint__: str
|
__hint__: str
|
||||||
|
|||||||
@@ -12,10 +12,12 @@ from heurams.services.logger import get_logger
|
|||||||
|
|
||||||
logger = get_logger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class AtomRegister_runtime(TypedDict):
|
class AtomRegister_runtime(TypedDict):
|
||||||
locked: bool # 只读锁定标识符
|
locked: bool # 只读锁定标识符
|
||||||
min_rate: int # 最低评分
|
min_rate: int # 最低评分
|
||||||
|
|
||||||
|
|
||||||
class AtomRegister(TypedDict):
|
class AtomRegister(TypedDict):
|
||||||
nucleon: Nucleon
|
nucleon: Nucleon
|
||||||
nucleon_path: pathlib.Path
|
nucleon_path: pathlib.Path
|
||||||
@@ -54,7 +56,7 @@ class Atom:
|
|||||||
"orbital": None,
|
"orbital": None,
|
||||||
"orbital_path": None, # 允许设置为 None, 此时使用 nucleon 文件内的推荐配置
|
"orbital_path": None, # 允许设置为 None, 此时使用 nucleon 文件内的推荐配置
|
||||||
"orbital_fmt": "toml",
|
"orbital_fmt": "toml",
|
||||||
"runtime": {"locked": False, "min_rate": 0x3f3f3f3f}
|
"runtime": {"locked": False, "min_rate": 0x3F3F3F3F},
|
||||||
}
|
}
|
||||||
self.do_eval()
|
self.do_eval()
|
||||||
logger.debug("Atom 初始化完成")
|
logger.debug("Atom 初始化完成")
|
||||||
@@ -75,19 +77,20 @@ class Atom:
|
|||||||
Args:
|
Args:
|
||||||
rating (int): 评分
|
rating (int): 评分
|
||||||
"""
|
"""
|
||||||
self.registry['runtime']['min_rate'] = min(rating, self.registry['runtime']['min_rate'])
|
self.registry["runtime"]["min_rate"] = min(
|
||||||
|
rating, self.registry["runtime"]["min_rate"]
|
||||||
|
)
|
||||||
|
|
||||||
def lock(self, locked = -1):
|
def lock(self, locked=-1):
|
||||||
"""锁定, 效果等同于 self.registry['runtime']['locked'] = locked 或者返回是否锁定
|
"""锁定, 效果等同于 self.registry['runtime']['locked'] = locked 或者返回是否锁定"""
|
||||||
"""
|
|
||||||
if locked == 1:
|
if locked == 1:
|
||||||
self.registry['runtime']['locked'] = True
|
self.registry["runtime"]["locked"] = True
|
||||||
return 1
|
return 1
|
||||||
elif locked == 0:
|
elif locked == 0:
|
||||||
self.registry['runtime']['locked'] = False
|
self.registry["runtime"]["locked"] = False
|
||||||
return 1
|
return 1
|
||||||
elif locked == -1:
|
elif locked == -1:
|
||||||
return self.registry['runtime']["locked"]
|
return self.registry["runtime"]["locked"]
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def revise(self):
|
def revise(self):
|
||||||
@@ -96,11 +99,10 @@ class Atom:
|
|||||||
"""
|
"""
|
||||||
if self.registry["runtime"]["locked"]:
|
if self.registry["runtime"]["locked"]:
|
||||||
logger.debug(f"允许总评分: {self.registry['runtime']['min_rate']}")
|
logger.debug(f"允许总评分: {self.registry['runtime']['min_rate']}")
|
||||||
self.registry["electron"].revisor(self.registry['runtime']["min_rate"])
|
self.registry["electron"].revisor(self.registry["runtime"]["min_rate"])
|
||||||
else:
|
else:
|
||||||
logger.debug("禁止总评分")
|
logger.debug("禁止总评分")
|
||||||
|
|
||||||
|
|
||||||
def do_eval(self):
|
def do_eval(self):
|
||||||
"""
|
"""
|
||||||
执行并以结果替换当前单元的所有 eval 语句
|
执行并以结果替换当前单元的所有 eval 语句
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class Electron:
|
|||||||
logger.debug("Electron.is_due: 检查 ident='%s'", self.ident)
|
logger.debug("Electron.is_due: 检查 ident='%s'", self.ident)
|
||||||
result = self.algo.is_due(self.algodata)
|
result = self.algo.is_due(self.algodata)
|
||||||
logger.debug("is_due 结果: %s", result)
|
logger.debug("is_due 结果: %s", result)
|
||||||
return (result and self.is_activated())
|
return result and self.is_activated()
|
||||||
|
|
||||||
def is_activated(self):
|
def is_activated(self):
|
||||||
result = self.algodata[self.algo.algo_name]["is_activated"]
|
result = self.algodata[self.algo.algo_name]["is_activated"]
|
||||||
|
|||||||
@@ -44,7 +44,9 @@ class TestDashboardScreenUnit(unittest.TestCase):
|
|||||||
|
|
||||||
# 创建目录
|
# 创建目录
|
||||||
for dir_key in ["nucleon_dir", "electron_dir", "orbital_dir", "cache_dir"]:
|
for dir_key in ["nucleon_dir", "electron_dir", "orbital_dir", "cache_dir"]:
|
||||||
pathlib.Path(config_data["paths"][dir_key]).mkdir(parents=True, exist_ok=True)
|
pathlib.Path(config_data["paths"][dir_key]).mkdir(
|
||||||
|
parents=True, exist_ok=True
|
||||||
|
)
|
||||||
|
|
||||||
# 使用 ConfigContext 设置配置
|
# 使用 ConfigContext 设置配置
|
||||||
self.config_ctx = ConfigContext(self.config)
|
self.config_ctx = ConfigContext(self.config)
|
||||||
@@ -60,16 +62,19 @@ class TestDashboardScreenUnit(unittest.TestCase):
|
|||||||
screen = DashboardScreen()
|
screen = DashboardScreen()
|
||||||
# 手动调用 compose 并收集部件
|
# 手动调用 compose 并收集部件
|
||||||
from textual.app import ComposeResult
|
from textual.app import ComposeResult
|
||||||
|
|
||||||
result = screen.compose()
|
result = screen.compose()
|
||||||
widgets = list(result)
|
widgets = list(result)
|
||||||
# 检查是否包含 Header 和 Footer
|
# 检查是否包含 Header 和 Footer
|
||||||
from textual.widgets import Header, Footer
|
from textual.widgets import Header, Footer
|
||||||
|
|
||||||
header_present = any(isinstance(w, Header) for w in widgets)
|
header_present = any(isinstance(w, Header) for w in widgets)
|
||||||
footer_present = any(isinstance(w, Footer) for w in widgets)
|
footer_present = any(isinstance(w, Footer) for w in widgets)
|
||||||
self.assertTrue(header_present)
|
self.assertTrue(header_present)
|
||||||
self.assertTrue(footer_present)
|
self.assertTrue(footer_present)
|
||||||
# 检查是否有 ScrollableContainer
|
# 检查是否有 ScrollableContainer
|
||||||
from textual.containers import ScrollableContainer
|
from textual.containers import ScrollableContainer
|
||||||
|
|
||||||
container_present = any(isinstance(w, ScrollableContainer) for w in widgets)
|
container_present = any(isinstance(w, ScrollableContainer) for w in widgets)
|
||||||
self.assertTrue(container_present)
|
self.assertTrue(container_present)
|
||||||
# 使用 query_one 查找 union-list,即使屏幕未挂载也可能有效
|
# 使用 query_one 查找 union-list,即使屏幕未挂载也可能有效
|
||||||
@@ -117,7 +122,9 @@ class TestDashboardScreenPilot(unittest.TestCase):
|
|||||||
config_data["timestamp_override"] = -1
|
config_data["timestamp_override"] = -1
|
||||||
|
|
||||||
for dir_key in ["nucleon_dir", "electron_dir", "orbital_dir", "cache_dir"]:
|
for dir_key in ["nucleon_dir", "electron_dir", "orbital_dir", "cache_dir"]:
|
||||||
pathlib.Path(config_data["paths"][dir_key]).mkdir(parents=True, exist_ok=True)
|
pathlib.Path(config_data["paths"][dir_key]).mkdir(
|
||||||
|
parents=True, exist_ok=True
|
||||||
|
)
|
||||||
|
|
||||||
self.config_ctx = ConfigContext(self.config)
|
self.config_ctx = ConfigContext(self.config)
|
||||||
self.config_ctx.__enter__()
|
self.config_ctx.__enter__()
|
||||||
@@ -128,7 +135,7 @@ class TestDashboardScreenPilot(unittest.TestCase):
|
|||||||
|
|
||||||
def test_dashboard_loads_with_pilot(self):
|
def test_dashboard_loads_with_pilot(self):
|
||||||
"""使用 Pilot 测试 DashboardScreen 加载。"""
|
"""使用 Pilot 测试 DashboardScreen 加载。"""
|
||||||
with patch('heurams.interface.__main__.environment_check'):
|
with patch("heurams.interface.__main__.environment_check"):
|
||||||
app = HeurAMSApp()
|
app = HeurAMSApp()
|
||||||
# 注意:Pilot 在 Textual 6.9.0 中的用法可能不同
|
# 注意:Pilot 在 Textual 6.9.0 中的用法可能不同
|
||||||
# 以下为示例代码,可能需要调整
|
# 以下为示例代码,可能需要调整
|
||||||
|
|||||||
Reference in New Issue
Block a user