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