改进
This commit is contained in:
@@ -5,7 +5,11 @@ from textual.containers import Center
|
||||
from textual.screen import Screen
|
||||
from enum import Enum, auto
|
||||
|
||||
from heurams.context import config_var
|
||||
from heurams.kernel.reactor import *
|
||||
import heurams.kernel.particles as pt
|
||||
import heurams.kernel.puzzles as pz
|
||||
from .. import shim
|
||||
|
||||
class AtomState(Enum):
|
||||
FAILED = auto()
|
||||
@@ -13,10 +17,13 @@ class AtomState(Enum):
|
||||
|
||||
class MemScreen(Screen):
|
||||
BINDINGS = [
|
||||
("q", "pop_screen", "返回"),
|
||||
("p", "pop_screen", "上一个"),
|
||||
("d", "toggle_dark", "改变色调"),
|
||||
("q", "pop_screen", "返回主菜单"),
|
||||
("v", "play_voice", "朗读"),
|
||||
]
|
||||
if config_var.get()["quick_pass"]:
|
||||
BINDINGS.append(("k", "quick_pass", "跳过"))
|
||||
|
||||
def __init__(self, atoms: list):
|
||||
super().__init__(name=None, id=None, classes=None)
|
||||
@@ -24,11 +31,17 @@ class MemScreen(Screen):
|
||||
self.phaser = Phaser(atoms)
|
||||
self.procession: Procession = self.phaser.current_procession() # type: ignore
|
||||
|
||||
def current_widget(self):
|
||||
self.fission = Fission(self.procession.current_atom, self.phaser.state)
|
||||
puzzle: pz.BasePuzzle = next(self.fission.generate())
|
||||
print(shim.puzzle2widget[puzzle])
|
||||
return shim.puzzle2widget[puzzle](atom = self.procession.current_atom)
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Header(show_clock=True)
|
||||
with Center():
|
||||
yield Static(f"当前进度: {self.procession.process()}/{self.procession.total_length()}")
|
||||
yield Label()
|
||||
self.mount(self.current_widget())
|
||||
yield Button("重新学习此单元", id="re-recognize", variant="warning")
|
||||
yield Footer()
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ class PreparationScreen(Screen):
|
||||
content = ""
|
||||
for nucleon, orbital in self.nucleons_with_orbital:
|
||||
nucleon: pt.Nucleon
|
||||
print(nucleon.payload)
|
||||
# print(nucleon.payload)
|
||||
content += " - " + nucleon["content"] + " \n"
|
||||
return content
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
"""Kernel 操作辅助函数库"""
|
||||
import random
|
||||
import heurams.kernel.particles as pt
|
||||
import heurams.kernel.puzzles as pz
|
||||
import heurams.interface.widgets as pzw
|
||||
staging = {} # 细粒度缓存区, 是 ident -> quality 的封装
|
||||
def report_to_staging(atom: pt.Atom, quality):
|
||||
staging[atom.ident] = min(quality, staging[atom.ident])
|
||||
@@ -12,3 +15,9 @@ def deploy_to_electron():
|
||||
else:
|
||||
pt.atom_registry[atom_ident].register['electron'].revisor(quality=quality, is_new_activation=True)
|
||||
clear()
|
||||
puzzle2widget = {
|
||||
pz.RecognitionPuzzle: pzw.Recognition,
|
||||
pz.ClozePuzzle: pzw.ClozePuzzle,
|
||||
pz.MCQPuzzle: pzw.MCQPuzzle,
|
||||
pz.BasePuzzle: pzw.BasePuzzleWidget,
|
||||
}
|
||||
7
src/heurams/interface/widgets/__init__.py
Normal file
7
src/heurams/interface/widgets/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from .base_puzzle_widget import BasePuzzleWidget
|
||||
from .basic_puzzle import BasicEvaluation
|
||||
from .cloze_puzzle import ClozePuzzle
|
||||
from .finished import Finished
|
||||
from .mcq_puzzle import MCQPuzzle
|
||||
from .placeholder import Placeholder
|
||||
from .recognition import Recognition
|
||||
@@ -22,7 +22,7 @@ import copy
|
||||
import random
|
||||
from .. import shim
|
||||
|
||||
class DrawCard(BasePuzzleWidget):
|
||||
class MCQPuzzle(BasePuzzleWidget):
|
||||
def __init__(self, *children: Widget, atom: pt.Atom, name: str | None = None, id: str | None = None, classes: str | None = None, disabled: bool = False, markup: bool = True) -> None:
|
||||
super().__init__(*children, atom=atom, name=name, id=id, classes=classes, disabled=disabled, markup=markup)
|
||||
self.inputlist = []
|
||||
|
||||
@@ -30,9 +30,9 @@ class Recognition(BasePuzzleWidget):
|
||||
|
||||
def compose(self):
|
||||
with Center():
|
||||
yield Static(f"[dim]{self.atom[1]['translation']}[/]")
|
||||
yield Static(f"[dim]{self.atom.register['nucleon']['translation']}[/]")
|
||||
yield Label(f"")
|
||||
s = str(self.atom[1]["content"])
|
||||
s = str(self.atom.register['nucleon']["content"])
|
||||
replace_dict = {
|
||||
", ": ",",
|
||||
". ": ".",
|
||||
@@ -53,15 +53,16 @@ class Recognition(BasePuzzleWidget):
|
||||
f"[b][b]{i.replace('/', ' ')}[/][/]",
|
||||
id="sentence" + str(hash(i)),
|
||||
)
|
||||
for i in self.atom[2]["testdata"]["additional_inf"]:
|
||||
if self.atom[1][i]:
|
||||
if isinstance(self.atom[1][i], list):
|
||||
for j in self.atom[1][i]:
|
||||
yield Markdown(f"### {self.atom[2]['keydata'][i]}: {j}")
|
||||
# 处理orbital/展示配置
|
||||
for i in self.atom.register["orbital"] ["testdata"]["additional_inf"]:
|
||||
if self.atom.register['nucleon'][i]:
|
||||
if isinstance(self.atom.register['nucleon'][i], list):
|
||||
for j in self.atom.register['nucleon'][i]:
|
||||
yield Markdown(f"### {self.atom.register["orbital"] ['keydata'][i]}: {j}")
|
||||
continue
|
||||
if isinstance(self.atom[1][i], Dict):
|
||||
if isinstance(self.atom.register['nucleon'][i], Dict):
|
||||
t = ""
|
||||
for j, k in self.atom[1][i].items(): # type: ignore
|
||||
for j, k in self.atom.register['nucleon'][i].items(): # type: ignore
|
||||
t += f"> **{j}**: {k} \n"
|
||||
yield Markdown(t, id="tran")
|
||||
with Center():
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
from typing import TypedDict
|
||||
|
||||
class Orbital(TypedDict):
|
||||
quick_view: list
|
||||
quick_review: list
|
||||
recognition: list
|
||||
final_review: list
|
||||
puzzle_config: dict
|
||||
finished: None
|
||||
unsure: None
|
||||
|
||||
"""一份示例
|
||||
["__metadata__.orbital"] # 内置的推荐学习方案
|
||||
|
||||
@@ -7,16 +7,19 @@ Puzzle 模块 - 谜题生成系统
|
||||
from .base import BasePuzzle
|
||||
from .cloze import ClozePuzzle
|
||||
from .mcq import MCQPuzzle
|
||||
from .recognition import RecognitionPuzzle
|
||||
|
||||
__all__ = [
|
||||
'BasePuzzle',
|
||||
'ClozePuzzle',
|
||||
'MCQPuzzle',
|
||||
'RecognitionPuzzle',
|
||||
]
|
||||
|
||||
puzzles = {
|
||||
"mcq": MCQPuzzle,
|
||||
"cloze": ClozePuzzle,
|
||||
"recognition": RecognitionPuzzle,
|
||||
"base": BasePuzzle,
|
||||
}
|
||||
|
||||
|
||||
12
src/heurams/kernel/puzzles/recognition.py
Normal file
12
src/heurams/kernel/puzzles/recognition.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# mcq.py
|
||||
from .base import BasePuzzle
|
||||
import random
|
||||
|
||||
class RecognitionPuzzle(BasePuzzle):
|
||||
"""识别占位符"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def refresh(self):
|
||||
pass
|
||||
@@ -7,9 +7,12 @@ class Fission():
|
||||
"""裂变器: 单原子调度展开器"""
|
||||
def __init__(self, atom: pt.Atom, phase = PhaserState.RECOGNITION):
|
||||
self.atom = atom
|
||||
self.orbital = atom.register["orbital"]["puzzle_config"][phase]
|
||||
self.orbital = atom.register["orbital"][phase.value]
|
||||
print(self.orbital)
|
||||
self.puzzles = list()
|
||||
for item, possibility in self.orbital:
|
||||
for item, possibility in self.orbital: # type: ignore
|
||||
if not isinstance(possibility, float):
|
||||
possibility = float(possibility)
|
||||
while possibility > 1:
|
||||
self.puzzles.append(puz.puzzles[item])
|
||||
possibility -= 1
|
||||
|
||||
Reference in New Issue
Block a user