78 Commits

Author SHA1 Message Date
pluv face433660 fix: 修改一处语法错误 2026-04-27 02:27:29 +08:00
pluv a0180b8cc0 chore: 说明依赖 2026-04-27 02:26:32 +08:00
pluv b818a1a0a4 chore: 更新依赖和文档 2026-04-27 02:04:52 +08:00
pluv 0aa9803b76 feat: 高精度时间戳支持与 SM-15M 改进 2026-04-25 02:14:55 +08:00
pluv f3049fde90 feat: 增加早期 FSRS 支持 2026-04-25 01:54:18 +08:00
pluv 2c9e854507 test: 增加测试 2026-04-25 01:38:33 +08:00
pluv 6ed1455111 docs: 修改文档 2026-04-24 15:40:42 +08:00
pluv df00d49e0b docs: 修改文档 2026-04-24 15:38:10 +08:00
pluv 613b4ba045 style: 代码格式化 2026-04-23 00:13:57 +08:00
pluv aaee4d513e docs: 更新文档 2026-04-22 23:39:20 +08:00
pluv 39ea047367 feat(interface): 组件自动聚焦与键盘操作改进 2026-04-22 22:54:25 +08:00
pluv 2c583d97d7 fix(interface): 修复 CSS_PATH 导致的样式覆写问题 2026-04-22 06:55:58 +08:00
pluv 7278cba258 perf: 用 autoflake 删除无用依赖
没想到居然能意外地大幅提升启动速度
2026-04-22 06:44:59 +08:00
pluv e65db69fc6 feat: 开发 unifront 前端会话模块 2026-04-21 16:52:04 +08:00
pluv 9dd6733063 refactor: 开始翻新状态机 2026-04-21 12:52:30 +08:00
pluv bcdfddce10 fix: 修复部分问题 2026-04-21 02:06:28 +08:00
pluv 6f183e4d9d style: 格式化代码 2026-04-21 00:17:03 +08:00
pluv 4246061c29 fix: 优化 CSS 结构 2026-04-21 00:15:57 +08:00
pluv cf2f29cbd7 fix: 修复 Lict 问题 2026-04-20 18:55:25 +08:00
pluv a960d06d0a perf: 脏标记优化 Lict 对象操作复杂度 2026-04-20 18:43:27 +08:00
pluv d01dbe2648 feat: 用户界面实现算法共存与切换 2026-04-20 17:50:36 +08:00
pluv 4ca9c65bea feat: 代码格式化, 改进仪表盘, 新增多CSS支持 2026-04-20 16:30:04 +08:00
pluv 8677e828c7 feat: 试增加单元集独立设置 2026-04-20 07:39:57 +08:00
pluv 709e15663b feat: 增加 ZMQ 调试服务器并完善设置功能 2026-04-20 06:37:46 +08:00
pluv 85925b9d44 feat: 补全设置提示与完善设置页 2026-04-20 05:05:44 +08:00
pluv 82fd8ab199 feat(interface): 图形化设置页原型 2026-04-20 03:33:05 +08:00
pluv 334d04444d style: 删除旧配置文件 2026-04-20 01:46:40 +08:00
pluv d1a1fa193f refactor: 对配置处理器和配置结构进行重构 2026-04-20 01:44:43 +08:00
pluv a8cd774123 fix: 变更哈希注册表以修复重复键造成的崩溃 2026-04-19 12:08:58 +08:00
pluv 0572848803 feat: FAST-0 特殊算法 2026-04-19 00:05:49 +08:00
pluv 279a78f7ce style: 移除设计不当的部分模块 2026-04-16 13:20:12 +08:00
pluv 2a388642e0 build: 修改依赖并引入外部库 2026-03-27 19:31:40 +08:00
pluv 92b4772eda feat(interface): 改进界面 2026-01-28 03:35:58 +08:00
pluv b38eaf4ef6 feat(interface): 改进仪表盘 2026-01-22 06:13:01 +08:00
pluv dde6df9bf0 fix: 修复若干问题 2026-01-17 05:45:45 +08:00
pluv 1077fcab39 fix(interface): 修复按钮标识和一个哈希问题 2026-01-15 12:49:57 +08:00
pluv bcb198f4d4 feat(interface): 改进状态显示 2026-01-13 23:39:10 +08:00
pluv ed361f88e2 build: 使用 uv 包管理器 2026-01-09 00:47:34 +08:00
pluv dd50dc7511 fix: 改进 2026-01-08 01:00:08 +08:00
pluv 67809463f1 fix: 小范围修补 2026-01-08 00:56:04 +08:00
pluv c051f0ffdd feat: 一系列新功能 2026-01-08 00:05:00 +08:00
pluv 1398368e18 feat(interface): 完成队列式记忆模块更新 2026-01-06 20:32:27 +08:00
pluv 85f9e84da4 fix: 修复完成屏幕问题 2026-01-06 19:58:46 +08:00
pluv 1f97a0c5ed fix: 修正逻辑问题 2026-01-06 18:28:57 +08:00
pluv 7d0f4e1466 feat: 更新状态机 2026-01-05 05:25:14 +08:00
pluv 1c297d3949 fix: 改进代码 2026-01-04 04:46:19 +08:00
pluv 5f64ae7250 fix(interface): 界面兼容性改进 2026-01-04 04:14:57 +08:00
pluv d9bf28cf75 fix(interface): 完成主要屏幕重构 2026-01-04 03:46:45 +08:00
pluv f4fd966373 fix: 部分修复重构数据格式差异 2026-01-04 02:11:07 +08:00
pluv 8cd6a8ccc6 feat(reactor): 状态机进一步改进 2026-01-04 00:28:44 +08:00
pluv 64223ce948 feat: 改进状态机 2026-01-03 13:08:08 +08:00
pluv e7e26e3e45 feat(kernel): 状态机改进 2026-01-03 05:05:41 +08:00
pluv 64c9a5c1a7 feat: 完成部分界面重构 2026-01-02 06:12:49 +08:00
pluv 238013ac46 feat: 改进对象系统 2026-01-01 20:18:18 +08:00
pluv 52ef6c65d4 feat: 基本完成对象系统更新 2026-01-01 16:19:46 +08:00
pluv 3ce102b358 feat: 改进粒子对象 2026-01-01 06:36:27 +08:00
pluv e830989368 feat: 进一步改进 2025-12-31 00:57:07 +08:00
pluv f056aaf00d feat: 一些改进 2025-12-29 21:53:20 +08:00
pluv 82560ef4e7 refactor: 部分更改数据结构 2025-12-28 06:16:21 +08:00
pluv ddcebb6dcd style: 格式化代码 2025-12-21 23:44:13 +08:00
pluv ce4860b930 feat(interface): 增加智能单元集排序 2025-12-21 23:42:02 +08:00
pluv 44dfd63212 fix: 暂时禁用实验性功能 2025-12-21 23:06:17 +08:00
pluv f6572cf5dd refactor(synctool): 改进同步方案 2025-12-21 21:18:31 +08:00
pluv 5c35e14d0f feat(synctool): 虚拟文件系统初步方案 2025-12-21 18:48:25 +08:00
pluv 490b87c639 style: 格式化代码 2025-12-21 07:56:10 +08:00
pluv 22eea3d668 feat(synctool): 增加同步功能 2025-12-21 07:49:19 +08:00
pluv 29b5978f8a feat(kernel): 添加算法切换设置 2025-12-21 06:48:30 +08:00
pluv 94f788d8f4 style: 更新版本号和合并规则 2025-12-21 06:34:17 +08:00
pluv ebaaac81db fix(interface): 修复仪表盘详情 2025-12-21 06:27:00 +08:00
pluv b8cfc03c2e feat(interface): 更改启动方式 2025-12-21 06:06:16 +08:00
pluv 9b7b633ec0 fix(interface): 修复显示问题 2025-12-21 05:47:22 +08:00
pluv fd0c197e98 feat: 自动音频播放与改进设计 2025-12-21 05:32:58 +08:00
pluv 4070246041 style(version): 更新版本号 2025-12-21 03:02:29 +08:00
pluv 083f813651 feat: 实验性 SM-15M 算法实现
实验性 SM-15M 逆向工程算法实现
2025-12-21 02:15:23 +08:00
pluv 2600dffee3 style: isort 格式化 2025-12-19 15:13:42 +08:00
pluv b09e67b3eb style: 格式化代码 2025-12-19 15:08:26 +08:00
pluv 218dba21f2 fix(interface): 修复默认配置文件 2025-12-18 15:53:18 +08:00
pluv 3866b9620c refactor: 完成 0.4.0 版本更新
完成 0.4.0 版本更新, 为了消除此前提交消息风格不一致与错误提交超大文件的问题, 维持代码统计数据的准确性和提交消息风格的一致性, 重新初始化仓库; 旧的提交历史在 HeurAMS-legacy 仓库(https://gitea.imwangzhiyu.xyz/ajax/HeurAMS-legacy)
2025-12-17 22:31:38 +08:00
154 changed files with 8177 additions and 8602 deletions
+157 -29
View File
@@ -1,19 +1,34 @@
# HeurAMS specific rules # Project specific additions
*.log.* .devflag
*.log
*.pkl
/data
# Editor
.vscode/ .vscode/
.directory
__pycache__/
.idea/ .idea/
cache/
data/repo/cngk
data/repo/eotgk
data/repo/evtgk
data/misc
data/cache
data/session
*.egg-info/
build/
dist/
old/
AGENT.md
AGENTS.md
*.log.*
*.pkl
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
*.py[cod] *.py[cod]
*$py.class *$py.class
# C extensions
*.so
# Distribution / packaging # Distribution / packaging
.Python
build/ build/
develop-eggs/ develop-eggs/
dist/ dist/
@@ -32,6 +47,16 @@ share/python-wheels/
*.egg *.egg
MANIFEST MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports # Unit test / coverage reports
htmlcov/ htmlcov/
.tox/ .tox/
@@ -46,10 +71,73 @@ coverage.xml
.hypothesis/ .hypothesis/
.pytest_cache/ .pytest_cache/
cover/ cover/
.claude/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook # Jupyter Notebook
.ipynb_checkpoints .ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly used for packaging.
#poetry.lock
#poetry.toml
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
#pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments # Environments
.env .env
.venv .venv
@@ -59,32 +147,72 @@ ENV/
env.bak/ env.bak/
venv.bak/ venv.bak/
# Linux # Spyder project settings
*~ .spyderproject
.fuse_hidden* .spyproject
.directory
.Trash-*
.nfs*
## KDE Dolphin
.directory
# macOS # Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
.idea/
# Audio cache and temporary files
*.mp3
*.wav
*.ogg
*.tmp
# LLM cache files
*.cache
*.jsonl
# Log files
*.log
logs/
# OS generated files
.DS_Store .DS_Store
.AppleDouble .DS_Store?
.LSOverride
._* ._*
.AppleDB .Spotlight-V100
.AppleDesktop .Trashes
ehthumbs.db
Thumbs.db
# Windows # Windows
Thumbs.db Thumbs.db
Thumbs.db:encryptable
ehthumbs.db ehthumbs.db
ehthumbs_vista.db Desktop.ini
[Dd]esktop.ini
$RECYCLE.BIN/
*.lnk
# Other trash # Linux
AGENT.md *~
# It's not AGENTS.md
# VSCode
.vscode/
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Temporary files
*.tmp
*.temp
-50
View File
@@ -1,50 +0,0 @@
# AI Coding Assistant Guide
This document provides guidance for AI tools and developers using AI assistance to contribute code to the HeurAMS project. Generally, this file will be automatically loaded into the context of various AI tools.
AI tools should read this `/AGENTS.md` file in its entirety.
## Reference Documents
When assisting with HeurAMS development, AI tools should follow standard development practices and procedures. They should automatically check, or check upon user issuing an "init/初始化" command:
- [Contributing Guide](/CONTRIBUTING.md)
- [README](/README.md)
- [Architecture Overview](/docs/ARCHITECTURE.md)
## Prohibited Actions
1. AI must not automatically generate PR or patch files
2. AI must not modify existing code without human confirmation
3. AI must not generate formatted files without using formatting tools
4. AI must not fix any "bugs" without human confirmation
5. AI must not engage in any "cowboy coding" that bypasses project design principles or creates separate libraries
6. AI must not directly operate pip, uv, apt, or other tools to modify external dependencies or tools — human developers should handle dependencies themselves
7. AI must not write new comments in a language different from the existing comment language of any existing file
8. AI must not overwrite files without reading them first
9. **Modification of this `/AGENTS.md` file is absolutely forbidden**
## License & Legal Requirements
All contributions must comply with licensing requirements. All code must be compatible with the AGPL-3.0-or-later license and the project's additional exemption clause (located at lines 237-245 at the end of the LICENSE file).
## Signed-off-by & DCO
AI agents are **strictly forbidden** from adding Signed-off-by tags.
Only humans can legally certify the DCO.
Human committers are responsible for:
- Reviewing all AI-generated code
- Ensuring compliance with licensing requirements
- Adding their own Signed-off-by tag to certify the DCO
- Taking responsibility for contributions
AI assistants are responsible for:
- Understanding the runtime environment, such as the operating system or specific distribution
- Following the rules outlined in this document
- Proactively reminding developers using AI tools
This document references <a href="https://docs.kernel.org/process/coding-assistants.html" target="_blank" rel="noopener noreferrer">AI Coding Assistants — The Linux Kernel documentation</a>
+41 -12
View File
@@ -68,7 +68,7 @@ graph TB
项目以物理粒子隐喻为核心, 将记忆单元拆解为三个模型: 项目以物理粒子隐喻为核心, 将记忆单元拆解为三个模型:
### Nucleon (核子) - 内容层 ### Nucleon (核子) 内容层
``` ```
Nucleon(ident, payload, common) Nucleon(ident, payload, common)
@@ -79,7 +79,7 @@ Nucleon(ident, payload, common)
- 从 `repo.payload``repo.typedef["common"]` 配对创建. - 从 `repo.payload``repo.typedef["common"]` 配对创建.
- 一旦创建, 内容不可修改 (`__setitem__` 抛出 `AttributeError`). - 一旦创建, 内容不可修改 (`__setitem__` 抛出 `AttributeError`).
### Electron (电子) - 状态层 ### Electron (电子) 状态层
``` ```
Electron(ident, algodata, algo_name) Electron(ident, algodata, algo_name)
@@ -89,7 +89,7 @@ Electron(ident, algodata, algo_name)
- `algodata` 是到仓库 `algodata.lict` 中对应字典的**引用**, 修改即持久化. - `algodata` 是到仓库 `algodata.lict` 中对应字典的**引用**, 修改即持久化.
- 核心方法:`activate()` (标记激活)、`revisor()` (评分迭代)、`is_due()` (到期判断). - 核心方法:`activate()` (标记激活)、`revisor()` (评分迭代)、`is_due()` (到期判断).
### Orbital (轨道) - 策略层 ### Orbital (轨道) 策略层
``` ```
orbital = { orbital = {
@@ -104,7 +104,7 @@ orbital = {
- 定义复习阶段流程和各阶段内谜题选择策略的纯字典. - 定义复习阶段流程和各阶段内谜题选择策略的纯字典.
- 每个阶段对应一组 `(谜题类型, 概率系数)` 元组列表, 概率系数 >1 的部分表示强制重复次数. - 每个阶段对应一组 `(谜题类型, 概率系数)` 元组列表, 概率系数 >1 的部分表示强制重复次数.
### Atom (原子) - 运行时组装 ### Atom (原子) 运行时组装
``` ```
Atom(nucleon, electron, orbital) Atom(nucleon, electron, orbital)
@@ -124,18 +124,21 @@ graph LR
Algodata[(algodata.json)] Algodata[(algodata.json)]
Schedule[(schedule.toml)] Schedule[(schedule.toml)]
end end
subgraph "运行时组装" subgraph "运行时组装"
Nucleon -->|内容| Atom Nucleon -->|内容| Atom
Electron -->|状态| Atom Electron -->|状态| Atom
Orbital -->|策略| Atom Orbital -->|策略| Atom
end end
Payload -->|Repo| Nucleon Payload --> Nucleon
Common -->|Repo| Nucleon Common --> Nucleon
Algodata -->|Repo| Electron Algodata --> Electron
Schedule -->|Repo| Orbital Schedule --> Orbital
``` ```
______________________________________________________________________
## 调度反应器 (Reactor) ## 调度反应器 (Reactor)
调度反应器是核心业务流程引擎, 采用三层嵌套的有限状态机设计 (基于 `transitions` 库). 调度反应器是核心业务流程引擎, 采用三层嵌套的有限状态机设计 (基于 `transitions` 库).
@@ -154,12 +157,12 @@ graph LR
| **ExpanderState** | `exammode` | 考试模式 (正面答题) | | **ExpanderState** | `exammode` | 考试模式 (正面答题) |
| | `retronly` | 回溯模式 (仅识别) | | | `retronly` | 回溯模式 (仅识别) |
### 状态机嵌套结构 ### 三层嵌套结构
```mermaid ```mermaid
graph TB graph TB
subgraph "Router (全局路由器)" subgraph "Router (全局路由器)"
R[Router<br/>状态: unsure→quick_review<br/>→recognition→final_review<br/>→finished] R[Router<br/>状态: unsure→quick_review→recognition→final_review→finished]
P1[Procession 队列1: 快速复习] P1[Procession 队列1: 快速复习]
P2[Procession 队列2: 新记忆] P2[Procession 队列2: 新记忆]
P3[Procession 队列3: 总复习] P3[Procession 队列3: 总复习]
@@ -219,7 +222,7 @@ Router.__init__(atoms)
└─ Algorithm.revisor(algodata, feedback) └─ Algorithm.revisor(algodata, feedback)
``` ```
评分累积机制: 原子在多谜题阶段的最终评分取所有谜题的最低评分 (`min_rate`), 确保严格评估. ______________________________________________________________________
## 算法系统 ## 算法系统
@@ -257,9 +260,11 @@ Router.__init__(atoms)
} }
``` ```
______________________________________________________________________
## 仓库系统 (Repo) ## 仓库系统 (Repo)
仓库 TOML/JSON 文件目录, 无数据库依赖. 仓库 TOML/JSON 文件目录, 无数据库依赖.
### 目录结构 ### 目录结构
@@ -298,6 +303,8 @@ classDiagram
- `_generate_particles_data()` 在初始化时自动将 payload 数据转换为 `Nucleon` 所需的格式. - `_generate_particles_data()` 在初始化时自动将 payload 数据转换为 `Nucleon` 所需的格式.
- 默认保存列表 `default_save_list = ["algodata"]`, 仅持久化算法状态. - 默认保存列表 `default_save_list = ["algodata"]`, 仅持久化算法状态.
______________________________________________________________________
## Lict 集合 ## Lict 集合
`Lict` 继承 `MutableSequence`, 同时维护列表和字典访问: `Lict` 继承 `MutableSequence`, 同时维护列表和字典访问:
@@ -313,6 +320,8 @@ lict.dicted_data # 纯字典导出
脏同步机制:修改列表时自动同步字典, 修改字典时自动同步列表. 用于 `payload``algodata` 的双模式访问需求. 脏同步机制:修改列表时自动同步字典, 修改字典时自动同步列表. 用于 `payload``algodata` 的双模式访问需求.
______________________________________________________________________
## 配置系统 (ConfigDict) ## 配置系统 (ConfigDict)
`ConfigDict` 继承 `UserDict`, 是**单例模式**的 TOML 懒加载配置管理器. `ConfigDict` 继承 `UserDict`, 是**单例模式**的 TOML 懒加载配置管理器.
@@ -352,6 +361,8 @@ with ConfigContext(test_config):
... # 临时使用测试配置 ... # 临时使用测试配置
``` ```
______________________________________________________________________
## 提供者系统 (Providers) ## 提供者系统 (Providers)
可插拔的后端实现, 通过 `providers/__init__.py` 中的字典注册. 可插拔的后端实现, 通过 `providers/__init__.py` 中的字典注册.
@@ -366,6 +377,8 @@ with ConfigContext(test_config):
选择方式:`services/*.toml` 中的 `provider` 字段. 选择方式:`services/*.toml` 中的 `provider` 字段.
______________________________________________________________________
## 谜题系统 (Puzzles) ## 谜题系统 (Puzzles)
谜题引擎用于在复习阶段生成评估视图: 谜题引擎用于在复习阶段生成评估视图:
@@ -380,6 +393,8 @@ with ConfigContext(test_config):
谜题通过轨道策略 (Orbital)在 `Expander` 中按概率展开, 每个原子可产生多个谜题, 每个谜题独立评分. 谜题通过轨道策略 (Orbital)在 `Expander` 中按概率展开, 每个原子可产生多个谜题, 每个谜题独立评分.
______________________________________________________________________
## 服务层 ## 服务层
| 服务 | 文件 | 说明 | | 服务 | 文件 | 说明 |
@@ -397,6 +412,8 @@ with ConfigContext(test_config):
日志系统:每个模块通过 `get_logger(__name__)` 创建自己的日志器, 日志文件 10MB 轮转, 最多 5 个备份, 追加到 `heurams.log`. 日志系统:每个模块通过 `get_logger(__name__)` 创建自己的日志器, 日志文件 10MB 轮转, 最多 5 个备份, 追加到 `heurams.log`.
______________________________________________________________________
## 复习全流程 ## 复习全流程
```mermaid ```mermaid
@@ -436,3 +453,15 @@ sequenceDiagram
Router-->>UI: 完成 (finished) Router-->>UI: 完成 (finished)
UI->>User: 显示总结 UI->>User: 显示总结
``` ```
______________________________________________________________________
## 关键设计决策
1. **无数据库** — 所有持久化基于 TOML/JSON 文件目录, 方便版本管理和手动编辑.
2. **Lict 双模式访问** — payload 和 algodata 同时支持列表迭代和字典查找, 兼顾批处理和随机访问.
3. **物理隐喻分离** — 内容 (Nucleon)、状态 (Electron)、策略 (Orbital) 三者正交, 可独立替换, 便于组合不同算法和内容类型.
4. **transitions 状态机** — 使用 `transitions` 库实现 Router → Procession → Expander 三层嵌套状态机, 每个层次职责明确.
5. **Evalizer eval 模板** — 使用 `eval()` 实现动态模板替换, 功能灵活但存在安全风险 (标记为待替换).
6. **配置单例**`ConfigDict` 以规范化路径为键实现单例, 避免多实例导致的配置不一致问题.
7. **评分累积** — 原子在多谜题阶段的最终评分取所有谜题的最低评分 (`min_rate`), 确保严格评估.
+65 -68
View File
@@ -1,119 +1,116 @@
# Contributing Guide & Development # 贡献指南与二次开发
Welcome and thank you for supporting this project! 欢迎为此项目做出贡献!
Currently, the primary project repository server is <a href="https://git.pluv27.top/pluv/HeurAMS" target="_blank" rel="noopener noreferrer">git.pluv27.top</a>, which manages synchronization, ensures availability, and accepts collaboration from multiple communities. Mirror syncs are set up on <a href="https://github.com/pluvium27/HeurAMS" target="_blank" rel="noopener noreferrer">GitHub</a>, <a href="https://invent.kde.org/pluv/HeurAMS" target="_blank" rel="noopener noreferrer">KDE Invent</a>, and <a href="https://gitee.com/pluv/HeurAMS" target="_blank" rel="noopener noreferrer">Gitee</a>. ## 开发规范
This does not affect the project's acceptance of PRs from <a href="https://github.com/pluvium27/HeurAMS" target="_blank" rel="noopener noreferrer">GitHub</a>, <a href="https://invent.kde.org/pluv/HeurAMS" target="_blank" rel="noopener noreferrer">KDE Invent</a>, and <a href="https://gitee.com/pluv/HeurAMS" target="_blank" rel="noopener noreferrer">Gitee</a>. PRs accepted on GitHub, KDE Invent, and Gitee will retain contributor attribution and be synced back to all platforms as-is. Contributions on any platform are welcome. 分支划分:
> [!NOTE] - `main` 分支: 稳定版本, 仅当稳定版本释出或修补版本时将 `dev` 合并到 `main`
> We have begun development of a modern cross-platform frontend based on the KDE UI framework `Kirigami`, called "KiriMemo" (package name "org.kde.kirimemo"). Note that it is not a KDE project.\ - `dev` 分支: 主线开发版本, 自身仅用于非重构的问题修复和整合功能分支
> It directly reuses the Python kernel via `PyOtherSide`, providing a modern UI for Windows, Linux, macOS, Android, iOS, and Plasma Mobile.\ - 功能与重构分支: 从 `dev` 分支创建, 命名格式为 `feature/描述``fix/描述``refactor/v版本号`
> If you are skilled in C++, QML, Qt, and KDE frameworks, you are welcome to join the KiriMemo project development. - 不要将功能与重构分支先应被合并至 `dev` 后在 `dev` 完成文档开发后再释出至 `main`
## Development Conventions 代码格式化:
Branch structure: - 安装工具:
- `dev` branch (default branch): Mainline development branch. Used only for non-refactoring bug fixes and integration of feature branches. Pull requests are merged into this branch.
- `master` branch: Mainline stable version. `dev` is merged into `master` only when a stable version is released or a patch version is prepared.
- Feature and refactoring branches: Created from `dev`, named as `feature/description` or `fix/description` or `refactor/description` or `next/version`.
- Feature and refactoring branches should first be merged into `dev`, then into `master`.
Code formatting:
- Install tools:
```bash ```bash
python -m pip install black autoflake mdformat python -m pip install black autoflake mdformat
``` ```
- For Python, use `black` and `autoflake`.\ - 对于 Python, 使用 `black` `autoflake` 格式化\
Commands: 命令:
```bash ```bash
# black's multi-threading may have compatibility issues in some environments # black 的多线程在某些环境下有兼容性问题
black . --workers=1 black . --workers=1
``` ```
```bash ```bash
# autoflake: note to exclude __init__.py # autoflake 注意排除 __init__.py
autoflake --in-place --remove-all-unused-imports --recursive ./src/ --exclude __init__.py autoflake --in-place --remove-all-unused-imports --recursive ./src/ --exclude __init__.py
``` ```
- For Markdown, use `mdformat`.\ - 对于 Markdown, 使用 `mdformat` 格式化
Command: 命令:
```bash ```bash
mdformat --number . mdformat --number .
``` ```
- For Textual CSS, use `prettier`. - 对于 Textual CSS, 可以使用 `prettier` 格式化
- Formatting is not mandatory and can be consolidated into a single `style` commit, but code on `master` and `dev` branches should be kept clean for review. - 格式化不是必需的, 可以整合入一次 `style` 提交, 但 `main` 和 `dev` 分支上的代码应尽量整洁, 以便合并时审查
Commit messages: 提交消息:
- Write clear commit messages in Simplified Chinese or English. - 使用简体中文或英文撰写清晰的提交消息
- Commit message format: Follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification. The `koji` tool is recommended. - 提交消息格式: 遵循 [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) 规范, 建议使用 `koji` 工具
Merge method: 合并方式:
- For consistency and traceability, Fast-forward merges have been prohibited since the repository was re-initialized after the v0.4.0 refactoring. - 为了一致性和可追溯性, 项目自 v0.4.0 重构后重新初始化仓库起就禁止使用 Fast-forward 合并
- You can set `git config merge.ff false`. - 可以设置 `git config merge.ff false`
Commit author format:\ ## 设置开发环境
Due to the quirky git hook on KDE Invent infrastructure, the commit Author field must appear to be a real name (e.g., "Wang Zhiyu" instead of "wangzhiyu"; otherwise, KDE Invent's hook will reject the push).\
Therefore, please ensure your git configuration uses a proper name-like format (e.g., `git config user.name "Li Hua"`, i.e., must include a space). A real name is not required; the email field has no restrictions. You can also repeat a single name twice (e.g., "Thura Thura") to pass the check.
## Setting Up Development Environment
```bash ```bash
git clone https://git.pluv27.top/pluv/HeurAMS # Default branch is dev, no need to switch # 克隆仓库
git clone https://git.pluv27.top/pluv/HeurAMS
cd HeurAMS cd HeurAMS
# If using uv (recommended) # 可能需要切换到 dev 分支
git checkout dev
# 如果决定使用 uv (推荐)
## 首先要安装uv, 例如通过 pip 或者其他包管理器
python3 -m pip install uv python3 -m pip install uv
uv sync --all-extras # Sync development environment uv sync # 同步开发运行环境
uv run heurams uv run heurams # 验证包安装
# If using native Python environment (not recommended, but retained for environments where uv and hardlinks are not supported, e.g., termux) uv run tui # 启动 TUI
python3 -m pip install -e .[all] # Install dependencies and HeurAMS as a local package # 如果决定使用原生 python 环境 (不推荐, 但我们保留了这种方式以便在不便支持 uv 与硬链接的环境和文件系统(例如 termux)运行 HeurAMS)
python3 -m heurams # Verify installation ## 安装依赖并将 HeurAMS 安装为本地包
python3 -m pip install -r requirements.txt
python3 -m pip install -e .
python3 -m heurams.interface # Launch TUI python3 -m heurams # 验证安装
python3 -m heurams.__interface__ # 启动 TUI
``` ```
## License & External References ## 许可证与外部引用
Contributors retain copyright of their contributions and agree that their contributions will be released under the AGPL-3.0 license (including the additional local API call exemption clause). 贡献者拥有其贡献部分的版权同意其贡献将在 AGPL-3.0 许可证下发布.
Please note in your PR description if: 如果您认为有必要引入其他开源的 vendor, 请在 PR 中注明或手动联系以便我们审查 vendor 许可证并更改此处和网站上的关于与版权声明
- You need to introduce other open-source vendor code 如果您认为有必要引入其他专有的网络服务(就像现在项目中的 edgetts), 请也在 PR 中注明
- You need to introduce other proprietary online services (e.g., edgetts in the current project)
- You need to upgrade a dependency or runtime environment version
## New User Interface Frontends 如果您认为有必要升级某个依赖或运行环境的版本, 请也在 PR 中注明
HeurAMS is designed as a frontend-independent library, meaning: ## 新的用户界面前端与其他语言移植
- Our built-in Textual TUI frontend is not the only available frontend. HeurAMS 被设计为一个可独立于前端的程序库, 这意味着:
- If you have developed a usable HeurAMS frontend (e.g., a not-yet-implemented Flutter frontend) and open-sourced it under AGPL-3.0/GPL-3.0, you can contact us to transfer it to the HeurAMS official repository for joint maintenance. You will retain your copyright and can lead development under that repository. :) - 我们的内置 Textual TUI 前端不是唯一可用的前端
- You can also call HeurAMS as an independent process/service in your own projects. Per AGPL-3.0 and this project's additional license terms, if the call occurs on the same host and does not involve external network forwarding, it is exempt from specific obligations of the license and will not be "contaminated" by AGPL-3.0. To this end, we are improving the optional cross-process RPC module, which will become a cross-platform standard component of the HeurAMS kernel. - 您可以在自己的项目中以独立进程/服务调用 HeurAMS (但不能在代码中链接), 而免于受 AGPL-3.0 "污染". 为了这点, 我们正在完善可选择启用的跨进程 RPC 模块, 这将成为潜进内核的跨平台标准件.
- If you develop another piece of software through independent process/service invocation and open-source it but prefer not to use the AGPL-3.0/GPL-3.0 license, you can also contact us. We would be happy to add your project link to our friendly links. - 如果您有一个自己开发的且可用的 HeurAMS 前端 (例如我们暂未实现的 flutter 前端), 并且以 AGPL-3.0/GPL-3.0 开放源代码, 可以联系我们将它转移到 HeurAMS 的官方仓库中以便共同维护, 您将保留您的版权并可主导该仓库下的开发工作 :)
## Non-Software Contributions - 如果您通过独立进程/服务调用方式开发了另外的软件, 开源但不愿使用 AGPL-3.0/GPL-3.0 许可证, 也可以联系我们, 我们乐于将您的项目链接添加到友链中
Even if you are not a software developer, you are welcome to contribute! - 如果您想创建程序库的其他语言 (例如 dart 或 rust) 版本以协助此语言下的方便集成, 并且同样以 AGPL-3.0/GPL-3.0 开放源代码, 也可以联系我们将它转移到 HeurAMS 的官方仓库中以便共同维护, 您将保留您的版权并可主导该仓库下的开发工作 :)
You can: ## 软件开发之外的贡献
- Help create or proofread translations for the software interface and documentation in various languages 即使您不是软件开发人员, 我们也欢迎您加入贡献!
- Create open memory unit sets (including but not limited to text, images, and audio) for other users
- Improve the software documentation
- Answer questions from other users or share your experience
- Propose new ideas or report issues in the discussion area
You decide your role! 您可以:
- 协助创建各种语言的翻译来翻译软件的界面 (但我们目前还没有 i18n 平台, 所以如果您想贡献翻译, 可能需要手动联系我们)
- 制作图像、主题、音效乃至制作开放的记忆单元集给其他用户使用
- 改进软件配套的文档
- 维护软件的开发/交流群组
- 给其他用户答疑解惑或分享自己的经验
- 在讨论区提出新想法或反馈问题
您的角色您来定!
-119
View File
@@ -1,119 +0,0 @@
# 贡献指南与二次开发
欢迎支持此项目!
目前, 项目仓库主服务器为<a href="https://git.pluv27.top/pluv/HeurAMS" target="_blank" rel="noopener noreferrer">作者的 Gitea 实例</a>, 它负责管理同步, 保证可用性并同时接受来自多个社区的协作, 并在 <a href="https://github.com/pluvium27/HeurAMS" target="_blank" rel="noopener noreferrer">GitHub</a>, <a href="https://invent.kde.org/pluv/HeurAMS" target="_blank" rel="noopener noreferrer">KDE Invent</a> 和 <a href="https://gitee.com/pluv/HeurAMS" target="_blank" rel="noopener noreferrer">Gitee</a> 设置了镜像同步.
这丝毫不影响项目接受来自 <a href="https://github.com/pluvium27/HeurAMS" target="_blank" rel="noopener noreferrer">GitHub</a>, <a href="https://invent.kde.org/pluv/HeurAMS" target="_blank" rel="noopener noreferrer">KDE Invent</a> 和 <a href="https://gitee.com/pluv/HeurAMS" target="_blank" rel="noopener noreferrer">Gitee</a> 的 PR, 在 GitHub, KDE Invent 和 Gitee 所接受的 PR 会保留贡献者标识并按原样同步回所有平台, 欢迎在任意平台为项目做出贡献.
> [!NOTE]
> 我们已经开始着手于基于 KDE 用户界面框架 `Kirigami` 的现代跨平台前端开发, 称作 "KiriMemo", 包名是 "org.kde.kirimemo", 但其并非 KDE 项目\
> 它通过 `PyOtherSide` 直接复用 python 内核, 为 Windows, Linux, macOS, Android, iOS 和 Plasma Mobile 提供现代用户界面
> 如果您善于开发 C++, QML, Qt 与 KDE 框架, 欢迎加入到 KiriMemo 项目的开发
## 开发规范
分支划分:
- `dev` 分支(仓库默认分支): 主线开发分支, 自身仅用于非重构的问题修复和整合功能分支, 拉取请求在该分支合并
- `master` 分支: 主线稳定版本, 仅当稳定版本释出或修补版本时将 `dev` 合并到 `master`
- 功能与重构分支: 从 `dev` 分支创建, 命名格式为 `feature/描述``fix/描述``refactor/描述``next/版本号`
- 功能与重构分支应先合并至 `dev`, 再合并至 `master`
代码格式化:
- 安装工具:
```bash
python -m pip install black autoflake mdformat
```
- 对于 Python, 使用 `black` 与 `autoflake` 格式化\
命令:
```bash
# black 的多线程在某些环境下有兼容性问题
black . --workers=1
```
```bash
# autoflake 注意排除 __init__.py
autoflake --in-place --remove-all-unused-imports --recursive ./src/ --exclude __init__.py
```
- 对于 Markdown, 使用 `mdformat` 格式化
命令:
```bash
mdformat --number .
```
- 对于 Textual CSS, 可以使用 `prettier` 格式化
- 格式化不是必需的, 可以整合入一次 `style` 提交, 但 `master` 和 `dev` 分支上的代码应尽量整洁, 以便合并时审查
提交消息:
- 使用简体中文或英文撰写清晰的提交消息
- 提交消息格式: 遵循 [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) 规范, 建议使用 `koji` 工具
合并方式:
- 为了一致性和可追溯性, 项目自 v0.4.0 重构后重新初始化仓库起就禁止使用 Fast-forward 合并
- 可以设置 `git config merge.ff false`
提交署名方式:
由于 KDE Invent 设施的奇怪 git hook, commit 的 Author 字段需要看起来像个真名(例如 Wang Zhiyu 不能写为 wangzhiyu, 否则 KDE Invent 的 hook 会拒绝 push),
所以请确保您的 git 配置使用了类似正式姓名的格式 (例如 git config user.name "Li Hua", 也即中间需要空格), 不一定要真实姓名, 邮箱无要求, 也可以将单名重复使用两次 (例如 Thura Thura) 以通过检测.
## 设置开发环境
```bash
git clone https://git.pluv27.top/pluv/HeurAMS # 默认分支为 dev, 所以不必切换分支
cd HeurAMS
# 如果决定使用 uv (推荐)
python3 -m pip install uv
uv sync --all-extras # 同步开发运行环境
uv run heurams
# 如果决定使用原生 python 环境 (不推荐, 但我们保留了这种方式以便在不便支持 uv 与硬链接的环境和文件系统(例如 termux)上运行)
python3 -m pip install -e .[all] # 安装依赖并将 HeurAMS 安装为本地包
python3 -m heurams # 验证安装
python3 -m heurams.interface # 启动 TUI
```
## 许可证与外部引用
贡献者拥有其贡献部分的版权同意其贡献将在 AGPL-3.0 许可证(包括附加的本机 API 调用豁免条款)下发布.
如有以下情况, 请在 PR 描述中注明:
- 如果需要引入其他开源 vendor
- 如果需要引入其他专有的网络服务(例如当前项目中的 edgetts)
- 如果需要升级某个依赖或运行环境的版本
## 新的用户界面前端
HeurAMS 被设计为一个可独立于前端的程序库, 这意味着:
- 我们的内置 Textual TUI 前端不是唯一可用的前端
- 如果您有一个自己开发的且可用的 HeurAMS 前端 (例如未实现的 Flutter 前端), 并且以 AGPL-3.0/GPL-3.0 开放源代码, 可以联系我们将它转移到 HeurAMS 的官方仓库中以便共同维护, 您将保留您的版权并可主导该仓库下的开发工作 :)
- 您还可以在自己的项目中以独立进程/服务调用 HeurAMS, 根据 AGPL-3.0 及本项目的附加许可条款, 如果调用发生在同一主机上且不涉及外部网络转发, 则可豁免许可证规定的特定义务而免于受 AGPL-3.0 "污染". 为了这点, 我们正在完善可选择启用的跨进程 RPC 模块, 这将成为潜进内核的跨平台标准件.
- 如果您通过独立进程/服务调用方式开发了另外的软件, 开源但不愿使用 AGPL-3.0/GPL-3.0 许可证, 也可以联系我们, 我们乐于将您的项目链接添加到友链中
## 软件开发之外的贡献
即使您不是软件开发人员, 我们也欢迎您加入贡献!
您可以:
- 协助创建或核对各种语言的翻译来翻译软件的界面和文档
- 制作开放的记忆单元集(包括但不限于文字、图像、音效)给其他用户使用
- 改进软件配套的文档
- 给其他用户答疑解惑或分享自己的经验
- 在讨论区提出新想法或反馈问题
您的角色您来定!
+524 -108
View File
@@ -1,27 +1,60 @@
GNU AFFERO GENERAL PUBLIC LICENSE GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007 Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. of this license document, but changing it is not allowed.
Preamble Preamble
The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software. The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software. Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public. A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version. The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license. An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and modification follow. The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS TERMS AND CONDITIONS
@@ -29,217 +62,600 @@ The precise terms and conditions for copying, distribution and modification foll
"This License" refers to version 3 of the GNU Affero General Public License. "This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. "The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based on the Program. A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code. 1. Source Code.
The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work.
A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work. subprograms and other parts of the work.
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that same work. The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions. 2. Basic Permissions.
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law. 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies. 4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions. 5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified it, and giving a relevant date. You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms. 6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). "Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms. 7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. "Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination. 8. Termination.
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies. 9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients. 10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents. 11. Patents.
A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent If you convey a covered work, knowingly relying on a patent license,
license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom. 12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may If conditions are imposed on you (whether by court order, agreement or
not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License. 13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph. Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License. Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License. 14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation. Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty. 15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability. 16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16. 17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
HeurAMS <one line to give the program's name and a brief idea of what it does.>
Copyright (C) 2025 Wang Zhiyu (pluvium27) Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail. Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements. If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see <http://www.gnu.org/licenses/>. You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
--- For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.
Additional Permission under AGPL Section 7
Local API exemption: When the program is accessed solely via API (including RPC, REST API, GraphQL, or any machine-to-machine interface) from a caller on the same host machine, the source disclosure requirement of AGPL Section 13 is waived.
Any API call from a different machine (including LAN, private network, or the internet) remains fully subject to AGPL Section 13.
This exemption does NOT apply to human-facing web interfaces.
+106 -107
View File
@@ -1,143 +1,142 @@
# HeurAMS - Heuristic Auxiliary Memorizing Scheduler # 潜进 (HeurAMS) - 启发式辅助记忆调度器
[中文](README_zh.md) | English ## 概述
## Overview "潜进" (HeurAMS: Heuristic Auxiliary Memorizing Scheduler, 启发式记忆辅助调度器) 是一个基于启发式算法与认知科学理论的辅助记忆调度器, 旨在帮助用户更高效地进行记忆工作与学习规划, 也是一个开放, 优雅, 易于扩展的间隔重复调度器实验平台, 旨在帮助研究者更高效地进行前沿记忆算法的研究.
HeurAMS "潜进" (Heuristic Auxiliary Memorizing Scheduler) is an auxiliary memorizing scheduler based on heuristic algorithms and cognitive science theories, designed to help users memorize and plan learning more efficiently. ## 项目结构
It is also an open, elegant, and extensible spaced repetition scheduler experiment platform, intended to help researchers conduct investigations, experiments, and research on cutting-edge memory algorithms more efficiently.
[Detailed Introduction](docs/INTRODUCTION.md) | [Screenshots](docs/SCREENSHOTS.md) 这个仓库是 "潜进" 的核心程序库在 python 语言下的实现\
包含数据模型与框架, 并内置了基于 textual 框架的前端实现 (interface 子模块)\
除了通过内置前端进行学习外, 开发者也能在 python 环境中导入 `heurams` 库, 使用框架构建其他辅助记忆功能前端或其他应用程序
<p align="left"> ## 特性
<a href="https://github.com/pluvium27/HeurAMS" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/GitHub-fafafa?style=for-the-badge&logo=github&logoColor=181717" alt="GitHub" /></a><a href="https://invent.kde.org/pluv/HeurAMS" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/KDE_Invent-1D99F3?style=for-the-badge&logo=kde&logoColor=white" alt="KDE Invent" /></a><a href="https://gitee.com/pluv/HeurAMS" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/Gitee-C71D23?style=for-the-badge&logo=gitee&logoColor=white" alt="Gitee" /></a><a href="https://git.pluv27.top/pluv/HeurAMS" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/git.pluv27.top-609926?style=for-the-badge&logo=gitea&logoColor=white" alt="git.pluv27.top" /></a>
</p>
## Quick Start ### 间隔重复调度器
### Installation > 许多出版物都广泛讨论了不同重复间隔对学习效果的影响. 特别是, 间隔效应被认为是一种普遍现象. 间隔效应是指, 如果重复的间隔是分散/稀疏的, 而不是集中重复, 那么学习任务的表现会更好. 因此, 有观点提出, 学习中使用的最佳重复间隔是**最长的, 但不会导致遗忘的间隔**.
#### Install from Package Manager - 软件开箱即用, 无需多加配置即可使用默认的 `SM-2` 算法进行学习
- 此外, 算法模块是 "潜进" 内核 (heurams.kernel) 中的一等公民, 内核天然支持插拔各型算法
- 无需安装繁杂的插件即可分单元集完成算法快速切换与调优, 研究者可以方便地修改算法模块以便捷地进行研究与测试
- 内置 `SM-2` 简单间隔重复算法, 此算法亦用作 `Anki` 闪卡记忆软件的默认闪卡调度器
- 还内置 `NSP-0` 筛选用非间隔重复算法以便快速筛选记忆内容, `FSRS` 先进间隔重复算法作为效率更高的调度器, 与 `SM-15M (移植自 sm.js 项目)` 复杂间隔重复算法(逆向工程)
- 算法模块可以标记记忆项目, 也可以动态规划每个记忆单元的记忆间隔时间表, 动态跟踪记忆反馈数据, 以优化长期记忆保留率与稳定性
- 得益于项目的模块化架构与单元集结构设计, 一个项目甚至可以与任意种算法共存并互通, 这对研究者及想探索/实验高效率方法的用户极其友好
HeurAMS (package name `heurams`) is in early development and not yet available on PyPI. ### 多模态学习进程
However, you can install stable and development versions from the repository using pip, which requires a Python environment (Python 3.12.13 or later recommended).
Install from the stable `master` branch with optional dependencies for user experience (recommended): `Anki` 的 SQLite `apkg` 包不同, 潜进项目坚持使用人类可读的文件夹组织单元集, 这带来了若干好处, 包括:
- 人类可读: 您可以用任意工具, 乃至一个记事本自由修改记忆载荷数据而无需打开软件
- 元数据配置: 配置自由度极高, 可以任意组合, 重造, 乃至创造新内容
- 测验, 算法与知识互相隔离: 您的记忆项目不再是单一的闪卡, 而是 `载荷(payload)``谜题(puzzle)` 通过 `元数据(typedef)` 抽象成的 `核子(nucleon)` 对象, 在程序内部和 `算法数据(algodata)` 抽象成的 `电子`, `调度设置(schedule)` 定义的 `轨道(orbital)` 共同有机组合成的运行时对象 `原子(atom)`! 这意味着一条知识不仅可以用若干不同的算法规划, 还可以用多种并行的谜题类型测验, 极大地提升您的学习效果和丰富度. 作为学习者, 您无需担忧这些概念复杂--仅需从云端下载单元集即可开箱即用上述特性!
- 多模态学习
- 软件自身集成了文本转语音 (TTS) , 音频与语言模型 (LLM) 模块, 这些功能乃至功能本身都是可插拔, 可扩展, 可切换驱动的, 这为内容创建了极大的丰富度
- 软件内置多种谜题类型, 包括选择题 (MCQ), 填空题 (Cloze) 与识别题 (Recognition), 您可在同一单元应用多种, 或是选择启用
- 软件天然支持动态内容生成, 支持宏驱动的模板系统, 根据上下文乃至语言模型动态生成知识点的解析
- 在间隔重复研究尚被 SuperMemo 系列独占的时代, Wozniak 就早已表示 "如果不能理解知识, 就无需记忆它". 今天, 我们依然相信理解是记忆的基石
- 云同步与分享优化: 由于我们的记忆数据和单元集文件都是文本文件, 故可进行快速的增量同步而无需完整地上传所有文件, 并且设计天然支持分享内容的版本控制, 如果您想分享单文件, 我们也支持 .zip/.tar.gz/.tar.xz 导入与导出
- 性能提升: 得益于现代且支持分块的文件组织结构, 潜进能在保持高自由度的同时仅使用 python 就能达到敏捷且低占用的用户体验
### 实用用户界面
- 响应式 Textual 框架构建的跨平台 TUI 界面
- 支持触屏/鼠标/键盘多操作模式
- 简洁直观的复习流程设计
## 快速开始
### 从包管理器安装
潜进(heurams) 处于早期开发考虑, 尚未上架 PyPI, 但您可以用我们的基础设施安装稳定版和开发版本.
> [!CAUTION]
> 对于部分 Linux 发行版和 Android Termux 用户:\
> 您需要先行安装 `cmake` 和 `libzmq` 才能正确安装项目的 `zmq` 依赖\
> 例如在 termux 上先运行 `pkg install cmake clang libzmq`\
> 项目功能本身不依赖它, 但需要该依赖用于启动可选的调试服务器
#### 稳定版本
``` ```
pip install --upgrade 'heurams[basic] @ https://git.pluv27.top/pluv/HeurAMS/archive/master.zip' python -m pip install heurams[all] -i https://pypi.pluv27.top/root/stable/+simple/ # 安装全部可选依赖(推荐)
``` ```
Install from the more recent, roughly stable `dev` branch with optional dependencies (if you want cutting-edge improvements): #### 开发版本
``` ```
pip install --force-reinstall --no-deps 'heurams[basic] @ https://git.pluv27.top/pluv/HeurAMS/archive/dev.zip' python -m pip install heurams[all] -i https://pypi.pluv27.top/root/dev/+simple/ # 安装全部可选依赖(推荐)
``` ```
Install the general audio module for desktop computers (based on playsound3):\ #### 依赖组说明
(Not applicable for termux environments; termux has built-in audio support)
``` 由于部分依赖只被少数功能需要, 所以我们把可选依赖分得比较细, 前面的命令会安装所有可选依赖, 以下是依赖组列表
pip install --upgrade 'heurams[audio-playsound] @ https://git.pluv27.top/pluv/HeurAMS/archive/master.zip'
```
> You can also install from specific branches like `refactor/...` to test particular changes. - 基础依赖: (只能驱动程序库)
- tabulate: 终端表格
- toml: TOML 文件加载
- transitions: 状态机依赖
- `interface` 依赖组: (基本用户界面依赖)
- textual: 终端用户界面
- psutil: 获取系统信息
- `algo-fsrs` 依赖组:
- py-fsrs: FSRS 算法模块需要
- `tts-edgetts` 依赖组:
- edge-tts:微软文本转语音
- `misc-jieba` 依赖组:
- jieba: 中文智能分词所需
- `llm-openai` 依赖组:
- openai: OpenAI API 所需
- `audio-playsound` 依赖组:
- playsound: 通用音频播放
- pygobject: playsound 依赖
- `dev` 依赖组:
- zmq: 远程调试服务器所需
- pytest: 测试所需
- pytest-cov: 测试所需
- `all` 依赖组:
- 包含以上所有依赖
[Dependency Group Reference](docs/INTRODUCTION.md#package-dependency-groups) ### 从源码安装
#### Install from Source 我们提供原生 python 和 uv 两种安装方式.\
详见[贡献指南](CONTRIBUTING.md).
We provide two source installation methods: native Python and uv. ## 项目结构
See the [Contributing Guide - Setting up Development Environment](CONTRIBUTING.md#setting-up-development-environment) for details.
### Usage 详见[架构说明](ARCHITECTURE.md).
Run `heurams` in your terminal, and you will see help information: ## 参与项目
```plain 欢迎参与到项目协作中! 请参阅 [CONTRIBUTING.md](CONTRIBUTING.md) 了解贡献指南.
~ $ heurams
Usage: heurams [OPTIONS] COMMAND [ARGS]...
HeurAMS 0.5.1 - Heuristic Auxiliary Memorizing Scheduler ## 许可证
Options: ### 项目本身
-v, --version Show the version and exit.
-h, --help Show this message and exit.
Commands: 本项目基于 AGPL-3.0 许可证开源. 详见根目录下 [LICENSE](LICENSE) 文件.
help Show this help message
tui Launch the built-in basic user interface (TUI)
version Print version information
```
Start the basic user interface by typing `heurams tui`: ### 第三方代码
```plain 项目在 `src/heurams/vendor/` 目录下嵌入或在其他位置间接使用了以下第三方代码(可能有修改):
~ $ heurams tui
Welcome to the basic user interface!
Loading config and context... Done! (2ms)
Loading UI framework... Done! (89ms)
Loading UI layout... Done! (56ms)
Component directory: <package directory>
Working directory: <working directory, ./data folder will be created here>
Pre-work total: 147ms
(Your terminal will now display the TUI) #### py-fsrs (open-spaced-repetition)
```
Check the version with `heurams -v`: - 上游版本: 6.3.1
- 引用方式: vendor
- 位置: `src/heurams/vendor/pyfsrs/`
- 原项目: [py-fsrs](https://github.com/open-spaced-repetition/py-fsrs)
- 原版权: Copyright (c) 2026 Open Spaced Repetition Contributors
- 原许可证: MIT License
``` #### SM.js (slaypni)
~ $ heurams -v
HeurAMS 0.5.1 stable (fulcrum/支点), Linux
```
## Frequently Asked Questions (FAQ) - 上游版本: commit `6e3bb4afaf484426deb4a9fa3bcffe42ac066b45` (2015年2月4日上游已停止维护)
- 引用方式: 将 coffeescript 重写为 python 并间接引用, 数学原理一致; 并对重写后代码进行逻辑, 性能与标准化 API 改进
- 位置: `src/heurams/kernel/algorithms/sm15m*.py`
- 原项目: [SM.js](https://github.com/slaypni/SM-15)
- 原版权: Copyright (c) 2014 Kazuaki Tanida
- 原许可证: MIT License
See [FAQ](docs/FAQ.md). 本项目受益于他们无私且优秀的工作.
## Project Architecture
See [Architecture Overview](docs/ARCHITECTURE.md).
## Contributing
Contributions are welcome!
See the [Contributing Guide](CONTRIBUTING.md).
For AI-assisted development guidelines, see [AGENTS.md](AGENTS.md).
## Project Identity
HeurAMS project identity assets are located in `./src/heurams/assets/art/` directory:
<img src="src/heurams/assets/art/banner128-light.png" height="96px" title="Bitmap Banner (Opaque)">
<div style="display: flex; flex-wrap: wrap; gap: 5px;">
<img src="src/heurams/assets/art/logo.svg" height="96px" title="Vector Icon">
<img src="src/heurams/assets/art/logo-mono-light.svg" height="96px" title="Monochrome Light Vector Icon">
<img src="src/heurams/assets/art/logo-mono-dark.svg" height="96px" title="Monochrome Dark Vector Icon">
</div>
Colors: `#1660A5 (Ocean Blue)` `#545F70 (Blue Gray)` `#FFFFFF (Monochrome Light Icon White)` `#1A1A1A (Monochrome Dark Icon Deep Black)` `#2f2f35 (Text Color)`.
## License
### Project
This project is open source under the AGPL-3.0 license, with an additional exemption clause for local API calls, making it more permissive than the standard AGPL-3.0.
See the [LICENSE](LICENSE) file in the root directory.
### Third-Party Code
The project embeds or directly uses the following third-party code or its derivatives (possibly with modifications) in `src/heurams/vendor/` or other locations:
#### SM.js
- Upstream version: commit `6e3bb4a` (upstream discontinued as of Feb 4, 2015)
- Usage: Rewritten from CoffeeScript to Python with indirect reference, maintaining the same mathematical principles; improved logic, performance, and standardized API
- Location: `src/heurams/kernel/algorithms/sm15m.py`
- Original project: [SM.js](https://github.com/slaypni/SM-15)
- Original copyright: Copyright (c) 2014 Kazuaki Tanida
- Original license: MIT License
This project benefits from their selfless and excellent work.
-144
View File
@@ -1,144 +0,0 @@
# HeurAMS "潜进" - 启发式辅助记忆调度器
中文 | [English](README.md)
## 概述
HeurAMS "潜进" (Heuristic Auxiliary Memorizing Scheduler, 启发式记忆辅助调度器) 是一种基于启发式算法与认知科学理论的辅助记忆调度器, 旨在帮助用户更高效地进行记忆工作与学习规划,
也是一种开放, 优雅, 易于扩展的间隔重复调度器实验平台, 旨在帮助研究者更高效地进行前沿记忆算法的调查实验与研究.
[详细介绍](docs/INTRODUCTION_zh.md) [屏幕截图](docs/SCREENSHOTS_zh.md)
<p align="left">
<a href="https://github.com/pluvium27/HeurAMS" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/GitHub-fafafa?style=for-the-badge&logo=github&logoColor=181717" alt="GitHub" /></a><a href="https://invent.kde.org/pluv/HeurAMS" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/KDE_Invent-1D99F3?style=for-the-badge&logo=kde&logoColor=white" alt="KDE Invent" /></a><a href="https://gitee.com/pluv/HeurAMS" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/Gitee-C71D23?style=for-the-badge&logo=gitee&logoColor=white" alt="Gitee" /></a><a href="https://git.pluv27.top/pluv/HeurAMS" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/git.pluv27.top-609926?style=for-the-badge&logo=gitea&logoColor=white" alt="git.pluv27.top" /></a>
</p>
## 快速开始
### 安装软件
#### 从包管理器安装
潜进 (包名是 `heurams`) 处于早期开发考虑, 尚未上架 PyPI.
但可以用 pip 从仓库安装稳定版和开发版本, 这要求设备上安装了 python 环境 (建议 3.12.13 及之后版本).
从稳定的 `master` 分支安装, 并安装适用于用户体验的可选依赖(推荐):
```
pip install --upgrade 'heurams[basic] @ https://git.pluv27.top/pluv/HeurAMS/archive/master.zip'
```
从较前沿, 大致稳定的 `dev` 分支安装, 并安装适用于用户体验的可选依赖(如果您追求较前沿的改进):
```
pip install --force-reinstall --no-deps 'heurams[basic] @ https://git.pluv27.top/pluv/HeurAMS/archive/dev.zip'
```
安装适用于一般计算机的通用音频模块 (基于 playsound3):\
(此项不适用于 termux 环境, termux 的音频支持是内建的)
```
pip install --upgrade 'heurams[audio-playsound] @ https://git.pluv27.top/pluv/HeurAMS/archive/master.zip'
```
> 您也可以从 `refactor/...` 等特定分支安装以测试某项更改
[依赖分组说明](docs/INTRODUCTION_zh.md#包依赖组说明)
#### 从源码安装
我们提供原生 python 和 uv 两种源码安装方式.\
详见[贡献指南 - 设置开发环境](CONTRIBUTING_zh.md#设置开发环境).
### 使用软件
在终端中运行 `heurams`, 您会看到一系列帮助信息, 例如:
```plain
~ $ heurams
Usage: heurams [OPTIONS] COMMAND [ARGS]...
HeurAMS 0.5.1 - 启发式辅助记忆调度器
Options:
-v, --version Show the version and exit.
-h, --help Show this message and exit.
Commands:
help 显示此帮助信息
tui 启动内置基本用户界面 (TUI)
version 输出版本信息
```
可以通过键入 `heurams tui` 启动基本用户界面, 例如:
```plain
~ $ heurams tui
欢迎使用基本用户界面!
加载配置与上下文... 已完成! (耗时: 2ms)
加载用户界面框架... 已完成! (耗时: 89ms)
加载用户界面布局... 已完成! (耗时: 56ms)
组件目录: <软件包所在目录>
工作目录: <运行目录, 将在此目录下建立 ./data 文件夹>
前置工作共计耗时: 147ms
(此时您的终端将转为呈现美观的 TUI 基本用户界面)
```
通过键入 `heurams -v` 查看版本:
```
~ $ heurams -v
HeurAMS 0.5.1 stable (fulcrum/支点), Linux
```
## 常见问题 (FAQ)
详见[常见问题](docs/FAQ_zh.md).
## 项目架构
详见[架构说明](docs/ARCHITECTURE_zh.md).
## 参与项目
欢迎参与到项目协作中!\
详见[贡献指南](CONTRIBUTING_zh.md).\
关于 AI 辅助开发的说明, 请参阅 [AGENTS.md](AGENTS.md).
## 项目标识
HeurAMS 项目标识如下, 文件(位图和矢量图)位于 `./src/heurams/assets/art/` 目录.
<img src="src/heurams/assets/art/banner128-light.png" height="96px" title="位图横幅(不透明)">
<div style="display: flex; flex-wrap: wrap; gap: 5px;">
<img src="src/heurams/assets/art/logo.svg" height="96px" title="矢量图标">
<img src="src/heurams/assets/art/logo-mono-light.svg" height="96px" title="单色明亮矢量图标">
<img src="src/heurams/assets/art/logo-mono-dark.svg" height="96px" title="单色暗色矢量图标">
</div>
颜色分别是: `#1660A5 (海蓝色)` `#545F70 (蓝灰色)` `#FFFFFF (单色明亮图标白色)` `#1A1A1A (单色暗色图标深黑色)` `#2f2f35 (文字颜色)`.
## 许可证
### 项目本身
本项目基于 AGPL-3.0 许可证开放源代码, 并有一个豁免本机 API 调用的附加条款, 较标准 AGPL-3.0 更宽松.
详见根目录下 [LICENSE](LICENSE) 文件.
### 第三方代码
项目在 `src/heurams/vendor/` 目录下嵌入或在其他位置直接使用了以下第三方代码或其衍生作品 (可能有修改):
#### SM.js
- 上游版本: commit `6e3bb4a` (2015年2月4日上游已停止维护)
- 引用方式: 将 coffeescript 重写为 python 并间接引用, 数学原理一致; 并对重写后代码进行逻辑, 性能与标准化 API 改进
- 位置: `src/heurams/kernel/algorithms/sm15m.py`
- 原项目: [SM.js](https://github.com/slaypni/SM-15)
- 原版权: Copyright (c) 2014 Kazuaki Tanida
- 原许可证: MIT License
本项目受益于他们无私且优秀的工作.
@@ -10,7 +10,7 @@ quick_pass = true
_quick_pass_desc = "[调试] 启用快速应答功能(跳过测验)" _quick_pass_desc = "[调试] 启用快速应答功能(跳过测验)"
auto_pass = false auto_pass = false
_auto_pass_desc = "[调试] 自动通过测试模式" _auto_pass_desc = "[调试] 自动通过测试模式"
scheduled_num = 35 scheduled_num = 420
_scheduled_num_desc = "默认记忆单元数量\n可被单元集设置覆盖" _scheduled_num_desc = "默认记忆单元数量\n可被单元集设置覆盖"
refresh_on_resume = true refresh_on_resume = true
_refresh_on_resume_desc = "[调试] 每当 Screen 激活后都刷新状态" _refresh_on_resume_desc = "[调试] 每当 Screen 激活后都刷新状态"
@@ -1,2 +1,2 @@
min_denominator = " 1" min_denominator = "2"
_min_denominator_desc = "设空比例系数的倒数" _min_denominator_desc = "设空比例系数的倒数"
+11
View File
@@ -0,0 +1,11 @@
algorithm = "NSP-0"
_algorithm_desc = "记忆调度算法"
scheduled_num = 420
_scheduled_num_desc = "单次记忆单元数量"
[_algorithm_candidate]
NSP-0 = "筛选用非间隔重复调度器"
none = "不设置默认调度器"
SM-2 = "第二代 SuperMemo 简单间隔重复调度器"
SM-15M = "第15代 SuperMemo 复杂间隔重复调度器 (不稳定且逆向工程)"
FSRS = "先进开放间隔重复调度器"
+11
View File
@@ -0,0 +1,11 @@
algorithm = "SM-2"
_algorithm_desc = "记忆调度算法"
scheduled_num = 20
_scheduled_num_desc = "单次记忆单元数量"
[_algorithm_candidate]
NSP-0 = "筛选用非间隔重复调度器"
none = "不设置默认调度器"
SM-2 = "第二代 SuperMemo 简单间隔重复调度器"
SM-15M = "第15代 SuperMemo 复杂间隔重复调度器 (不稳定且逆向工程)"
FSRS = "先进开放间隔重复调度器"
@@ -2,7 +2,7 @@ provider = "playsound"
_provider_desc = "音频驱动类型" _provider_desc = "音频驱动类型"
[_provider_candidate] [_provider_candidate]
playsound = "Python 桌面跨平台音频系统, 使用了 playsound3 替代了老旧的 playsound" playsound = "python 跨平台音频系统"
termux = "Android Termux 音频系统" termux = "Android Termux 音频系统"
mpg123 = "通用音频系统, 依赖系统 mpg123" mpg123 = "通用音频系统, 依赖系统 mpg123"
pulseaudio = "高级音频路由系统" pulseaudio = "高级音频路由系统"
@@ -1,4 +1,4 @@
provider = "none" provider = "openai"
_provider_desc = "模型接口类型" _provider_desc = "模型接口类型"
[_provider_candidate] [_provider_candidate]
@@ -1,4 +1,4 @@
provider = "none" provider = "webdav"
_provider_desc = "同步服务驱动类型" _provider_desc = "同步服务驱动类型"
[_provider_candidate] [_provider_candidate]
+1
View File
@@ -0,0 +1 @@
[]
+1
View File
@@ -0,0 +1 @@
{}
+4
View File
@@ -0,0 +1,4 @@
title = "高考必背古诗文-筛选"
package = "cngk-t"
author = "__heurams__"
desc = "高考古诗文 60 篇"
File diff suppressed because it is too large Load Diff
+11
View File
@@ -0,0 +1,11 @@
schedule = ["quick_review", "recognition", "final_review"]
[routes]
quick_review = [["FillBlank", "1.0"], ["Recognition", "1.0"]]
recognition = [["FillBlank", "1.0"]]
final_review = [["FillBlank", "1.0"], ["Recognition", "1.0"]]
[annotation]
"quick_review" = "复习旧知"
"recognition" = "新知识"
"final_review" = "总复习"
+17
View File
@@ -0,0 +1,17 @@
[annotation]
note = "笔记"
keyword_note = "关键词翻译"
translation = "语句翻译"
delimiter = "分隔符"
content = "内容"
tts_text = "文本转语音文本"
[common]
delimiter = "/"
tts_text = "eval:payload['content'].replace('/', '')"
[common.puzzles] # 谜题定义
# 我们称 "Recognition" 为 recognition 谜题的 alia
"Recognition" = { __origin__ = "recognition", __hint__ = "", primary = "eval:payload['content']", secondary = ["eval:payload['keyword_note']", "eval:payload['note']"], top_dim = ["eval:payload['translation']"] }
"SelectMeaning" = { __origin__ = "mcq", __hint__ = "eval:payload['content']", primary = "eval:payload['content']", mapping = "eval:payload['keyword_note']", jammer = "eval:list(payload['keyword_note'].values())", max_riddles_num = "eval:default['mcq']['max_riddles_num']", prefix = "选择正确项: " }
"FillBlank" = { __origin__ = "cloze", __hint__ = "", text = "eval:payload['content']", delimiter = "eval:nucleon['delimiter']", min_denominator = "eval:default['cloze']['min_denominator']"}
-438
View File
@@ -1,438 +0,0 @@
## Overall Architecture Overview
```mermaid
graph TB
subgraph "User Interface Layer (TUI)"
TUI[Textual App]
Screens[Application Screens]
Widgets[Puzzle Widgets]
end
subgraph "Kernel Layer"
Reactor[Scheduling Reactor]
Algorithms[Algorithm Modules]
Particles[Data Models]
Puzzles[Puzzle Engine]
RepoLib[Repository System]
Auxiliary[Auxiliary Tools]
end
subgraph "Service Layer"
Config[Config Management ConfigDict]
Logger[Logging System]
Timer[Time Service]
Audio[Audio Service]
TTS[TTS Service]
Favorites[Favorites Management]
Attic[Persistence]
Hasher[Hash Service]
end
subgraph "Provider Layer"
AudioProv[Audio Provider]
TTSProv[TTS Provider]
LLMProv[LLM Provider]
end
subgraph "Data Layer"
RepoDir[TOML/JSON Repository Directory]
ConfigDir[TOML Config Directory]
Logs[Log Files]
end
TUI --> Screens
Screens --> Reactor
Screens --> RepoLib
Screens --> Widgets
Widgets --> Puzzles
Widgets --> Reactor
Reactor --> Algorithms
Reactor --> Particles
Reactor --> Puzzles
Particles --> RepoLib
RepoLib --> Config
RepoLib --> Auxiliary
Auxiliary --> Lict
Auxiliary --> Evalizer
TUI --> Config
TUI --> Logger
TUI --> Audio
TUI --> TTS
Config --> ConfigDir
Audio --> AudioProv
TTS --> TTSProv
Attic --> RepoDir
```
## Data Model
The project uses the physical particle metaphor as its core, decomposing memory units into three models:
### Nucleon - Content Layer
```
Nucleon(ident, payload, common)
```
- **Read-only** content container. Compiles and expands `payload` and `common` via `Evalizer` (an `eval()`-based template system).
- Contains `puzzles` field, defining which puzzle types this memory unit supports.
- Created by pairing `repo.payload` and `repo.typedef["common"]`.
- Once created, content cannot be modified (`__setitem__` raises `AttributeError`).
### Electron - State Layer
```
Electron(ident, algodata, algo_name)
```
- Wrapper for algorithm state data. Each Electron is bound to one algorithm (`algorithms[algo_name]`).
- `algodata` is a **reference** to the corresponding dictionary in the repository's `algodata.lict` — modifications are persisted immediately.
- Core methods: `activate()` (mark as activated), `revisor()` (rating iteration), `is_due()` (due check).
### Orbital - Strategy Layer
```
orbital = {
"schedule": ["quick_review", "recognition"],
"routes": {
"quick_review": [["MCQ", "1.0"], ["Cloze", "0.5"]],
"recognition": [["Recognition", "1.0"]],
}
}
```
- A plain dictionary defining the review phase flow and puzzle selection strategy within each phase.
- Each phase corresponds to a list of `(puzzle_type, probability_coefficient)` tuples; coefficients >1 indicate forced repetition count.
### Atom - Runtime Assembly
```
Atom(nucleon, electron, orbital)
```
- Runtime composition of the three, with `runtime` flags (`locked`, `min_rate`, `new_activation`).
- The basic unit operated on by the UI and scheduling layers.
- `revise()` calls `electron.revisor(min_rate)` when `locked` is true, performing the final rating iteration.
**Relationship Diagram**:
```mermaid
graph LR
subgraph "Persistent Storage"
Payload[(payload.toml)]
Common[(typedef.toml)]
Algodata[(algodata.json)]
Schedule[(schedule.toml)]
end
subgraph "Runtime Assembly"
Nucleon -->|Content| Atom
Electron -->|State| Atom
Orbital -->|Strategy| Atom
end
Payload -->|Repo| Nucleon
Common -->|Repo| Nucleon
Algodata -->|Repo| Electron
Schedule -->|Repo| Orbital
```
## Scheduling Reactor
The Scheduling Reactor is the core business process engine, designed as a three-layer nested finite state machine (based on the `transitions` library).
### State Enumeration
| State Machine | State | Description |
|---------------|-------|-------------|
| **RouterState** | `unsure` | Initial state, auto-advances |
| | `quick_review` | Quick review phase |
| | `recognition` | New memory recognition phase |
| | `final_review` | Final comprehensive review phase |
| | `finished` | Complete, execute rating |
| **ProcessionState** | `active` | In progress |
| | `finished` | Completed |
| **ExpanderState** | `exammode` | Exam mode (frontal answering) |
| | `retronly` | Retrospective mode (recognition only) |
### State Machine Nesting Structure
```mermaid
graph TB
subgraph "Router (Global Router)"
R[Router<br/>State: unsure→quick_review<br/>→recognition→final_review<br/>→finished]
P1[Procession Queue 1: Quick Review]
P2[Procession Queue 2: New Memories]
P3[Procession Queue 3: Final Review]
R --> P1
R --> P2
R --> P3
end
subgraph "Procession (Single-Phase Queue)"
P1 --> E1[Expander Atom A]
P1 --> E2[Expander Atom B]
P1 --> E3[Expander Atom C]
M{forward} --> |Done| Finish((FINISHED))
end
subgraph "Expander (Single Atom Expander)"
E1 --> S[(Orbital Strategy)]
S -->|Probability Expansion| PZ1[Puzzle 1: MCQ]
S -->|Probability Expansion| PZ2[Puzzle 2: Cloze]
PZ1 -->|Rating| RPT[report]
PZ2 -->|Rating| RPT
RPT -->|finish| RETRO[retronly mode]
end
```
### Data Flow Detail
```
Router.__init__(atoms)
├─ Split atoms into new/old
│ ├─ old_atoms → Procession(quick_review) "Initial review"
│ └─ new_atoms → Procession(recognition) "New memories"
└─ all atoms → Procession(final_review) "Final review"
└─ Procession.forward()
├─ cursor >= len(atoms) → finish()
└─ cursor < len(atoms) → next_atom
└─ Procession.get_expander()
└─ Expander(atom, route)
├─ Read orbital.routes[route_value]
├─ Probability expansion → self.puzzles_inf
├─ exammode → display puzzles sequentially
├─ report(rating) → record minimum rating
├─ forward() → next puzzle or finish → retronly
└─ retronly → display Recognition
└─ Atom.revise()
└─ Electron.revisor(min_rate)
└─ Algorithm.revisor(algodata, feedback)
```
Rating accumulation: The final rating for an atom across multiple puzzles takes the minimum rating (`min_rate`) across all puzzles, ensuring strict evaluation.
## Algorithm System
All algorithms inherit from `BaseAlgorithm`, implemented in a class-method style, registered via the `algorithms` dictionary.
| Algorithm | File | Status | Description |
|-----------|------|--------|-------------|
| **SM-2** | `sm2.py` | ✅ Complete | Classic SuperMemo 1987 algorithm |
| **NSP-0** | `nsp0.py` | ✅ Complete | Non-spaced filtering scheduler |
| **SM-15M** | `sm15m.py` | ✅ Complete | SM-15 ported from CoffeeScript |
| **FSRS** | `fsrs.py` | ✅ Partial | Optimizer not available |
| **Base** | `base.py` | ✅ Base class | Defines `AlgodataDict` structure and defaults |
Each algorithm provides the following class methods:
| Method | Function |
|--------|----------|
| `revisor(algodata, feedback, is_new_activation)` | Iterate memory data based on rating |
| `is_due(algodata)` | Check if due for review |
| `get_rating(algodata)` | Get rating information |
| `nextdate(algodata)` | Get next review timestamp |
| `check_integrity(algodata)` | Validate algodata data structure integrity |
### Algorithm Data Structure (AlgodataDict)
```python
{
"real_rept": int, # Actual review count
"rept": int, # Current repetition count
"interval": int, # Interval in days
"last_date": int, # Last review date
"next_date": int, # Next due date
"is_activated": int, # Whether activated (0/1)
"last_modify": float, # Last modification timestamp
}
```
## Repository System (Repo)
The repository is a directory of TOML/JSON files with no database dependency.
### Directory Structure
```
data/repo/<package_name>/
├── manifest.toml # Meta info: title, author, package, desc
├── typedef.toml # Common metadata, puzzle definitions, annotations
├── payload.toml # Memory items (key=ident)
├── algodata.json # Algorithm state (key=ident)
└── schedule.toml # Orbital/review strategy
```
### Repo Class Design
```mermaid
classDiagram
class Repo {
+dict schedule
+Lict payload
+dict manifest
+dict typedef
+Lict algodata
+Path source
+Lict nucleonic_data_lict
+dict orbitic_data
+Lict electronic_data_lict
+from_repodir(source) ~Repo
+from_dict(dictdata) ~Repo
+create_new_repo() ~Repo
+persist_to_repodir(save_list, source)
+export_to_dict() dict
}
```
- `payload` and `algodata` use `Lict` (list+dict hybrid container), supporting dual-mode access.
- `_generate_particles_data()` automatically converts payload data to `Nucleon`-required format during initialization.
- Default save list: `default_save_list = ["algodata"]`, only persists algorithm state.
## Lict Collection
`Lict` extends `MutableSequence`, maintaining both list and dictionary access:
```python
lict = Lict()
lict.append(("key1", value1)) # List append
lict["key1"] # Dict access
lict[0] # Index access
lict.keys() # All keys
lict.dicted_data # Plain dict export
```
Dirty sync mechanism: modifying the list automatically syncs to the dictionary; modifying the dictionary automatically syncs to the list. Used for dual-mode access to `payload` and `algodata`.
## Configuration System (ConfigDict)
`ConfigDict` extends `UserDict`, a **singleton** TOML lazy-loading configuration manager.
### Configuration Directory Convention
```
data/config/
├── _.toml # Top-level defaults (recursive merge)
├── interface/
│ ├── _.toml # Interface layer defaults
│ ├── global.toml
│ └── puzzles.toml
├── services/
│ ├── _.toml # Services layer defaults
│ ├── audio.toml
│ └── tts.toml
└── repo/
└── _.toml
```
- `_.toml` files = defaults for that directory level, merged into parent
- Suffixed files = lazy-loaded on demand
- Subdirectories = recursive sub-configuration
### Context Management
```python
from heurams.context import config_var, ConfigContext
# Global access
config = config_var.get()
algo = config["interface"]["global"]["algorithm"]
# Scope override
with ConfigContext(test_config):
... # Temporarily use test configuration
```
## Provider System (Providers)
Pluggable backend implementations, registered via dictionaries in `providers/__init__.py`.
| Category | Provider | Description |
|----------|----------|-------------|
| **TTS** | `edge_tts` | Microsoft Edge TTS (online) |
| | `basetts` | Stub base class (not implemented) |
| **Audio** | `playsound` | Cross-platform audio playback |
| | `termux` | Android Termux environment |
| **LLM** | `openai` | OpenAI compatible API (not fully implemented) |
Selection method: `provider` field in `services/*.toml`.
## Puzzle System (Puzzles)
The puzzle engine generates evaluation views during review phases:
| Puzzle | File | Description |
|--------|------|-------------|
| **MCQ** | `mcq.py` | Multiple Choice Questions |
| **Cloze** | `cloze.py` | Cloze Deletion |
| **Recognition** | `recognition.py` | Recognition identification |
| **Guess** | `guess.py` | Word meaning guessing |
| **Base** | `base.py` | Abstract base class |
Puzzles are expanded probabilistically by the Orbital strategy in the `Expander`. Each atom can generate multiple puzzles, and each puzzle is rated independently.
## Service Layer
| Service | File | Description |
|---------|------|-------------|
| **Config** | `config.py` | `ConfigDict(UserDict)` TOML lazy-loading singleton |
| **Logger** | `logger.py` | `get_logger(name)` → hierarchical logger (`heurams.*`) |
| **Timer** | `timer.py` | `get_daystamp()` / `get_timestamp()`, supports configurable override |
| **Audio** | `audio_service.py` | Audio playback, routes to configured audio provider |
| **TTS** | `tts_service.py` | Text-to-speech, routes to configured TTS provider |
| **Favorites** | `favorite_service.py` | JSON5-persisted favorites manager (singleton) |
| **Attic** | `attic.py` | Structured pickle persistence, supports `<DAYSTAMP>`/`<TIMESTAMP>` placeholders |
| **Hasher** | `hasher.py` | MD5 hashing |
| **Epath** | `epath.py` | Dot-notation nested dict access (`epath(dct, "a.b.c")`) |
| **TextProc** | `textproc.py` | `truncate()`, `domize()`, `undomize()` |
Logging system: Each module creates its own logger via `get_logger(__name__)`. Log files rotate at 10MB, max 5 backups, appended to `heurams.log`.
## Complete Review Flow
```mermaid
sequenceDiagram
participant User as User
participant UI as TUI
participant Router as Router
participant Procession as Procession
participant Expander as Expander
participant Atom as Atom
participant Electron as Electron
participant Algo as Algorithm
User->>UI: Start Review
UI->>Router: Router(atoms)
Router->>Procession: Create review queue
Router->>Procession: Create new memory queue
Router->>Procession: Create final review queue
Procession->>Expander: Expand current atom
Expander->>Expander: Parse orbital strategy
Expander-->>UI: Display puzzle
User->>UI: Rate (1-5)
UI->>Expander: report(rating)
Expander->>Expander: forward() next puzzle
Expander-->>UI: Next puzzle or retrospective
Expander->>Expander: finish() → retronly
Expander-->>UI: Recognition retrospective
User->>UI: Final rating
UI->>Atom: revise()
Atom->>Electron: revisor(min_rate)
Electron->>Algo: revisor(algodata, feedback)
Algo-->>Electron: Update algodata
Algo-->>Atom: Update interval, next_date
Procession->>Procession: forward() next atom
Procession-->>Router: Queue complete
Router->>Router: Switch phase
Router-->>UI: Complete (finished)
UI->>User: Show summary
```
-416
View File
@@ -1,416 +0,0 @@
# Frequently Asked Questions
## What is a terminal emulator?
A terminal emulator is an application that simulates and uses a terminal within a graphical desktop environment, e.g., KDE Konsole, GNOME Terminal, Windows Terminal, iTerm2, etc.
The old, modest little black window on older Windows (conhost.exe) is also a terminal emulator, but it has poor support for this software's basic user interface (and all modern terminal applications). We recommend using WezTerm (supports sixel) or Windows Terminal (does not support sixel) on Windows.
## Does the software support mobile devices?
The basic user interface (Textual TUI) works well in Android Termux.
Additionally, the KiriMemo frontend under development is based on the KDE Kirigami framework and will natively support Android and iOS.
## What is the difference between HeurAMS and Anki?
At a high level:
| Aspect | HeurAMS | Anki |
|--------|---------|------|
| Data format | Text files (TOML/JSON), human-readable | Proprietary compressed format with SQLite and resources (.apkg) |
| Review modes | Multi-phase flow + multiple puzzle types | Single/double-sided flashcards |
| Algorithm system | Modular, pluggable, multiple algorithm options | Built-in SM-2 / FSRS |
| Plugin ecosystem | Smaller, manifests as "capability extensions" like new algorithms or services | Larger, but uses unrestricted "monkey patching" |
| User base | Small | Large |
| Existing resource richness | Low | High |
| AI-assisted unit set/deck creation | Natively supported | Difficult |
| License | AGPL-3.0 with additional exemption clause | AGPL-3.0 |
## Is the software free?
Yes, completely free and open source. You can use all features without paying anything.
## How do I use this dark-looking interface?
First, if you just want a light color scheme, press the `d` key or click the "d theme" button to switch to a light interface. :)
Thanks to Microsoft's decades of "the command line is outdated" education, and the poor experience of `conhost.exe` and `cmd.exe`, it's completely normal to feel uncomfortable with a terminal user interface.
But in reality, even though it looks like an old computer screen, Textual and terminal standards are more modern than you might think.
### You can use the mouse
Modern terminal emulators (such as Windows Terminal, Konsole, iTerm2, WezTerm, etc.) support a feature called "Mouse Tracking". When Textual starts, it sends special instructions to the terminal to report mouse events.
So contrary to what you might expect, you can actually click buttons with your mouse, just like in regular software.
### You can also use the keyboard
- `Tab` key switches focus between different areas
- `Arrow keys` move up and down in lists
- `Enter` confirms a selection
- `q` goes back
- Key hints are displayed on screen, e.g., `[n] Navigator` means pressing `n` opens the navigator
### Touchscreen also works
On tablets or phones in Termux, you can touch or swipe to operate.
## How do I start the software?
First, ensure Python (3.12.13 recommended) is installed on your system along with the required HeurAMS components.
### Windows
Open "Command Prompt" or "PowerShell", enter the following command and press Enter, or save it as a shortcut:
```
python -m heurams.interface
```
### macOS
Open the "Terminal" application and enter the above command.
### Linux
Open your terminal emulator (usually Ctrl + Alt + T) and enter the above command.
If you find typing the command every time too cumbersome, you can create a desktop shortcut or script file. See online tutorials for details.
## How do I exit the software?
Press the `q` key to return to the main screen, then exit.
Your learning progress is saved automatically and will not be lost.
## Images are very pixelated and blurry, what should I do?
This means the image is being displayed in Halfcell compatibility mode.
The terminal emulator needs to support the sixel image protocol for high-quality image display. For terminals that don't support it, the software can only display images in low-quality compatibility mode.
- WezTerm (all major OS): Supported
- KDE Konsole: Supported
- GNOME Terminal: Not supported
- iTerm2 (macOS): Supported
- Windows Terminal: Not supported
- mintty (Windows): Supported
If your terminal doesn't support images, other software features are unaffected — only images in memorization content won't be displayed.
## Chinese characters display as garbled text or boxes?
This means your terminal's Chinese font is not set correctly. Please check:
1. You are not using terminals like getty or xterm that explicitly do not support non-ASCII fonts
2. In the terminal settings, choose a font that supports Chinese, such as "Noto Sans SC", "Microsoft YaHei", "Source Han Sans"
3. Ensure the terminal's character encoding is set to UTF-8 (usually the default)
## Where is my data stored? Will it be lost?
Data is stored in the `data/` folder under the software installation directory:
- You can open and modify files directly with a text editor
- Copy the `data/` folder to a USB drive or cloud storage for backup (regular backups recommended)
- Even if the software is uninstalled, as long as you keep the `data/` folder, all learning records will be preserved when you reinstall and copy it back
## How do I share my unit sets with friends?
Find the corresponding folder under `data/repo/`, copy the entire folder, and send it to your friend. They can place it in their own `data/repo/` directory to use it.
You can also export as a single text file or compressed archive and share via messaging apps, email, etc.
## I can't copy/paste content?
Generally, in a terminal:
- Copy: Ctrl+Shift+C
- Paste: Ctrl+Shift+V
This differs from regular software habits (because Ctrl+C means "interrupt process" in terminal semantics), but you'll get used to it quickly.
## The font is too small/large?
Adjust the "font size" option in your terminal emulator settings.
The software follows the terminal's font settings.
## Why does my interface look different from the screenshots?
The screenshots were taken using Konsole on KDE Plasma desktop, 80x25 character size, with Cascadia Code and Noto Sans SC fonts.
If your terminal size is larger, the interface will have more room. Using different fonts or operating systems may result in slight visual differences.
Functionality is identical.
## What do the ratings (1-5) mean? How should I rate?
We should note that we strongly discourage the Anki-like approach of having users directly self-rate their performance (implemented as `basic_puzzle` in our program, used primarily for algorithm testing).
We believe this approach is highly subjective and requires you to think about "What score am I?", "Am I being too optimistic?", "Am I scoring too low?", "What if I rate incorrectly?" — a series of questions that interrupt the memorization process and cause anxiety. This essentially shifts responsibility to the user and contradicts cognitive science principles.
Moreover, this approach is detrimental to academic research and experimentation, as user self-rated data is unreliable.
Therefore, HeurAMS frontends have built-in automatic rating systems based on user behavior analysis, i.e., "puzzles".
It automatically rates you based on the difficulty of the question and your answering behavior (including but not limited to correctness, number of operations undone, effective answering time).
However, if you or a unit set chooses to use `basic_puzzle`, or if you plan to implement your own automatic rating system, the meaning of scores is as follows:
| Score | Meaning | Description |
|-------|---------|-------------|
| 1 | Completely forgotten | Couldn't recall at all, as if never learned |
| 2 | Vague | Seems familiar, but couldn't answer |
| 3 | Some impression | Recalled after thinking for a while, not very certain |
| 4 | Relatively smooth | Could answer, but hesitated slightly |
| 5 | Very easy | Immediately recalled, no effort |
- Scoring **1-2**: The software considers you haven't mastered it and will schedule another review soon
- Scoring **3**: Normal mastery, review at the planned interval
- Scoring **4-5**: Well mastered, the next review interval will be extended
We suggest you don't overthink it, just score based on your first instinct — the software will automatically adjust the review pace based on your ratings.
Of course, we still recommend avoiding this approach and using other puzzle types for evaluation when possible.
You might think this method allows users to directly "intervene" with the algorithm, similar to Baicizhan's "斩" (chop) feature for skipping familiar content. In reality, you don't need to do that: we have built-in "quick pass/correct response" functionality, equivalent to directly selecting "5".
## Do I need to open the software every day? What if I don't study?
In theory, you don't need to open it every day. The software automatically records when each knowledge point is due for review next.
However, it is recommended to open the software daily to check your status.
Even if you skip studying for days or weeks:
- Knowledge points you've already learned won't disappear — they'll just need a few more reviews next time
- Learning records are safely stored in the `data/` folder and won't be lost
For best results, try to follow the software's review reminders; but it's okay to skip a few days when you're busy.
## Can I study multiple subjects simultaneously?
Yes.
Each subject or course can be made into an independent "unit set".
## I changed computers. How do I migrate data?
1. On the old computer, copy the entire `data/` folder to a USB drive or cloud storage
2. Install HeurAMS on the new computer
3. Overwrite the new computer's `data/` folder with the one from the USB drive
All learning records, configurations, and unit sets are fully migrated.
## I don't understand some terminology
| Term | Meaning |
|------|---------|
| **Unit Set** | Like a "book" or "course", containing a series of knowledge points |
| **Puzzle** | A question type to test you (MCQ, Cloze, etc.) |
| **Algorithm** | The "intelligent scheduler" that decides when to review which knowledge point |
| **Review Queue** | The list of knowledge points due for review today |
| **Activation** | Starting to learn a knowledge point for the first time |
| **Due** | A knowledge point is due for review |
## The software is stuck/unresponsive?
1. First, wait a moment
2. If that doesn't work, close the terminal window directly
3. Reopen the software
4. If you have time, please report the issue. We apologize for the inconvenience.
## Will using both Anki and HeurAMS cause conflicts?
No.
They are independent software programs with no data interference. You can gradually migrate content to HeurAMS, or use both together.
## Do I need to install Python?
Yes. HeurAMS is a Python-based software.
- Windows/macOS: Download and install from python.org
- Linux: Python is usually pre-installed
- Android: Install the Termux app, then install Python within Termux (run `pkg in python`)
If you see an error like "python is not recognized as an internal or external command", Python is not properly installed or added to your system PATH. Search for "Python installation tutorial" and follow the steps.
The recommended Python version for HeurAMS is 3.12.13.
## Is the software safe? Could it contain viruses?
HeurAMS is open source software. All code is publicly available for inspection and contains no viruses or backdoors.
It only reads and writes to its own `data/` folder and will not touch other files on your computer.
## The software shows an error with a lot of text I don't understand?
1. Copy the error message
2. First check if this page covers your issue
3. If not, upload it along with the software logs to issues, and we will handle it as soon as possible
## Can I pause mid-review? Will it restart from the beginning?
There is currently no save-state functionality, but we will add it soon.
## How do I see how much I've learned? Are there statistics?
The dashboard interface displays statistical information.
You can return to the dashboard anytime via the navigator.
## I feel the review is too fast/slow. Can I adjust it?
Yes. You can change the review pace by switching algorithms, adjusting algorithm parameters, or changing the number of memory units.
Relevant settings can be found in the settings interface.
## Can I change the interface color/theme?
Yes. The Textual framework provides various themes.
## I accidentally deleted something. Can I recover it?
This depends on whether your system has a recycle bin enabled. The software itself does not have an auto-backup function.
## Can I carry the software on a USB drive?
Yes. Copy the entire HeurAMS folder to a USB drive, install Python on any computer, and run it. Learning data in the `data/` directory will also be carried along.
## How do I turn off voice reading?
Find the TTS-related option in the settings interface and disable it.
## Where can I download unit sets made by others?
Currently, there is no official unit set marketplace.
However, as the community grows, users may share unit sets in the future. You can also share unit sets with friends.
## Can I export learning content for printing?
Yes.
The software supports exporting unit sets as a single text file, which you can open and print with any text editor. You can also copy content directly into software like Word.
## I want to start over from scratch. How do I reset?
Delete the `algodata.json` file in the corresponding unit set folder under `data/repo/` to reset all learning progress.
## How do I create my own unit set?
Create a new folder under `data/repo/` with the following files:
```
data/repo/my_pack/
├── manifest.toml # Meta info: title, author, etc.
├── typedef.toml # Common field definitions and puzzle configuration
├── payload.toml # Memory item content
├── algodata.json # Algorithm state data (can be empty)
└── schedule.toml # Review strategy configuration
```
You can also use the tools we provide to convert from CSV format, or use AI tools to generate unit sets.
## How do I switch algorithms?
Detailed instructions are available in the settings interface.
## How do I import from Anki?
There is currently no migration tool, as the design philosophies of the two software programs differ.
But keep an eye on the HeurStudio project — it will fundamentally solve content creation and migration issues. :)
## Why not Flutter?
Flutter is an excellent framework for building cross-platform graphical interfaces. One of HeurAMS's design goals is to keep the core library independent of any specific frontend.
However, Flutter is not as good as PyOtherSide when it comes to "integrating Python" — it can only communicate with the library through RPC standard components. Additionally, Flutter's desktop multi-window support has not been officially and stably supported, so we temporarily abandoned Flutter in favor of Kirigami.
Currently, we have prioritized the development of a Textual-based TUI frontend and a Kirigami-based native frontend. However, this does not preclude the possibility of a Flutter or other framework frontend in the future.
If you are interested in developing a Flutter frontend, please refer to the [Contributing Guide](../CONTRIBUTING.md#new-user-interface-frontends).
## Does the software need internet access?
Core review functionality works completely offline. The following features require internet:
- Edge TTS provider for Text-to-Speech
- LLM providers (e.g., OpenAI compatible API)
- Downloading unit sets from remote repositories
## What is the "local API call exemption" in the license?
In short, if you use HeurAMS in your own program through local inter-process API communication (such as RPC calls on the same host) without network forwarding, your program is not bound by the AGPL-3.0 license.
This additional clause is designed to encourage the development of third-party frontends and tools.
Therefore, HeurAMS's license is effectively more permissive than the original AGPL-3.0.
## What is the difference between HeurAMS and Baicizhan?
At a high level:
| Aspect | HeurAMS | Baicizhan |
|--------|---------|-----------|
| Usage scenario | Computer/Terminal | Mobile App |
| Learning content | Any knowledge, unlimited languages and subjects | English vocabulary |
| Memory strategy | Multiple algorithms, customizable review flow | Fixed algorithm, not adjustable |
| Quiz methods | Multiple puzzle types: MCQ, Cloze, Recognition | Picture-word matching, audio-meaning selection, etc. |
| Content creation | Self-created or imported, completely free | Official word books only |
| Cost | Completely free, no in-app purchases | Free memorization + paid courses |
| Data ownership | Data in your hands, text files | Data cannot be extracted |
| Offline use | Core functionality fully offline | Some features require internet |
| Learning statistics | Basic statistics | Check-in/Leaderboard/Social |
## Baicizhan has picture association memory. Does HeurAMS have it too?
Yes.
If your terminal supports image display (such as Konsole or WezTerm), unit sets can include images that will be displayed during review.
However, you need to add images to the unit set yourself.
## Baicizhan has check-ins and leaderboards. Does HeurAMS have them?
Currently no.
HeurAMS does not have check-ins, leaderboards, or social features, and does not collect your learning data.
## Baicizhan has ready-made word books. Where can I find content for HeurAMS?
Baicizhan's courses are officially made. HeurAMS content needs to be created by yourself or obtained from the community.
See "How do I create my own unit set?" for details.
## Baicizhan is convenient to use on mobile. Can HeurAMS be used on mobile?
Yes, but at this stage it requires some setup.
Android users can install Termux to run HeurAMS's basic user interface.
Additionally, the KiriMemo frontend under development will natively support Android and iOS, requiring no setup from users.
## Baicizhan helps with vocabulary. What else can HeurAMS be used for?
Any knowledge that requires memorization: foreign language vocabulary, medical terminology, legal texts, historical dates, chemical equations, programming syntax, musical notation...
Unit set content is entirely defined by you.
## Baicizhan is effective for learning English. Will HeurAMS be less effective?
Considering that Baicizhan's algorithms and vocabulary database are effectively closed-source, we have no way of knowing the algorithm source.
However, HeurAMS's architecture design ensures that once a unit set is created, it can be at least as effective as Baicizhan — or even better.
HeurAMS's spaced repetition algorithms are based on the same cognitive science principles, and the algorithms are transparent and adjustable, allowing you to freely choose the scheduling strategy that best suits you.
## How do I participate in the project?
See the [Contributing Guide](../CONTRIBUTING.md).
Even if you are not a developer, you can participate by writing documentation, creating memory unit sets, translating the interface, answering questions, and more.
-416
View File
@@ -1,416 +0,0 @@
# 常见问题
## 什么是终端模拟器?
终端模拟器是在图形桌面环境中模拟并使用终端的应用程序, 例如 KDE Konsole, GNOME Terminal, Windows Terminal, iTerm2 等.
较旧 Windows 的那个很寒酸的小黑窗口也是终端模拟器(conhost.exe), 但它对此软件基本用户界面(以及一切现代终端应用)支持不佳, 建议在 Windows 平台使用 WezTerm (支持 sixel) 或 Windows Terminal (不支持 sixel).
## 软件支持移动设备吗?
基本用户界面 (Textual TUI) 可在 Android Termux 中良好运行.
此外, 正在开发的 KiriMemo 前端基于 KDE Kirigami 框架, 将原生支持 Android 和 iOS.
## HeurAMS 和 Anki 有什么区别?
大体地说:
| 方面 | HeurAMS | Anki |
|------|---------|------|
| 数据格式 | 文本文件 (TOML/JSON), 人类可读 | SQLite 和资源文件组成的专有压缩格式 (.apkg) |
| 复习模式 | 多阶段流程 + 多种谜题类型 | 单面/双面闪卡 |
| 算法系统 | 模块化, 可插拔, 多种算法可选 | 内置 SM-2 / FSRS |
| 插件生态 | 较少, 体现于类似微内核架构的"能力扩展", 例如新算法或新服务 | 多, 但为不受限的"猴子补丁" |
| 用户基数 | 少 | 多 |
| 现有资源丰富度 | 少 | 多 |
| AI 辅助产生单元集/牌组 | 原生支持 | 困难 |
| 协议 | AGPL-3.0, 有一个附加豁免条款 | AGPL-3.0 |
## 软件是免费的吗?
是的, 完全免费, 且开源. 您无需支付任何费用即可使用全部功能.
## 黑乎乎的这个界面我怎么用?
首先, 如果您只是想要一个亮色模式, 可以直接按下 `d` 键或点击 "d 主题" 按钮, 这会让您的界面变得白乎乎的(
得益于微软几十年对用户进行的"命令行即落后"教育, 以及 `conhost.exe``cmd.exe` 的糟糕体验, 您对终端用户界面感到不适应是完全正常的.
但实际上, 虽然看起来像老式电脑屏幕, Textual 和终端标准其实比您想象得要现代一些.
### 可以用鼠标
现代终端模拟器 (如 Windows Terminal、Konsole、iTerm2、WezTerm 等) 支持一个叫做 "鼠标跟踪" (Mouse Tracking) 的功能, 而 Textual 启动时会发送特殊指令给终端让它报告鼠标事件.
所以可能和您的想象不同, 您事实上可以直接用鼠标点击按钮, 就像使用普通软件一样.
### 也可以用键盘
- `Tab` 键在不同区域之间切换焦点
- `方向键` 在列表中上下移动
- `Enter` 确认选择
- `q` 返回
- 屏幕上会有按键提示, 例如 `[n] 导航器` 表示按 `n` 键打开导航器
### 触屏也可以
在平板或手机 Termux 中, 您可以触摸或者滑动屏幕操作.
## 我怎么启动这个软件?
首先需要确保系统中安装了 Python (推荐 3.12.13 版本) 并安装了 HeurAMS 的所需组件.
### Windows
打开"命令提示符"或"PowerShell", 输入以下命令后按回车, 或者把这玩意另存为快捷方式:
```
python -m heurams.interface
```
### macOS
打开"终端"应用程序, 输入以上命令.
### Linux
打开您的终端模拟器 (一般是按 Ctrl + Alt + T), 输入以上命令.
如果您觉得每次输入命令太麻烦, 可以创建一个桌面快捷方式或脚本文件, 详见网上的相关教程.
## 我怎么退出软件?
按键盘上的 `q` 键返回主界面后退出.
您的学习进度会自动保存, 不会丢失.
## 图片像素很大, 模糊得像马赛克一样怎么办?
这说明图像以 Halfcell 兼容模式显示
终端模拟器需要支持 sixel 图像协议才能高清地显示图片, 对于不支持的图片, 软件只能以低清的兼容模式显示.
- WezTerm (适用于几乎所有操作系统): 支持
- KDE Konsole: 支持
- GNOME Terminal: 不支持
- iTerm2 (macOS): 支持
- Windows Terminal: 不支持
- mintty (Windows): 支持
如果您的终端不支持图片, 软件的其他功能不受影响, 只是记忆内容中的图片无法显示.
## 中文显示成乱码或方框怎么办?
这说明您没有正确设置终端中文字体. 请检查:
1. 您没有使用 getty 和 xterm 这种明确不支持非 ASCII 字体的终端
2. 终端设置中的字体选项, 选择一款支持中文的字体, 例如 "Noto Sans SC", "微软雅黑", "Source Han Sans"
3. 确保终端的字符编码设置为 UTF-8 (通常是默认值)
## 我的数据存哪里了? 会不会丢?
数据存储在软件安装目录下的 `data/` 文件夹中:
- 您可以用记事本直接打开查看和修改
- 复制粘贴 `data/` 文件夹到 U 盘或网盘即可完成备份 (推荐定期备份)
- 即使软件卸载了, 只要保留 `data/` 文件夹, 重新安装后复制回去, 所有学习记录都在
## 怎么跟朋友分享我的单元集?
找到 `data/repo/` 下的对应文件夹, 复制整个文件夹发给朋友即可. 对方把它放到自己的 `data/repo/` 目录下就能用.
您也可以导出为单一文本文件或压缩包, 通过微信、QQ、邮件等方式分享.
## 我复制粘贴不了内容?
一般来说, 在终端中:
- 复制: Ctrl+Shift+C
- 粘贴: Ctrl+Shift+V
这和普通软件的操作习惯不太一样(因为 Ctrl + C 在终端中的语义是 "中断进程"), 但稍加适应即可.
## 字体太小/太大怎么办?
在您的终端模拟器设置中找到"字体大小"选项进行调整.
软件会跟随终端的字体设置.
## 为什么我的界面和截图不一样?
截图使用的是 KDE Plasma 桌面上的 Konsole, 80x25 字符尺寸, Cascadia Code 和 Noto Sans SC 字体.
如果您的终端尺寸更大, 界面会更宽裕; 如果使用不同字体或者不同操作系统, 视觉效果会略有差异.
功能上完全一致.
## 评分 (1-5) 是什么意思? 我该怎么打分?
需要说明的是, 我们非常不鼓励这种类似 Anki, 让用户自己直接给自己评分的单元集设计(在我们的程序中, 这种方式的实现被称为 `basic_puzzle`, 基本只用于算法测试).
因为我们认为这种方式非常主观, 而且还需要您思考"我是多少分""我是不是乐观了""我是不是分低了""我要是把分评错了怎么办"这一系列打断记忆进程且令人焦虑的问题, 这本质上是把责任推给用户, 并且违背了认知科学原理.
并且这种方式于学术研究与实验不利, 用户自评分产生的数据是不可靠的.
因此 HeurAMS 的前端内建了基于用户行为分析的自动评分系统, 也就是"谜题".
它会根据题目本身难度和您的答题行为(包括但不限于正确性, 操作回退次数, 有效答题时间)并自动为您评分.
但如果您或者某个单元集选择使用 `basic_puzzle`, 或者打算自己实现自动评分系统, 分数含义如下:
| 分数 | 含义 | 说明 |
|------|------|------|
| 1 | 完全忘了 | 一点都没想起来, 跟没学过一样 |
| 2 | 模糊 | 好像见过, 但答不上来 |
| 3 | 有点印象 | 想了一会儿才答对, 不太确定 |
| 4 | 比较顺利 | 能答对, 但稍微犹豫了一下 |
| 5 | 非常轻松 | 立刻反应过来, 毫不费力 |
-**1-2 分**: 软件会认为您还没掌握, 短期内会再次安排复习
-**3 分**: 正常掌握, 按计划间隔复习
-**4-5 分**: 掌握得很好, 下次复习间隔会拉长
我们建议您不要纠结, 凭第一感觉打分就好, 软件会根据您的评分自动调整复习节奏.
当然我们还是建议尽量避免这种方式并尽量使用其他谜题评测.
您可能认为那种方式可以让用户直接"干预"算法, 类似百词斩的"斩"功能用于跳过已经熟悉的内容, 实际上您并不需要那样做: 我们内建了"快速通过/正确应答"功能, 等同于直接选择"5".
## 我每天都要打开软件吗? 不学会怎样?
理论上不需要每天打开. 软件会自动记录每个知识点下次该复习的时间.
但建议您每天打开软件看下状态.
即使隔了几天甚至几周没学:
- 已经记住的知识点不会消失, 只是下次复习时会多复习几次
- 学习记录完好保存在 `data/` 文件夹里, 不会丢失
建议尽量按软件的提醒复习, 效果最好; 但忙的时候跳过几天也没关系.
## 能同时学多个科目吗?
可以.
每个科目或课程可以做成独立的"单元集".
## 我换电脑了, 怎么迁移数据?
1. 在旧电脑上复制整个 `data/` 文件夹到 U 盘或网盘
2. 在新电脑上安装好 HeurAMS
3. 用 U 盘里的 `data/` 文件夹覆盖新电脑上的 `data/` 文件夹
所有学习记录、配置、单元集全部迁移完毕.
## 一些术语听不懂
| 术语 | 意思 |
|------|--------|
| **单元集** | 相当于"一本书"或"一门课", 包含一系列知识点 |
| **谜题** | 测试您的题目类型 (选择题、填空题等) |
| **算法** | 决定什么时候该复习哪个知识点的"智能排课表" |
| **复习队列** | 今天需要复习的知识点列表 |
| **激活** | 第一次开始学习某个知识点 |
| **到期** | 到了该复习这个知识点的时间了 |
## 软件卡住了/没反应怎么办?
1. 建议先等片刻
2. 如果不行, 直接关闭终端窗口
3. 重新打开软件
4. 如果您有时间的话, 欢迎报告问题, 我们为此深表歉意
## 同时用 Anki 和 HeurAMS 会冲突吗?
不会.
两者是独立的软件, 数据互不影响. 您可以逐步将内容迁移到 HeurAMS, 也可以两个一起用.
## 我需要安装 Python 吗?
需要的, HeurAMS 是基于 Python 的软件.
- Windows/macOS: 从 python.org 下载安装即可
- Linux: 系统通常已自带 Python
- Android: 安装 Termux 应用, 然后在 Termux 中安装 Python (运行 `pkg in python`)
如果看到"python 不是内部或外部命令"的提示, 说明 Python 没有正确安装或添加到系统路径, 搜索"Python 安装教程"按步骤操作即可.
HeurAMS 建议的 Python 版本是 3.12.13.
## 软件安全吗? 会不会有病毒?
HeurAMS 是开源软件, 所有代码公开可查阅, 不会有病毒或后门.
它只读写自己的 `data/` 文件夹, 不会动您电脑上的其他文件.
## 软件报错, 出现一堆我看不懂的英文怎么办?
1. 把错误信息复制下来
2. 先找一下这个页面有没有收录您遇到的问题
3. 如果没有, 可以和软件日志一起上传到 issues, 我们会尽快处理
## 复习到一半可以暂停吗? 下次会从头开始吗?
暂时没有保存中间状态的功能, 但我们很快会添加.
## 怎么看我学了多少? 有统计吗?
仪表盘界面会显示统计信息.
您可以通过导航器随时回到仪表盘查看.
## 我觉得复习太快/太慢了, 能调吗?
可以. 您可以通过切换算法或调整算法参数或改变记忆单元数来改变复习节奏.
在设置界面可以找到相关设置.
## 能换界面颜色/主题吗?
能的, Textual 框架提供了多种主题.
## 我不小心删了东西, 能恢复吗?
这取决于您系统是否启用回收站, 软件本身没有自动备份功能.
## 能把软件放 U 盘随身带吗?
可以. 将整个 HeurAMS 文件夹复制到 U 盘, 在任意电脑上安装 Python 后运行即可. `data/` 目录下的学习数据也会一同携带.
## 怎么关掉语音朗读?
在设置界面中找到 TTS 相关选项, 将其关闭即可.
## 哪里可以下载别人做好的单元集?
目前项目还没有官方的单元集市场.
但随着社区发展, 未来可能会有用户分享的单元集, 您也可以和朋友互相分享.
## 我能把学习内容导出打印吗?
可以.
软件本身支持将单元集导出为单一文本文件, 您可以用任何文本编辑器打开并打印. 也可以直接复制内容到 Word 等软件.
## 我想从头重新学, 怎么重置?
删除 `data/repo/` 下对应单元集文件夹中的 `algodata.json` 文件即可重置所有学习进度.
## 如何创建自己的单元集?
`data/repo/` 目录下创建一个新文件夹, 包含以下文件即可:
```
data/repo/my_pack/
├── manifest.toml # 元信息: title, author 等
├── typedef.toml # 通用字段定义和谜题配置
├── payload.toml # 记忆条目内容
├── algodata.json # 算法状态数据 (可留空)
└── schedule.toml # 复习策略配置
```
您也可以使用我们提供的工具从 CSV 等格式转换, 或利用 AI 工具生成.
## 如何切换算法?
设置界面中有详细的说明.
## 如何从 Anki 导入?
暂时没有迁移工具, 因为两个软件的设计思路不同.
但欢迎关注 HeurStudio 项目, 它能从根本上解决内容创建与迁移问题 :)
## 为什么不用 Flutter?
Flutter 是构建跨平台图形界面的优秀框架, HeurAMS 的设计目标之一是保持核心程序库独立于特定前端.
但 Flutter 在 "集成 python" 方面不如 PyOtherSide, 只能通过 RPC 标准件和程序库通讯, 并且 Flutter 的桌面多窗口一直以来没有被官方稳定支持, 所以我们暂时放弃了 Flutter 而选择了 Kirigami.
当前我们优先开发了基于 Textual 的 TUI 前端和基于 Kirigami 的原生前端, 但这不排除未来出现 Flutter 或其他框架前端的可能性.
如果您有兴趣开发 Flutter 前端, 欢迎参考[贡献指南](../CONTRIBUTING_zh.md#%E6%96%B0%E7%9A%84%E7%94%A8%E6%88%B7%E7%95%8C%E9%9D%A2%E5%89%8D%E7%AB%AF).
## 软件需要联网吗?
核心复习功能完全离线可用. 以下功能需要联网:
- 文本转语音 (TTS) 的 Edge TTS 提供者
- LLM 提供者 (如 OpenAI 兼容 API)
- 从远程仓库下载单元集
## 许可证中的"本机 API 调用豁免"是什么?
简言之, 如果您在自己的程序中通过本地进程间 API 方式的通信 (如同一主机上的 RPC 调用) 使用 HeurAMS, 而无需通过网络转发, 则您的程序不受 AGPL-3.0 许可证的约束.
这项附加条款旨在鼓励第三方前端和工具的开发.
所以 HeurAMS 的许可证实质上是比原始的 AGPL-3.0 松一点的.
## HeurAMS 和百词斩有什么区别?
大体地说:
| 方面 | HeurAMS | 百词斩 |
|------|---------|--------|
| 使用场景 | 电脑/终端 | 手机 App |
| 学习内容 | 任何知识, 不限语言和科目 | 英语单词 |
| 记忆策略 | 多算法可选, 可自定义复习流程 | 固定算法, 不可调 |
| 测验方式 | 选择题/填空题/识别题等多种谜题 | 看图选词/听音选义等多种谜题 |
| 内容创建 | 自己创建或导入, 完全自由 | 仅官方提供词书 |
| 费用 | 完全免费, 无内购 | 免费记忆功能 + 付费课程 |
| 数据所有权 | 数据在您自己手上, 文本文件 | 数据不可被提取 |
| 离线使用 | 核心功能完全离线 | 部分功能需联网 |
| 学习统计 | 基础统计 | 打卡/排行榜/社交 |
## 百词斩有图片联想记忆, HeurAMS 也有吗?
支持.
如果您的终端支持图片显示 (如 Konsole 或者 WezTerm), 单元集中可以包含图片, 复习时会直接展示.
但图片需要您自己放入单元集.
## 百词斩有打卡和排行榜, HeurAMS 有吗?
目前没有.
HeurAMS 不设打卡、排行榜或社交功能, 也不向任何人收集您的学习数据.
## 百词斩有现成的词书, HeurAMS 去哪找内容?
百词斩的课程是官方制作好的, HeurAMS 的内容需要您自己创建或从社区获取.
详见"如何创建自己的单元集?".
## 百词斩在手机上用很方便, HeurAMS 能在手机用吗?
可以, 但现阶段需要您"折腾"一下.
Android 手机安装 Termux 后可运行 HeurAMS 的基本用户界面.
此外, 正在开发的 KiriMemo 前端将原生支持 Android 和 iOS, 这就不需要用户去折腾了.
## 百词斩能背单词, HeurAMS 还能学什么?
任何需要记忆的知识都可以: 外语单词、医学名词、法律条文、历史年代、化学方程式、编程语法、乐谱符号...
单元集的内容完全由您自己定义.
## 百词斩学英语效果很好, 换成 HeurAMS 会不会效果差?
考虑到百词斩的算法和词库是事实上闭源的, 我们无从得知算法来源.
但 HeurAMS 的架构设计可保证单元集制成后效果不比百词斩差, 甚至优于百词斩.
HeurAMS 的间隔重复算法基于相同的认知科学原理, 且算法透明可调, 您可以自由选择最适合自己的调度策略.
## 如何参与项目?
详见[贡献指南](../CONTRIBUTING_zh.md).
即使不是开发者, 您也可以通过编写文档、制作记忆单元集、翻译界面、答疑等方式参与.
-83
View File
@@ -1,83 +0,0 @@
## Features
### Spaced Repetition Scheduler
> Numerous publications have extensively discussed the effects of different repetition intervals on learning outcomes. In particular, the spacing effect is considered a universal phenomenon. The spacing effect refers to the fact that learning performance improves when repetitions are distributed/spaced rather than massed. Therefore, it has been proposed that the optimal repetition interval for learning is the **longest interval that does not lead to forgetting**.
- The software works out of the box, using the default `SM-2` algorithm for learning without additional configuration
- The algorithm module is a first-class citizen in the kernel (`heurams.kernel`), which natively supports pluggable algorithms of various types
- No complicated plugins required — algorithms can be quickly switched and tuned per unit set, enabling researchers to easily modify algorithm modules for convenient research and testing
- Defaults to the `SM-2` simple spaced repetition algorithm, also used as the default flashcard scheduler for Anki
- Also includes `NSP-0` non-spaced filtering algorithm for rapid content screening, `FSRS` advanced spaced repetition algorithm as a more efficient scheduler, and `SM-15M` (ported from sm.js project) complex spaced repetition algorithm (reverse-engineered)
- Algorithm modules can tag memorization items, dynamically plan memory interval schedules for each unit, and track memory feedback data to optimize long-term retention and stability
- Thanks to the modular architecture and unit set structure design, the same unit set can coexist and interoperate with any algorithm — extremely friendly for researchers and users exploring/experimenting with efficient methods
### Multimodal Learning Process
Unlike Anki's SQLite `.apkg` packages, we insist on using human-readable folder-organized unit sets, which brings several benefits:
- **Human-readable**: You can freely modify memorization payload data with any tool, even a simple text editor, without opening the software
- **Metadata configuration**: Extremely flexible configuration — you can freely combine, remix, or even create new content
- **Quiz, algorithm, and knowledge isolation**: A piece of knowledge is no longer a single flashcard; it can not only be scheduled with different algorithms but also tested with multiple parallel puzzle types, greatly enhancing learning effectiveness and richness. As a learner, you don't need to worry about complexity — just download a unit set from the cloud and use these features out of the box!
- **Multimodal learning**
- The software integrates Text-to-Speech (TTS), audio, and LLM modules — all pluggable, extensible, and driver-switchable, creating great content richness
- Built-in puzzle types include Multiple Choice Questions (MCQ), Cloze Deletion, and Recognition, all applicable to the same unit or selectively enabled
- Natively supports dynamic content generation with macro-driven template systems that generate knowledge point explanations based on context or even LLMs
- In the era when SuperMemo series dominated spaced repetition research, Wozniak already stated, "If you cannot understand knowledge, you don't need to memorize it." Today, we still believe understanding is the foundation of memorization
- **Cloud sync and sharing optimized**:
- Since memory data and unit set files are text files, fast incremental sync is possible without uploading all files, and the design natively supports version control
- If you want to share a single file, the software supports exporting as a compressed package or merging into a single text file for sharing on platforms like pastebin
- **Performance**: Thanks to the modern, chunked file organization structure, HeurAMS achieves agile and low-footprint user experience using only Python while maintaining high flexibility
- **AI-assisted friendly**: Imagine you have some `.apkg` decks or a large amount of textbook content — you can conveniently and efficiently use AI tools to create HeurAMS-compatible unit sets
### Built-in Practical User Interface
Although not the only frontend, the responsive Textual framework-based built-in terminal user interface has unique advantages in many scenarios:
- Cross-platform, with touch/mouse/keyboard multi-operation modes
- Compatible with almost all modern terminal emulators
- High-quality image display on terminal emulators that [support the sixel protocol](https://www.arewesixelyet.com/)
- Low-resolution compatibility display mode for terminals that don't support sixel
- Deployable as a service via textual-web, usable from any browser
- Clean, intuitive, keyboard-friendly, full-featured, and efficient UI design
- Easy to embed: can run in getty/kmscon without any desktop graphics service
- Low resource footprint, smooth operation
- Convenient for testing and debugging the library
View [Screenshots](SCREENSHOTS.md).
## Package Dependency Groups
Since some dependencies are only needed by a few features, we split optional dependencies into fine-grained groups. Here are the dependency groups:
| Dependency Group | Included Modules | Description |
|------------------|------------------|-------------|
| Build System | hatchling | Build-time installation |
| Minimal | tabulate, toml, transitions, click | Core driver libraries, always required |
| interface | textual | Basic user interface dependencies |
| algo-fsrs | fsrs | FSRS algorithm module |
| tts-edgetts | edge-tts | Microsoft Text-to-Speech |
| llm | llms-py | API calls |
| audio-playsound | playsound3 | General audio module |
| dev | zmq, pytest, pytest-cov | Development, debugging, and testing tools |
| basic | [tts-edgetts], [llm], [algo-fsrs | Lighter dependency group for user experience (recommended) |
| all | All of the above | Complete installation group |
## About This Repository
This repository is the Python implementation of the HeurAMS core library.
It contains data models and framework, and includes a built-in frontend based on the Textual framework (interface submodule).
Besides learning through the built-in frontend, developers can import the `heurams` library in a Python environment or communicate with `heurams` library instances via `RPC`, using the framework to build other auxiliary memory frontends or applications.
All repositories of the project group:
| Project Name | Status | Description | Package Name | Tech Stack | Target Platform |
| :--- | :--- | :--- | :--- | :--- | :--- |
| HeurAMS | In Development<br/>Prototype Usable | General core library with basic UI | `heurams` | Python | Standard Python Environment |
| KiriMemo | In Development<br/>Prototype Usable | Modern cross-platform frontend based on KDE technology | `org.kde.kirimemo` | C++, Qt6, Kirigami, PyOtherSide | Desktop & Mobile |
| ArkMemo | In Development | Modern cross-platform frontend based on ArkUI | `top.pluv27.arkmemo` | ArkTS, ArkUI | Mobile Devices |
| HeurStudio | Planned | AI-assisted single-unit set advanced creation and editing tool | `top.pluv27.heurstudio` | C++, Qt6, Kirigami, PyOtherSide | Desktop |
| HeurSync | In Development | User data sync server<br/>with Web frontend and leaderboard | `heursync` | Go, SQL | Web & Server |
| HeurRepo | In Development | Unit set document source server<br/>and sharing platform | `heurrepo` | Go, SQL | Web & Server |
Although the last three might sound a bit ambitious, our roadmap is clear.
-84
View File
@@ -1,84 +0,0 @@
## 特性
### 间隔重复调度器
> 许多出版物都广泛讨论了不同重复间隔对学习效果的影响. 特别是, 间隔效应被认为是一种普遍现象. 间隔效应是指, 如果重复的间隔是分散/稀疏的, 而不是集中重复, 那么学习任务的表现会更好. 因此, 有观点提出, 学习中使用的最佳重复间隔是**最长的, 但不会导致遗忘的间隔**.
- 软件开箱即用, 无需多加配置即可使用默认的 `SM-2` 算法进行学习
- 算法模块是 "潜进" 内核 (heurams.kernel) 中的一等公民, 内核天然支持插拔各型算法
- 无需安装繁杂的插件即可分单元集完成算法快速切换与调优, 研究者可以方便地修改算法模块以便捷地进行研究与测试
- 默认使用 `SM-2` 简单间隔重复算法, 此算法亦用作 `Anki` 闪卡记忆软件的默认闪卡调度器
- 还内置了 `NSP-0` 筛选用非间隔重复算法以便快速筛选记忆内容, `FSRS` 先进间隔重复算法作为效率更高的调度器, 与 `SM-15M (移植自 sm.js 项目)` 复杂间隔重复算法(逆向工程)
- 算法模块可以标记记忆项目, 也可以动态规划每个记忆单元的记忆间隔时间表, 动态跟踪记忆反馈数据, 以优化长期记忆保留率与稳定性
- 得益于项目的模块化架构与单元集结构设计, 同一个单元集可以与任意种算法共存并互通, 这对研究者及想探索/实验高效率方法的用户极其友好
### 多模态学习进程
与 Anki 的 SQLite `.apkg` 包不同, 我们坚持使用人类可读的文件夹组织单元集, 这带来了若干好处, 包括:
- 人类可读: 您可以用任意工具, 乃至一个记事本自由修改记忆载荷数据而无需打开软件
- 元数据配置: 配置自由度极高, 可以任意组合, 重造, 乃至创造新内容
- 测验, 算法与知识互相隔离: 一条知识不再是单一的闪卡, 不仅可以用若干不同的算法规划, 还可以用多种并行的谜题类型测验, 极大地提升学习效果和丰富度. 作为学习者, 您无需担忧概念复杂--仅需从云端下载单元集即可开箱即用上述特性!
- 多模态学习
- 软件自身集成了文本转语音 (TTS) , 音频与语言模型 (LLM) 模块, 这些功能乃至功能本身都是可插拔, 可扩展, 可切换驱动的, 这为内容创建了极大的丰富度
- 软件内置多种谜题类型, 包括选择题 (MCQ), 填空题 (Cloze) 与识别题 (Recognition), 您可在同一单元应用多种, 或是选择性启用
- 软件天然支持动态内容生成, 支持宏驱动的模板系统, 根据上下文乃至语言模型动态生成知识点的解析
- 在间隔重复研究尚被 SuperMemo 系列独占的时代, Wozniak 就早已表示 "如果不能理解知识, 就无需记忆它". 今天, 我们依然相信理解是记忆的基石
- 云同步与分享优化:
- 由于记忆数据和单元集文件都是文本文件, 故可进行快速的增量同步而无需完整地上传所有文件, 并且设计天然支持版本控制
- 如果您想分享单文件, 软件也支持导出为压缩包或合并成单文本文件以通过纯文本文件形式在 pastebin 等平台分享
- 性能提升: 得益于现代且支持分块的文件组织结构, 潜进能在保持高自由度的同时仅使用 python 就能达到敏捷且低占用的用户体验
- AI 辅助友好: 想象您有一些 `.apkg` 牌组或一大段教材内容, 您可以方便且高效率地使用 AI 工具以创建可在 HeurAMS 使用的单元集
### 内置实用用户界面
尽管不是唯一前端, 但响应式 Textual 框架构建的内置终端用户界面在多种场景下仍具有独特优势:
- 跨平台, 并支持触屏/鼠标/键盘多操作模式
- 与几乎所有现代终端模拟器相容
- 对于<a href="https://www.arewesixelyet.com/" target="_blank" rel="noopener noreferrer">支持 sixel 协议的终端模拟器</a>, 可高清显示图像内容
- 对于不支持 sixel 协议的终端模拟器, 也支持图片低清的兼容显示模式
- 可通过 textual-web 作为服务部署, 并在任意浏览器使用
- 简洁直观, 键盘友好, 全功能且高效率的用户界面设计
- 易于嵌入: 可在 getty/kmscon 中运行而无需任何桌面图形服务
- 资源占用小, 运行流畅, 不拖泥带水
- 便于测试与调试程序库
查看[屏幕截图](SCREENSHOTS_zh.md).
## 包依赖组说明
由于部分依赖只被少数功能需要, 所以我们把可选依赖分得比较细, 前面提供的命令会安装部分可选依赖, 以下是依赖组列表:
| 依赖组 | 包含模块 | 说明 |
|--------|----------|------|
| 构建系统 | hatchling | 构建时安装 |
| 最小化安装 | tabulate, toml, transitions, click | 核心驱动程序库, 始终必需 |
| interface | textual | 基本用户界面依赖 |
| algo-fsrs | fsrs | FSRS 算法模块 |
| tts-edgetts | edge-tts | 微软文本转语音 |
| llm | llms-py | API 调用 |
| audio-playsound | playsound3 | 通用音频模块 |
| dev | zmq, pytest, pytest-cov | 开发调试与测试工具 |
| basic | [tts-edgetts], [llm], [algo-fsrs] | 适用于用户体验的较轻依赖组(推荐) |
| all | 以上所有依赖 | 完整安装组 |
## 关于此仓库
此仓库为 HeurAMS "潜进" 的核心程序库在 python 语言下的实现\
包含数据模型与框架, 并内置了基于 textual 框架的前端实现 (interface 子模块)\
除了通过内置前端进行学习外, 开发者也能在 python 环境中导入 `heurams` 库或使用 `RPC``heurams` 程序库实例通讯, 使用框架构建其他辅助记忆功能前端或其他应用程序
项目组的所有仓库如下:
| 项目名称 | 状态 | 说明 | 包名 | 技术栈 | 目标平台 |
| :--- | :--- | :--- | :--- | :--- | :--- |
| HeurAMS | 开发中<br/>原型可用 | 提供通用核心程序库与基本用户界面 | `heurams` | Python | 标准 Python 环境 |
| KiriMemo | 开发中<br/>原型可用 | 基于 KDE 技术的现代跨平台前端 | `org.kde.kirimemo` | C++, Qt6, Kirigami, PyOtherSide | 桌面与移动设备 |
| ArkMemo | 开发中 | 基于 ArkUI 的现代跨平台前端 | `top.pluv27.arkmemo` | ArkTS, ArkUI | 移动设备 |
| HeurStudio | 计划中 | AI 辅助的单体单元集高级创建与编辑工具 | `top.pluv27.heurstudio` | C++, Qt6, Kirigami, PyOtherSide | 桌面 |
| HeurSync | 开发中 | 用户数据同步服务器<br/>集成 Web 前端与排行榜 | `heursync` | Go, SQL | 网页与服务器 |
| HeurRepo | 开发中 | 单元集文档源服务器<br/>与单元集分享平台 | `heurrepo` | Go, SQL | 网页与服务器 |
尽管现在后三样有点画大饼的意思, 但是我们的路线是明了的
-73
View File
@@ -1,73 +0,0 @@
# User Interface Screenshots
The HeurAMS project currently has two frontend implementations. This document presents their screenshots (kept as up-to-date as possible):
- **Textual Basic User Interface** (`heurams.interface`): A built-in cross-platform TUI built with the Python Textual framework, supporting touch, mouse, and keyboard operation modes. This is the current out-of-the-box default frontend.
- **KiriMemo** (`org.kde.kirimemo`): A modern cross-platform frontend based on the KDE Kirigami framework, built with C++ and QML, directly reusing the Python kernel via `PyOtherSide`, providing native experiences across multiple platforms (not yet stable).
<!--- ArkMemo (top.pluv27.arkmemo): A modern mobile device frontend based on ArkUI, built with ArkTS, calling the Python kernel via API, providing native experiences for Android, HarmonyOS, and iOS platforms (not yet stable)-->
Feel free to contribute code to existing frontends or develop your own.\
See the [Contributing Guide](../CONTRIBUTING.md#new-user-interface-frontends).
## Screenshots of the Basic User Interface
> The terminal emulator used for screenshots is KDE Konsole.\
> Fonts used: Cascadia Code and Noto Sans SC.\
> Terminal size set to 80x25 (the software also supports larger terminal sizes).
### Dashboard & Navigator
The dashboard provides an overview of the learning panel, including entry points for different functional areas, statistics, and a unit set overview.\
The navigator is a practical modal window that lets you quickly switch between various features. Press the `n` key or click the button below to open/close the navigator from any screen.
<div style="display: flex; flex-wrap: wrap; gap: 10px;">
<img src="../screenshots/dashboard_1.png" width="48%">
<img src="../screenshots/dashboard_2.png" width="48%">
<img src="../screenshots/navigator_1.png" width="48%">
</div>
### Preparation Screen & Pre-cache Tool
The preparation screen shows unit set basic information and the learning status of each unit, providing entry points for learning and pre-caching.\
The pre-cache tool allows you to pre-cache TTS resources to ensure a smooth review experience and offline review capability. Even without pre-caching, resources are loaded automatically during review playback.
<div style="display: flex; flex-wrap: wrap; gap: 10px;">
<img src="../screenshots/preparation.png" width="48%">
<img src="../screenshots/precache_1.png" width="48%">
</div>
### Review Queue Screen
The main screen for queue-based learning and memorization.\
The same knowledge point can generate multiple puzzle types for evaluation. The software includes built-in Cloze, Recognition, and other test types, allowing you to complete different tests sequentially during the review flow.
<div style="display: flex; flex-wrap: wrap; gap: 10px;">
<img src="../screenshots/memoqueue_cloze_1.png" width="48%">
<img src="../screenshots/memoqueue_recognition_1.png" width="48%">
<img src="../screenshots/memoqueue_recognition_2.png" width="48%">
</div>
### Settings Screen
The configuration screen includes algorithm selection, provider switching for audio and various services, as well as interface and algorithm settings.
<div style="display: flex; flex-wrap: wrap; gap: 10px;">
<img src="../screenshots/setting_1.png" width="48%">
<img src="../screenshots/setting_2.png" width="48%">
</div>
### Other Screens
The favorites manager lets you manage your manually marked personal collections.\
The about page provides program version number, license information, and more.
<div style="display: flex; flex-wrap: wrap; gap: 10px;">
<img src="../screenshots/about_1.png" width="48%">
<img src="../screenshots/favmanager_1.png" width="48%">
</div>
## Screenshots of the KiriMemo Frontend
Screenshots will be added when the KiriMemo frontend development stabilizes.
<!-- TODO: Add screenshots -->
-73
View File
@@ -1,73 +0,0 @@
# 用户界面屏幕截图
潜进 (HeurAMS) 项目目前有两个前端实现, 此文档用于呈现它们的截图 (尽量与最新版本同步):
- Textual 基本用户界面 (heurams.interface): 基于 Python Textual 框架构建的程序库内置跨平台 TUI 界面, 支持触屏、鼠标、键盘多操作模式, 是当前开箱即用的默认前端.
- KiriMemo (org.kde.kirimemo): 基于 KDE Kirigami 框架的现代跨平台前端, 使用 C++ 和 QML 构建, 通过 `PyOtherSide` 直接复用 Python 内核, 为多种平台提供原生体验 (尚未稳定).
<!--- ArkMemo (top.pluv27.arkmemo): 基于 ArkUI 的现代移动设备前端, 使用 ArkTS 构建, 通过 API 调用 Python 内核, 为 Android, HarmonyOS, iOS 平台提供原生体验 (尚未稳定)-->
欢迎为现有前端贡献代码, 或开发您自己的前端.\
详见[贡献指南](../CONTRIBUTING_zh.md#%E6%96%B0%E7%9A%84%E7%94%A8%E6%88%B7%E7%95%8C%E9%9D%A2%E5%89%8D%E7%AB%AF).
## 基本用户界面前端的截图
> 截图所使用的终端模拟器为 KDE Konsole\
> 字体为 Cascadia Code 和 Noto Sans SC\
> 终端尺寸设置为 80x25 (软件也支持更大的终端尺寸)
### 仪表盘与导航器
仪表盘包含学习面板的总体视图, 包括不同功能区域的操作入口, 统计信息, 以及单元集概览.\
导航器是一个实用的模态窗口, 能带您在多种功能间自如切换, 按 `n` 键或单击下方按钮可在任意界面迅速打开/关闭导航器.
<div style="display: flex; flex-wrap: wrap; gap: 10px;">
<img src="../screenshots/dashboard_1.png" width="48%">
<img src="../screenshots/dashboard_2.png" width="48%">
<img src="../screenshots/navigator_1.png" width="48%">
</div>
### 准备界面与预缓存工具
学习准备界面展示了单元集基本信息和每个单元的学习状态, 并提供了学习和预缓存的入口.\
预缓存工具使您能提前预缓存文本转语音资源以确保复习流程的顺畅体验和离线复习能力, 但即使您不预先缓存, 资源也会在复习播放时被自动加载.
<div style="display: flex; flex-wrap: wrap; gap: 10px;">
<img src="../screenshots/preparation.png" width="48%">
<img src="../screenshots/precache_1.png" width="48%">
</div>
### 记忆队列界面
队列式学习记忆的主要界面.\
同一知识点可产生多种谜题类型的评估方式, 软件内置完形填空与识别题等多种测试类型, 您可在复习流程中按顺序完成不同测试.
<div style="display: flex; flex-wrap: wrap; gap: 10px;">
<img src="../screenshots/memoqueue_cloze_1.png" width="48%">
<img src="../screenshots/memoqueue_recognition_1.png" width="48%">
<img src="../screenshots/memoqueue_recognition_2.png" width="48%">
</div>
### 设置界面
配置界面包含算法选择、音频与多种服务的提供者切换、以及界面与算法设置等选项.
<div style="display: flex; flex-wrap: wrap; gap: 10px;">
<img src="../screenshots/setting_1.png" width="48%">
<img src="../screenshots/setting_2.png" width="48%">
</div>
### 其他界面
收藏管理器可管理您手动标记的个人收藏集.\
关于页面提供了程序版本号、许可协议等信息.
<div style="display: flex; flex-wrap: wrap; gap: 10px;">
<img src="../screenshots/about_1.png" width="48%">
<img src="../screenshots/favmanager_1.png" width="48%">
</div>
## KiriMemo 前端的截图
截图将在 KiriMemo 前端开发趋于稳定后补充.
<!-- TODO: 补充截图 -->
+21 -28
View File
@@ -1,7 +1,7 @@
[project] [project]
name = "heurams" name = "heurams"
version = "0.5.1" version = "0.5.0"
authors = [{ name = "Wang Zhiyu", email = "pluvium27@outlook.com" }] authors = [{ name = "pluvium27", email = "pluvium27@outlook.com" }]
description = "Heuristic Auxiliary Memory Scheduler" description = "Heuristic Auxiliary Memory Scheduler"
readme = "README.md" readme = "README.md"
requires-python = ">=3.12" requires-python = ">=3.12"
@@ -13,27 +13,32 @@ license = "AGPL-3.0-or-later"
license-files = ["LICENSE"] license-files = ["LICENSE"]
dependencies = [ # 这些依赖只能驱动 kernel 程序库 dependencies = [ # 这些依赖只能驱动 kernel 程序库
"click>=8.3.3",
"fastapi>=0.136.1",
"tabulate>=0.10.0", "tabulate>=0.10.0",
"toml>=0.10.2", "toml>=0.10.2",
"transitions>=0.9.3", "transitions>=0.9.3",
"uvicorn[standard]>=0.47.0",
] ]
[project.optional-dependencies] [project.optional-dependencies]
interface = [ # 基本用户界面依赖 interface = [ # 基本用户界面依赖
"textual>=8.2.5", "textual>=8.2.3",
"psutil>=7.2.2",
] ]
algo-fsrs = [ algo-fsrs = [
"fsrs>=6.3.1", # FSRS 算法底层依赖 "fsrs>=6.3.1", # FSRS 算法底层依赖
] ]
tts-edgetts = [ tts-edgetts = [
"edge-tts>=7.2.8", # 微软 TTS "edge-tts>=7.2.8", # 微软 TTS
] ]
llm = ["llms-py>=3.0.0"] misc-jieba = [
audio-playsound = ["playsound3>=3.3.1"] "jieba>=0.42.1", # 用于中文智能分词
]
llm-openai = [
"openai>=2.32.0",
]
audio-playsound = [
"playsound==1.2.2",
"pygobject>=3.56.2", # playsound 依赖它
]
dev = [ # 调试所需依赖 dev = [ # 调试所需依赖
"zmq>=0.0.0", # 用于 ZMQ 远程调试服务器, 在 linux 上建议先安装 libzmq "zmq>=0.0.0", # 用于 ZMQ 远程调试服务器, 在 linux 上建议先安装 libzmq
"pytest>=8.0.0", # 用于普通测试 "pytest>=8.0.0", # 用于普通测试
@@ -42,27 +47,20 @@ dev = [ # 调试所需依赖
all = [ all = [
"heurams[algo-fsrs]", "heurams[algo-fsrs]",
"heurams[tts-edgetts]", "heurams[tts-edgetts]",
"heurams[llm]", "heurams[misc-jieba]",
"heurams[llm-openai]",
"heurams[audio-playsound]", "heurams[audio-playsound]",
"heurams[dev]", "heurams[dev]",
] ]
basic = [
"heurams[algo-fsrs]",
"heurams[interface]",
"heurams[tts-edgetts]",
"heurams[llm]",
]
[project.urls] [project.urls]
Homepage = "https://ams.pluv27.top" Homepage = "https://ams.pluv.top"
Issues = "https://github.com/heurams/heurams/issues" Issues = "https://github.com/heurams/heurams/issues"
[[tool.uv.index]]
url = "https://mirrors.ustc.edu.cn/pypi/simple"
default = true
[project.scripts] [project.scripts]
heurams = "heurams.__main__:main" heurams = "heurams.__main__:main"
tui = "heurams.interface.__main__:main"
heurams-tui = "heurams.interface.__main__:main"
[tool.pytest.ini_options] [tool.pytest.ini_options]
testpaths = ["tests"] testpaths = ["tests"]
@@ -74,10 +72,5 @@ markers = [
] ]
[build-system] [build-system]
requires = ["hatchling"] requires = ["uv_build>=0.7.19"]
build-backend = "hatchling.build" build-backend = "uv_build"
[dependency-groups]
dev = [
"httpx>=0.28.1",
]
+8
View File
@@ -0,0 +1,8 @@
edge-tts==7.0.2
jieba==0.42.1
openai==1.0.0
playsound==1.2.2
tabulate>=0.9.0
textual==7.0.0
toml==0.10.2
transitions==0.9.3
Binary file not shown.

Before

Width:  |  Height:  |  Size: 351 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 221 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 330 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 203 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 220 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 237 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 317 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 179 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 177 KiB

+4 -1
View File
@@ -1,4 +1,7 @@
print("欢迎使用 HeurAMS 及其组件!")
# 补充日志记录
from heurams.services.logger import get_logger from heurams.services.logger import get_logger
logger = get_logger(__name__) logger = get_logger(__name__)
logger.info("HeurAMS is imported") logger.info("欢迎使用 HeurAMS 及其组件!")
+17 -112
View File
@@ -1,118 +1,23 @@
"""命令行入口 import heurams.services.version as ver
"""
import platform
import click
from heurams.i18n import _, setup_locale
from heurams.services.version import ver, stage, codename, codename_cn
from heurams.services.logger import get_logger
logger = get_logger(__name__)
def _apply_locale(ctx, param, value):
"""立即显式应用 locale"""
if value:
setup_locale(value)
return value
class _I18nGroup(click.Group):
"""在运行时完成翻译工作的命令组"""
_option_help_map: dict[str, str] = {
"version": "Show the version and exit.",
"locale": "Explicitly specify locale (defaults to LANG env).",
"host": "Listening address",
"port": "Listening port",
"reload": "Development mode hot reload",
}
def format_help(self, ctx, formatter):
# 重新翻译每个子命令的帮助信息
for cmd in self.commands.values():
raw = getattr(cmd, "_raw_help", None)
if raw is not None:
cmd.help = _(raw)
# Re-translate every option's help text by name lookup.
for param in self.params:
if isinstance(param, click.Option) and param.name in self._option_help_map:
param.help = _(self._option_help_map[param.name])
self.help = _("HeurAMS {ver} - Heuristic Auxiliary Memorizing Scheduler").format(
ver=ver
)
return super().format_help(ctx, formatter)
class _I18nCommand(click.Command):
"""在运行时完成翻译工作的命令"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._raw_help = self.help or (self.short_help or "")
@click.group(
cls=_I18nGroup,
invoke_without_command=True,
context_settings={"help_option_names": ["-h", "--help"]},
)
@click.version_option(
ver, "-v", "--version",
prog_name="HeurAMS",
message=f"%(prog)s %(version)s {stage} ({codename}/{codename_cn}), {platform.system()}",
help=_I18nGroup._option_help_map["version"],
)
@click.option(
"--locale", "-l", default=None,
callback=_apply_locale,
is_eager=True,
expose_value=True,
help=_I18nGroup._option_help_map["locale"],
)
@click.pass_context
def cli(ctx, locale):
if ctx.invoked_subcommand is None:
click.echo(cli.get_help(ctx))
ctx.exit(0)
@cli.command(cls=_I18nCommand)
def tui():
"""Launch the built-in user interface (TUI)"""
import heurams.interface.__main__ as tui_module
tui_module.main()
@cli.command(cls=_I18nCommand)
@click.option("--host", default="127.0.0.1", help=_I18nGroup._option_help_map["host"])
@click.option("--port", default=8821, help=_I18nGroup._option_help_map["port"], type=int)
@click.option("--reload", is_flag=True, help=_I18nGroup._option_help_map["reload"])
def serve(host, port, reload):
"""Launch the API service (unifront)"""
from heurams.unifront.server import create_app
app = create_app()
click.echo(
_("unifront API service started: http://{host}:{port}").format(
host=host, port=port
)
)
import uvicorn
uvicorn.run(app, host=host, port=port, reload=reload, log_level="info")
@cli.command(cls=_I18nCommand, name="help")
@click.pass_context
def help_cmd(ctx):
"""Show this help message"""
click.echo(cli.get_help(ctx.parent))
# __main__.py
def main(): def main():
cli() prompt = f"""HeurAMS {ver.ver} 已经被成功地安装在系统中.
HeurAMS 被设计为一个带有辅助记忆调度器功能的软件包, 无法直接被执行, 但可被其他 Python 程序调用.
若您想启动内置的基本用户界面:
请运行 python -m heurams.interface,
或者 python -m heurams.interface.__main__
python 代指您使用的解释器, 在某些发行版中可能是 python3, 而 python 命令被指向了 python2.
尽管项目保留了 requirements.txt, 我们仍不推荐使用系统 python 和原始 venv 进行开发.
项目的推荐开发环境工具是 uv.
如果你的环境已经安装了 uv:
先运行 uv sync 同步环境, 此命令只需要执行一遍, uv 会自动处理依赖.
然后通过运行 uv run tui 启动内置基本用户界面.
此时您的解释器在项目目录里的 .venv/bin 中, 使用 IDE 开发前, 务必切换解释器!
注意: 一个常见的误区是, 执行 interface 下的 __main__.py 运行基本用户界面, 这会导致 Python 上下文环境异常, 请不要这样做."""
print(prompt)
if __name__ == "__main__": if __name__ == "__main__":
logger.info("HeurAMS cmdline entrypoint invoked")
main() main()
Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

-25
View File
@@ -1,25 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="0 0 554.4 554.4" version="1.1">
<defs>
<style type="text/css">*{stroke-linejoin: round; stroke-linecap: butt}</style>
</defs>
<title>HeurAMS Monochrome Logo - Dark</title>
<desc>Dark monochrome logo of the HeurAMS Project</desc>
<g id="figure_1">
<g id="patch_1">
<path d="M 0 554.4 L 554.4 554.4 L 554.4 0 L 0 0 L 0 554.4 z" style="fill: none"/>
</g>
<g id="axes_1">
<g id="patch_2">
<path d="M 66.528 487.872 L 199.584 487.872 L 199.584 354.816 L 66.528 354.816 z" clip-path="url(#p4da876c7a0)" style="fill: #1A1A1A; stroke: #1A1A1A; stroke-linejoin: miter"/>
</g>
<g id="patch_3">
<path d="M 199.584 354.816 L 487.872 354.816 L 487.872 66.528 L 199.584 66.528 z" clip-path="url(#p4da876c7a0)" style="fill: #1A1A1A; stroke: #1A1A1A; stroke-linejoin: miter"/>
</g>
</g>
</g>
<defs>
<clipPath id="p4da876c7a0">
<rect x="0" y="0" width="554.4" height="554.4"/>
</clipPath>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

@@ -1,25 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="0 0 554.4 554.4" version="1.1">
<defs>
<style type="text/css">*{stroke-linejoin: round; stroke-linecap: butt}</style>
</defs>
<title>HeurAMS Monochrome Logo - Light</title>
<desc>Light monochrome logo of the HeurAMS Project</desc>
<g id="figure_1">
<g id="patch_1">
<path d="M 0 554.4 L 554.4 554.4 L 554.4 0 L 0 0 L 0 554.4 z" style="fill: none"/>
</g>
<g id="axes_1">
<g id="patch_2">
<path d="M 66.528 487.872 L 199.584 487.872 L 199.584 354.816 L 66.528 354.816 z" clip-path="url(#p4da876c7a0)" style="fill: #ffffff; stroke: #ffffff; stroke-linejoin: miter"/>
</g>
<g id="patch_3">
<path d="M 199.584 354.816 L 487.872 354.816 L 487.872 66.528 L 199.584 66.528 z" clip-path="url(#p4da876c7a0)" style="fill: #ffffff; stroke: #ffffff; stroke-linejoin: miter"/>
</g>
</g>
</g>
<defs>
<clipPath id="p4da876c7a0">
<rect x="0" y="0" width="554.4" height="554.4"/>
</clipPath>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

-25
View File
@@ -1,25 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="0 0 554.4 554.4" version="1.1">
<defs>
<style type="text/css">*{stroke-linejoin: round; stroke-linecap: butt}</style>
</defs>
<title>HeurAMS Logo</title>
<desc>The logo of the HeurAMS Project</desc>
<g id="figure_1">
<g id="patch_1">
<path d="M 0 554.4 L 554.4 554.4 L 554.4 0 L 0 0 L 0 554.4 z" style="fill: none"/>
</g>
<g id="axes_1">
<g id="patch_2">
<path d="M 66.528 487.872 L 199.584 487.872 L 199.584 354.816 L 66.528 354.816 z" clip-path="url(#p4da876c7a0)" style="fill: #1660a5; stroke: #1660a5; stroke-linejoin: miter"/>
</g>
<g id="patch_3">
<path d="M 199.584 354.816 L 487.872 354.816 L 487.872 66.528 L 199.584 66.528 z" clip-path="url(#p4da876c7a0)" style="fill: #545f70; stroke: #545f70; stroke-linejoin: miter"/>
</g>
</g>
</g>
<defs>
<clipPath id="p4da876c7a0">
<rect x="0" y="0" width="554.4" height="554.4"/>
</clipPath>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 1.0 KiB

View File
View File
View File
+6 -15
View File
@@ -1,6 +1,6 @@
"""全局上下文模块 """
全局上下文管理模块
初始化并管理基准路径, 程序配置对象, 并提供调试所需上下文管理器 以及基准路径
""" """
import pathlib import pathlib
@@ -19,21 +19,12 @@ workdir = pathlib.Path.cwd()
"""工作目录路径.""" """工作目录路径."""
logger = get_logger(__name__) logger = get_logger(__name__)
logger.info(f"rootdir: {rootdir}") logger.debug(f"包目录: {rootdir}")
logger.info(f"workdir: {workdir}") logger.debug(f"工作目录: {workdir}")
default_data = rootdir / "assets" / "data"
user_data = workdir / "data"
if not user_data.exists():
logger.info("Create a new data directory: %s", user_data)
import shutil
shutil.copytree(default_data, user_data)
else:
(workdir / "data" / "config").mkdir(parents=True, exist_ok=True) (workdir / "data" / "config").mkdir(parents=True, exist_ok=True)
config_var: ContextVar[ConfigDict] = ContextVar( config_var: ContextVar[ConfigDict].get = ContextVar(
"config_var", "config_var",
default=ConfigDict(workdir / "data" / "config"), default=ConfigDict(workdir / "data" / "config"),
) )
-38
View File
@@ -1,38 +0,0 @@
"""国际化支持模块
基于 GNU gettext, 并使用英文 (en_US) 作为 msgid 的基础语言.
"""
import gettext
import os
from pathlib import Path
import locale
from heurams.context import rootdir
_LOCALE_DIR = rootdir / "locale"
_DEFAULT_LOCALE = "en_US"
_translation = gettext.NullTranslations()
def setup_locale(_locale: str | None = None) -> None:
"""获得翻译项.
如果没有找到对应的 locale, 就回退到原始 msgid.
"""
global _translation
if _locale is None:
_locale = locale.getlocale()[0]
try:
_translation = gettext.translation(
"heurams", localedir=str(_LOCALE_DIR), languages=[_locale], fallback=True
)
except FileNotFoundError:
_translation = gettext.NullTranslations()
def _(message: str) -> str:
"""执行翻译的函数"""
return _translation.gettext(message)
# 导入时初始化
setup_locale()
+22 -23
View File
@@ -2,53 +2,52 @@ from time import sleep, perf_counter
# import gc # import gc
# gc.set_threshold(100, 1, 1) # gc.set_threshold(100, 1, 1)
from heurams.i18n import _ print("欢迎使用基本用户界面!")
print("加载配置与上下文... ", end="", flush=True)
print(_("Welcome to the basic user interface!"))
print(_("Loading config and context... "), end="", flush=True)
_start_all = perf_counter() _start_all = perf_counter()
_start = _start_all _start = _start_all
from heurams.context import rootdir, workdir, config_var from heurams.context import rootdir, workdir, config_var
_end = perf_counter() _end = perf_counter()
print(_("Done! ({time}ms)").format(time=round(1000 * (_end - _start)))) print(f"已完成! (耗时: {round(1000 * (_end - _start))}ms)")
print(_("Loading UI framework... "), end="", flush=True) print("加载用户界面框架... ", end="", flush=True)
_start = perf_counter() _start = perf_counter()
from textual.app import App from textual.app import App
from textual.widgets import Button
_end = perf_counter() _end = perf_counter()
print(_("Done! ({time}ms)").format(time=round(1000 * (_end - _start)))) print(f"已完成! (耗时: {round(1000 * (_end - _start))}ms)")
print(_("Loading UI layout... "), end="", flush=True) print("加载用户界面布局... ", end="", flush=True)
_start = perf_counter() _start = perf_counter()
from .screens.about import AboutScreen
from .screens.dashboard import DashboardScreen from .screens.dashboard import DashboardScreen
from .screens.navigator import NavigatorScreen from .screens.navigator import NavigatorScreen
from .screens.precache import PrecachingScreen from .screens.precache import PrecachingScreen
from .screens.setting import SettingScreen from .screens.setting import SettingScreen
from .screens.synctool import SyncScreen from .screens.synctool import SyncScreen
from .screens.about import AboutScreen
from . import shim from . import shim
_end = perf_counter() _end = perf_counter()
print(_("Done! ({time}ms)").format(time=round(1000 * (_end - _start)))) print(f"已完成! (耗时: {round(1000 * (_end - _start))}ms)")
print(_("Component directory: {path}").format(path=rootdir)) print(f"组件目录: {rootdir}")
print(_("Working directory: {path}").format(path=workdir)) print(f"工作目录: {workdir}")
_end_all = perf_counter() _end_all = perf_counter()
print(_("Pre-work total: {time}ms").format(time=round(1000 * (_end_all - _start_all)))) print(f"前置工作共计耗时: {round(1000 * (_end_all - _start_all))}ms")
class HeurAMSApp(App): class HeurAMSApp(App):
TITLE = "HeurAMS" TITLE = "潜进"
CSS_PATH = rootdir / "interface" / "css" / "main.tcss" CSS_PATH = rootdir / "interface" / "css" / "main.tcss"
SUB_TITLE = _("Heuristic Auxiliary Memorizing Scheduler") SUB_TITLE = "启发式辅助记忆调度器"
BINDINGS = [ BINDINGS = [
("q", "go_back", _("Quit")), ("q", "go_back", "退出"),
("d", "toggle_dark", _("Theme")), ("d", "toggle_dark", "主题"),
("n", "app.push_screen('navigator')", _("Navigate")), ("n", "app.push_screen('navigator')", "导航"),
("s", "app.push_screen('setting')", _("Settings")), ("s", "app.push_screen('setting')", "设置"),
("z", "app.push_screen('about')", _("About")), ("z", "app.push_screen('about')", "关于"),
] ]
SCREENS = { SCREENS = {
"dashboard": DashboardScreen, "dashboard": DashboardScreen,
@@ -73,8 +72,9 @@ class HeurAMSApp(App):
) -> None: # 用来给没使用/禁用的快捷键占位, 因为 Binding 删除不了 ) -> None: # 用来给没使用/禁用的快捷键占位, 因为 Binding 删除不了
pass pass
''' # 移除烦人的 "rich traceback"
# 移除烦人的 "rich traceback", 但可能导致未定义行为出现, 所以注释掉 # Textual 官方不会管这破事, 写 Rich 写入脑了导致的
# 不知道哪来的自信改标准库的 traceback
# https://github.com/Textualize/textual/discussions/6255 # https://github.com/Textualize/textual/discussions/6255
# NOTE: 进行 textual 版本升级时, 确保查看过上游代码, 尤其是 App 的 _exception # NOTE: 进行 textual 版本升级时, 确保查看过上游代码, 尤其是 App 的 _exception
# 如果行为变了就把下面的删了 (虽然有 fallback) # 如果行为变了就把下面的删了 (虽然有 fallback)
@@ -89,4 +89,3 @@ class HeurAMSApp(App):
self._close_messages_no_wait() self._close_messages_no_wait()
raise self._exception raise self._exception
super().panic(*args) # ditto super().panic(*args) # ditto
'''
+20 -3
View File
@@ -1,15 +1,31 @@
from heurams.interface import * from heurams.interface import *
from heurams.context import config_var from heurams.context import config_var
from heurams.i18n import _
from heurams.services.logger import get_logger from heurams.services.logger import get_logger
import threading import threading
import zmq
import pickle import pickle
logger = get_logger(__name__) logger = get_logger(__name__)
def environment_check():
from pathlib import Path
logger.debug("检查环境路径")
subdir = ["cache/voice", "repo", "global", "config"]
for i in subdir:
i = Path(config_var.get()["global"]["paths"]["data"]) / i
if not i.exists():
logger.info("创建目录: %s", i)
print(f"创建 {i}")
i.mkdir(exist_ok=True, parents=True)
else:
logger.debug("目录已存在: %s", i)
print(f"找到 {i}")
logger.debug("环境检查完成")
def start_debug_server(app): def start_debug_server(app):
import zmq
logger = get_logger("zmq_debug") logger = get_logger("zmq_debug")
context = zmq.Context() context = zmq.Context()
socket = context.socket(zmq.REP) socket = context.socket(zmq.REP)
@@ -22,7 +38,7 @@ def start_debug_server(app):
code = pickle.loads(msg) code = pickle.loads(msg)
namespace = {"app": app, "logger": logger, "config_var": config_var} namespace = {"app": app, "logger": logger, "config_var": config_var}
if first: if first:
app.title += _(" [Debug Connected]") app.title += " [调试已连接]"
first = 0 first = 0
try: try:
# 先尝试 eval # 先尝试 eval
@@ -40,6 +56,7 @@ def start_debug_server(app):
def main(): def main():
environment_check()
app = HeurAMSApp() app = HeurAMSApp()
-21
View File
@@ -13,24 +13,3 @@ NavigatorScreen {
border: thick $background 80%; border: thick $background 80%;
background: $surface; background: $surface;
} }
.favorite-item {
height: auto;
}
.favorite-item-btn {
dock: right;
width: 8;
padding: 0;
}
.memoqueue-container {
padding: 1 2;
width: auto;
}
.memoqueue-container > * {
border: heavy $secondary;
width: 1fr;
padding: 0 1 0 1;
}
@@ -2,7 +2,3 @@
height: auto; height: auto;
width: auto; width: auto;
} }
.hori {
height: auto;
}
+63 -49
View File
@@ -1,26 +1,27 @@
"""About screen""" """关于界面"""
from textual.app import ComposeResult from textual.app import ComposeResult
from textual.containers import ScrollableContainer from textual.containers import ScrollableContainer
from textual.screen import Screen from textual.screen import Screen
from textual.widgets import Button, Footer, Header, Label, Markdown from textual.widgets import Button, Footer, Header, Label, Markdown
from textual import events, on from textual import events, on
import heurams.services.version as version import heurams.services.version as version
from heurams.context import * from heurams.context import *
from heurams.i18n import _
import platform import platform
import shutil import shutil
import psutil
import os import os
import sys import sys
class AboutScreen(Screen): class AboutScreen(Screen):
BINDINGS = [ BINDINGS = [
("q", "go_back", _("Back")), ("q", "go_back", "返回"),
("z", "go_back", _("About")), ("z", "go_back", "关于"),
] ]
SUB_TITLE = _("About") SUB_TITLE = "关于"
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@@ -38,64 +39,64 @@ class AboutScreen(Screen):
show_clock=config_var.get()["interface"]["global"]["clock_on_header"] show_clock=config_var.get()["interface"]["global"]["clock_on_header"]
) )
with ScrollableContainer(id="about_container"): with ScrollableContainer(id="about_container"):
yield Label(_("[b]About & Version Info[/b]")) yield Label("[b]关于与版本信息[/b]")
# Get system info
# 获取系统信息
textual_version = self._get_textual_version() textual_version = self._get_textual_version()
terminal_info = self._get_terminal_info() terminal_info = self._get_terminal_info()
python_version = self._get_python_version() python_version = self._get_python_version()
os_version = self._get_os_version() os_version = self._get_os_version()
disk_usage = self._get_disk_usage() disk_usage = self._get_disk_usage()
memory_info = self._get_memory_info()
about_text = _( about_text = f"""
"""# About HeurAMS # 关于 "潜进"
Main library version: `{ver}-python` 主程序库版本: `{version.ver}-python`
UI frontend: `Textual TUI (Basic UI)` 用户界面分支: `Textual TUI (基本用户界面)`
UI version: `{ver}` 用户界面版本: `{version.ver}`
API codename: `{codename}` API 版本代号: `{version.codename.capitalize()}`
> A heuristic auxiliary memorizing scheduler based on heuristic algorithms and cognitive science theories, designed to help users memorize and plan learning more efficiently. 一个基于启发式算法与认知科学理论的辅助记忆调度器, 旨在帮助用户更高效地进行记忆工作与学习规划.
> An open, elegant, and extensible spaced repetition scheduler experimental platform, designed to help researchers conduct investigations, experiments, and research on cutting-edge memory algorithms more efficiently. 一个开放, 优雅, 易于扩展的间隔重复调度器实验平台, 旨在帮助研究者更高效地进行前沿记忆算法的研究.
You can visit the project homepage at https://ams.pluv27.top for user guides, development documentation and software updates, and participate in software development and improvement. 以 AGPL-3.0 开放源代码, 这直接意味着任何个体直接基于此代码对外或内部提供的应用和服务, 无论本地或网络, 必须向所有用户公开完整修改后的源代码, 且继续沿用 AGPL-3.0 协议.
Open source under the GNU Affero General Public License (version 3), with an additional exemption clause for local API calls, used for other frontend to library interface calls. 您正使用的 TUI 用户界面是 python 版本程序库自带的基本用户界面, 以作为第一个全功能前端实现与程序库测试套件, 位于程序库根目录中的 interface 文件夹.
You are using the built-in terminal user interface, which is the first full-featured frontend implementation and library test suite, located in the interface subdirectory of the library. 您可在项目主页 https://ams.pluv27.top 获取用户指南, 开发文档与软件更新.
Developers: 如果您觉得这个软件有用, 可以考虑参与贡献, 或在它的源代码仓库给它添加一个星标 :)
- Wang Zhiyu ([@pluvium27](https://github.com/pluvium27)): Project initiator and lead developer
Special thanks to the following individuals and groups; their algorithms and theories form the cornerstone of the current software algorithms: 您的慷慨支持, 我们必当涌泉相报.
- [Piotr A. Woźniak](https://supermemo.guru/wiki/Piotr_Wozniak): SM-2 algorithm and SM-15 algorithm theory 开发人员列表:
- [Jarrett Ye](https://github.com/L-M-Sherlock): FSRS algorithm and spaced repetition theory references
- [Kazuaki Tanida](https://github.com/slaypni): CoffeeScript reverse implementation of SM-15 algorithm
- [Open Spaced Repetition](https://github.com/open-spaced-repetition): FSRS algorithm underlying implementation
# Runtime Environment - Wang Zhiyu([@pluvium27](https://github.com/pluvium27)): 发起项目与主要维护者
Python interpreter version: {python_version} 特别感谢以下人士, 他们的算法与理论构成了此软件现有算法的基石:
Python interpreter path: {executable}
Textual framework version: {textual_version}
Terminal emulator: {terminal_info}
Operating system version: {os_version}
Disk free space: {disk_usage}
When reporting issues, please copy this information into the issue description and attach `heurams.log` as an attachment to help developers locate the error.""" - [Piotr A. Woźniak](https://supermemo.guru/wiki/Piotr_Wozniak): SM-2 算法与 SM-15 算法理论
).format( - [Kazuaki Tanida](https://github.com/slaypni): SM-15 算法的 CoffeeScript 实现
ver=version.ver, - [Thoughts Memo](https://www.zhihu.com/people/L.M.Sherlock): 中文文献参考
codename=version.codename.capitalize(),
python_version=python_version,
executable=sys.executable, # 运行环境信息
textual_version=textual_version,
terminal_info=terminal_info, Python 解释器版本: {python_version}
os_version=os_version, Python 解释器路径: {sys.executable}
disk_usage=disk_usage, Textual 框架版本: {textual_version}
) 终端模拟器: {terminal_info}
操作系统版本: {os_version}
存储余量: {disk_usage}
内存大小: {memory_info}
报告问题时, 请复制这些信息到问题描述, 并上传软件日志 `heurams.log` 作为附件, 以协助开发者定位错误
"""
yield Markdown(about_text, classes="about-markdown") yield Markdown(about_text, classes="about-markdown")
yield Button( yield Button(
_("Back to Main"), "返回主界面",
id="back_button", id="back_button",
variant="primary", variant="primary",
flat=True, flat=True,
@@ -112,20 +113,22 @@ When reporting issues, please copy this information into the issue description a
self.action_go_back() self.action_go_back()
def _get_textual_version(self) -> str: def _get_textual_version(self) -> str:
"""获取 Textual 框架版本"""
try: try:
import textual import textual
return textual.__version__ return textual.__version__
except (ImportError, AttributeError): except (ImportError, AttributeError):
return _("Unknown") return "未知"
def _get_terminal_info(self) -> str: def _get_terminal_info(self) -> str:
"""获取终端模拟器信息"""
terminal = shutil.which("terminal") terminal = shutil.which("terminal")
if terminal: if terminal:
return terminal return terminal
# Try from environment variables # 尝试从环境变量获取
terminal_env = os.environ.get("TERM_PROGRAM") or os.environ.get("TERM") terminal_env = os.environ.get("TERM_PROGRAM") or os.environ.get("TERM")
return terminal_env or _("Unknown") return terminal_env or "未知"
def _get_python_version(self) -> str: def _get_python_version(self) -> str:
"""获取 Python 解释器版本""" """获取 Python 解释器版本"""
@@ -160,9 +163,20 @@ When reporting issues, please copy this information into the issue description a
def _get_disk_usage(self) -> str: def _get_disk_usage(self) -> str:
"""获取磁盘使用情况""" """获取磁盘使用情况"""
usage = shutil.disk_usage("/") try:
usage = psutil.disk_usage("/")
free_gb = usage.free / (1024**3) free_gb = usage.free / (1024**3)
total_gb = usage.total / (1024**3) total_gb = usage.total / (1024**3)
percent_free = (free_gb / total_gb) * 100 percent_free = (free_gb / total_gb) * 100
#print(f"{free_gb:.1f} GB ({percent_free:.1f}%)")
return f"{free_gb:.1f} GB ({percent_free:.1f}%)" return f"{free_gb:.1f} GB ({percent_free:.1f}%)"
except Exception:
return "未知"
def _get_memory_info(self) -> str:
"""获取内存信息"""
try:
memory = psutil.virtual_memory()
total_gb = memory.total / (1024**3)
return f"{total_gb:.1f} GB"
except Exception:
return "未知"
+23 -46
View File
@@ -1,4 +1,4 @@
"""Dashboard screen""" """仪表盘界面"""
from functools import reduce from functools import reduce
from pathlib import Path from pathlib import Path
@@ -14,7 +14,6 @@ import heurams.kernel.particles as pt
import heurams.services.timer as timer import heurams.services.timer as timer
import heurams.services.version as version import heurams.services.version as version
from heurams.context import * from heurams.context import *
from heurams.i18n import _
from heurams.kernel.particles import * from heurams.kernel.particles import *
from heurams.kernel.repolib import * from heurams.kernel.repolib import *
from heurams.services.logger import get_logger from heurams.services.logger import get_logger
@@ -26,11 +25,11 @@ logger = get_logger(__name__)
class DashboardScreen(Screen): class DashboardScreen(Screen):
"""Main dashboard screen""" """主仪表盘屏幕"""
SUB_TITLE = _("Dashboard") SUB_TITLE = "仪表盘"
BINDINGS = [ BINDINGS = [
("q", "go_back", _("Back")), ("q", "go_back", "返回"),
] ]
CSS_PATH = rootdir / "interface" / "css" / "screens" / "dashboard.tcss" CSS_PATH = rootdir / "interface" / "css" / "screens" / "dashboard.tcss"
@@ -47,50 +46,45 @@ class DashboardScreen(Screen):
self._load_data() self._load_data()
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
"""Compose UI components""" """组合界面组件"""
if config_var.get()["interface"]["global"]["show_header"]: if config_var.get()["interface"]["global"]["show_header"]:
yield Header( yield Header(
show_clock=config_var.get()["interface"]["global"]["clock_on_header"] show_clock=config_var.get()["interface"]["global"]["clock_on_header"]
) )
with ScrollableContainer(): with ScrollableContainer():
yield Horizontal( yield Horizontal( # 顶部的状态
Vertical( Vertical(
Label(_("Current daystamp: {ds}").format(ds=timer.get_daystamp())), Label(f"当前日时间戳: {timer.get_daystamp()}"),
Label( Label(
_("Timezone offset: UTC+{offset}").format(offset=str(config_var.get()['services']['timer']['timezone_offset'] / 3600).removesuffix('.0')) f"应用时区修正: UTC+{str(config_var.get()['services']['timer']['timezone_offset'] / 3600).removesuffix('.0')}"
), ),
Label( Label(
_("Default algorithm: {algo}").format(algo=config_var.get()['interface']['global']['algorithm']), f"默认算法设置: {config_var.get()['interface']['global']['algorithm']}",
), ),
classes="left", classes="left",
), ),
Vertical( Vertical(
Label(_("Loaded {n} repo(s)").format(n=len(self.repos))), Label(f"已加载 {len(self.repos)} 个单元集"),
Label( Label(
_("Total {n} unit(s)").format(n=reduce(lambda x, y: x + y, map(lambda x: x.progress['total'], self.repos)) if self.repos else 0) f"共计 {reduce(lambda x, y: x + y, map(lambda x: x.progress['total'], self.repos))} 个单元"
), ),
Label( Label(
_("Activated {n} unit(s)").format(n=reduce(lambda x, y: x + y, map(lambda x: x.progress['touched'], self.repos)) if self.repos else 0) f"已激活 {reduce(lambda x, y: x + y, map(lambda x: x.progress['touched'], self.repos))} 个单元"
), ),
Label(f""), Label(f""),
classes="right", classes="right",
), ),
id="header", id="header",
) )
yield ListView(id="repo_list", classes="repo-list") yield ListView(id="repo_list", classes="repo-list") # 单元集选择
from heurams.services.attic import Attic from heurams.services.attic import Attic
a = Attic("ana", {"totaltime": 0, "openpuzzles": 0, "puzzles_err": 0}) a = Attic("ana", {"totaltime": 0, "openpuzzles": 0, "puzzles_err": 0})
yield Label(_("Version {ver}-{stage}").format(ver=version.ver, stage=version.stage)) yield Label(f"版本 {version.ver} {version.stage.capitalize()}") # 版本信息
yield Label( yield Label(
_("Processed {puzzles} puzzles in {time}s, accuracy {accuracy}, speed {speed} puzzle(s)/s").format( f"{round(a.data['totaltime'], 2)} 秒内处理了 {a.data['openpuzzles']} 个谜题, 正确率{'无法求解' if not a.data['openpuzzles'] else ' ' + str(round(100 * (1 - a.data['puzzles_err']/a.data['openpuzzles']), 2)) + '%'}, 平均速度{'无法求解' if not a.data['totaltime'] else ' ' + str(round(a.data['openpuzzles']/a.data['totaltime'], 2)) + ' 个每秒'}",
puzzles=a.data['openpuzzles'],
time=round(a.data['totaltime'], 2),
accuracy=_("N/A") if not a.data['openpuzzles'] else str(round(100 * (1 - a.data['puzzles_err']/a.data['openpuzzles']), 2)) + '%',
speed=_("N/A") if not a.data['totaltime'] else str(round(a.data['openpuzzles']/a.data['totaltime'], 2)),
),
id="analysis", id="analysis",
) # Version info ) # 版本信息
yield Footer() yield Footer()
@on(events.ScreenResume) @on(events.ScreenResume)
@@ -146,28 +140,9 @@ class DashboardScreen(Screen):
repo.preview["review"] += 1 repo.preview["review"] += 1
# initial_time = min(initial_time, e.) # initial_time = min(initial_time, e.)
repo.need_review = timer.get_daystamp() >= repo.nearest_review_time repo.need_review = timer.get_daystamp() >= repo.nearest_review_time
repo.prompt = _( repo.prompt = f"""{repo.manifest['title']} \\[{repo.config['algorithm']}]
"""{title} [{algo}] [d]进度: {repo.progress['touched']}/{repo.progress['total']} ({round(repo.progress['touched']/repo.progress['total']*100, 1)}%)[/d]
[d]Progress: {touched}/{total} ({pct}%)[/d] [d]{f'需要学习: {repo.preview['review']}R + {repo.preview['new']}U' if repo.need_review else (f"暂未开始: 0R + {repo.preview['new']}U" if not repo.progress['have_activated_ever'] else '无需操作')}[/d]"""
[d]{status}[/d]"""
).format(
title=repo.manifest["title"],
algo=repo.config["algorithm"],
touched=repo.progress["touched"],
total=repo.progress["total"],
pct=round(repo.progress["touched"] / repo.progress["total"] * 100, 1),
status=(
_("Due: {review}R + {new}U").format(
review=repo.preview["review"], new=repo.preview["new"]
)
if repo.need_review
else (
_("Not started: 0R + {new}U").format(new=repo.preview["new"])
if not repo.progress["have_activated_ever"]
else _("Up to date")
)
),
)
def on_mount(self) -> None: def on_mount(self) -> None:
"""挂载组件时初始化""" """挂载组件时初始化"""
@@ -185,7 +160,8 @@ class DashboardScreen(Screen):
repo_list_widget.append( repo_list_widget.append(
ListItem( ListItem(
Static( Static(
_("No repo directories found in {path}.\nPlease import a repo and restart, or create a new one.").format(path=config_var.get()['global']['paths']['repo']) f"{config_var.get()['global']['paths']['repo']} 中未找到任何仓库.\n"
"请导入仓库后重启应用, 或者新建空的仓库."
), ),
id="not-found", id="not-found",
) )
@@ -199,7 +175,7 @@ class DashboardScreen(Screen):
list_item = ListItem( list_item = ListItem(
*[Label(line) for line in r.prompt.splitlines()], *[Label(line) for line in r.prompt.splitlines()],
Button( Button(
_("Start Learning"), f"开始学习",
flat=True, flat=True,
variant="primary", variant="primary",
id=f"slaunch_repo_{r.manifest['package']}", id=f"slaunch_repo_{r.manifest['package']}",
@@ -234,6 +210,7 @@ class DashboardScreen(Screen):
def on_button_pressed(self, event: Button.Pressed) -> None: def on_button_pressed(self, event: Button.Pressed) -> None:
"""处理按钮点击事件""" """处理按钮点击事件"""
logger.debug(f"event.button.id: {event.button.id}")
if event.button.id.startswith("slaunch_repo_"): # type: ignore if event.button.id.startswith("slaunch_repo_"): # type: ignore
from .preparation import launch from .preparation import launch
+54 -57
View File
@@ -1,4 +1,4 @@
"""Favorites manager screen""" """收藏夹管理器界面"""
import base64 import base64
from pathlib import Path from pathlib import Path
@@ -7,7 +7,7 @@ from typing import List, Optional
from textual import events, on from textual import events, on
from textual.app import ComposeResult from textual.app import ComposeResult
from textual.containers import ScrollableContainer, Horizontal from textual.containers import ScrollableContainer
from textual.screen import Screen from textual.screen import Screen
from textual.widgets import ( from textual.widgets import (
Button, Button,
@@ -16,12 +16,12 @@ from textual.widgets import (
Label, Label,
ListItem, ListItem,
ListView, ListView,
Markdown,
Static, Static,
) )
from textual import events, on from textual import events, on
from heurams.context import config_var from heurams.context import config_var
from heurams.i18n import _
from heurams.kernel.repolib import Repo from heurams.kernel.repolib import Repo
from heurams.services.favorite_service import FavoriteItem, favorite_manager from heurams.services.favorite_service import FavoriteItem, favorite_manager
from heurams.services.logger import get_logger from heurams.services.logger import get_logger
@@ -30,12 +30,12 @@ logger = get_logger(__name__)
class FavoriteManagerScreen(Screen): class FavoriteManagerScreen(Screen):
"""Favorites manager screen""" """收藏夹管理器屏幕"""
SUB_TITLE = _("Favorites") SUB_TITLE = "收藏夹"
BINDINGS = [ BINDINGS = [
("q", "go_back", _("Back")), ("q", "go_back", "返回"),
("d", "toggle_dark", ""), ("d", "toggle_dark", ""),
] ]
@@ -50,12 +50,12 @@ class FavoriteManagerScreen(Screen):
self._load_favorites() self._load_favorites()
def _load_favorites(self) -> None: def _load_favorites(self) -> None:
"""Load favorites list""" """加载收藏列表"""
self.favorites = favorite_manager.get_all() self.favorites = favorite_manager.get_all()
logger.info("Loaded %d favorites", len(self.favorites)) logger.debug("加载 %d 个收藏项", len(self.favorites))
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
"""Compose UI components""" """组合界面组件"""
if config_var.get()["interface"]["global"]["show_header"]: if config_var.get()["interface"]["global"]["show_header"]:
yield Header( yield Header(
@@ -63,10 +63,10 @@ class FavoriteManagerScreen(Screen):
) )
with ScrollableContainer(id="favorites-container"): with ScrollableContainer(id="favorites-container"):
if not self.favorites: if not self.favorites:
yield Label(_("No favorites"), classes="empty-label") yield Label("暂无收藏", classes="empty-label")
yield Static(_("Press * in the memorization screen to add favorites.")) yield Static("使用 * 键在记忆界面中添加收藏.")
else: else:
yield Label(_("Total {n} favorite(s)").format(n=len(self.favorites)), classes="count-label") yield Label(f"{len(self.favorites)} 个收藏项", classes="count-label")
yield ListView(id="favorites-list") yield ListView(id="favorites-list")
yield Footer() yield Footer()
@@ -84,66 +84,63 @@ class FavoriteManagerScreen(Screen):
list_view.append(self._create_favorite_item(fav)) # type: ignore list_view.append(self._create_favorite_item(fav)) # type: ignore
def _encode_favorite_key(self, repo_path: str, ident: str) -> str: def _encode_favorite_key(self, repo_path: str, ident: str) -> str:
"""Encode repo path and identifier into a safe button ID part""" """编码仓库路径和标识符为安全的按钮 ID 部分"""
# Use \x00 as separator between the two parts, then base64 encode # 使用 \x00 分隔两部分,然后进行 base64 编码
combined = f"{repo_path}\x00{ident}" combined = f"{repo_path}\x00{ident}"
encoded = base64.urlsafe_b64encode(combined.encode()).decode() encoded = base64.urlsafe_b64encode(combined.encode()).decode()
# Strip padding # 去掉填充的等号
return encoded.rstrip("=") return encoded.rstrip("=")
def _decode_favorite_key(self, key: str) -> tuple[str, str]: def _decode_favorite_key(self, key: str) -> tuple[str, str]:
"""Decode button ID part back to repo path and identifier""" """解码按钮 ID 部分为仓库路径和标识符"""
# Pad to make length multiple of 4 # 补全等号以使长度是4的倍数
padded = key + "=" * ((4 - len(key) % 4) % 4) padded = key + "=" * ((4 - len(key) % 4) % 4)
decoded = base64.urlsafe_b64decode(padded.encode()).decode() decoded = base64.urlsafe_b64decode(padded.encode()).decode()
repo_path, ident = decoded.split("\x00", 1) repo_path, ident = decoded.split("\x00", 1)
return repo_path, ident return repo_path, ident
def _create_favorite_item(self, fav: FavoriteItem) -> ListItem: def _create_favorite_item(self, fav: FavoriteItem) -> ListItem:
"""Create a favorite list item""" """创建收藏项列表项"""
# Try to get repo info # 尝试获取仓库信息
repo_info = self._get_repo_info(fav.repo_path, fav) repo_info = self._get_repo_info(fav.repo_path, fav)
title = repo_info.get("title", fav.repo_path) if repo_info else fav.repo_path title = repo_info.get("title", fav.repo_path) if repo_info else fav.repo_path
content_preview = repo_info.get("content_preview", "") if repo_info else ""
added_time = self._format_time(fav.added) added_time = self._format_time(fav.added)
# Build display text # 构建显示文本
display_text = f"{fav.ident}\n" display_text = f"[b]{title}[/b] ({fav.ident})\n"
display_text += _(" [d]Added: {time}\n From {title}[/d]").format(time=added_time, title=title) if content_preview:
display_text += f"{content_preview}\n"
display_text += f"添加于: {added_time}"
if fav.tags: if fav.tags:
display_text += f"{', '.join(fav.tags)}" display_text += f" 标签: {', '.join(fav.tags)}"
# Create safe button ID # 创建安全的按钮 ID
button_key = self._encode_favorite_key(fav.repo_path, fav.ident) button_key = self._encode_favorite_key(fav.repo_path, fav.ident)
# Create list item with remove button # 创建列表项,包含移除按钮
container = Horizontal( container = ScrollableContainer(
Label(display_text, classes="favorite-content"), Markdown(display_text, classes="favorite-content"),
Button( Button("移除", id=f"remove-{button_key}", variant="error"),
_("Remove"),
id=f"remove-{button_key}",
variant="error",
flat=True,
classes="favorite-item-btn",
),
classes="favorite-item", classes="favorite-item",
) )
return ListItem(container) return ListItem(container)
def _get_repo_info(self, repo_path: str, fav: FavoriteItem) -> Optional[dict]: def _get_repo_info(self, repo_path: str, fav: FavoriteItem) -> Optional[dict]:
"""Get repo info (title, atom content preview)""" """获取仓库信息(标题、原子内容预览)"""
try: try:
data_repo = Path(config_var.get()["global"]["paths"]["data"]) / "repo" data_repo = Path(config_var.get()["global"]["paths"]["data"]) / "repo"
repo_dir = data_repo / repo_path repo_dir = data_repo / repo_path
if not repo_dir.exists(): if not repo_dir.exists():
logger.warning("Repo directory does not exist: %s", repo_dir) logger.warning("仓库目录不存在: %s", repo_dir)
return None return None
repo = Repo.from_repodir(repo_dir) repo = Repo.from_repodir(repo_dir)
# Get atom content preview # 获取原子内容预览
content_preview = "" content_preview = ""
payload = repo.payload payload = repo.payload
# Find the payload entry matching ident # 查找对应 ident 的 payload 条目
for ident_key, content in payload: for ident_key, content in payload:
if ident_key == fav.ident: if ident_key == fav.ident:
# Truncate long content # 截断过长的内容
if isinstance(content, dict) and "content" in content: if isinstance(content, dict) and "content" in content:
text = content["content"] text = content["content"]
else: else:
@@ -158,53 +155,53 @@ class FavoriteManagerScreen(Screen):
"content_preview": content_preview, "content_preview": content_preview,
} }
except Exception as e: except Exception as e:
logger.error("Failed to get repo info: %s", e) logger.error("获取仓库信息失败: %s", e)
return None return None
def _format_time(self, timestamp: int) -> str: def _format_time(self, timestamp: int) -> str:
"""Format timestamp as datetime string""" """格式化时间戳"""
from datetime import datetime from datetime import datetime
dt = datetime.fromtimestamp(timestamp) dt = datetime.fromtimestamp(timestamp)
return dt.strftime("%Y-%m-%d %H:%M") return dt.strftime("%Y-%m-%d %H:%M")
def on_button_pressed(self, event: Button.Pressed) -> None: def on_button_pressed(self, event: Button.Pressed) -> None:
"""Handle button press event""" """处理按钮点击事件"""
button_id = event.button.id button_id = event.button.id
if button_id and button_id.startswith("remove-"): if button_id and button_id.startswith("remove-"):
# Extract encoded key # 提取编码后的键
key = button_id[7:] # Remove "remove-" prefix key = button_id[7:] # 去掉 "remove-" 前缀
try: try:
repo_path, ident = self._decode_favorite_key(key) repo_path, ident = self._decode_favorite_key(key)
self._remove_favorite(repo_path, ident) self._remove_favorite(repo_path, ident)
except Exception as e: except Exception as e:
logger.error("Failed to parse button ID: %s", e) logger.error("解析按钮 ID 失败: %s", e)
self.app.notify(_("Operation failed: invalid button identifier"), severity="error") self.app.notify("操作失败: 无效的按钮标识", severity="error")
def _remove_favorite(self, repo_path: str, ident: str) -> None: def _remove_favorite(self, repo_path: str, ident: str) -> None:
"""Remove a favorite item""" """移除收藏项"""
if favorite_manager.remove(repo_path, ident): if favorite_manager.remove(repo_path, ident):
self.app.notify(_("Removed favorite: {ident}").format(ident=ident), severity="information") self.app.notify(f"已移除收藏: {ident}", severity="information")
# Reload list # 重新加载列表
self._load_favorites() self._load_favorites()
# Refresh UI # 刷新界面
self._refresh_list() self._refresh_list()
else: else:
self.app.notify(_("Failed to remove: {ident}").format(ident=ident), severity="error") self.app.notify(f"移除失败: {ident}", severity="error")
def _refresh_list(self) -> None: def _refresh_list(self) -> None:
"""Refresh the list display""" """刷新列表显示"""
container = self.query_one("#favorites-container") container = self.query_one("#favorites-container")
# Clear container # 清空容器
for child in container.children: for child in container.children:
child.remove() child.remove()
# Re-compose # 重新组合
if not self.favorites: if not self.favorites:
container.mount(Label(_("No favorites"), classes="empty-label")) container.mount(Label("暂无收藏", classes="empty-label"))
container.mount(Static(_("Press * in the memorization screen to add favorites."))) container.mount(Static("使用 * 键在记忆界面中添加收藏。"))
else: else:
container.mount( container.mount(
Label(_("Total {n} favorite(s)").format(n=len(self.favorites)), classes="count-label") Label(f"{len(self.favorites)} 个收藏项", classes="count-label")
) )
list_view = ListView(id="favorites-list") list_view = ListView(id="favorites-list")
container.mount(list_view) container.mount(list_view)
+34 -45
View File
@@ -1,4 +1,4 @@
"""Queue-based memorization screen""" """队列式记忆工作界面"""
from pathlib import Path from pathlib import Path
@@ -12,11 +12,9 @@ from textual import events, on
import heurams.kernel.particles as pt import heurams.kernel.particles as pt
from heurams.context import config_var, rootdir from heurams.context import config_var, rootdir
from heurams.i18n import _
from heurams.kernel.reactor import * from heurams.kernel.reactor import *
from heurams.services.favorite_service import favorite_manager from heurams.services.favorite_service import favorite_manager
from heurams.services.logger import get_logger from heurams.services.logger import get_logger
from heurams.services.attic import Attic
from .. import shim from .. import shim
@@ -25,24 +23,23 @@ logger = get_logger(__name__)
class MemScreen(Screen): class MemScreen(Screen):
BINDINGS = [ BINDINGS = [
("q", "go_back_notif", _("Back")), ("q", "go_back", "返回"),
("p", "prev", _("Previous")), ("p", "prev", "查看上一个"),
("d", "toggle_dark", ""), ("d", "toggle_dark", ""),
("v", "play_voice", _("Read Aloud")), ("v", "play_voice", "朗读"),
("*", "toggle_favorite", _("Favorite")), ("*", "toggle_favorite", "收藏"),
("r", "resume_mark"), ("r", "resume_mark"),
("Q", "go_back"),
("n", "block_prompt"), ("n", "block_prompt"),
("s", "block_prompt"), ("s", "block_prompt"),
("z", "block_prompt"), ("z", "block_prompt"),
] ]
SUB_TITLE = _("Learning") SUB_TITLE = "学习中"
CSS_PATH = rootdir / "interface" / "css" / "screens" / "memoqueue.tcss" CSS_PATH = rootdir / "interface" / "css" / "screens" / "memoqueue.tcss"
if config_var.get()["interface"]["global"]["quick_pass"]: if config_var.get()["interface"]["global"]["quick_pass"]:
BINDINGS.append(("k", "quick_pass", _("Correct"))) BINDINGS.append(("k", "quick_pass", "正确应答"))
BINDINGS.append(("f", "quick_fail", _("Incorrect"))) BINDINGS.append(("f", "quick_fail", "错误应答"))
rating = reactive(-1) rating = reactive(-1)
@@ -75,13 +72,13 @@ class MemScreen(Screen):
yield Header( yield Header(
show_clock=config_var.get()["interface"]["global"]["clock_on_header"] show_clock=config_var.get()["interface"]["global"]["clock_on_header"]
) )
with ScrollableContainer(classes="memoqueue-container"): with ScrollableContainer():
yield Label(self._get_progress_text(), id="head_stat") yield Label(self._get_progress_text(), id="head_stat")
yield ScrollableContainer(id="puzzle_container") yield ScrollableContainer(id="puzzle_container")
yield Footer() yield Footer()
def update_state(self): def update_state(self):
"""Update state machine""" """更新状态机"""
self.procession: Procession = self.router.current_procession() # type: ignore self.procession: Procession = self.router.current_procession() # type: ignore
self.atom: pt.Atom = self.procession.current_atom # type: ignore self.atom: pt.Atom = self.procession.current_atom # type: ignore
@@ -102,17 +99,16 @@ class MemScreen(Screen):
atom=self.atom, alia=puzzle["alia"] # type: ignore atom=self.atom, alia=puzzle["alia"] # type: ignore
) )
except Exception as e: except Exception as e:
logger.error(f"Failed to expand puzzle: {e}") logger.debug(f"调度展开出错: {e}")
return Static(_("Failed to generate puzzle: {e}").format(e=e)) return Static(f"无法生成谜题 {e}")
def _get_progress_text(self): def _get_progress_text(self):
s = "" s = f"阶段: {self.procession.route.name}\n"
# 收藏状态
if self.repo is not None: if self.repo is not None:
fav_status = _("Favorited") if self._is_current_atom_favorited() else _("Not favorited") fav_status = "已收藏" if self._is_current_atom_favorited() else "未收藏"
s += f"[{fav_status}] " s += f"收藏: {fav_status}\n"
s += f"[{self.procession.process() + 1}/{self.procession.total_length()}] \\[{self.procession.route.name}]\n" s += f"进度: {self.procession.process() + 1}/{self.procession.total_length()}"
if self.procession.cursor - 1 >= 0:
s += _("Previous: {ident}").format(ident=f"[d]{self.procession.atoms[self.procession.cursor - 1]['ident']}[/d]")
return s return s
def update_display(self): def update_display(self):
@@ -121,7 +117,7 @@ class MemScreen(Screen):
progress_widget.update(self._get_progress_text()) # type: ignore progress_widget.update(self._get_progress_text()) # type: ignore
def mount_puzzle(self): def mount_puzzle(self):
"""Mount current puzzle widget""" """挂载当前谜题组件"""
if self.procession.route == RouterState.FINISHED: if self.procession.route == RouterState.FINISHED:
self.mount_finished_widget() self.mount_finished_widget()
return return
@@ -131,7 +127,7 @@ class MemScreen(Screen):
container.mount(self.puzzle_widget()) container.mount(self.puzzle_widget())
def mount_finished_widget(self): def mount_finished_widget(self):
"""Mount finished widget""" """挂载已完成组件"""
a = Attic("ana", {"finished": 0}) a = Attic("ana", {"finished": 0})
a.data["finished"] += 1 a.data["finished"] += 1
container = self.query_one("#puzzle_container") container = self.query_one("#puzzle_container")
@@ -140,12 +136,8 @@ class MemScreen(Screen):
from heurams.interface.widgets.finished import Finished from heurams.interface.widgets.finished import Finished
if config_var.get()["interface"]["global"]["persist_to_file"]: if config_var.get()["interface"]["global"]["persist_to_file"]:
self.repo.persist_to_repodir() self.save_func()
container.mount( container.mount(Finished(is_saved=["interface"]["global"]["persist_to_file"]))
Finished(
is_saved=config_var.get()["interface"]["global"]["persist_to_file"]
)
)
def on_button_pressed(self, event): def on_button_pressed(self, event):
event.stop() event.stop()
@@ -154,7 +146,7 @@ class MemScreen(Screen):
self.run_worker(self.play_voice, exclusive=True, thread=True) self.run_worker(self.play_voice, exclusive=True, thread=True)
def play_voice(self): def play_voice(self):
"""Read current content aloud""" """朗读当前内容"""
from pathlib import Path from pathlib import Path
from heurams.services.audio_service import play_by_path from heurams.services.audio_service import play_by_path
@@ -205,7 +197,7 @@ class MemScreen(Screen):
if not self.atom.registry["runtime"]["locked"]: if not self.atom.registry["runtime"]["locked"]:
if not self.atom.registry["electron"].is_activated(): if not self.atom.registry["electron"].is_activated():
self.atom.registry["electron"].activate() self.atom.registry["electron"].activate()
logger.debug(f"Activated atom: {self.atom}") logger.debug(f"激活原子 {self.atom}")
self.atom.lock(1) self.atom.lock(1)
self.atom.minimize(5) self.atom.minimize(5)
else: else:
@@ -227,9 +219,6 @@ class MemScreen(Screen):
self.update_state() # 刷新状态 self.update_state() # 刷新状态
self.expander = self.procession.get_expander() self.expander = self.procession.get_expander()
def action_go_back_notif(self):
self.notify(_("Are you sure? Press uppercase Q to go back."))
def action_go_back(self): def action_go_back(self):
self.app.pop_screen() self.app.pop_screen()
@@ -240,44 +229,44 @@ class MemScreen(Screen):
self.rating = 3 self.rating = 3
def _get_repo_rel_path(self) -> str: def _get_repo_rel_path(self) -> str:
"""Get repo relative path (relative to data/repo)""" """获取仓库相对路径(相对于 data/repo"""
if self.repo is None: if self.repo is None:
return "" return ""
# self.repo.source is the Path object pointing to the repo directory # self.repo.source 是 Path 对象,指向仓库目录
repo_full_path = self.repo.source repo_full_path = self.repo.source
data_repo_path = Path(config_var.get()["global"]["paths"]["data"]) / "repo" data_repo_path = Path(config_var.get()["global"]["paths"]["data"]) / "repo"
try: try:
rel_path = repo_full_path.relative_to(data_repo_path) rel_path = repo_full_path.relative_to(data_repo_path)
return str(rel_path) return str(rel_path)
except ValueError: except ValueError:
# If not under data/repo, return the full path as string # 如果不在 data/repo 下,则返回完整路径(字符串形式)
return str(repo_full_path) return str(repo_full_path)
def _is_current_atom_favorited(self) -> bool: def _is_current_atom_favorited(self) -> bool:
"""Check if current atom is favorited""" """检查当前原子是否已收藏"""
if self.repo is None: if self.repo is None:
return False return False
repo_path = self._get_repo_rel_path() repo_path = self._get_repo_rel_path()
return favorite_manager.has(repo_path, self.atom.ident) return favorite_manager.has(repo_path, self.atom.ident)
def action_toggle_favorite(self): def action_toggle_favorite(self):
"""Toggle favorite status""" """切换收藏状态"""
if self.repo is None: if self.repo is None:
self.app.notify(_("Cannot favorite: no repo associated"), severity="error") self.app.notify("无法收藏:未关联仓库", severity="error")
return return
repo_path = self._get_repo_rel_path() repo_path = self._get_repo_rel_path()
ident = self.atom.ident ident = self.atom.ident
if favorite_manager.has(repo_path, ident): if favorite_manager.has(repo_path, ident):
favorite_manager.remove(repo_path, ident) favorite_manager.remove(repo_path, ident)
self.app.notify(_("Unfavorited: {ident}").format(ident=ident), severity="information") self.app.notify(f"已取消收藏:{ident}", severity="information")
else: else:
favorite_manager.add(repo_path, ident) favorite_manager.add(repo_path, ident)
self.app.notify(_("Favorited: {ident}").format(ident=ident), severity="information") self.app.notify(f"已收藏:{ident}", severity="information")
# Update display if needed # 更新显示(如果需要)
self.update_display() self.update_display()
def action_block_prompt(self): def action_block_prompt(self):
self.app.notify(_("This function is not available during memorization. Please finish or go back first."), severity="error") self.app.notify("功能在记忆界面中不可用, 完成或返回后再试", severity="error")
def action_resume_mark(self): def action_resume_mark(self):
from heurams.services.attic import Attic from heurams.services.attic import Attic
@@ -286,4 +275,4 @@ class MemScreen(Screen):
a = Attic("ana") a = Attic("ana")
l = a.data["last"] l = a.data["last"]
a.data["last"] = time.time() a.data["last"] = time.time()
self.app.notify(_("Time resume corrected: {old} -> {new}").format(old=l, new=a.data['last'])) self.app.notify(f"时间恢复已修正: {l} -> {a.data['last']}")
+19 -17
View File
@@ -4,7 +4,6 @@ from textual.screen import ModalScreen
from textual.widgets import Button, Label, ListItem, ListView, Static from textual.widgets import Button, Label, ListItem, ListView, Static
from heurams.i18n import _
from heurams.services.logger import get_logger from heurams.services.logger import get_logger
from .favmgr import FavoriteManagerScreen from .favmgr import FavoriteManagerScreen
@@ -13,33 +12,36 @@ logger = get_logger(__name__)
class NavigatorScreen(ModalScreen): class NavigatorScreen(ModalScreen):
"""Navigator modal screen""" """导航器模态窗口"""
BINDINGS = [ BINDINGS = [
("q", "go_back", _("Back")), ("q", "go_back", "返回"),
("escape", "go_back", _("Back")), ("escape", "go_back", "返回"),
("n", "go_back", _("Switch")), ("n", "go_back", "切换"),
] ]
SCREENS = [ SCREENS = [
(_("Dashboard"), "dashboard"), ("仪表盘", "dashboard"),
(_("Cache Manager"), "precache_all"), # ("创建仓库", "repo_creator"),
(_("Favorites"), FavoriteManagerScreen), ("缓存管理器", "precache_all"),
(_("Settings Page"), "setting"), ("收藏夹", FavoriteManagerScreen),
(_("Sync Tool"), "synctool"), ("设置页面", "setting"),
(_("About"), "about"), # ("调试日志", "logviewer"),
("同步工具", "synctool"),
("关于此软件", "about"),
# ("仓库编辑器", "repo_editor"),
] ]
OTHERS = [ OTHERS = [
(_("Exit"), "self.app.exit()"), ("退出程序", "self.app.exit()"),
(_("Project Homepage"), "webbrowser.open('https://ams.pluv27.top')"), ("项目主页", "webbrowser.open('https://ams.imwangzhiyu.xyz')"),
] ]
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
"""Compose UI components""" """组合界面组件"""
with Grid(id="dialog"): with Grid(id="dialog"):
yield Label( yield Label(
_("[b]Select a function to navigate to\nor a memorization session instance[/b]\n\nTips will be displayed here"), "[b]请选择要跳转的功能\n或记忆会话实例[/b]\n\n将在此处显示提示",
classes="title-label", classes="title-label",
) )
yield ListView( yield ListView(
@@ -47,9 +49,9 @@ class NavigatorScreen(ModalScreen):
id="nav-list", id="nav-list",
classes="nav-list-view", classes="nav-list-view",
) )
yield Static(_("Press Enter to switch\nAll sessions will be saved")) yield Static("按下回车以完成切换\n所有会话将被保存")
yield Button( yield Button(
_("Close (n)"), "关闭 (n)",
id="close_button", id="close_button",
variant="primary", variant="primary",
classes="close-button", classes="close-button",
+58 -66
View File
@@ -1,4 +1,4 @@
"""Cache tool screen""" """缓存工具界面"""
import pathlib import pathlib
@@ -13,15 +13,14 @@ from textual import events, on
import heurams.kernel.particles as pt import heurams.kernel.particles as pt
import heurams.services.hasher as hasher import heurams.services.hasher as hasher
from heurams.context import * from heurams.context import *
from heurams.i18n import _
# Compatibility cache path: prefer paths.cache, otherwise data/cache # 兼容性缓存路径:优先使用 paths.cache,否则使用 data/cache
paths = config_var.get()["global"]["paths"] paths = config_var.get()["global"]["paths"]
cache_dir = pathlib.Path(paths.get("cache", paths["data"] + "/cache")) / "voice" cache_dir = pathlib.Path(paths.get("cache", paths["data"] + "/cache")) / "voice"
def human_size(bytes_num: int) -> str: def human_size(bytes_num: int) -> str:
"""Format byte count as human-readable string""" """将字节数格式化为人类可读的字符串"""
for unit in ["B", "KB", "MB", "GB", "TB"]: for unit in ["B", "KB", "MB", "GB", "TB"]:
if bytes_num < 1024.0: if bytes_num < 1024.0:
return f"{bytes_num:.2f} {unit}" return f"{bytes_num:.2f} {unit}"
@@ -30,18 +29,18 @@ def human_size(bytes_num: int) -> str:
class PrecachingScreen(Screen): class PrecachingScreen(Screen):
"""Audio file pre-caching screen """预缓存音频文件屏幕
Cache memory unit audio files, all (default) or some memory units (optional params) 缓存记忆单元音频文件, 全部(默认) 或部分记忆单元(可选参数传入)
Args: Args:
nucleons (list): Optional list containing Nucleon objects only nucleons (list): 可选列表, 仅包含 Nucleon 对象
desc (list): Optional string containing description of this call desc (list): 可选字符串, 包含对此次调用的文字描述
""" """
SUB_TITLE = _("Cache Manager") SUB_TITLE = "缓存管理器"
BINDINGS = [ BINDINGS = [
("q", "go_back", _("Back")), ("q", "go_back", "返回"),
] ]
def __init__(self, nucleons: list = [], desc: str = ""): def __init__(self, nucleons: list = [], desc: str = ""):
@@ -56,7 +55,7 @@ class PrecachingScreen(Screen):
self.precache_worker = None self.precache_worker = None
self.cancel_flag = 0 self.cancel_flag = 0
self.desc = desc self.desc = desc
# 不再需要缓存配置, 保留配置读取以兼容 # 不再需要缓存配置保留配置读取以兼容
self.cache_stats = { self.cache_stats = {
"total_size": 0, "total_size": 0,
"file_count": 0, "file_count": 0,
@@ -68,7 +67,7 @@ class PrecachingScreen(Screen):
self._update_cache_stats() self._update_cache_stats()
def _get_total_units(self) -> int: def _get_total_units(self) -> int:
"""Get total units across all repos""" """获取所有仓库的总单元数"""
from heurams.context import config_var from heurams.context import config_var
from heurams.kernel.repolib import Repo from heurams.kernel.repolib import Repo
@@ -90,7 +89,7 @@ class PrecachingScreen(Screen):
shim.set_term_title(f"{self.app.TITLE} - {self.SUB_TITLE}") shim.set_term_title(f"{self.app.TITLE} - {self.SUB_TITLE}")
def _update_cache_stats(self) -> None: def _update_cache_stats(self) -> None:
"""Update cache statistics""" """更新缓存统计信息"""
total_size = 0 total_size = 0
file_count = 0 file_count = 0
cached_units = 0 cached_units = 0
@@ -118,25 +117,21 @@ class PrecachingScreen(Screen):
show_clock=config_var.get()["interface"]["global"]["clock_on_header"] show_clock=config_var.get()["interface"]["global"]["clock_on_header"]
) )
with ScrollableContainer(id="precache_container"): with ScrollableContainer(id="precache_container"):
yield Label(_("[b]Audio Pre-cache[/b]"), classes="title-label") yield Label("[b]音频预缓存[/b]", classes="title-label")
with Container(): with Container():
yield Static( yield Static(
_("Cache rate: {rate:.1f}% ({cached} / {total} units)").format( f"缓存率: {self.cache_stats.get('cache_rate', 0):.1f}% (已缓存 {self.cache_stats.get('cached_units', 0)} / {self.cache_stats.get('total_units', 0)} 个单元)",
rate=self.cache_stats.get('cache_rate', 0),
cached=self.cache_stats.get('cached_units', 0),
total=self.cache_stats.get('total_units', 0),
),
classes="cache-usage-text", classes="cache-usage-text",
) )
if self.nucleons: if self.nucleons:
yield Static( yield Static(
_("Target units from: [b]{desc}[/b]").format(desc=self.desc), classes="target-info" f"目标单元归属: [b]{self.desc}[/b]", classes="target-info"
) )
yield Static( yield Static(
_("Unit count: {n}").format(n=len(self.nucleons)), classes="target-info" f"单元数量: {len(self.nucleons)}", classes="target-info"
) )
else: else:
yield Static(_("Target: all units"), classes="target-info") yield Static("目标: 所有单元", classes="target-info")
yield Static(id="status", classes="status-info") yield Static(id="status", classes="status-info")
yield Static(id="current_item", classes="current-item") yield Static(id="current_item", classes="current-item")
@@ -144,72 +139,69 @@ class PrecachingScreen(Screen):
with Horizontal(classes="button-group"): with Horizontal(classes="button-group"):
if not self.is_precaching: if not self.is_precaching:
yield Button( yield Button(
_("Start Pre-cache"), id="start_precache", variant="primary" "开始预缓存", id="start_precache", variant="primary"
) )
else: else:
yield Button( yield Button(
_("Cancel Pre-cache"), id="cancel_precache", variant="error" "取消预缓存", id="cancel_precache", variant="error"
) )
yield Button(_("Clear Cache"), id="clear_cache", variant="warning") yield Button("清空缓存", id="clear_cache", variant="warning")
yield Button(_("Back"), id="go_back", variant="default") yield Button("返回", id="go_back", variant="default")
with Container(classes="cache-info"): with Container(classes="cache-info"):
yield Static(_("Cache path: {path}").format(path=cache_dir), classes="cache-path") yield Static(f"缓存路径: {cache_dir}", classes="cache-path")
yield Static( yield Static(
_("Files: {n}").format(n=self.cache_stats['file_count']), classes="cache-count" f"文件数: {self.cache_stats['file_count']}", classes="cache-count"
) )
yield Static( yield Static(
_("Total size: {size}").format(size=self.cache_stats['human_size']), classes="cache-size" f"总大小: {self.cache_stats['human_size']}", classes="cache-size"
) )
yield Button( yield Button(
_("Refresh"), id="refresh_cache_stats", variant="default", flat=True "刷新", id="refresh_cache_stats", variant="default", flat=True
) )
yield Static(_("If you leave this screen, ongoing cache processes will stop automatically.")) yield Static("若您离开此界面, 未完成的缓存进程会自动停止.")
yield Static(_('Cache supports "resume from break".')) yield Static('缓存程序支持 "断点续传".')
yield Footer() yield Footer()
def on_mount(self): def on_mount(self):
"""Initialise state on mount""" """挂载时初始化状态"""
self.update_status(_("Ready"), _("Waiting to start...")) self.update_status("就绪", "等待开始...")
self._update_cache_display() self._update_cache_display()
def update_status(self, status, current_item="", progress=None): def update_status(self, status, current_item="", progress=None):
"""Update status display""" """更新状态显示"""
status_widget = self.query_one("#status", Static) status_widget = self.query_one("#status", Static)
item_widget = self.query_one("#current_item", Static) item_widget = self.query_one("#current_item", Static)
progress_bar = self.query_one("#progress_bar", ProgressBar) progress_bar = self.query_one("#progress_bar", ProgressBar)
status_widget.update(_("Status: {s}").format(s=status)) status_widget.update(f"状态: {status}")
item_widget.update(_("Current item: {item}").format(item=current_item) if current_item else "") item_widget.update(f"当前项目: {current_item}" if current_item else "")
if progress is not None: if progress is not None:
progress_bar.progress = progress progress_bar.progress = progress
progress_bar.advance(0) # Refresh display progress_bar.advance(0) # 刷新显示
def _update_cache_display(self) -> None: def _update_cache_display(self) -> None:
"""Update cache info display""" """更新缓存信息显示"""
# Update stats # 更新统计信息
self._update_cache_stats() self._update_cache_stats()
# Update cache rate progress bar # 更新缓存率进度条
# Update cache size and file count display # 更新缓存大小和文件数显示
cache_count_widget = self.query_one(".cache-count", Static) cache_count_widget = self.query_one(".cache-count", Static)
cache_size_widget = self.query_one(".cache-size", Static) cache_size_widget = self.query_one(".cache-size", Static)
cache_usage_text = self.query_one(".cache-usage-text", Static) cache_usage_text = self.query_one(".cache-usage-text", Static)
if cache_count_widget: if cache_count_widget:
cache_count_widget.update(_("Files: {n}").format(n=self.cache_stats['file_count'])) cache_count_widget.update(f"文件数: {self.cache_stats['file_count']}")
if cache_size_widget: if cache_size_widget:
cache_size_widget.update(_("Total size: {size}").format(size=self.cache_stats['human_size'])) cache_size_widget.update(f"总大小: {self.cache_stats['human_size']}")
if cache_usage_text: if cache_usage_text:
cache_usage_text.update( cache_usage_text.update(
_("Cache rate: {rate:.1f}% ({cached} / {total} units)").format( f"缓存率: {self.cache_stats.get('cache_rate', 0):.1f}% "
rate=self.cache_stats.get('cache_rate', 0), f"(已缓存 {self.cache_stats.get('cached_units', 0)} / {self.cache_stats.get('total_units', 0)} 个单元)"
cached=self.cache_stats.get('cached_units', 0),
total=self.cache_stats.get('total_units', 0),
)
) )
def precache_by_text(self, text: str): def precache_by_text(self, text: str):
"""Pre-cache audio for a single text string""" """预缓存单段文本的音频"""
cache_dir.mkdir(parents=True, exist_ok=True) cache_dir.mkdir(parents=True, exist_ok=True)
cache_file = cache_dir / f"{hasher.get_md5(text)}.wav" cache_file = cache_dir / f"{hasher.get_md5(text)}.wav"
@@ -220,21 +212,21 @@ class PrecachingScreen(Screen):
convertor(text, cache_file) convertor(text, cache_file)
return 1 return 1
except Exception as e: except Exception as e:
print(f"Pre-cache failed '{text}': {e}") print(f"预缓存失败 '{text}': {e}")
return 0 return 0
return 1 return 1
def precache_by_nucleon(self, nucleon: pt.Nucleon): def precache_by_nucleon(self, nucleon: pt.Nucleon):
"""Cache based on Nucleon""" """依据 Nucleon 缓存"""
ret = self.precache_by_text(nucleon["tts_text"]) ret = self.precache_by_text(nucleon["tts_text"])
return ret return ret
def precache_by_list(self, nucleons: list): def precache_by_list(self, nucleons: list):
"""Cache based on Nucleons list""" """依据 Nucleons 列表缓存"""
for idx, nucleon in enumerate(nucleons): for idx, nucleon in enumerate(nucleons):
# print(f"PROC: {nucleon}") # print(f"PROC: {nucleon}")
worker = get_current_worker() worker = get_current_worker()
if worker and worker.is_cancelled: # Function running in worker and has been cancelled if worker and worker.is_cancelled: # 函数在worker中执行且已被取消
return False return False
text = nucleon["tts_text"] text = nucleon["tts_text"]
# self.current_item = text[:30] + "..." if len(text) > 50 else text # self.current_item = text[:30] + "..." if len(text) > 50 else text
@@ -244,12 +236,12 @@ class PrecachingScreen(Screen):
# print(self.total) # print(self.total)
progress = int((self.processed / self.total) * 100) if self.total > 0 else 0 progress = int((self.processed / self.total) * 100) if self.total > 0 else 0
# print(progress) # print(progress)
self.update_status(_("Processing ({i}/{total})").format(i=idx + 1, total=len(nucleons)), text, progress) self.update_status(f"正处理 ({idx + 1}/{len(nucleons)})", text, progress)
ret = self.precache_by_nucleon(nucleon) ret = self.precache_by_nucleon(nucleon)
if not ret: if not ret:
self.update_status( self.update_status(
_("Error"), "出错",
_("Failed, skipping: {item}").format(item=self.current_item), f"处理失败, 跳过: {self.current_item}",
) )
import time import time
@@ -294,7 +286,7 @@ class PrecachingScreen(Screen):
def on_button_pressed(self, event: Button.Pressed) -> None: def on_button_pressed(self, event: Button.Pressed) -> None:
event.stop() event.stop()
if event.button.id == "start_precache" and not self.is_precaching: if event.button.id == "start_precache" and not self.is_precaching:
# Start pre-cache # 开始预缓存
if self.nucleons: if self.nucleons:
self.precache_worker = self.run_worker( self.precache_worker = self.run_worker(
self.precache_by_nucleons, self.precache_by_nucleons,
@@ -311,32 +303,32 @@ class PrecachingScreen(Screen):
) )
elif event.button.id == "cancel_precache" and self.is_precaching: elif event.button.id == "cancel_precache" and self.is_precaching:
# Cancel pre-cache # 取消预缓存
if self.precache_worker: if self.precache_worker:
self.precache_worker.cancel() self.precache_worker.cancel()
self.is_precaching = False self.is_precaching = False
self.processed = 0 self.processed = 0
self.progress = 0 self.progress = 0
self.update_status(_("Cancelled"), _("Pre-cache cancelled by user"), 0) self.update_status("已取消", "预缓存操作被用户取消", 0)
elif event.button.id == "clear_cache": elif event.button.id == "clear_cache":
# Clear cache # 清空缓存
try: try:
import shutil import shutil
shutil.rmtree(cache_dir, ignore_errors=True) shutil.rmtree(cache_dir, ignore_errors=True)
self.update_status(_("Cleared"), _("Audio cache cleared"), 0) self.update_status("已清空", "音频缓存已清空", 0)
self._update_cache_display() # Update cache stats display self._update_cache_display() # 更新缓存统计显示
except Exception as e: except Exception as e:
self.update_status(_("Error"), _("Failed to clear cache: {error}").format(error=e)) self.update_status("错误", f"清空缓存失败: {e}")
self.cancel_flag = 1 self.cancel_flag = 1
self.processed = 0 self.processed = 0
self.progress = 0 self.progress = 0
elif event.button.id == "refresh_cache_stats": elif event.button.id == "refresh_cache_stats":
# Refresh cache stats # 刷新缓存统计信息
self._update_cache_display() self._update_cache_display()
self.app.notify(_("Cache info refreshed"), severity="information") self.app.notify("缓存信息已刷新", severity="information")
elif event.button.id == "go_back": elif event.button.id == "go_back":
self.action_go_back() self.action_go_back()
+20 -23
View File
@@ -1,4 +1,4 @@
"""Memorization preparation screen""" """记忆准备界面"""
from textual.app import ComposeResult from textual.app import ComposeResult
from textual.containers import ScrollableContainer, Horizontal from textual.containers import ScrollableContainer, Horizontal
@@ -19,7 +19,6 @@ from textual import events, on
import heurams.kernel.particles as pt import heurams.kernel.particles as pt
from heurams.context import * from heurams.context import *
from heurams.context import config_var from heurams.context import config_var
from heurams.i18n import _
from heurams.kernel.repolib import * from heurams.kernel.repolib import *
from heurams.kernel.algorithms import algorithms from heurams.kernel.algorithms import algorithms
from heurams.services.logger import get_logger from heurams.services.logger import get_logger
@@ -29,11 +28,11 @@ logger = get_logger(__name__)
class PreparationScreen(Screen): class PreparationScreen(Screen):
SUB_TITLE = _("Prepare Repository") SUB_TITLE = "准备记忆集"
BINDINGS = [ BINDINGS = [
("q", "go_back", _("Back")), ("q", "go_back", "返回"),
("p", "precache", _("Cache")), ("p", "precache", "缓存"),
("d", "toggle_dark", ""), ("d", "toggle_dark", ""),
("0,1,2,3", "app.push_screen('about')", ""), ("0,1,2,3", "app.push_screen('about')", ""),
] ]
@@ -62,40 +61,29 @@ class PreparationScreen(Screen):
) )
with ScrollableContainer(id="main_container"): with ScrollableContainer(id="main_container"):
yield Markdown( yield Markdown(
_("**Ready**: `{title}`\n").format(title=self.repo.manifest['title']), id="title" f"**准备就绪**: `{self.repo.manifest['title']}`\n", id="title"
) )
yield Label(_("Repo path: {path}").format(path=self.repo.source)) yield Label(f"单元集路径: {self.repo.source}")
yield Label( yield Label(
_("Progress: {touched}/{total} [{pct}%]").format( f"学习完成度: {self.repo.progress['touched']}/{len(self.repo)} [d]\\[{round(self.repo.progress['touched']/self.repo.progress['total']*100, 1)}%][/d]"
touched=self.repo.progress['touched'],
total=len(self.repo),
pct=round(self.repo.progress['touched'] / self.repo.progress['total'] * 100, 1)
)
) )
yield Label( yield Label(
_("Scheduling algorithm: {algo} {desc}").format( f"调度算法: {self.repo.config["algorithm"]} {algorithms[self.repo.config["algorithm"]].desc}"
algo=self.repo.config["algorithm"],
desc=algorithms[self.repo.config["algorithm"]].desc
)
) )
yield Label( yield Label(
_("Study count: {total} = {review} [d][Review][/d] + {new} [d][New][/d]\n").format( f"学习数量: {self.repo.preview['review'] + self.scheduled_num} = {self.repo.preview['review']} [d][复习][/d] + {self.scheduled_num} [d][新识记][/d]\n",
total=self.repo.preview['review'] + self.scheduled_num,
review=self.repo.preview['review'],
new=self.scheduled_num,
),
id="schnum_label", id="schnum_label",
) )
yield Horizontal( yield Horizontal(
Button( Button(
_("Start Memorizing"), "开始记忆",
id="start_memorizing_button", id="start_memorizing_button",
variant="primary", variant="primary",
classes="btn", classes="btn",
), ),
Button( Button(
_("Manage Cache"), "管理缓存",
id="precache_button", id="precache_button",
variant="success", variant="success",
classes="btn", classes="btn",
@@ -111,6 +99,14 @@ class PreparationScreen(Screen):
yield Static(i, classes="unit-statline") yield Static(i, classes="unit-statline")
yield Footer() yield Footer()
# def watch_scheduled_num(self, old_scheduled_num, new_scheduled_num):
# logger.debug("响应", old_scheduled_num, "->", new_scheduled_num)
# try:
# one = self.query_one("#schnum_label")
# one.update(f"单次记忆数量: {new_scheduled_num}") # type: ignore
# except:
# pass
def load_data(self): def load_data(self):
self.scheduled_num = self.repo.config["scheduled_num"] self.scheduled_num = self.repo.config["scheduled_num"]
content = "" content = ""
@@ -158,6 +154,7 @@ class PreparationScreen(Screen):
def on_button_pressed(self, event: Button.Pressed) -> None: def on_button_pressed(self, event: Button.Pressed) -> None:
event.stop() event.stop()
logger.debug("按下按钮")
if event.button.id == "start_memorizing_button": if event.button.id == "start_memorizing_button":
launch(repo=self.repo, app=self.app, scheduled_num=self.scheduled_num) launch(repo=self.repo, app=self.app, scheduled_num=self.scheduled_num)
+13 -14
View File
@@ -1,4 +1,4 @@
"""Settings screen""" """设置页面"""
from textual.app import ComposeResult from textual.app import ComposeResult
from textual.containers import ScrollableContainer, Horizontal from textual.containers import ScrollableContainer, Horizontal
@@ -16,7 +16,6 @@ from textual.widgets import (
from textual import events, on from textual import events, on
from heurams.context import * from heurams.context import *
from heurams.i18n import _
from heurams.kernel.particles import * from heurams.kernel.particles import *
from heurams.kernel.repolib import * from heurams.kernel.repolib import *
from heurams.services.logger import get_logger from heurams.services.logger import get_logger
@@ -27,12 +26,12 @@ logger = get_logger(__name__)
class SettingScreen(Screen): class SettingScreen(Screen):
"""Settings screen""" """设置页面屏幕"""
SUB_TITLE = _("Settings") SUB_TITLE = "设置"
BINDINGS = [ BINDINGS = [
("q", "go_back", _("Back")), ("q", "go_back", "返回"),
("s", "go_back", _("Settings")), ("s", "go_back", "设置"),
] ]
CSS_PATH = rootdir / "interface" / "css" / "screens" / "setting.tcss" CSS_PATH = rootdir / "interface" / "css" / "screens" / "setting.tcss"
@@ -51,13 +50,13 @@ class SettingScreen(Screen):
shim.set_term_title(f"{self.app.TITLE} - {self.SUB_TITLE}") shim.set_term_title(f"{self.app.TITLE} - {self.SUB_TITLE}")
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
"""Compose UI components""" """组合界面组件"""
if config_var.get()["interface"]["global"]["show_header"]: if config_var.get()["interface"]["global"]["show_header"]:
yield Header( yield Header(
show_clock=config_var.get()["interface"]["global"]["clock_on_header"] show_clock=config_var.get()["interface"]["global"]["clock_on_header"]
) )
with ScrollableContainer(): with ScrollableContainer():
yield Label("[b]" + _("Settings") + "[/b]") yield Label("[b]设置页面[/b]")
for i in config_var.get(): for i in config_var.get():
if i.startswith("_"): if i.startswith("_"):
continue continue
@@ -68,7 +67,7 @@ class SettingScreen(Screen):
title=i + f'\n[d]{config_var.get().get(f"_{i}_desc", "")}[/d]', title=i + f'\n[d]{config_var.get().get(f"_{i}_desc", "")}[/d]',
) )
yield Label( yield Label(
_("Changes are saved immediately when you leave this page, but restart is recommended to ensure the new configuration is applied."), "退出页面时, 所作的更改会立即保存, 但仍建议重启软件以确保新的配置得到应用",
classes="foot", classes="foot",
) )
yield Footer() yield Footer()
@@ -139,7 +138,7 @@ class SettingScreen(Screen):
Label(i + f'\n[d]{parent.get(f"_{i}_desc", "")}[/d]'), Label(i + f'\n[d]{parent.get(f"_{i}_desc", "")}[/d]'),
Input( Input(
value=str(parent[i]), value=str(parent[i]),
placeholder=_("Requires a float"), placeholder="要求一个浮点数",
type="number", type="number",
id=domize(f"{parent_epath}.{i}"), id=domize(f"{parent_epath}.{i}"),
), ),
@@ -152,7 +151,7 @@ class SettingScreen(Screen):
Label(i + f'\n[d]{parent.get(f"_{i}_desc", "")}[/d]'), Label(i + f'\n[d]{parent.get(f"_{i}_desc", "")}[/d]'),
Input( Input(
value=parent[i], value=parent[i],
placeholder=_("Requires a string"), placeholder="要求一个字符串",
type="text", type="text",
id=domize(f"{parent_epath}.{i}"), id=domize(f"{parent_epath}.{i}"),
), ),
@@ -177,7 +176,7 @@ class SettingScreen(Screen):
Label(i + f'\n[d]{parent.get(f"_{i}_desc", "")}[/d]'), Label(i + f'\n[d]{parent.get(f"_{i}_desc", "")}[/d]'),
Input( Input(
value=str(parent[i]), value=str(parent[i]),
placeholder=_("Requires an integer"), placeholder="要求一个整数",
type="integer", type="integer",
id=domize(f"{parent_epath}.{i}"), id=domize(f"{parent_epath}.{i}"),
), ),
@@ -187,9 +186,9 @@ class SettingScreen(Screen):
elif isinstance(parent[i], list): elif isinstance(parent[i], list):
pass pass
else: else:
lst.append(Label(_("Unknown type"))) lst.append(Label("未知类型"))
return lst return lst
return [Label(_("No sub-items"))] return [Label("无子项")]
def on_mount(self) -> None: def on_mount(self) -> None:
"""挂载组件时初始化""" """挂载组件时初始化"""
+83 -93
View File
@@ -1,4 +1,4 @@
"""Sync tool screen""" """同步工具界面"""
import pathlib import pathlib
import time import time
@@ -12,12 +12,11 @@ from textual.worker import get_current_worker
from textual import events, on from textual import events, on
from heurams.context import * from heurams.context import *
from heurams.i18n import _
class SyncScreen(Screen): class SyncScreen(Screen):
BINDINGS = [("q", "go_back", _("Back"))] BINDINGS = [("q", "go_back", "返回")]
def __init__(self, nucleons: list = [], desc: str = ""): def __init__(self, nucleons: list = [], desc: str = ""):
super().__init__(name=None, id=None, classes=None) super().__init__(name=None, id=None, classes=None)
@@ -40,67 +39,67 @@ class SyncScreen(Screen):
show_clock=config_var.get()["interface"]["global"]["clock_on_header"] show_clock=config_var.get()["interface"]["global"]["clock_on_header"]
) )
with ScrollableContainer(id="sync_container"): with ScrollableContainer(id="sync_container"):
# Title and connection status # 标题和连接状态
yield Static(_("Sync Tool"), classes="title") yield Static("同步工具", classes="title")
yield Static("", id="status_label", classes="status") yield Static("", id="status_label", classes="status")
# Config info # 配置信息
yield Static(_("Sync protocol: {proto}").format(proto=config_var.get()['services']['sync'])) yield Static(f"同步协议: {config_var.get()['services']['sync']}")
yield Static(_("Server Configuration:"), classes="section_title") yield Static("服务器配置:", classes="section_title")
with Horizontal(classes="config_info"): with Horizontal(classes="config_info"):
yield Static(_("Remote server:"), classes="config_label") yield Static("远程服务器:", classes="config_label")
yield Static("", id="server_url", classes="config_value") yield Static("", id="server_url", classes="config_value")
with Horizontal(classes="config_info"): with Horizontal(classes="config_info"):
yield Static(_("Remote path:"), classes="config_label") yield Static("远程路径:", classes="config_label")
yield Static("", id="remote_path", classes="config_value") yield Static("", id="remote_path", classes="config_value")
with Horizontal(classes="control_buttons"): with Horizontal(classes="control_buttons"):
yield Button(_("Test Connection"), id="test_connection", variant="primary") yield Button("测试连接", id="test_connection", variant="primary")
yield Button(_("Start Sync"), id="start_sync", variant="success") yield Button("开始同步", id="start_sync", variant="success")
yield Button(_("Pause"), id="pause_sync", variant="warning", disabled=True) yield Button("暂停", id="pause_sync", variant="warning", disabled=True)
yield Button(_("Cancel"), id="cancel_sync", variant="error", disabled=True) yield Button("取消", id="cancel_sync", variant="error", disabled=True)
yield Static(_("Sync Progress"), classes="section_title") yield Static("同步进度", classes="section_title")
yield ProgressBar(id="progress_bar", show_percentage=True, total=100) yield ProgressBar(id="progress_bar", show_percentage=True, total=100)
yield Static("", id="progress_label", classes="progress_text") yield Static("", id="progress_label", classes="progress_text")
yield Static(_("Sync Log"), classes="section_title") yield Static("同步日志", classes="section_title")
yield Static("", id="log_output", classes="log_output") yield Static("", id="log_output", classes="log_output")
yield Footer() yield Footer()
def on_mount(self): def on_mount(self):
"""Initialise state on mount""" """挂载时初始化状态"""
self.update_ui_from_config() self.update_ui_from_config()
self.log_message(_("Sync tool started")) self.log_message("同步工具已启动")
def update_ui_from_config(self): def update_ui_from_config(self):
"""Update UI with config info""" """更新 UI 显示配置信息"""
try: try:
sync_cfg: dict = config_var.get()["providers"]["sync"]["webdav"] sync_cfg: dict = config_var.get()["providers"]["sync"]["webdav"]
# Update server URL # 更新服务器 URL
url = sync_cfg.get("url", _("Not configured")) url = sync_cfg.get("url", "未配置")
url_widget = self.query_one("#server_url") url_widget = self.query_one("#server_url")
url_widget.update(url) # type: ignore url_widget.update(url) # type: ignore
# Update remote path # 更新远程路径
remote_path = sync_cfg.get("remote_path", "/") remote_path = sync_cfg.get("remote_path", "/")
path_widget = self.query_one("#remote_path") path_widget = self.query_one("#remote_path")
path_widget.update(remote_path) # type: ignore path_widget.update(remote_path) # type: ignore
# Update status label # 更新状态标签
status_widget = self.query_one("#status_label") status_widget = self.query_one("#status_label")
if self.sync_service and self.sync_service.client: if self.sync_service and self.sync_service.client:
status_widget.update(_("Sync service ready")) # type: ignore status_widget.update("同步服务已就绪") # type: ignore
status_widget.add_class("ready") status_widget.add_class("ready")
else: else:
status_widget.update(_("Sync service not configured or not enabled")) # type: ignore status_widget.update("同步服务未配置或未启用") # type: ignore
status_widget.add_class("error") status_widget.add_class("error")
except Exception as e: except Exception as e:
self.log_message(_("Failed to update UI: {error}").format(error=e), is_error=True) self.log_message(f"更新 UI 失败: {e}", is_error=True)
def update_status(self, status, current_item="", progress=None): def update_status(self, status, current_item="", progress=None):
"""Update status display""" """更新状态显示"""
try: try:
status_widget = self.query_one("#status_label") status_widget = self.query_one("#status_label")
status_widget.update(status) # type: ignore status_widget.update(status) # type: ignore
@@ -113,28 +112,28 @@ class SyncScreen(Screen):
progress_label.update(f"{progress}% - {current_item}" if current_item else f"{progress}%") # type: ignore progress_label.update(f"{progress}% - {current_item}" if current_item else f"{progress}%") # type: ignore
except Exception as e: except Exception as e:
self.log_message(_("Failed to update status: {error}").format(error=e), is_error=True) self.log_message(f"更新状态失败: {e}", is_error=True)
def log_message(self, message: str, is_error: bool = False): def log_message(self, message: str, is_error: bool = False):
"""Add log message and update display""" """添加日志消息并更新显示"""
timestamp = time.strftime("%H:%M:%S") timestamp = time.strftime("%H:%M:%S")
prefix = "[ERROR]" if is_error else "[INFO]" prefix = "[ERROR]" if is_error else "[INFO]"
log_line = f"{timestamp} {prefix} {message}" log_line = f"{timestamp} {prefix} {message}"
self.log_messages.append(log_line) self.log_messages.append(log_line)
# Keep log lines under max # 保持日志行数不超过最大值
if len(self.log_messages) > self.max_log_lines: if len(self.log_messages) > self.max_log_lines:
self.log_messages = self.log_messages[-self.max_log_lines :] self.log_messages = self.log_messages[-self.max_log_lines :]
# Update log display # 更新日志显示
try: try:
log_widget = self.query_one("#log_output") log_widget = self.query_one("#log_output")
log_widget.update("\n".join(self.log_messages)) # type: ignore log_widget.update("\n".join(self.log_messages)) # type: ignore
except Exception: except Exception:
pass # Ignore if widget not ready pass # 如果组件未就绪,忽略错误
def on_button_pressed(self, event: Button.Pressed) -> None: def on_button_pressed(self, event: Button.Pressed) -> None:
"""Handle button press events""" """处理按钮点击事件"""
button_id = event.button.id button_id = event.button.id
if button_id == "test_connection": if button_id == "test_connection":
@@ -149,133 +148,124 @@ class SyncScreen(Screen):
event.stop() event.stop()
def test_connection(self): def test_connection(self):
"""Test WebDAV server connection""" """测试 WebDAV 服务器连接"""
if not self.sync_service: if not self.sync_service:
self.log_message(_("Sync service not initialised, please check configuration"), is_error=True) self.log_message("同步服务未初始化,请检查配置", is_error=True)
self.update_status(_("Sync service not initialised")) self.update_status("同步服务未初始化")
return return
self.log_message(_("Testing WebDAV connection...")) self.log_message("正在测试 WebDAV 连接...")
self.update_status(_("Testing connection...")) self.update_status("正在测试连接...")
try: try:
success = self.sync_service.test_connection() success = self.sync_service.test_connection()
if success: if success:
self.log_message(_("Connection test successful")) self.log_message("连接测试成功")
self.update_status(_("Connection OK")) self.update_status("连接正常")
else: else:
self.log_message(_("Connection test failed"), is_error=True) self.log_message("连接测试失败", is_error=True)
self.update_status(_("Connection failed")) self.update_status("连接失败")
except Exception as e: except Exception as e:
self.log_message(_("Connection test error: {error}").format(error=e), is_error=True) self.log_message(f"连接测试异常: {e}", is_error=True)
self.update_status(_("Connection error")) self.update_status("连接异常")
def start_sync(self): def start_sync(self):
"""Start syncing""" """开始同步"""
if not self.sync_service: if not self.sync_service:
self.log_message(_("Sync service not initialised, cannot start sync"), is_error=True) self.log_message("同步服务未初始化,无法开始同步", is_error=True)
return return
if self.is_syncing: if self.is_syncing:
self.log_message(_("Sync already in progress"), is_error=True) self.log_message("同步已在进行中", is_error=True)
return return
self.is_syncing = True self.is_syncing = True
self.is_paused = False self.is_paused = False
self.update_button_states() self.update_button_states()
self.log_message(_("Starting data sync...")) self.log_message("开始同步数据...")
self.update_status(_("Syncing..."), progress=0) self.update_status("正在同步...", progress=0)
# Start background sync task # 启动后台同步任务
self.run_worker(self.perform_sync, thread=True) self.run_worker(self.perform_sync, thread=True)
def perform_sync(self): def perform_sync(self):
"""Execute sync task (runs in background thread)""" """执行同步任务(在后台线程中运行)"""
worker = get_current_worker() worker = get_current_worker()
try: try:
# Get local directories to sync # 获取需要同步的本地目录
from heurams.context import config_var from heurams.context import config_var
config = config_var.get() config = config_var.get()
paths = config.get("paths", {}) paths = config.get("paths", {})
# Sync nucleon directory # 同步 nucleon 目录
nucleon_dir = pathlib.Path(paths.get("nucleon_dir", "./data/nucleon")) nucleon_dir = pathlib.Path(paths.get("nucleon_dir", "./data/nucleon"))
if nucleon_dir.exists(): if nucleon_dir.exists():
self.log_message(_("Syncing nucleon directory: {dir}").format(dir=nucleon_dir)) self.log_message(f"同步 nucleon 目录: {nucleon_dir}")
self.update_status(_("Syncing nucleon directory..."), progress=10) self.update_status(f"同步 nucleon 目录...", progress=10)
result = self.sync_service.sync_directory(nucleon_dir) # type: ignore result = self.sync_service.sync_directory(nucleon_dir) # type: ignore
if result.get("success"): if result.get("success"):
self.log_message( self.log_message(
_("nucleon sync complete: uploaded {up}, downloaded {down}").format( f"nucleon 同步完成: 上传 {result.get('uploaded', 0)} 个, 下载 {result.get('downloaded', 0)}"
up=result.get('uploaded', 0),
down=result.get('downloaded', 0),
)
) )
else: else:
self.log_message( self.log_message(
_("nucleon sync failed: {err}").format(err=result.get('error', _('Unknown error'))), f"nucleon 同步失败: {result.get('error', '未知错误')}",
is_error=True, is_error=True,
) )
# Sync electron directory # 同步 electron 目录
electron_dir = pathlib.Path(paths.get("electron_dir", "./data/electron")) electron_dir = pathlib.Path(paths.get("electron_dir", "./data/electron"))
if electron_dir.exists(): if electron_dir.exists():
self.log_message(_("Syncing electron directory: {dir}").format(dir=electron_dir)) self.log_message(f"同步 electron 目录: {electron_dir}")
self.update_status(_("Syncing electron directory..."), progress=60) self.update_status(f"同步 electron 目录...", progress=60)
result = self.sync_service.sync_directory(electron_dir) # type: ignore result = self.sync_service.sync_directory(electron_dir) # type: ignore
if result.get("success"): if result.get("success"):
self.log_message( self.log_message(
_("electron sync complete: uploaded {up}, downloaded {down}").format( f"electron 同步完成: 上传 {result.get('uploaded', 0)} 个, 下载 {result.get('downloaded', 0)}"
up=result.get('uploaded', 0),
down=result.get('downloaded', 0),
)
) )
else: else:
self.log_message( self.log_message(
_("electron sync failed: {err}").format(err=result.get('error', _('Unknown error'))), f"electron 同步失败: {result.get('error', '未知错误')}",
is_error=True, is_error=True,
) )
# Sync orbital directory (if exists) # 同步 orbital 目录(如果存在)
orbital_dir = pathlib.Path(paths.get("orbital_dir", "./data/orbital")) orbital_dir = pathlib.Path(paths.get("orbital_dir", "./data/orbital"))
if orbital_dir.exists(): if orbital_dir.exists():
self.log_message(_("Syncing orbital directory: {dir}").format(dir=orbital_dir)) self.log_message(f"同步 orbital 目录: {orbital_dir}")
self.update_status(_("Syncing orbital directory..."), progress=80) self.update_status(f"同步 orbital 目录...", progress=80)
result = self.sync_service.sync_directory(orbital_dir) # type: ignore result = self.sync_service.sync_directory(orbital_dir) # type: ignore
if result.get("success"): if result.get("success"):
self.log_message( self.log_message(
_("orbital sync complete: uploaded {up}, downloaded {down}").format( f"orbital 同步完成: 上传 {result.get('uploaded', 0)} 个, 下载 {result.get('downloaded', 0)}"
up=result.get('uploaded', 0),
down=result.get('downloaded', 0),
)
) )
else: else:
self.log_message( self.log_message(
_("orbital sync failed: {err}").format(err=result.get('error', _('Unknown error'))), f"orbital 同步失败: {result.get('error', '未知错误')}",
is_error=True, is_error=True,
) )
# Sync complete # 同步完成
self.update_status(_("Sync complete"), progress=100) self.update_status("同步完成", progress=100)
self.log_message(_("All directories synced")) self.log_message("所有目录同步完成")
except Exception as e: except Exception as e:
self.log_message(_("Error during sync: {error}").format(error=e), is_error=True) self.log_message(f"同步过程中发生错误: {e}", is_error=True)
self.update_status(_("Sync failed")) self.update_status("同步失败")
finally: finally:
# Reset sync state # 重置同步状态
self.is_syncing = False self.is_syncing = False
self.is_paused = False self.is_paused = False
self.update_button_states() # type: ignore self.update_button_states() # type: ignore
def pause_sync(self): def pause_sync(self):
"""Pause sync""" """暂停同步"""
if not self.is_syncing: if not self.is_syncing:
return return
@@ -283,14 +273,14 @@ class SyncScreen(Screen):
self.update_button_states() self.update_button_states()
if self.is_paused: if self.is_paused:
self.log_message(_("Sync paused")) self.log_message("同步已暂停")
self.update_status(_("Sync paused")) self.update_status("同步已暂停")
else: else:
self.log_message(_("Sync resumed")) self.log_message("同步已恢复")
self.update_status(_("Syncing...")) self.update_status("正在同步...")
def cancel_sync(self): def cancel_sync(self):
"""Cancel sync""" """取消同步"""
if not self.is_syncing: if not self.is_syncing:
return return
@@ -298,11 +288,11 @@ class SyncScreen(Screen):
self.is_paused = False self.is_paused = False
self.update_button_states() self.update_button_states()
self.log_message(_("Sync cancelled")) self.log_message("同步已取消")
self.update_status(_("Sync cancelled")) self.update_status("同步已取消")
def update_button_states(self): def update_button_states(self):
"""Update button states""" """更新按钮状态"""
try: try:
start_button = self.query_one("#start_sync") start_button = self.query_one("#start_sync")
pause_button = self.query_one("#pause_sync") pause_button = self.query_one("#pause_sync")
@@ -312,14 +302,14 @@ class SyncScreen(Screen):
start_button.disabled = True start_button.disabled = True
pause_button.disabled = False pause_button.disabled = False
cancel_button.disabled = False cancel_button.disabled = False
pause_button.label = _("Resume") if self.is_paused else _("Pause") # type: ignore pause_button.label = "继续" if self.is_paused else "暂停" # type: ignore
else: else:
start_button.disabled = False start_button.disabled = False
pause_button.disabled = True pause_button.disabled = True
cancel_button.disabled = True cancel_button.disabled = True
except Exception as e: except Exception as e:
self.log_message(_("Failed to update button state: {error}").format(error=e), is_error=True) self.log_message(f"更新按钮状态失败: {e}", is_error=True)
def action_go_back(self): def action_go_back(self):
self.app.pop_screen() self.app.pop_screen()
+19 -20
View File
@@ -5,7 +5,6 @@ from textual.widgets import Button, Label, Static
import heurams.kernel.particles as pt import heurams.kernel.particles as pt
from heurams.i18n import _
from .base_puzzle_widget import BasePuzzleWidget from .base_puzzle_widget import BasePuzzleWidget
@@ -33,49 +32,49 @@ class BasicEvaluation(BasePuzzleWidget):
class RatingChanged(Message): class RatingChanged(Message):
def __init__(self, rating: int) -> None: def __init__(self, rating: int) -> None:
self.rating = rating # Rating value (0-5) self.rating = rating # 评分值 (0-5)
super().__init__() super().__init__()
# Feedback mapping # 反馈映射表
feedback_mapping = { feedback_mapping = {
"feedback_5": {"rating": 5, "text": _("Perfect recall")}, "feedback_5": {"rating": 5, "text": "完美回想"},
"feedback_4": {"rating": 4, "text": _("Correct after hesitation")}, "feedback_4": {"rating": 4, "text": "犹豫后正确"},
"feedback_3": {"rating": 3, "text": _("Correct with difficulty")}, "feedback_3": {"rating": 3, "text": "困难地正确"},
"feedback_2": {"rating": 2, "text": _("Wrong but familiar")}, "feedback_2": {"rating": 2, "text": "错误但熟悉"},
"feedback_1": {"rating": 1, "text": _("Wrong and unfamiliar")}, "feedback_1": {"rating": 1, "text": "错误且不熟"},
"feedback_0": {"rating": 0, "text": _("Complete blank")}, "feedback_0": {"rating": 0, "text": "完全空白"},
} }
def compose(self): def compose(self):
# Show main content # 显示主要内容
yield Label(self.atom.registry["nucleon"]["content"], id="main") yield Label(self.atom.registry["nucleon"]["content"], id="main")
# Show instruction (optional) # 显示评估说明(可选)
yield Static(_("Evaluate how well you remember this content: "), classes="instruction") yield Static("请评估你对这个内容的记忆程度: ", classes="instruction")
# Button container # 按钮容器
with ScrollableContainer(id="button_container"): with ScrollableContainer(id="button_container"):
btn = {} btn = {}
btn["5"] = Button( btn["5"] = Button(
_("Perfect recall"), variant="success", id="feedback_5", classes="choice" "完美回想", variant="success", id="feedback_5", classes="choice"
) )
btn["4"] = Button( btn["4"] = Button(
_("Correct after hesitation"), variant="success", id="feedback_4", classes="choice" "犹豫后正确", variant="success", id="feedback_4", classes="choice"
) )
btn["3"] = Button( btn["3"] = Button(
_("Correct with difficulty"), variant="warning", id="feedback_3", classes="choice" "困难地正确", variant="warning", id="feedback_3", classes="choice"
) )
btn["2"] = Button( btn["2"] = Button(
_("Wrong but familiar"), variant="warning", id="feedback_2", classes="choice" "错误但熟悉", variant="warning", id="feedback_2", classes="choice"
) )
btn["1"] = Button( btn["1"] = Button(
_("Wrong and unfamiliar"), variant="error", id="feedback_1", classes="choice" "错误且不熟", variant="error", id="feedback_1", classes="choice"
) )
btn["0"] = Button( btn["0"] = Button(
_("Complete blank"), variant="error", id="feedback_0", classes="choice" "完全空白", variant="error", id="feedback_0", classes="choice"
) )
# Layout buttons # 布局按钮
yield Horizontal(btn["5"], btn["4"]) yield Horizontal(btn["5"], btn["4"])
yield Horizontal(btn["3"], btn["2"]) yield Horizontal(btn["3"], btn["2"])
yield Horizontal(btn["1"], btn["0"]) yield Horizontal(btn["1"], btn["0"])
+5 -11
View File
@@ -2,7 +2,7 @@ import copy
import random import random
from typing import TypedDict from typing import TypedDict
from textual.containers import ScrollableContainer, Horizontal from textual.containers import ScrollableContainer
from textual.widget import Widget from textual.widget import Widget
from textual.widgets import Button, Label, Markdown from textual.widgets import Button, Label, Markdown
from textual.events import Key from textual.events import Key
@@ -10,7 +10,6 @@ from textual.events import Key
import heurams.kernel.particles as pt import heurams.kernel.particles as pt
import heurams.kernel.puzzles as pz import heurams.kernel.puzzles as pz
from heurams.services.hasher import hash from heurams.services.hasher import hash
from heurams.i18n import _
from heurams.services.logger import get_logger from heurams.services.logger import get_logger
from .base_puzzle_widget import BasePuzzleWidget from .base_puzzle_widget import BasePuzzleWidget
@@ -72,7 +71,6 @@ class ClozePuzzle(BasePuzzleWidget):
# 渲染当前问题的选项 # 渲染当前问题的选项
with ScrollableContainer(id="btn-container") as s: with ScrollableContainer(id="btn-container") as s:
c = 0 c = 0
btns = []
for i in self.ans: for i in self.ans:
h = str(hash(i)) h = str(hash(i))
if hash(i) in self.hashmap.keys(): if hash(i) in self.hashmap.keys():
@@ -80,16 +78,12 @@ class ClozePuzzle(BasePuzzleWidget):
c += 1 c += 1
self.hashmap[h] = i self.hashmap[h] = i
btnid = f"sel000-{h}" btnid = f"sel000-{h}"
logger.debug(f"建立按钮 {btnid}")
self.btn_shortcuts[f"{c}"] = btnid self.btn_shortcuts[f"{c}"] = btnid
btns.append(Button(f"{i}", id=f"{btnid}", classes="cloze-option-btn")) yield Button(f"[{c}] {i}", id=f"{btnid}")
for i in range((len(btns) + 1) // 2):
if 2 * i + 1 + 1 <= len(btns):
yield Horizontal(btns[i], btns[len(btns) - 1 - i], classes="hori")
else:
yield btns[i]
s.focus() s.focus()
yield Button(_("Backspace"), id="delete") yield Button("退格", id="delete")
self.btn_shortcuts[f"0"] = "delete" self.btn_shortcuts[f"0"] = "delete"
self.btn_shortcuts[f"backspace"] = "delete" self.btn_shortcuts[f"backspace"] = "delete"
self.btn_shortcuts[f"delete"] = "delete" self.btn_shortcuts[f"delete"] = "delete"
@@ -136,7 +130,7 @@ class ClozePuzzle(BasePuzzleWidget):
self.atom.minimize(rating) self.atom.minimize(rating)
def on_key(self, event: Key) -> None: def on_key(self, event: Key) -> None:
# self.notify(event.key) self.notify(event.key)
if event.key in self.btn_shortcuts: if event.key in self.btn_shortcuts:
btn_id = self.btn_shortcuts.get(event.key) btn_id = self.btn_shortcuts.get(event.key)
btn_id = "#" + btn_id btn_id = "#" + btn_id
+3 -5
View File
@@ -1,8 +1,6 @@
from textual.widget import Widget from textual.widget import Widget
from textual.widgets import Button, Label from textual.widgets import Button, Label
from heurams.i18n import _
class Finished(Widget): class Finished(Widget):
def __init__( def __init__(
@@ -28,9 +26,9 @@ class Finished(Widget):
) )
def compose(self): def compose(self):
yield Label(_("This memorization session is finished"), id="finished_msg") yield Label("本次记忆进程结束", id="finished_msg")
yield Label(_("Algorithm data {}").format(_("saved") if self.is_saved else _("not saved"))) yield Label(f"算法数据{'已保存' if self.is_saved else "未能保存"}")
yield Button(_("Back to Menu"), flat=True, id="back-to-menu") yield Button("返回上一级", flat=True, id="back-to-menu")
def on_button_pressed(self, event): def on_button_pressed(self, event):
button_id = event.button.id button_id = event.button.id
+15 -7
View File
@@ -1,4 +1,4 @@
# Multiple-choice puzzle # 单项选择题
from typing import TypedDict from typing import TypedDict
from textual.containers import ScrollableContainer from textual.containers import ScrollableContainer
@@ -8,7 +8,6 @@ from textual.widgets import Button, Label
import heurams.kernel.particles as pt import heurams.kernel.particles as pt
import heurams.kernel.puzzles as pz import heurams.kernel.puzzles as pz
from heurams.services.hasher import hash from heurams.services.hasher import hash
from heurams.i18n import _
from heurams.services.logger import get_logger from heurams.services.logger import get_logger
from textual.events import Key from textual.events import Key
from .base_puzzle_widget import BasePuzzleWidget from .base_puzzle_widget import BasePuzzleWidget
@@ -66,10 +65,15 @@ class MCQPuzzle(BasePuzzleWidget):
def compose(self): def compose(self):
setting: Setting = self.atom.registry["nucleon"]["puzzles"][self.alia] setting: Setting = self.atom.registry["nucleon"]["puzzles"][self.alia]
if len(self.inputlist) > len(self.puzzle.options):
logger.debug("ERR IDX")
logger.debug(self.inputlist)
logger.debug(self.puzzle.options)
else:
current_options = self.puzzle.options[len(self.inputlist)] current_options = self.puzzle.options[len(self.inputlist)]
yield Label(setting["primary"], id="sentence") yield Label(setting["primary"], id="sentence")
yield Label(self.puzzle.wording[len(self.inputlist)], id="puzzle") yield Label(self.puzzle.wording[len(self.inputlist)], id="puzzle")
yield Label(_("Current input: {input}").format(input=self.inputlist), id="inputpreview") yield Label(f"当前输入: {self.inputlist}", id="inputpreview")
# 渲染当前问题的选项 # 渲染当前问题的选项
c = 0 c = 0
@@ -81,19 +85,21 @@ class MCQPuzzle(BasePuzzleWidget):
h = str(hash(i)) h = str(hash(i))
self.hashmap[h] = i self.hashmap[h] = i
btnid = f"sel{str(self.cursor).zfill(3)}-{h}" btnid = f"sel{str(self.cursor).zfill(3)}-{h}"
logger.debug(f"建立按钮 {btnid}")
self.btn_shortcuts[f"{c}"] = f"{btnid}" self.btn_shortcuts[f"{c}"] = f"{btnid}"
yield Button(f"[{c}] " + i, id=f"{btnid}") yield Button(f"[{c}] " + i, id=f"{btnid}")
s.focus() s.focus()
yield Button(_("Backspace"), id="delete") yield Button("退格", id="delete")
self.btn_shortcuts["0"] = f"delete" self.btn_shortcuts["0"] = f"delete"
self.btn_shortcuts["delete"] = f"delete" self.btn_shortcuts["delete"] = f"delete"
self.btn_shortcuts["backspace"] = f"delete" self.btn_shortcuts["backspace"] = f"delete"
def update_display(self, error=0): def update_display(self, error=0):
# Update preview label # 更新预览标签
preview = self.query_one("#inputpreview") preview = self.query_one("#inputpreview")
preview.update(_("Current input: {input}").format(input=self.inputlist)) # type: ignore preview.update(f"当前输入: {self.inputlist}") # type: ignore
logger.debug("已经更新预览标签")
# 更新问题标签 # 更新问题标签
puzzle_label = self.query_one("#puzzle") puzzle_label = self.query_one("#puzzle")
current_question_index = len(self.inputlist) current_question_index = len(self.inputlist)
@@ -116,7 +122,7 @@ class MCQPuzzle(BasePuzzleWidget):
# 选项选择处理 # 选项选择处理
answer_text = self.hashmap[button_id[7:]] # type: ignore answer_text = self.hashmap[button_id[7:]] # type: ignore
self.inputlist.append(answer_text) self.inputlist.append(answer_text)
logger.debug(f"Input list: {self.inputlist}") logger.debug(f"{self.inputlist}")
# 检查是否完成所有题目 # 检查是否完成所有题目
if len(self.inputlist) >= len(self.puzzle.answer): if len(self.inputlist) >= len(self.puzzle.answer):
is_correct = self.inputlist == self.puzzle.answer is_correct = self.inputlist == self.puzzle.answer
@@ -137,6 +143,7 @@ class MCQPuzzle(BasePuzzleWidget):
def refresh_buttons(self): def refresh_buttons(self):
"""刷新按钮显示(用于题目切换)""" """刷新按钮显示(用于题目切换)"""
# 移除所有选项按钮 # 移除所有选项按钮
logger.debug("刷新按钮")
self.cursor += 1 self.cursor += 1
container = self.query_one("#btn-container") container = self.query_one("#btn-container")
buttons_to_remove = [ buttons_to_remove = [
@@ -146,6 +153,7 @@ class MCQPuzzle(BasePuzzleWidget):
] ]
container.focus() container.focus()
for button in buttons_to_remove: for button in buttons_to_remove:
logger.info(button)
container.remove_children("#" + button.id) # type: ignore container.remove_children("#" + button.id) # type: ignore
# 添加当前题目的选项按钮 # 添加当前题目的选项按钮
+2 -4
View File
@@ -1,8 +1,6 @@
from textual.widget import Widget from textual.widget import Widget
from textual.widgets import Button, Label from textual.widgets import Button, Label
from heurams.i18n import _
class Placeholder(Widget): class Placeholder(Widget):
def __init__( def __init__(
@@ -25,8 +23,8 @@ class Placeholder(Widget):
) )
def compose(self): def compose(self):
yield Label(_("Sample Label"), id="testlabel") yield Label("示例标签", id="testlabel")
yield Button(_("Sample Button"), id="testbtn", classes="choice") yield Button("示例按钮", id="testbtn", classes="choice")
def on_button_pressed(self, event): def on_button_pressed(self, event):
pass pass
+2 -3
View File
@@ -6,7 +6,6 @@ from textual.widget import Widget
from textual.widgets import Button, Label, Markdown, Static from textual.widgets import Button, Label, Markdown, Static
import heurams.kernel.particles as pt import heurams.kernel.particles as pt
from heurams.i18n import _
from heurams.services.logger import get_logger from heurams.services.logger import get_logger
from .base_puzzle_widget import BasePuzzleWidget from .base_puzzle_widget import BasePuzzleWidget
@@ -87,7 +86,7 @@ class Recognition(BasePuzzleWidget):
for item in cfg["secondary"]: for item in cfg["secondary"]:
if isinstance(item, list): if isinstance(item, list):
for j in item: for j in item:
yield Markdown(_("### Note: {note}").format(note=j)) # TODO ANNOTATION yield Markdown(f"### 笔记: {j}") # TODO ANNOTATION
continue continue
if isinstance(item, Dict): if isinstance(item, Dict):
total = "" total = ""
@@ -98,7 +97,7 @@ class Recognition(BasePuzzleWidget):
yield Markdown(item) yield Markdown(item)
with Center() as c: with Center() as c:
with Button(_("I know this"), id="ok") as b: with Button("我已知晓", id="ok") as b:
b.focus() b.focus()
def on_button_pressed(self, event: Button.Pressed) -> None: def on_button_pressed(self, event: Button.Pressed) -> None:
+1 -1
View File
@@ -1,3 +1,3 @@
# Kernel - HeurAMS 核心 # Kernel - HeurAMS 核心
包括记忆规划相关状态机, 算法, 仓库系统, 辅助库与数据结构, 可脱离业务层 记忆规划相关算法与数据结构, 可脱离业务层
+18 -11
View File
@@ -1,14 +1,21 @@
import importlib
import pkgutil
from pathlib import Path
from .base import BaseAlgorithm from .base import BaseAlgorithm
from .sm2 import SM2Algorithm
from .sm15m import SM15MAlgorithm
from .nsp0 import NSP0Algorithm
from .fsrs import FSRSAlgorithm
__path__ = [str(Path(__file__).parent)] __all__ = [
"SM2Algorithm",
"BaseAlgorithm",
"SM15MAlgorithm",
"NSP0Algorithm",
"FSRSAlgorithm",
]
for _finder, _name, _ispkg in pkgutil.iter_modules(__path__): algorithms = {
if _name == "base": "SM-2": SM2Algorithm,
continue "NSP-0": NSP0Algorithm,
importlib.import_module(f".{_name}", __package__) "SM-15M": SM15MAlgorithm,
"FSRS": FSRSAlgorithm,
algorithms = BaseAlgorithm.get_registry() "Base": BaseAlgorithm,
}
+18 -11
View File
@@ -5,21 +5,11 @@ from heurams.services.logger import get_logger
logger = get_logger(__name__) logger = get_logger(__name__)
_registry: dict[str, type["BaseAlgorithm"]] = {}
class BaseAlgorithm: class BaseAlgorithm:
algo_name = "BaseAlgorithm" algo_name = "BaseAlgorithm"
desc = "算法基类" desc = "算法基类"
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
_registry[cls.algo_name] = cls
@classmethod
def get_registry(cls) -> dict[str, type["BaseAlgorithm"]]:
return dict(_registry)
class AlgodataDict(TypedDict): class AlgodataDict(TypedDict):
real_rept: int real_rept: int
rept: int rept: int
@@ -44,21 +34,38 @@ class BaseAlgorithm:
cls, algodata: dict, feedback: int = 5, is_new_activation: bool = False cls, algodata: dict, feedback: int = 5, is_new_activation: bool = False
) -> None: ) -> None:
"""迭代记忆数据""" """迭代记忆数据"""
logger.debug(
"BaseAlgorithm.revisor 被调用, algodata keys: %s, feedback: %d, is_new_activation: %s",
list(algodata.keys()) if algodata else [],
feedback,
is_new_activation,
)
@classmethod @classmethod
def is_due(cls, algodata) -> int: def is_due(cls, algodata) -> int:
"""是否应该复习""" """是否应该复习"""
logger.debug(
"BaseAlgorithm.is_due 被调用, algodata keys: %s",
list(algodata.keys()) if algodata else [],
)
return 1 return 1
@classmethod @classmethod
def get_rating(cls, algodata) -> str: def get_rating(cls, algodata) -> str:
"""获取评分信息""" """获取评分信息"""
logger.debug(
"BaseAlgorithm.rate 被调用, algodata keys: %s",
list(algodata.keys()) if algodata else [],
)
return "" return ""
@classmethod @classmethod
def nextdate(cls, algodata) -> int: def nextdate(cls, algodata) -> int:
"""获取下一次记忆时间戳""" """获取下一次记忆时间戳"""
logger.debug(
"BaseAlgorithm.nextdate 被调用, algodata keys: %s",
list(algodata.keys()) if algodata else [],
)
return -1 return -1
@classmethod @classmethod
+23 -14
View File
@@ -3,7 +3,7 @@ FSRS 算法模块 — 基于 py-fsrs 的现代间隔重复调度器
基于: https://github.com/open-spaced-repetition/py-fsrs 基于: https://github.com/open-spaced-repetition/py-fsrs
""" """
import json
import os import os
import pathlib import pathlib
from datetime import datetime, timezone, timedelta from datetime import datetime, timezone, timedelta
@@ -20,20 +20,19 @@ from .base import BaseAlgorithm
logger = get_logger(__name__) logger = get_logger(__name__)
# 全局 Scheduler 状态文件路径 # 全局 Scheduler 状态文件路径
_SCHEDULER_STATE_FILE = ( _SCHEDULER_STATE_FILE = pathlib.Path(
pathlib.Path(config_var.get()["global"]["paths"]["misc"]) config_var.get()["global"]["paths"]["data"]
/ "fsrs_scheduler_state.json" ) / "global" / "fsrs_scheduler_state.json"
)
def _get_global_scheduler(): def _get_global_scheduler():
"""获取全局 FSRS Scheduler 实例, 从文件加载或创建新的""" """获取全局 FSRS Scheduler 实例从文件加载或创建新的"""
if os.path.exists(_SCHEDULER_STATE_FILE): if os.path.exists(_SCHEDULER_STATE_FILE):
try: try:
with open(_SCHEDULER_STATE_FILE, "r", encoding="utf-8") as f: with open(_SCHEDULER_STATE_FILE, "r", encoding="utf-8") as f:
return Scheduler.from_json(f.read()) return Scheduler.from_json(f.read())
except Exception: except Exception:
logger.warning("No former FSRS Scheduler file founded, creating new instance") logger.warning("FSRS Scheduler 状态文件加载失败,创建新实例")
return Scheduler() return Scheduler()
@@ -45,7 +44,7 @@ def _save_global_scheduler(scheduler):
with open(_SCHEDULER_STATE_FILE, "w", encoding="utf-8") as f: with open(_SCHEDULER_STATE_FILE, "w", encoding="utf-8") as f:
f.write(data) f.write(data)
except Exception: except Exception:
logger.error("Failed to persist FSRS Scheduler state") logger.exception("FSRS Scheduler 状态保存失败")
def _feedback_to_rating(feedback: int) -> Rating: def _feedback_to_rating(feedback: int) -> Rating:
@@ -81,7 +80,7 @@ class FSRSAlgorithm(BaseAlgorithm):
# FSRS 特有字段 # FSRS 特有字段
fsrs_state: int # State 枚举值: 1=Learning, 2=Review, 3=Relearning fsrs_state: int # State 枚举值: 1=Learning, 2=Review, 3=Relearning
fsrs_step: int # 当前学习步进索引, -1 表示 None (Review 状态) fsrs_step: int # 当前学习步进索引, -1 表示 None (Review 状态)
fsrs_stability: float # 稳定性(秒), 0.0 表示尚未计算 fsrs_stability: float # 稳定性(秒)0.0 表示尚未计算
fsrs_difficulty: float # 难度 [1.0, 10.0], 0.0 表示尚未计算 fsrs_difficulty: float # 难度 [1.0, 10.0], 0.0 表示尚未计算
# 标准 BaseAlgorithm 兼容字段 # 标准 BaseAlgorithm 兼容字段
real_rept: int real_rept: int
@@ -137,7 +136,9 @@ class FSRSAlgorithm(BaseAlgorithm):
# last_review # last_review
last_date = data.get("last_date", 0) last_date = data.get("last_date", 0)
card.last_review = _daystamp_to_datetime(last_date) if last_date > 0 else None card.last_review = (
_daystamp_to_datetime(last_date) if last_date > 0 else None
)
return card return card
@@ -159,7 +160,9 @@ class FSRSAlgorithm(BaseAlgorithm):
if card.last_review if card.last_review
else data.get("last_date", 0) else data.get("last_date", 0)
) )
data["next_date"] = _datetime_to_daystamp(card.due) if card.due else 0 data["next_date"] = (
_datetime_to_daystamp(card.due) if card.due else 0
)
data["interval"] = max(0, data["next_date"] - data["last_date"]) data["interval"] = max(0, data["next_date"] - data["last_date"])
data["last_modify"] = get_timestamp() data["last_modify"] = get_timestamp()
return algodata return algodata
@@ -176,9 +179,14 @@ class FSRSAlgorithm(BaseAlgorithm):
feedback (int): 0-5 的记忆保留率量化参数 feedback (int): 0-5 的记忆保留率量化参数
is_new_activation: 是否为全新激活(重置为初始状态) is_new_activation: 是否为全新激活(重置为初始状态)
""" """
logger.debug(
"FSRS.revisor 开始, feedback: %d, is_new_activation: %s",
feedback,
is_new_activation,
)
if feedback == -1: if feedback == -1:
logger.debug("feedback = -1, update skipped") logger.debug("feedback -1, 跳过更新")
return return
scheduler = _get_global_scheduler() scheduler = _get_global_scheduler()
@@ -186,7 +194,7 @@ class FSRSAlgorithm(BaseAlgorithm):
if is_new_activation: if is_new_activation:
card = Card() card = Card()
logger.debug("New activation, create new Card") logger.debug("新激活,创建新 Card")
else: else:
card = cls._algodata_to_card(algodata) card = cls._algodata_to_card(algodata)
@@ -201,7 +209,8 @@ class FSRSAlgorithm(BaseAlgorithm):
algodata[cls.algo_name]["rept"] += 1 algodata[cls.algo_name]["rept"] += 1
logger.debug( logger.debug(
"FSRS.revisor finished: stability=%s, difficulty=%s, state=%s, " "next_date=%d", "FSRS.revisor 完成: stability=%s, difficulty=%s, state=%s, "
"next_date=%d",
card.stability, card.stability,
card.difficulty, card.difficulty,
card.state, card.state,
+3 -4
View File
@@ -10,7 +10,7 @@ logger = get_logger(__name__)
class NSP0Algorithm(BaseAlgorithm): class NSP0Algorithm(BaseAlgorithm):
algo_name = "NSP-0" algo_name = "NSP-0"
desc = "快速筛选用非间隔重复调度器" desc = "快速筛选用特殊调度器"
class AlgodataDict(TypedDict): class AlgodataDict(TypedDict):
real_rept: int real_rept: int
@@ -51,10 +51,9 @@ class NSP0Algorithm(BaseAlgorithm):
) )
if feedback == -1: if feedback == -1:
logger.debug("feedback = -1, update skipped") logger.debug("feedback -1, 跳过更新")
return return
algodata[cls.algo_name]["interval"] = 1 if feedback <= 3 else float("inf") algodata[cls.algo_name]["interval"] = 1 if feedback <= 3 else float("inf")
if not algodata[cls.algo_name]["important"]:
algodata[cls.algo_name]["important"] = ( algodata[cls.algo_name]["important"] = (
1 if feedback <= 3 else algodata[cls.algo_name]["important"] 1 if feedback <= 3 else algodata[cls.algo_name]["important"]
) )
@@ -65,7 +64,7 @@ class NSP0Algorithm(BaseAlgorithm):
algodata[cls.algo_name]["last_modify"] = timer.get_timestamp() algodata[cls.algo_name]["last_modify"] = timer.get_timestamp()
logger.debug( logger.debug(
"Update date: last_date=%d, next_date=%d, last_modify=%f", "更新日期: last_date=%d, next_date=%d, last_modify=%f",
algodata[cls.algo_name]["last_date"], algodata[cls.algo_name]["last_date"],
algodata[cls.algo_name]["next_date"], algodata[cls.algo_name]["next_date"],
algodata[cls.algo_name]["last_modify"], algodata[cls.algo_name]["last_modify"],
+18 -20
View File
@@ -4,7 +4,6 @@ SM-15M — 基于 sm.js 的间隔重复算法
基于: https://github.com/slaypni/sm.js 基于: https://github.com/slaypni/sm.js
原始 CoffeeScript (c) 2014 Kazuaki Tanida, MIT 许可证 原始 CoffeeScript (c) 2014 Kazuaki Tanida, MIT 许可证
""" """
import datetime import datetime
import json import json
import math import math
@@ -20,6 +19,7 @@ from heurams.services.timer import (
get_timestamp_ms, get_timestamp_ms,
daystamp_to_datetime, daystamp_to_datetime,
datetime_to_daystamp, datetime_to_daystamp,
get_now_datetime,
) )
from .base import BaseAlgorithm from .base import BaseAlgorithm
@@ -253,9 +253,9 @@ class ForgettingCurves:
pts = [] pts = []
for i in range(21): for i in range(21):
v = MIN_AF + NOTCH_AF * i v = MIN_AF + NOTCH_AF * i
y = math.exp(-1.0 / (10 + 1 * (a + 1)) * (i - a**0.6)) * ( y = math.exp(
self.REMEMBERED - self.sm.requested_fi -1.0 / (10 + 1 * (a + 1)) * (i - a ** 0.6)
) ) * (self.REMEMBERED - self.sm.requested_fi)
pts.append([v, min(self.REMEMBERED, y)]) pts.append([v, min(self.REMEMBERED, y)])
partial = [[0, self.REMEMBERED]] + pts partial = [[0, self.REMEMBERED]] + pts
row.append(ForgettingCurve(partial)) row.append(ForgettingCurve(partial))
@@ -427,9 +427,7 @@ class Item:
now = datetime.datetime.now() now = datetime.datetime.now()
af_idx = self.lapse if self.repetition == 0 else self.af_index() af_idx = self.lapse if self.repetition == 0 else self.af_index()
of_val = self.sm.ofm.of(self.repetition, af_idx) of_val = self.sm.ofm.of(self.repetition, af_idx)
self.of = max( self.of = max(1.0, (of_val - 1) * (self.interval(now) / self.optimum_interval) + 1)
1.0, (of_val - 1) * (self.interval(now) / self.optimum_interval) + 1
)
self.optimum_interval = round(self.optimum_interval * self.of) self.optimum_interval = round(self.optimum_interval * self.of)
self.previous_date = now self.previous_date = now
self.due_date = now + datetime.timedelta(milliseconds=self.optimum_interval) self.due_date = now + datetime.timedelta(milliseconds=self.optimum_interval)
@@ -602,10 +600,9 @@ class SM:
# Global state management # Global state management
# ============================================================================ # ============================================================================
_GLOBAL_STATE_FILE = ( _GLOBAL_STATE_FILE = pathlib.Path(
pathlib.Path(config_var.get()["global"]["paths"]["misc"]) config_var.get()["global"]["paths"]["data"]
/ "sm15m_global_state.json" ) / "global" / "sm15m_global_state.json"
)
def _get_global_sm(): def _get_global_sm():
@@ -614,7 +611,7 @@ def _get_global_sm():
with open(_GLOBAL_STATE_FILE, "r", encoding="utf-8") as f: with open(_GLOBAL_STATE_FILE, "r", encoding="utf-8") as f:
return SM.load(json.load(f)) return SM.load(json.load(f))
except Exception: except Exception:
logger.warning("Failed to load SM-15M global state file, creating new instance") logger.warning("SM-15M 全局状态文件加载失败,创建新实例")
sm = SM() sm = SM()
_save_global_sm(sm) _save_global_sm(sm)
return sm return sm
@@ -626,7 +623,7 @@ def _save_global_sm(sm):
with open(_GLOBAL_STATE_FILE, "w", encoding="utf-8") as f: with open(_GLOBAL_STATE_FILE, "w", encoding="utf-8") as f:
json.dump(sm.data(), f, indent=2) json.dump(sm.data(), f, indent=2)
except Exception: except Exception:
logger.error("Failed to save SM-15M global state") logger.exception("SM-15M 全局状态保存失败")
# ============================================================================ # ============================================================================
@@ -649,7 +646,7 @@ class SM15MAlgorithm(BaseAlgorithm):
# 毫秒精度(子日排程) # 毫秒精度(子日排程)
last_date_ms: int last_date_ms: int
next_date_ms: int next_date_ms: int
# BaseAlgorithm 兼容(天精度, 向后兼容) # BaseAlgorithm 兼容(天精度向后兼容)
real_rept: int real_rept: int
rept: int rept: int
interval: int interval: int
@@ -697,7 +694,7 @@ class SM15MAlgorithm(BaseAlgorithm):
opt_days * 24 * 60 * 60 * 1000 if opt_days > 0 else sm.interval_base opt_days * 24 * 60 * 60 * 1000 if opt_days > 0 else sm.interval_base
) )
# 毫秒精度优先, 退化至天精度 # 毫秒精度优先退化至天精度
last_date_ms = data.get("last_date_ms", 0) last_date_ms = data.get("last_date_ms", 0)
if last_date_ms: if last_date_ms:
item.previous_date = datetime.datetime(1970, 1, 1) + datetime.timedelta( item.previous_date = datetime.datetime(1970, 1, 1) + datetime.timedelta(
@@ -707,8 +704,7 @@ class SM15MAlgorithm(BaseAlgorithm):
last_date = data.get("last_date", 0) last_date = data.get("last_date", 0)
item.previous_date = ( item.previous_date = (
daystamp_to_datetime(last_date).replace(tzinfo=None) daystamp_to_datetime(last_date).replace(tzinfo=None)
if last_date > 0 if last_date > 0 else None
else None
) )
next_date_ms = data.get("next_date_ms", 0) next_date_ms = data.get("next_date_ms", 0)
@@ -749,7 +745,9 @@ class SM15MAlgorithm(BaseAlgorithm):
data["last_date"] = datetime_to_daystamp(item.previous_date) data["last_date"] = datetime_to_daystamp(item.previous_date)
data["next_date_ms"] = int(item.due_date.timestamp() * 1000) data["next_date_ms"] = int(item.due_date.timestamp() * 1000)
data["next_date"] = datetime_to_daystamp(item.due_date) data["next_date"] = datetime_to_daystamp(item.due_date)
data["interval"] = max(0, data["next_date"] - (data.get("last_date", 0) or 0)) data["interval"] = max(
0, data["next_date"] - (data.get("last_date", 0) or 0)
)
data["last_modify"] = get_timestamp() data["last_modify"] = get_timestamp()
return algodata return algodata
@@ -758,7 +756,7 @@ class SM15MAlgorithm(BaseAlgorithm):
cls, algodata: dict, feedback: int = 5, is_new_activation: bool = False cls, algodata: dict, feedback: int = 5, is_new_activation: bool = False
): ):
logger.debug( logger.debug(
"SM-15M.revisor, feedback=%d, is_new_activation=%s", "SM-15M.revisor 开始, feedback=%d, is_new_activation=%s",
feedback, feedback,
is_new_activation, is_new_activation,
) )
@@ -788,7 +786,7 @@ class SM15MAlgorithm(BaseAlgorithm):
algodata[cls.algo_name]["rept"] += 1 algodata[cls.algo_name]["rept"] += 1
logger.debug( logger.debug(
"SM-15M.revisor: repetition=%d, of=%.4f, next_date=%d", "SM-15M.revisor 完成: repetition=%d, of=%.4f, next_date=%d",
item.repetition, item.repetition,
item.of, item.of,
algodata[cls.algo_name]["next_date"], algodata[cls.algo_name]["next_date"],
+11 -11
View File
@@ -10,7 +10,7 @@ logger = get_logger(__name__)
class SM2Algorithm(BaseAlgorithm): class SM2Algorithm(BaseAlgorithm):
algo_name = "SM-2" algo_name = "SM-2"
desc = "SuperMemo2 (1987) 简单间隔重复调度器" desc = "经典间隔重复算法"
class AlgodataDict(TypedDict): class AlgodataDict(TypedDict):
efactor: float efactor: float
@@ -45,13 +45,13 @@ class SM2Algorithm(BaseAlgorithm):
quality (int): 记忆保留率量化参数 quality (int): 记忆保留率量化参数
""" """
logger.debug( logger.debug(
"SM2.revisor, feedback: %d, is_new_activation: %s", "SM2.revisor 开始, feedback: %d, is_new_activation: %s",
feedback, feedback,
is_new_activation, is_new_activation,
) )
if feedback == -1: if feedback == -1:
logger.debug("feedback = -1, update skipped") logger.debug("feedback -1, 跳过更新")
return return
algodata[cls.algo_name]["efactor"] = algodata[cls.algo_name]["efactor"] + ( algodata[cls.algo_name]["efactor"] = algodata[cls.algo_name]["efactor"] + (
@@ -60,7 +60,7 @@ class SM2Algorithm(BaseAlgorithm):
algodata[cls.algo_name]["efactor"] = max( algodata[cls.algo_name]["efactor"] = max(
1.3, algodata[cls.algo_name]["efactor"] 1.3, algodata[cls.algo_name]["efactor"]
) )
logger.debug("Update efactor: %f", algodata[cls.algo_name]["efactor"]) logger.debug("更新 efactor: %f", algodata[cls.algo_name]["efactor"])
if feedback < 3: if feedback < 3:
algodata[cls.algo_name]["rept"] = 0 algodata[cls.algo_name]["rept"] = 0
@@ -68,28 +68,28 @@ class SM2Algorithm(BaseAlgorithm):
logger.debug("feedback < 3, 重置 rept 和 interval") logger.debug("feedback < 3, 重置 rept 和 interval")
else: else:
algodata[cls.algo_name]["rept"] += 1 algodata[cls.algo_name]["rept"] += 1
logger.debug("Increase rept: %d", algodata[cls.algo_name]["rept"]) logger.debug("递增 rept: %d", algodata[cls.algo_name]["rept"])
algodata[cls.algo_name]["real_rept"] += 1 algodata[cls.algo_name]["real_rept"] += 1
logger.debug("Increase real_rept: %d", algodata[cls.algo_name]["real_rept"]) logger.debug("递增 real_rept: %d", algodata[cls.algo_name]["real_rept"])
if is_new_activation: if is_new_activation:
algodata[cls.algo_name]["rept"] = 0 algodata[cls.algo_name]["rept"] = 0
algodata[cls.algo_name]["efactor"] = 2.5 algodata[cls.algo_name]["efactor"] = 2.5
logger.debug("New activation, reset rept and efactor") logger.debug("新激活, 重置 rept efactor")
if algodata[cls.algo_name]["rept"] == 0: if algodata[cls.algo_name]["rept"] == 0:
algodata[cls.algo_name]["interval"] = 1 algodata[cls.algo_name]["interval"] = 1
logger.debug("rept=0, set interval=1") logger.debug("rept=0, 设置 interval=1")
elif algodata[cls.algo_name]["rept"] == 1: elif algodata[cls.algo_name]["rept"] == 1:
algodata[cls.algo_name]["interval"] = 6 algodata[cls.algo_name]["interval"] = 6
logger.debug("rept=1, set interval=6") logger.debug("rept=1, 设置 interval=6")
else: else:
algodata[cls.algo_name]["interval"] = round( algodata[cls.algo_name]["interval"] = round(
algodata[cls.algo_name]["interval"] * algodata[cls.algo_name]["efactor"] algodata[cls.algo_name]["interval"] * algodata[cls.algo_name]["efactor"]
) )
logger.debug( logger.debug(
"rept>1, providing interval: %d", algodata[cls.algo_name]["interval"] "rept>1, 计算 interval: %d", algodata[cls.algo_name]["interval"]
) )
algodata[cls.algo_name]["last_date"] = timer.get_daystamp() algodata[cls.algo_name]["last_date"] = timer.get_daystamp()
@@ -99,7 +99,7 @@ class SM2Algorithm(BaseAlgorithm):
algodata[cls.algo_name]["last_modify"] = timer.get_timestamp() algodata[cls.algo_name]["last_modify"] = timer.get_timestamp()
logger.debug( logger.debug(
"Update date: last_date=%d, next_date=%d, last_modify=%f", "更新日期: last_date=%d, next_date=%d, last_modify=%f",
algodata[cls.algo_name]["last_date"], algodata[cls.algo_name]["last_date"],
algodata[cls.algo_name]["next_date"], algodata[cls.algo_name]["next_date"],
algodata[cls.algo_name]["last_modify"], algodata[cls.algo_name]["last_modify"],
+3 -3
View File
@@ -63,7 +63,7 @@ class Atom:
) )
def lock(self, locked=-1): def lock(self, locked=-1):
logger.debug(f"Lock atom: {locked}") logger.debug(f"锁定参数 {locked}")
"""锁定, 效果等同于 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
@@ -80,13 +80,13 @@ class Atom:
PuzzleWidget handler 除了测试, 严禁直接执行 Electron revisor 函数, 否则造成逻辑混乱 PuzzleWidget handler 除了测试, 严禁直接执行 Electron revisor 函数, 否则造成逻辑混乱
""" """
if self.registry["runtime"]["locked"]: if self.registry["runtime"]["locked"]:
logger.debug(f"Rating allowed: {self.registry['runtime']['min_rate']}") logger.debug(f"允许总评分: {self.registry['runtime']['min_rate']}")
self.registry["electron"].revisor( self.registry["electron"].revisor(
self.registry["runtime"]["min_rate"], self.registry["runtime"]["min_rate"],
is_new_activation=self.registry["runtime"]["new_activation"], is_new_activation=self.registry["runtime"]["new_activation"],
) )
else: else:
logger.debug("Rating disallowed") logger.debug("禁止总评分")
def __getitem__(self, key): def __getitem__(self, key):
return self.registry[key] return self.registry[key]
+4 -2
View File
@@ -8,7 +8,9 @@ class BasePuzzle:
"""谜题基类""" """谜题基类"""
def refresh(self): def refresh(self):
raise NotImplementedError("Method refresh not implemented") logger.debug("BasePuzzle.refresh 被调用(未实现)")
raise NotImplementedError("谜题对象未实现 refresh 方法")
def __str__(self): def __str__(self):
return f"Puzzle: {type(self).__name__}" logger.debug("BasePuzzle.__str__ 被调用")
return f"谜题: {type(self).__name__}"
+7 -6
View File
@@ -27,20 +27,20 @@ class ClozePuzzle(BasePuzzle):
self.wording = "填空题 - 尚未刷新谜题" self.wording = "填空题 - 尚未刷新谜题"
self.answer = ["填空题 - 尚未刷新谜题"] self.answer = ["填空题 - 尚未刷新谜题"]
self.delimiter = delimiter self.delimiter = delimiter
logger.debug("ClozePuzzle inited") logger.debug("ClozePuzzle 初始化完成")
def refresh(self): # 刷新谜题 def refresh(self): # 刷新谜题
logger.debug("ClozePuzzle.refresh") logger.debug("ClozePuzzle.refresh 开始")
placeholder = "___SLASH___" placeholder = "___SLASH___"
tmp_text = self.text.replace(self.delimiter, placeholder) tmp_text = self.text.replace(self.delimiter, placeholder)
words = tmp_text.split(placeholder) words = tmp_text.split(placeholder)
if not words: if not words:
logger.warning("ClozePuzzle.refresh: nothing to proceed") logger.warning("ClozePuzzle.refresh: 无单词可处理")
return return
words = [word for word in words if word] words = [word for word in words if word]
logger.debug("ClozePuzzle.refresh: %d words splited", len(words)) logger.debug("ClozePuzzle.refresh: 分割出 %d 个单词", len(words))
num_blanks = min(max(1, len(words) // self.min_denominator), len(words)) num_blanks = min(max(1, len(words) // self.min_denominator), len(words))
logger.debug("ClozePuzzle.refresh: %d blank required", num_blanks) logger.debug("ClozePuzzle.refresh: 需要生成 %d 个填空", num_blanks)
indices_to_blank = random.sample(range(len(words)), num_blanks) indices_to_blank = random.sample(range(len(words)), num_blanks)
indices_to_blank.sort() indices_to_blank.sort()
blanked_words = list(words) blanked_words = list(words)
@@ -50,7 +50,8 @@ class ClozePuzzle(BasePuzzle):
answer.append(words[index]) answer.append(words[index])
self.answer = answer self.answer = answer
self.wording = "".join(blanked_words) self.wording = "".join(blanked_words)
logger.debug("ClozePuzzle.refresh, %d blanks generated", len(answer)) logger.debug("ClozePuzzle.refresh 完成, 生成 %d 个填空", len(answer))
def __str__(self): def __str__(self):
logger.debug("ClozePuzzle.__str__ 被调用")
return f"{self.wording}\n{str(self.answer)}" return f"{self.wording}\n{str(self.answer)}"
+3 -3
View File
@@ -65,8 +65,8 @@ class MCQPuzzle(BasePuzzle):
jammer: 传入的干扰项列表 jammer: 传入的干扰项列表
""" """
# 合并正确答案和传入的干扰项, 并去重 # 合并正确答案和传入的干扰项, 并去重
logger.debug(f"Answer table: {self.mapping}, {type(self.mapping)}") logger.debug(f"答案映射: {self.mapping}, {type(self.mapping)}")
logger.debug(f"Jammers: {jammer}, {type(jammer)}") logger.debug(f"干扰项: {jammer}, {type(jammer)}")
unique_jammers = set(jammer + list(self.mapping.values())) unique_jammers = set(jammer + list(self.mapping.values()))
self.jammer = list(unique_jammers) self.jammer = list(unique_jammers)
@@ -94,7 +94,7 @@ class MCQPuzzle(BasePuzzle):
Raises: Raises:
ValueError: 当mapping为空时不会抛出异常, 但会设置空谜题状态 ValueError: 当mapping为空时不会抛出异常, 但会设置空谜题状态
""" """
logger.debug("MCQPuzzle.refresh, mapping size=%d", len(self.mapping)) logger.debug("MCQPuzzle.refresh 开始, mapping size=%d", len(self.mapping))
if not self.mapping: if not self.mapping:
self._set_empty_puzzle() self._set_empty_puzzle()
return return

Some files were not shown because too many files have changed in this diff Show More