refactor: fold materials/ into actions/ (actions = workspace: prompts + templates + tools + materials)
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
# actions/ — 动作总览
|
||||
# actions/ — 工作台总览
|
||||
|
||||
`actions/` 是我(助手/大模型)在不同环节要执行的**动作**。每个文件一段「粘贴区」(代码块),可直接发给对应模型。
|
||||
`actions/` 是**工作台**:指令(提示词)+ 模板 + 工具 + 素材都在这里。
|
||||
- **指令**(`00`–`04`):每份含一段「粘贴区」,可直接发给对应模型。
|
||||
- **模板**:`_material-template.md` / `_session-template.md` / `_case-template.md`。
|
||||
- **工具**:`langdb.py`(读写 `me/lang.db`)、`build_dashboard.py`(渲染仪表盘)、`pdf_extract.py`(PDF→素材)。
|
||||
- **素材/示例**:`2026-10-14-*.md`(真实素材与示例)。
|
||||
|
||||
## 模型分工
|
||||
|
||||
@@ -23,13 +27,13 @@
|
||||
|
||||
### 模式 1 · 听写复述(`01`)
|
||||
1. 每日英语听力 APP 选材料,听 2–3 遍。(**材料你自己选,我不过问**)
|
||||
2. 原文**截图 / PDF** 发我 → 我转文字存 `materials/`。
|
||||
2. 原文**截图 / PDF** 发我 → 我转文字存 `actions/`。
|
||||
3. 把 `01-listen-retell.md` 粘贴区发给 DeepSeek,按阶段 0→3 走。
|
||||
4. 结果存 `logs/`;新词条(带掌握状态)汇成 JSON,经 `materials/langdb.py ingest` 写入 `me/lang.db`。
|
||||
4. 结果存 `logs/`;新词条(带掌握状态)汇成 JSON,经 `actions/langdb.py ingest` 写入 `me/lang.db`。
|
||||
|
||||
### 模式 2 · 场景训练(`02`)
|
||||
1. 你给案例,或只给想练的主题 / 词。(**选场景是这里才用到我**)
|
||||
2. 我从 `me/lang.db` 挑该练的词,选一个让它们自然出现的场景,写好豆包提示词存 `materials/`。
|
||||
2. 我从 `me/lang.db` 挑该练的词,选一个让它们自然出现的场景,写好豆包提示词存 `actions/`。
|
||||
3. 你把提示词发给**豆包**,开始语音对话。
|
||||
4. 对话重点发我 → 经 ingest 更新 `me/lang.db`(items / grammar_fixes / skills / training_log)。
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
**用途**:一个材料,听 2–3 遍 → 用英文复述写 **v1** → 看原文 → 改出 **v2** → 大声读。综合训练四维。
|
||||
|
||||
- **发给**:DeepSeek V4.1 PRO。
|
||||
- **素材**:每日英语听力 APP;原文截图发我转文字,存 `materials/`,再贴进本流程。
|
||||
- **素材**:每日英语听力 APP;原文截图发我转文字,存 `actions/`,再贴进本流程。
|
||||
|
||||
> 设计要点:不做逐句听写,做"两版法"——先凭听懂复述,再对照原文修订。
|
||||
|
||||
@@ -71,6 +71,6 @@
|
||||
|
||||
## 收尾落盘
|
||||
|
||||
1. 把 v1、v2、差异清单、报告存成 `logs/YYYY-MM-DD-lr-XX.md`(用 `materials/_session-template.md`)。
|
||||
2. 把【新词条 JSON】与【语法修正 JSON】交给 `materials/langdb.py ingest`,写入 `me/lang.db`(`items` / `grammar_fixes`)。
|
||||
3. 看状态:`python materials/build_dashboard.py`。
|
||||
1. 把 v1、v2、差异清单、报告存成 `logs/YYYY-MM-DD-lr-XX.md`(用 `actions/_session-template.md`)。
|
||||
2. 把【新词条 JSON】与【语法修正 JSON】交给 `actions/langdb.py ingest`,写入 `me/lang.db`(`items` / `grammar_fixes`)。
|
||||
3. 看状态:`python actions/build_dashboard.py`。
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
但在场景训练里,我会把你**待学的词汇 / 表达**织进场景,并**据此挑选适合的场景**——不是随便挑,而是让该练的词自然出现。
|
||||
|
||||
- **发给**:豆包(语音);提示词由我生成。
|
||||
- **产出**:`materials/YYYY-MM-DD-<slug>.md`(场景提示词=备选素材,放 `materials/`)
|
||||
- **产出**:`actions/YYYY-MM-DD-<slug>.md`(场景提示词=备选素材,放 `actions/`)
|
||||
|
||||
---
|
||||
|
||||
@@ -31,7 +31,7 @@ Rules:
|
||||
|
||||
输入来源二选一:
|
||||
|
||||
- **A. 你给案例**:按 `materials/_case-template.md` 填,或直接口述,我帮你补全。
|
||||
- **A. 你给案例**:按 `actions/_case-template.md` 填,或直接口述,我帮你补全。
|
||||
- **B. 你只给主题 / 想练的词**:我从 `me/lang.db` 的 `items` 表里挑当前该练的条目,据此选场景。
|
||||
|
||||
选词优先级(B):
|
||||
@@ -109,7 +109,7 @@ Start by greeting me in character.
|
||||
| 待学词(来自 `me/lang.db`) | `Phrases I should try to use` |
|
||||
| 难度旋钮(语速/复杂度/刁难) | 并入 `Rules` |
|
||||
|
||||
产出存 `materials/YYYY-MM-DD-<slug>.md`,格式见根 `README.md` 的「素材与场景怎么进来」。
|
||||
产出存 `actions/YYYY-MM-DD-<slug>.md`,格式见根 `README.md` 的「素材与场景怎么进来」。
|
||||
|
||||
---
|
||||
|
||||
@@ -140,6 +140,6 @@ Start by asking me what I want to talk about today. Keep the conversation going
|
||||
## 五、收尾落盘
|
||||
|
||||
- 豆包的报告重点 → `logs/YYYY-MM-DD-sc-XX.md`
|
||||
- 新表达(带 `status` / `first` / `fix`)与语法错误(概括成 issue、去重)→ 汇成 JSON,经 `materials/langdb.py ingest` 写入 `me/lang.db`(`items` / `grammar_fixes`)
|
||||
- 新表达(带 `status` / `first` / `fix`)与语法错误(概括成 issue、去重)→ 汇成 JSON,经 `actions/langdb.py ingest` 写入 `me/lang.db`(`items` / `grammar_fixes`)
|
||||
- 听说表现 → 写入 `me/lang.db` 的 `skills` / `training_log` 表
|
||||
- 更新根 `README.md` 场景库的「用到次数」
|
||||
|
||||
@@ -44,8 +44,8 @@
|
||||
|
||||
## 收尾落盘
|
||||
|
||||
把返回的 JSON 交给 `materials/langdb.py ingest`,更新 `me/lang.db` 对应行(`status` / `fix` / `hits` / `streak` / `next_review`)。可选:记一条 `logs/YYYY-MM-DD-rv-XX.md`。
|
||||
把返回的 JSON 交给 `actions/langdb.py ingest`,更新 `me/lang.db` 对应行(`status` / `fix` / `hits` / `streak` / `next_review`)。可选:记一条 `logs/YYYY-MM-DD-rv-XX.md`。
|
||||
|
||||
## 取到期条目的土办法(暂未写脚本)
|
||||
|
||||
在库里按 `next_review` 排序,挑 `next_review <= 今天` 的行贴给模型即可。日后由 `materials/stats.py` 自动完成。
|
||||
在库里按 `next_review` 排序,挑 `next_review <= 今天` 的行贴给模型即可。日后由 `actions/stats.py` 自动完成。
|
||||
|
||||
@@ -43,4 +43,4 @@
|
||||
|
||||
## 收尾落盘
|
||||
|
||||
把 4、5 的输出汇成 JSON,经 `materials/langdb.py ingest` 写入 `me/lang.db`(`training_log` / `skills` / `level_history`)。
|
||||
把 4、5 的输出汇成 JSON,经 `actions/langdb.py ingest` 写入 `me/lang.db`(`training_log` / `skills` / `level_history`)。
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
# Scenario — 2026-10-14 · airport-car-rental(机场取车)
|
||||
|
||||
- **来源**:用户提供 · 每日英语听力 APP 情景课(截图)
|
||||
- **模式**:2 场景训练
|
||||
- **发送给**:豆包(语音)
|
||||
- **我的等级**:CEFR A2+(听 A2+ / 说 A2)
|
||||
|
||||
---
|
||||
|
||||
## 案例原貌(APP 内容,供参考)
|
||||
|
||||
**场景**:在机场顺利取到预定的车辆 · 标签:机场 / 取车 / 预定
|
||||
|
||||
**① 预订信息询问**
|
||||
- Could you please provide your booking reference number?
|
||||
- What is the name on the rental agreement?
|
||||
- When is your planned pick-up time at the airport?
|
||||
- Do you have any additional requests for your rental car?
|
||||
|
||||
**② 完成取车手续**
|
||||
- Please show your identification and credit card.
|
||||
- You need to sign here on the agreement.
|
||||
- Here is your map and the checklist for the car.
|
||||
- The fuel policy is explained in the documentation.
|
||||
|
||||
**③ 车辆使用注意事项**
|
||||
- Remember to refuel before returning the car.
|
||||
- Please follow the instructions for collision damage waiver (CDW).
|
||||
- Keep this reference number for returning the car.
|
||||
- Make sure to return the car at the agreed return time.
|
||||
|
||||
**④ 确认车辆状况无误**
|
||||
- Please check the car for any existing damage.
|
||||
- Sign here to confirm the car's condition.
|
||||
- If there's any issue, please let us know before driving off.
|
||||
- Enjoy your holiday with the rental car!
|
||||
|
||||
**专业词汇**:credit card 信用卡;airport 机场(空港)
|
||||
|
||||
> 注:APP 给的多是**柜台工作人员**的台词。你要练的是**顾客一侧**的回答与主动提问,所以下面的交流点按"顾客要做的事"来设计。
|
||||
|
||||
---
|
||||
|
||||
## 最终提示词(整段复制给豆包)
|
||||
|
||||
```
|
||||
You are my English speaking partner in a role-play. Speak English with me through voice.
|
||||
|
||||
【Setting】I just landed at an airport and I'm at the rental car counter to pick up a car I reserved.
|
||||
【Your role】the rental car agent behind the counter
|
||||
【My role】the customer picking up the reserved car
|
||||
【My goal】get the car smoothly, understand the fuel policy and the insurance, and check the car before driving off
|
||||
【My level】CEFR A2+ (listening A2+, speaking A2). Use short sentences and easy words, slightly above my level. Speak slowly and clearly.
|
||||
|
||||
【Tasks I must complete (checkpoints)】
|
||||
1. Give my booking information: booking reference number, the name on the agreement, and my planned pick-up time.
|
||||
2. Mention any additional requests for the car (e.g. child seat, GPS, an extra driver).
|
||||
3. Finish the paperwork: show my ID and credit card, and sign the agreement.
|
||||
4. Ask you about the fuel policy and the collision damage waiver (CDW).
|
||||
5. Check the car for any existing damage and report anything I find.
|
||||
6. Confirm the return time and any return rules, then thank you and leave.
|
||||
|
||||
【Phrases I should try to use or understand】
|
||||
"booking reference number", "the name on the rental agreement", "pick-up time",
|
||||
"additional requests", "identification and credit card", "sign here",
|
||||
"fuel policy", "collision damage waiver (CDW)", "refuel before returning",
|
||||
"existing damage", "return the car at the agreed time", "before driving off".
|
||||
|
||||
【Rules】
|
||||
- Stay in character as the agent. Keep your turns to 1–2 short sentences, then wait for me.
|
||||
- Guide me through the checkpoints naturally; don't announce them as a list.
|
||||
- I may ask you questions or ask for clarification — answer normally, in character.
|
||||
- Correct me gently by repeating my sentence correctly (recast). Do NOT lecture during the talk.
|
||||
- If I'm stuck, give a short hint in easy English.
|
||||
- You may add small realistic complications (the car isn't ready yet, they only have a bigger car, you need a second ID), as long as it stays natural.
|
||||
|
||||
【When I say "wrap up" or all checkpoints are done】
|
||||
In Chinese, give me a report:
|
||||
- Checkpoints completed (✓/✗ one by one)
|
||||
- Speaking score 1–5 + estimated CEFR; listening performance
|
||||
- My top 3 errors + correct versions
|
||||
- Useful phrases for this scenario that I missed
|
||||
- New items as JSON (mark my mastery state: I said it correctly on my own → status "known", first "v1"; I only said it after your hint → "learning", first "v2"; I got it wrong → "fix" with "✗ wrong → ✓ right"):
|
||||
{"id":"e-0000","item":"...","level":"B1","meaning":"...","function":"...","context":"...","status":"known|learning|fix","first":"v1|v2","fix":"","tags":"...","source":"2026-10-14-airport-car-rental","added":"YYYY-MM-DD","hits":0,"streak":0,"next_review":"YYYY-MM-DD"}
|
||||
|
||||
Start by greeting me in character at the counter.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 收尾
|
||||
|
||||
- 对话后把豆包的报告发我 → 归档 `logs/YYYY-MM-DD-sc-01.md`。
|
||||
- 新表达与专业词(带 `status`/`first`/`fix`)经 ingest 写入 `me/lang.db` 的 `items` 表(`kind`=expression / word / phrase)。
|
||||
- 练完更新根 `README.md` 场景库的「用到次数」。
|
||||
@@ -0,0 +1,22 @@
|
||||
# Material — 2026-10-14 · economist-democratic-party
|
||||
|
||||
- **source**: 每日英语听力 APP · 外刊精读(The Economist)
|
||||
- **level**: 待定(自评偏 B2/C1,听力表现预计 A2)
|
||||
- **duration**: 待补
|
||||
- **screenshot**: 用户提供(未存盘)
|
||||
|
||||
---
|
||||
|
||||
## 原文
|
||||
|
||||
> ⚠️ **待补全**:截图正文分辨率不足,我只能可靠读出标题,正文无法保证准确转录。
|
||||
>
|
||||
> **标题(可确认)**:
|
||||
> **Unsolicited Advice: Can the Democratic Party move fast and fix things?**
|
||||
>
|
||||
> 请按栏目/段落**放大重发截图**(一次 1–2 屏),我再补全转录。
|
||||
|
||||
## 备注
|
||||
|
||||
- 若只是示范素材来源,无需转录,可直接用 APP 练习。
|
||||
- 本素材若使用,走模式 1(`actions/01-listen-retell.md`)。
|
||||
@@ -0,0 +1,86 @@
|
||||
# Session — 2026-10-14 · listen-retell · lost-keys
|
||||
|
||||
> 示例文件,演示一次线 A 训练长什么样。可删。
|
||||
|
||||
- **type**: listen-retell
|
||||
- **material level**: A2+
|
||||
- **source**: LLM 生成
|
||||
- **duration**: 35
|
||||
- **audio**: TTS 播放 2 遍
|
||||
|
||||
---
|
||||
|
||||
## 材料 / 原文
|
||||
|
||||
> Tom got home late last night. He put his bag on the table and went to the kitchen for a glass of water. When he came back, he couldn't find his keys. He looked under the sofa, checked his coat, and even searched the bathroom. Nothing. Then he remembered: he had left them in the front door. He laughed at himself, took the keys, and finally went to bed.
|
||||
|
||||
## v1(凭听复述)
|
||||
|
||||
Tom came home late. He put his bag and went to kitchen. After, he can not find his key. He look under sofa, check coat, and search bathroom. But nothing. Then he remember — he leave it in the front door. He laugh and go to bed.
|
||||
|
||||
## 差异清单(v1 vs 原文)
|
||||
|
||||
- 漏掉:`a glass of water`(只说了去厨房)、`took the keys`。
|
||||
- 误解:几乎没有大误解,主线抓对了。
|
||||
- 可升级表达:
|
||||
- `he couldn't find` 而不是 `he can not find`(时态)
|
||||
- `He looked under the sofa` 而不是 `He look under sofa`(时态 + 冠词)
|
||||
- `he had left them`(过去完成时,v1 用成一般过去)
|
||||
- `He laughed at himself`(固定说法)
|
||||
|
||||
## v2(修订稿)
|
||||
|
||||
Tom came home late last night. He put his bag on the table and went to the kitchen for a glass of water. When he came back, he couldn't find his keys. He looked under the sofa, checked his coat, and even searched the bathroom, but there was nothing. Then he remembered that he had left them in the front door. He laughed at himself, took the keys, and finally went to bed.
|
||||
|
||||
## 朗读自评
|
||||
|
||||
- 卡顿处:`had left them` 连读不顺。
|
||||
- 发音没把握:`searched` /sɜːrtʃt/、`laughed` /læft/。
|
||||
|
||||
## 教练报告
|
||||
|
||||
| 维度 | 分数(1–5) | CEFR |
|
||||
|---|---|---|
|
||||
| 听力理解 | 4 | A2+ |
|
||||
| 写作 | 2.5 | A2 |
|
||||
| 阅读 | 4 | B1 |
|
||||
| 口语 | 3 | A2 |
|
||||
|
||||
- 最大问题:**时态**——故事类材料里一般过去/过去完成混用,v1 几乎全用原形。
|
||||
- 下一步:再练 1 次叙事类 A2+ 材料,重点练过去时;把 `look for / look into / laugh at oneself` 入库,并优先复习 `grammar_fixes` 表的时态问题(g-0001/0002)。
|
||||
|
||||
## 掌握状态分类
|
||||
|
||||
- v1 就正确用出(→ `known`):`Tom / came home / his bag / went to bed`(基础词,本轮不单独入库)
|
||||
- v2 才用出(→ `learning`):`laugh at oneself`、`there was nothing`
|
||||
- **语法错误**(→ `grammar_fixes` 表,概括成问题、去重):
|
||||
- 时态 g-0001:一般过去时用了原形 → `he go / he look`
|
||||
- 时态 g-0002:过去完成时漏用 → `he leave it`(应 `he had left them`)
|
||||
- 冠词 g-0003:单数可数名词漏冠词 → `under sofa`(应 `under the sofa`)
|
||||
|
||||
> 这轮错的是**语法结构**(时态/冠词),不是词义——所以**不**在单词库为 go/look 建行,全部归到语法修正库。
|
||||
|
||||
## 新词条(JSON)
|
||||
|
||||
```json
|
||||
[
|
||||
{"id":"p-0005","item":"laugh at oneself","level":"B1","meaning":"自嘲","context":"He laughed at himself for forgetting the keys.","status":"learning","first":"v2","fix":"","tags":"动词短语,情绪","source":"2026-10-14-example","added":"2026-10-14","hits":0,"streak":0,"next_review":"2026-10-15"},
|
||||
{"id":"e-0007","item":"there was nothing","level":"A2","meaning":"什么都没有","function":"转题","context":"I searched everywhere, but there was nothing.","status":"learning","first":"v2","fix":"","tags":"口语,叙述","source":"2026-10-14-example","added":"2026-10-14","hits":0,"streak":0,"next_review":"2026-10-15"}
|
||||
]
|
||||
```
|
||||
|
||||
## 语法修正(写入 `grammar_fixes` 表)
|
||||
|
||||
> 按**问题**登记、去重;同一问题只更新那一行。
|
||||
|
||||
```json
|
||||
[
|
||||
{"id":"g-0001","category":"时态","issue":"一般过去时用了动词原形","rule":"go→went, look→looked, check→checked","examples":"✗ he go → ✓ he went;✗ he look → ✓ he looked","status":"fix","count":1,"first":"2026-10-14","last":"2026-10-14","next_review":"2026-10-15"},
|
||||
{"id":"g-0002","category":"时态","issue":"过去完成时漏用","rule":"先发生的过去动作: had + p.p.","examples":"✗ he leave it → ✓ he had left them","status":"fix","count":1,"first":"2026-10-14","last":"2026-10-14","next_review":"2026-10-15"},
|
||||
{"id":"g-0003","category":"冠词","issue":"单数可数名词漏冠词","rule":"单数可数名词前加 a/the","examples":"✗ under sofa → ✓ under the sofa","status":"fix","count":1,"first":"2026-10-14","last":"2026-10-14","next_review":"2026-10-15"}
|
||||
]
|
||||
```
|
||||
|
||||
## 备注
|
||||
|
||||
环境安静,TTS 语速 0.9x。听完第 2 遍才开始写 v1。
|
||||
@@ -0,0 +1,68 @@
|
||||
# Material — 2026-10-14 · issue3-classic-meetings
|
||||
|
||||
- **source**: 用户 PDF · `第3期_classic.pdf` · 商务英语听力(会议)
|
||||
- **level**: 估 **B2**(商务语域,对当前听力 A2+ 偏难)
|
||||
- **duration**: 约 4–5 分钟
|
||||
- **pdf**: `C:\Users\HUAWEI\Desktop\第3期_classic.pdf`
|
||||
|
||||
---
|
||||
|
||||
## 原文
|
||||
|
||||
### A. 正式会议(formal meeting)
|
||||
|
||||
On behalf of Vision Corporation, I'd like to call this meeting to order.
|
||||
|
||||
This is a meeting of some of the key players in our company: our top managers.
|
||||
|
||||
Our purpose this morning is to hear a presentation about a new initiative for outreach and marketing, and to discuss this plan with all of you.
|
||||
|
||||
This is a presentation that all of us have looked forward to.
|
||||
|
||||
This initiative marks a new milestone in the evolution of our company.
|
||||
|
||||
First, it serves as an assessment of where our company is now in terms of communicating its message to its customers domestically and abroad.
|
||||
|
||||
Furthermore, this plan has the potential to drive our company forward by transforming our corporate outreach and marketing strategies.
|
||||
|
||||
We are delighted that all of the major contributors to this initiative are here today.
|
||||
|
||||
They will use their unique perspectives to talk about the current state of affairs in terms of outreach and marketing, give details about the new proposed initiative, and outline the path for implementation.
|
||||
|
||||
### B. 非正式会议(informal meeting · Alex)
|
||||
|
||||
Okay, everybody. Please take a seat. Let's get started.
|
||||
|
||||
I've called this meeting of our top salespeople so that all of you get a chance to hear about the new plan to get our company out there in order to reach more of our potential market.
|
||||
|
||||
First, we'll hear a presentation from the team that has been working on this.
|
||||
|
||||
Then, we'll discuss it to get your feedback and put our heads together to see if there are any other ideas.
|
||||
|
||||
While the team is getting set up, let me say a few words.
|
||||
|
||||
What does this new plan mean for our company?
|
||||
|
||||
First, it's a reality check on where we are right now in terms of getting our message to our customers.
|
||||
|
||||
Second, this plan has the potential to move the company forward.
|
||||
|
||||
One of our main challenges, as you all know, is staying relevant in this changing market.
|
||||
|
||||
Today's presentation has some really innovative ideas about how we can do this.
|
||||
|
||||
### C. 讲解 / 短语注释(原文附带)
|
||||
|
||||
- **take a seat** — 坐下(an informal way of asking people to sit down in their chairs)
|
||||
- **call the meeting to order** — 宣布会议开始(= get it started)
|
||||
- **get the company out there / to get something out there** — 让公众更熟悉某事物;被更多人注意到(make something more familiar to the public / get noticed by other people)
|
||||
- 例:A new website always wants to get its message out there so that people learn about it and begin to visit it.
|
||||
|
||||
---
|
||||
|
||||
## 备注
|
||||
|
||||
- 原 PDF 头部有 `ES3L Podcast ... 507` 的抽取残留,来源编号未能确认。
|
||||
- **预习生词(预计是主要听力障碍)**:outreach / milestone / assessment / domestically and abroad / corporate / implementation / reality check / staying relevant / put our heads together。
|
||||
- **建议**:走模式 1(`actions/01-listen-retell.md`)。材料按 B2 对待;听 2–3 遍 → 复述写 v1 → 对照原文 → v2 → 大声读。
|
||||
- 与模式 2 结合:可让豆包按"公司内部会议"场景做场景训练。
|
||||
@@ -0,0 +1,19 @@
|
||||
# Case — <场景名>
|
||||
|
||||
> 你把这份填好(或口述)发我,我据此生成豆包提示词。填不全也没关系,我帮你补。
|
||||
|
||||
- **场景 / 地点 / 情况**:
|
||||
- **对方身份(AI 演谁)**:
|
||||
- **我的身份**:
|
||||
- **我的目标**:
|
||||
- **必须完成的沟通任务(交流点,4–6 条)**:
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
4.
|
||||
- **难度旋钮**:
|
||||
- 语速:慢 / 中 / 快
|
||||
- 句子复杂度:简单 / 略高于我
|
||||
- 要不要故意制造小麻烦(售罄、听错、排队…):要 / 不要
|
||||
- **想练的表达 / 语法点(可选)**:
|
||||
- **备注**:
|
||||
@@ -0,0 +1,16 @@
|
||||
# Material — YYYY-MM-DD · <slug>
|
||||
|
||||
- **source**: 每日英语听力 APP · <栏目/节目名> / 用户 PDF
|
||||
- **level**: <CEFR>
|
||||
- **duration**: <音频时长>
|
||||
- **screenshot**: <actions/raw/xxx.png> 或 **pdf**: <路径>
|
||||
|
||||
---
|
||||
|
||||
## 原文
|
||||
|
||||
<转录后的英文原文>
|
||||
|
||||
## 备注
|
||||
|
||||
<生词预判、难度感受、练习重点>
|
||||
@@ -0,0 +1,62 @@
|
||||
# Session — YYYY-MM-DD · <type> · <slug>
|
||||
|
||||
- **type**: listen-retell | speaking | scenario | review | weekly-check
|
||||
- **material level**: <CEFR>
|
||||
- **source**: <链接/文件名/seed>
|
||||
- **duration**: <分钟>
|
||||
- **audio**: <有/无,TTS/真实>
|
||||
|
||||
---
|
||||
|
||||
## 材料 / 原文
|
||||
|
||||
> <粘贴原文,或注明出处>
|
||||
|
||||
## v1(凭听复述)
|
||||
|
||||
<第一版英文>
|
||||
|
||||
## 差异清单(v1 vs 原文)
|
||||
|
||||
- 漏掉:
|
||||
- 误解:
|
||||
- 可升级表达:
|
||||
|
||||
## 掌握状态分类
|
||||
|
||||
- v1 就正确用出(→ `known`):
|
||||
- v2 才用出(→ `learning`):
|
||||
- 用错待修正(→ `fix`):
|
||||
|
||||
## v2(修订稿)
|
||||
|
||||
<第二版英文>
|
||||
|
||||
## 朗读自评
|
||||
|
||||
- 卡顿处:
|
||||
- 发音没把握:
|
||||
|
||||
## 教练报告
|
||||
|
||||
| 维度 | 分数(1–5) | CEFR |
|
||||
|---|---|---|
|
||||
| 听力理解 | | |
|
||||
| 写作 | | |
|
||||
| 阅读 | | |
|
||||
| 口语 | | |
|
||||
|
||||
- 最大问题:
|
||||
- 下一步:
|
||||
|
||||
## 新词条(JSON)
|
||||
|
||||
> 每条带 `status` / `first` / `fix`;经 `actions/langdb.py ingest` 写入 `me/lang.db`。
|
||||
|
||||
```json
|
||||
[]
|
||||
```
|
||||
|
||||
## 备注
|
||||
|
||||
<心情、环境、其它>
|
||||
@@ -0,0 +1,255 @@
|
||||
#!/usr/bin/env python3
|
||||
"""读取 me/lang.db,渲染 me/dashboard.html(自包含仪表盘)。
|
||||
|
||||
用法:
|
||||
python actions/build_dashboard.py
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import datetime as _dt
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
import langdb # noqa: E402
|
||||
|
||||
OUT = langdb.ME / "dashboard.html"
|
||||
|
||||
|
||||
HTML = r"""<!doctype html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Lang · 我的学习状态</title>
|
||||
<style>
|
||||
:root{
|
||||
--bg:#0f1115; --panel:#171a21; --panel2:#1e222b; --line:#2a2f3a;
|
||||
--fg:#e7e9ee; --muted:#9aa3b2; --accent:#5b8def;
|
||||
--known:#2ecc71; --learning:#f1c40f; --fix:#e74c3c;
|
||||
}
|
||||
*{box-sizing:border-box}
|
||||
body{margin:0;background:var(--bg);color:var(--fg);
|
||||
font:15px/1.55 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"PingFang SC","Microsoft YaHei",sans-serif}
|
||||
header{padding:22px 26px;border-bottom:1px solid var(--line);display:flex;
|
||||
justify-content:space-between;align-items:baseline;flex-wrap:wrap;gap:8px}
|
||||
h1{margin:0;font-size:20px;letter-spacing:.3px}
|
||||
.gen{color:var(--muted);font-size:13px}
|
||||
main{padding:22px 26px;max-width:1200px;margin:0 auto}
|
||||
h2{font-size:15px;text-transform:uppercase;letter-spacing:.8px;color:var(--muted);
|
||||
margin:30px 0 12px;font-weight:600}
|
||||
.cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:12px}
|
||||
.card{background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:16px}
|
||||
.card .k{color:var(--muted);font-size:13px}
|
||||
.card .v{font-size:28px;font-weight:700;margin-top:4px}
|
||||
.card .c{color:var(--muted);font-size:12px;margin-top:6px}
|
||||
.chart{background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:14px 12px 6px}
|
||||
.legend{display:flex;gap:16px;flex-wrap:wrap;font-size:13px;margin:0 6px 6px;color:var(--muted)}
|
||||
.legend i{display:inline-block;width:10px;height:10px;border-radius:2px;margin-right:5px;vertical-align:middle}
|
||||
table{width:100%;border-collapse:collapse;background:var(--panel);
|
||||
border:1px solid var(--line);border-radius:10px;overflow:hidden;font-size:13.5px}
|
||||
th,td{padding:9px 11px;text-align:left;border-bottom:1px solid var(--line);vertical-align:top}
|
||||
th{background:var(--panel2);color:var(--muted);font-weight:600;position:sticky;top:0}
|
||||
tr:last-child td{border-bottom:none}
|
||||
code,.mono{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:12.5px;color:#c9d1e2}
|
||||
.badge{display:inline-block;padding:1px 8px;border-radius:999px;font-size:12px;font-weight:600}
|
||||
.b-known{background:rgba(46,204,113,.15);color:var(--known)}
|
||||
.b-learning{background:rgba(241,196,15,.15);color:var(--learning)}
|
||||
.b-fix{background:rgba(231,76,60,.15);color:var(--fix)}
|
||||
.fx{color:#ffb4a8}
|
||||
.toolbar{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:10px}
|
||||
.toolbar button,.toolbar input{background:var(--panel2);color:var(--fg);
|
||||
border:1px solid var(--line);border-radius:8px;padding:6px 11px;font-size:13px;cursor:pointer}
|
||||
.toolbar button.on{border-color:var(--accent);color:#fff;background:#24314d}
|
||||
.toolbar input{cursor:text;min-width:200px}
|
||||
.muted{color:var(--muted)}
|
||||
.wrap{overflow:auto;max-height:70vh;border-radius:10px}
|
||||
footer{color:var(--muted);padding:30px 26px;font-size:12px;text-align:center}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Lang · 我的学习状态</h1>
|
||||
<span class="gen">生成于 __GENERATED__ · 数据源 me/lang.db</span>
|
||||
</header>
|
||||
<main>
|
||||
<h2>四维等级</h2>
|
||||
<div class="cards" id="skills"></div>
|
||||
|
||||
<h2>等级趋势</h2>
|
||||
<div class="chart" id="chart"></div>
|
||||
|
||||
<h2>掌握概览</h2>
|
||||
<div class="cards" id="overview"></div>
|
||||
|
||||
<h2>单词 / 词组 / 表达</h2>
|
||||
<div class="toolbar">
|
||||
<button data-f="all" class="on">全部</button>
|
||||
<button data-f="known">已掌握</button>
|
||||
<button data-f="learning">学习中</button>
|
||||
<button data-f="fix">待修正</button>
|
||||
<input id="q" placeholder="搜索 item / 释义 / 上下文…">
|
||||
</div>
|
||||
<div class="wrap"><table id="items"></table></div>
|
||||
|
||||
<h2>语法修正</h2>
|
||||
<div class="wrap"><table id="grammar"></table></div>
|
||||
|
||||
<h2>训练日志</h2>
|
||||
<div class="wrap"><table id="log"></table></div>
|
||||
|
||||
<h2>等级变更历史</h2>
|
||||
<div class="wrap"><table id="history"></table></div>
|
||||
</main>
|
||||
<footer>由 actions/build_dashboard.py 生成 · SQLite: me/lang.db</footer>
|
||||
<script>
|
||||
const DATA = __DATA__;
|
||||
const esc = s => String(s ?? "").replace(/[&<>"]/g, c => ({"&":"&","<":"<",">":">",'"':"""}[c]));
|
||||
const badge = s => s ? `<span class="badge b-${s}">${s}</span>` : "";
|
||||
const fx = s => s ? `<span class="fx mono">${esc(s)}</span>` : "";
|
||||
|
||||
// 四维等级
|
||||
document.getElementById("skills").innerHTML = DATA.skills.map(s => `
|
||||
<div class="card"><div class="k">${esc(s.name)}</div>
|
||||
<div class="v">${esc(s.level)||"—"}</div>
|
||||
<div class="c">置信度 ${esc(s.confidence)||"—"}</div></div>`).join("")
|
||||
|| `<div class="muted">无数据</div>`;
|
||||
|
||||
// 概览
|
||||
const ov = DATA.overview;
|
||||
const glyph = {word:"单词", phrase:"词组", expression:"表达", grammar:"语法"};
|
||||
document.getElementById("overview").innerHTML = Object.keys(glyph).map(k => {
|
||||
const o = ov[k];
|
||||
const parts = k === "grammar"
|
||||
? `待修正 ${o.fix} · 已克服 ${o.known||0}`
|
||||
: `已掌握 ${o.known} · 学习中 ${o.learning} · 待修正 ${o.fix}`;
|
||||
return `<div class="card"><div class="k">${glyph[k]}</div>
|
||||
<div class="v">${o.total}</div><div class="c">${parts}</div></div>`;
|
||||
}).join("");
|
||||
|
||||
// 词条表 + 过滤
|
||||
const KIND = {word:"单词", phrase:"词组", expression:"表达"};
|
||||
function renderItems() {
|
||||
const f = currentFilter, q = document.getElementById("q").value.trim().toLowerCase();
|
||||
const rows = DATA.items.filter(i =>
|
||||
(f === "all" || i.status === f) &&
|
||||
(!q || (i.item + i.meaning + i.context + i.tags).toLowerCase().includes(q)));
|
||||
document.getElementById("items").innerHTML =
|
||||
`<thead><tr><th>id</th><th>类型</th><th>条目</th><th>等级</th><th>释义</th>
|
||||
<th>上下文</th><th>状态</th><th>first</th><th>修正</th><th>标签</th></tr></thead><tbody>` +
|
||||
rows.map(i => `<tr>
|
||||
<td class="mono">${esc(i.id)}</td><td>${KIND[i.kind]||i.kind}</td>
|
||||
<td><b>${esc(i.item)}</b></td><td>${esc(i.level)}</td>
|
||||
<td>${esc(i.meaning)}</td><td class="muted">${esc(i.context)}</td>
|
||||
<td>${badge(i.status)}</td><td class="mono">${esc(i.first)}</td>
|
||||
<td>${fx(i.fix)}</td><td class="muted">${esc(i.tags)}</td></tr>`).join("") +
|
||||
`</tbody>`;
|
||||
}
|
||||
let currentFilter = "all";
|
||||
document.querySelectorAll(".toolbar button[data-f]").forEach(b => b.onclick = () => {
|
||||
currentFilter = b.dataset.f;
|
||||
document.querySelectorAll(".toolbar button[data-f]").forEach(x => x.classList.toggle("on", x === b));
|
||||
renderItems();
|
||||
});
|
||||
document.getElementById("q").oninput = renderItems;
|
||||
|
||||
// 语法
|
||||
document.getElementById("grammar").innerHTML =
|
||||
`<thead><tr><th>id</th><th>类别</th><th>问题</th><th>正确规则</th><th>例子</th>
|
||||
<th>状态</th><th>次数</th><th>最近</th><th>下次复习</th></tr></thead><tbody>` +
|
||||
(DATA.grammar.map(g => `<tr>
|
||||
<td class="mono">${esc(g.id)}</td><td>${esc(g.category)}</td>
|
||||
<td>${esc(g.issue)}</td><td class="muted">${esc(g.rule)}</td>
|
||||
<td>${fx(g.examples)}</td><td>${badge(g.status === "known" ? "known" : g.status)}</td>
|
||||
<td>${g.count}</td><td class="mono">${esc(g.last)}</td>
|
||||
<td class="mono">${esc(g.next_review)}</td></tr>`).join("") || "") + `</tbody>`;
|
||||
|
||||
// 训练日志
|
||||
document.getElementById("log").innerHTML =
|
||||
`<thead><tr><th>日期</th><th>类型</th><th>材料</th><th>听</th><th>说</th><th>读</th><th>写</th><th>备注</th></tr></thead><tbody>` +
|
||||
(DATA.log.map(l => `<tr><td class="mono">${esc(l.date)}</td><td>${esc(l.type)}</td>
|
||||
<td>${esc(l.material_level)}</td><td>${esc(l.listening)}</td><td>${esc(l.speaking)}</td>
|
||||
<td>${esc(l.reading)}</td><td>${esc(l.writing)}</td>
|
||||
<td class="muted">${esc(l.note)}</td></tr>`).join("") || "") + `</tbody>`;
|
||||
|
||||
// 等级历史
|
||||
document.getElementById("history").innerHTML =
|
||||
`<thead><tr><th>日期</th><th>变更</th></tr></thead><tbody>` +
|
||||
(DATA.history.map(h => `<tr><td class="mono">${esc(h.date)}</td>
|
||||
<td>${esc(h.text)}</td></tr>`).join("") || "") + `</tbody>`;
|
||||
|
||||
// 等级趋势图(从训练日志的每次等级画线)
|
||||
(function () {
|
||||
const LV = {A1:1, A2:2, B1:3, B2:4, C1:5, C2:6};
|
||||
const val = s => {
|
||||
const m = String(s || "").trim().toUpperCase().match(/^([ABC])([12])(\+?)/);
|
||||
return m ? LV[m[1] + m[2]] + (m[3] ? 0.5 : 0) : null;
|
||||
};
|
||||
const SK = [
|
||||
{k:"listening", l:"听", c:"#4da3ff"}, {k:"speaking", l:"说", c:"#f1c40f"},
|
||||
{k:"reading", l:"读", c:"#2ecc71"}, {k:"writing", l:"写", c:"#e879f9"}];
|
||||
const el = document.getElementById("chart");
|
||||
const pts = DATA.log.slice().sort((a, b) => a.date < b.date ? -1 : 1)
|
||||
.map(r => ({date: r.date, v: Object.fromEntries(SK.map(s => [s.k, val(r[s.k])]))}));
|
||||
if (!pts.some(p => SK.some(s => p.v[s.k] != null))) {
|
||||
el.innerHTML = '<div class="muted">暂无趋势数据</div>'; return;
|
||||
}
|
||||
const W = 760, H = 320, L = 46, R = 18, T = 16, B = 40, ymin = 0.7, ymax = 6.3;
|
||||
const xs = i => L + (pts.length === 1 ? (W - L - R) / 2 : i * (W - L - R) / (pts.length - 1));
|
||||
const ys = v => T + (ymax - v) * (H - T - B) / (ymax - ymin);
|
||||
let g = "";
|
||||
["A1","A2","B1","B2","C1","C2"].forEach((lab, i) => {
|
||||
const y = ys(i + 1);
|
||||
g += `<line x1="${L}" y1="${y}" x2="${W - R}" y2="${y}" stroke="var(--line)"/>`;
|
||||
g += `<text x="${L - 8}" y="${y + 4}" fill="var(--muted)" font-size="11" text-anchor="end">${lab}</text>`;
|
||||
});
|
||||
pts.forEach((p, i) => {
|
||||
g += `<text x="${xs(i)}" y="${H - 14}" fill="var(--muted)" font-size="11" text-anchor="middle">${p.date.slice(5)}</text>`;
|
||||
});
|
||||
SK.forEach(s => {
|
||||
const seq = pts.map((p, i) => ({i, v: p.v[s.k]})).filter(o => o.v != null);
|
||||
if (!seq.length) return;
|
||||
if (seq.length > 1)
|
||||
g += `<polyline fill="none" stroke="${s.c}" stroke-width="2" points="${seq.map(o => xs(o.i) + "," + ys(o.v)).join(" ")}"/>`;
|
||||
seq.forEach(o => {
|
||||
g += `<circle cx="${xs(o.i)}" cy="${ys(o.v)}" r="4" fill="${s.c}"><title>${s.l} ${o.v} · ${pts[o.i].date}</title></circle>`;
|
||||
});
|
||||
});
|
||||
el.innerHTML = `<div class="legend">` + SK.map(s => `<span><i style="background:${s.c}"></i>${s.l}</span>`).join("") +
|
||||
`</div><svg viewBox="0 0 ${W} ${H}" width="100%" preserveAspectRatio="xMidYMid meet">${g}</svg>`;
|
||||
})();
|
||||
|
||||
renderItems();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
|
||||
def main() -> int:
|
||||
conn = langdb.connect()
|
||||
data = langdb.export(conn)
|
||||
payload = {
|
||||
"generated": _dt.datetime.now().strftime("%Y-%m-%d %H:%M"),
|
||||
"skills": data["skills"],
|
||||
"overview": langdb.overview(conn),
|
||||
"items": data["items"],
|
||||
"grammar": data["grammar"],
|
||||
"log": data["training_log"],
|
||||
"history": data["level_history"],
|
||||
}
|
||||
conn.close()
|
||||
|
||||
html = (HTML
|
||||
.replace("__GENERATED__", payload["generated"])
|
||||
.replace("__DATA__", json.dumps(payload, ensure_ascii=False)))
|
||||
OUT.write_text(html, encoding="utf-8")
|
||||
print(f"HTML : {OUT.relative_to(ROOT)} "
|
||||
f"({len(payload['items'])} items, {len(payload['grammar'])} grammar)")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,317 @@
|
||||
#!/usr/bin/env python3
|
||||
"""me/lang.db —— 我的学习状态的唯一事实来源(SQLite)。
|
||||
|
||||
子命令:
|
||||
init 建库/建表(幂等)
|
||||
ingest FILE 把 JSON 写入库(FILE 用 - 读 stdin)
|
||||
export [FILE] 导出 JSON(无 FILE 则打印到 stdout)
|
||||
migrate-md 从 me/*.md 一次性迁移(首次/重建用)
|
||||
overview 打印掌握概览
|
||||
|
||||
写入 JSON 的顶层键(均可选):
|
||||
items / grammar / skills / training_log / level_history
|
||||
|
||||
字段见 DDL。items 的 kind 可由 id 前缀推断:w- 单词 / p- 词组 / e- 表达。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import re
|
||||
import sqlite3
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
ME = ROOT / "me"
|
||||
DB = ME / "lang.db"
|
||||
|
||||
DDL = """
|
||||
CREATE TABLE IF NOT EXISTS skills (
|
||||
id TEXT PRIMARY KEY, name TEXT, level TEXT, confidence TEXT, note TEXT
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS training_log (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, date TEXT, type TEXT, material_level TEXT,
|
||||
listening TEXT, speaking TEXT, reading TEXT, writing TEXT, note TEXT
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS level_history (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, date TEXT, text TEXT
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS items (
|
||||
id TEXT PRIMARY KEY, kind TEXT NOT NULL, item TEXT, level TEXT,
|
||||
meaning TEXT, context TEXT, status TEXT, first TEXT, fix TEXT,
|
||||
function TEXT, tags TEXT, source TEXT, added TEXT,
|
||||
hits INTEGER DEFAULT 0, streak INTEGER DEFAULT 0, next_review TEXT
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS grammar_fixes (
|
||||
id TEXT PRIMARY KEY, category TEXT, issue TEXT, rule TEXT, examples TEXT,
|
||||
status TEXT, count INTEGER DEFAULT 0, first TEXT, last TEXT, next_review TEXT
|
||||
);
|
||||
"""
|
||||
|
||||
KIND_BY_PREFIX = {"w": "word", "p": "phrase", "e": "expression"}
|
||||
|
||||
|
||||
# ---------- 连接 ----------
|
||||
|
||||
def connect() -> sqlite3.Connection:
|
||||
ME.mkdir(exist_ok=True)
|
||||
conn = sqlite3.connect(DB)
|
||||
conn.row_factory = sqlite3.Row
|
||||
conn.executescript(DDL)
|
||||
return conn
|
||||
|
||||
|
||||
# ---------- 写入 ----------
|
||||
|
||||
def _kind(d: dict) -> str:
|
||||
return d.get("kind") or KIND_BY_PREFIX.get((d.get("id") or "")[:1], "")
|
||||
|
||||
|
||||
def ingest(conn: sqlite3.Connection, payload: dict) -> dict[str, int]:
|
||||
n = {}
|
||||
items = payload.get("items", [])
|
||||
conn.executemany(
|
||||
"INSERT OR REPLACE INTO items VALUES "
|
||||
"(:id,:kind,:item,:level,:meaning,:context,:status,:first,:fix,"
|
||||
":function,:tags,:source,:added,:hits,:streak,:next_review)",
|
||||
[{
|
||||
"id": d.get("id", ""), "kind": _kind(d), "item": d.get("item", ""),
|
||||
"level": d.get("level", ""), "meaning": d.get("meaning", ""),
|
||||
"context": d.get("context", ""), "status": d.get("status", "learning"),
|
||||
"first": d.get("first", ""), "fix": d.get("fix", ""),
|
||||
"function": d.get("function", ""), "tags": d.get("tags", ""),
|
||||
"source": d.get("source", ""), "added": d.get("added", ""),
|
||||
"hits": int(d.get("hits") or 0), "streak": int(d.get("streak") or 0),
|
||||
"next_review": d.get("next_review", ""),
|
||||
} for d in items if d.get("id")])
|
||||
n["items"] = len([d for d in items if d.get("id")])
|
||||
|
||||
grammar = payload.get("grammar", [])
|
||||
conn.executemany(
|
||||
"INSERT OR REPLACE INTO grammar_fixes VALUES "
|
||||
"(:id,:category,:issue,:rule,:examples,:status,:count,:first,:last,:next_review)",
|
||||
[{
|
||||
"id": d.get("id", ""), "category": d.get("category", ""),
|
||||
"issue": d.get("issue", ""), "rule": d.get("rule", ""),
|
||||
"examples": d.get("examples", ""), "status": d.get("status", "fix"),
|
||||
"count": int(d.get("count") or 0), "first": d.get("first", ""),
|
||||
"last": d.get("last", ""), "next_review": d.get("next_review", ""),
|
||||
} for d in grammar if d.get("id")])
|
||||
n["grammar"] = len([d for d in grammar if d.get("id")])
|
||||
|
||||
skills = payload.get("skills", [])
|
||||
conn.executemany(
|
||||
"INSERT OR REPLACE INTO skills VALUES (:id,:name,:level,:confidence,:note)",
|
||||
[{
|
||||
"id": d.get("id", ""), "name": d.get("name", ""),
|
||||
"level": d.get("level", ""), "confidence": d.get("confidence", ""),
|
||||
"note": d.get("note", ""),
|
||||
} for d in skills if d.get("id")])
|
||||
n["skills"] = len([d for d in skills if d.get("id")])
|
||||
|
||||
added = 0
|
||||
for d in payload.get("training_log", []):
|
||||
r = {
|
||||
"date": d.get("date", ""), "type": d.get("type", ""),
|
||||
"material_level": d.get("material_level", d.get("material", "")),
|
||||
"listening": d.get("listening", ""), "speaking": d.get("speaking", ""),
|
||||
"reading": d.get("reading", ""), "writing": d.get("writing", ""),
|
||||
"note": d.get("note", ""),
|
||||
}
|
||||
if not r["date"]:
|
||||
continue
|
||||
cur = conn.execute(
|
||||
"INSERT INTO training_log (date,type,material_level,listening,speaking,reading,writing,note)"
|
||||
" SELECT :date,:type,:material_level,:listening,:speaking,:reading,:writing,:note"
|
||||
" WHERE NOT EXISTS (SELECT 1 FROM training_log WHERE date=:date AND type=:type"
|
||||
" AND material_level=:material_level AND note=:note)", r)
|
||||
added += cur.rowcount
|
||||
n["training_log"] = added
|
||||
|
||||
hist = 0
|
||||
for d in payload.get("level_history", []):
|
||||
if not d.get("date"):
|
||||
continue
|
||||
cur = conn.execute(
|
||||
"INSERT INTO level_history (date,text) SELECT :date,:text"
|
||||
" WHERE NOT EXISTS (SELECT 1 FROM level_history WHERE date=:date AND text=:text)",
|
||||
{"date": d.get("date", ""), "text": d.get("text", "")})
|
||||
hist += cur.rowcount
|
||||
n["level_history"] = hist
|
||||
|
||||
conn.commit()
|
||||
return n
|
||||
|
||||
|
||||
# ---------- 导出 ----------
|
||||
|
||||
def export(conn: sqlite3.Connection) -> dict:
|
||||
def rows(sql):
|
||||
return [dict(r) for r in conn.execute(sql)]
|
||||
return {
|
||||
"skills": rows("SELECT id,name,level,confidence,note FROM skills"),
|
||||
"training_log": rows(
|
||||
"SELECT date,type,material_level,listening,speaking,reading,writing,note"
|
||||
" FROM training_log ORDER BY date"),
|
||||
"level_history": rows("SELECT date,text FROM level_history ORDER BY date,id"),
|
||||
"items": rows(
|
||||
"SELECT id,kind,item,level,meaning,context,status,first,fix,function,tags,"
|
||||
"source,added,hits,streak,next_review FROM items ORDER BY id"),
|
||||
"grammar": rows(
|
||||
"SELECT id,category,issue,rule,examples,status,count,first,last,next_review"
|
||||
" FROM grammar_fixes ORDER BY id"),
|
||||
}
|
||||
|
||||
|
||||
def overview(conn: sqlite3.Connection) -> dict:
|
||||
def counts(where):
|
||||
c = {"known": 0, "learning": 0, "fix": 0}
|
||||
for r in conn.execute(
|
||||
f"SELECT status, COUNT(*) n FROM items WHERE {where} GROUP BY status"):
|
||||
if r["status"] in c:
|
||||
c[r["status"]] = r["n"]
|
||||
c["total"] = sum(c[k] for k in ("known", "learning", "fix"))
|
||||
return c
|
||||
|
||||
g = conn.execute(
|
||||
"SELECT SUM(status='fix') f, SUM(status='known') k, COUNT(*) t FROM grammar_fixes"
|
||||
).fetchone()
|
||||
return {
|
||||
"word": counts("kind='word'"),
|
||||
"phrase": counts("kind='phrase'"),
|
||||
"expression": counts("kind='expression'"),
|
||||
"grammar": {"fix": g["f"] or 0, "known": g["k"] or 0, "total": g["t"] or 0},
|
||||
}
|
||||
|
||||
|
||||
# ---------- 从 me/*.md 迁移(一次性) ----------
|
||||
|
||||
def _parse_tables(text: str) -> list[tuple[list[str], list[list[str]]]]:
|
||||
blocks, cur = [], []
|
||||
for ln in text.splitlines():
|
||||
s = ln.strip()
|
||||
if s.startswith("|") and s.endswith("|"):
|
||||
cur.append([c.strip() for c in s.strip("|").split("|")])
|
||||
elif cur:
|
||||
blocks.append(cur)
|
||||
cur = []
|
||||
if cur:
|
||||
blocks.append(cur)
|
||||
out = []
|
||||
for b in blocks:
|
||||
if len(b) < 2:
|
||||
continue
|
||||
header = b[0]
|
||||
rows = [r for r in b[1:] if not all(set(c) <= set("-: ") for c in r)]
|
||||
out.append((header, rows))
|
||||
return out
|
||||
|
||||
|
||||
def _to_dicts(header, rows):
|
||||
return [{h: (r[i] if i < len(r) else "") for i, h in enumerate(header)} for r in rows]
|
||||
|
||||
|
||||
def _cefr(cell: str) -> str:
|
||||
m = re.search(r"[ABC][12]\+?", cell or "")
|
||||
return m.group(0) if m else (cell or "").strip()
|
||||
|
||||
|
||||
def migrate_md(conn: sqlite3.Connection) -> dict | None:
|
||||
text = {p.name: p.read_text(encoding="utf-8")
|
||||
for p in ME.glob("*.md")}
|
||||
if not text:
|
||||
print("me/ 下没有 .md 可迁移(可能已迁移过)。", file=sys.stderr)
|
||||
return None
|
||||
payload: dict[str, list] = {"items": [], "grammar": [], "skills": [],
|
||||
"training_log": [], "level_history": []}
|
||||
for kind, fname in (("word", "word-bank.md"), ("phrase", "phrase-bank.md"),
|
||||
("expression", "expression-bank.md")):
|
||||
t = text.get(fname)
|
||||
if not t or not (tables := _parse_tables(t)):
|
||||
continue
|
||||
h, rows = tables[0]
|
||||
for d in _to_dicts(h, rows):
|
||||
if d.get("id"):
|
||||
d["kind"] = kind
|
||||
payload["items"].append(d)
|
||||
if (t := text.get("grammar-fixes.md")) and (tables := _parse_tables(t)):
|
||||
h, rows = tables[0]
|
||||
payload["grammar"] = [d for d in _to_dicts(h, rows) if d.get("id")]
|
||||
if (t := text.get("profile.md")) and (tables := _parse_tables(t)):
|
||||
h, rows = tables[0]
|
||||
for d in _to_dicts(h, rows):
|
||||
name = d.get("技能", "")
|
||||
if not name:
|
||||
continue
|
||||
key = ("reading" if "读" in name else "listening" if "听" in name
|
||||
else "speaking" if "说" in name else "writing" if "写" in name else name)
|
||||
payload["skills"].append({
|
||||
"id": key, "name": name, "level": _cefr(d.get("表现等级", "")),
|
||||
"confidence": d.get("置信度", ""),
|
||||
"note": d.get("依据 / 备注", d.get("备注", ""))})
|
||||
if len(tables) > 1:
|
||||
h, rows = tables[1]
|
||||
for d in _to_dicts(h, rows):
|
||||
if d.get("日期"):
|
||||
payload["training_log"].append({
|
||||
"date": d.get("日期", ""), "type": d.get("类型", ""),
|
||||
"material_level": d.get("材料等级", ""),
|
||||
"listening": d.get("听", ""), "speaking": d.get("说", ""),
|
||||
"reading": d.get("读", ""), "writing": d.get("写", ""),
|
||||
"note": d.get("备注", "")})
|
||||
for ln in t.splitlines():
|
||||
m = re.match(r"^-\s*`?(\d{4}-\d{2}-\d{2})`?\s*(.*)$", ln.strip())
|
||||
if m:
|
||||
payload["level_history"].append({"date": m.group(1), "text": m.group(2).strip()})
|
||||
return ingest(conn, payload)
|
||||
|
||||
|
||||
# ---------- CLI ----------
|
||||
|
||||
def main() -> int:
|
||||
for stream in (sys.stdin, sys.stdout, sys.stderr):
|
||||
try:
|
||||
stream.reconfigure(encoding="utf-8") # Windows 控制台/管道默认 GBK
|
||||
except (AttributeError, ValueError):
|
||||
pass
|
||||
ap = argparse.ArgumentParser(description="me/lang.db 管理")
|
||||
sub = ap.add_subparsers(dest="cmd")
|
||||
|
||||
sub.add_parser("init", help="建库/建表")
|
||||
p_in = sub.add_parser("ingest", help="JSON → 库")
|
||||
p_in.add_argument("file", help="JSON 文件,或 - 读 stdin")
|
||||
p_ex = sub.add_parser("export", help="库 → JSON")
|
||||
p_ex.add_argument("file", nargs="?", help="输出文件(省略则打印)")
|
||||
sub.add_parser("migrate-md", help="从 me/*.md 一次性迁移")
|
||||
sub.add_parser("overview", help="打印掌握概览")
|
||||
|
||||
args = ap.parse_args()
|
||||
if not args.cmd:
|
||||
ap.print_help()
|
||||
return 0
|
||||
|
||||
conn = connect()
|
||||
if args.cmd == "init":
|
||||
print(f"OK: {DB.relative_to(ROOT)} 已就绪")
|
||||
elif args.cmd == "ingest":
|
||||
raw = sys.stdin.read() if args.file == "-" else Path(args.file).read_text(encoding="utf-8")
|
||||
print("写入:", ingest(conn, json.loads(raw)))
|
||||
elif args.cmd == "export":
|
||||
out = json.dumps(export(conn), ensure_ascii=False, indent=2)
|
||||
if args.file:
|
||||
Path(args.file).write_text(out + "\n", encoding="utf-8")
|
||||
print(f"导出: {args.file}")
|
||||
else:
|
||||
print(out)
|
||||
elif args.cmd == "migrate-md":
|
||||
print("迁移:", migrate_md(conn))
|
||||
elif args.cmd == "overview":
|
||||
for k, v in overview(conn).items():
|
||||
print(f"{k:11} {v}")
|
||||
conn.close()
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env python3
|
||||
"""把听力材料的 PDF 抽成 actions/ 下的 Markdown 素材草稿。
|
||||
|
||||
用法:
|
||||
python actions/pdf_extract.py "C:/Users/HUAWEI/Desktop/第3期_classic.pdf"
|
||||
python actions/pdf_extract.py <pdf> --slug issue3-classic --level B2 --title "第3期 classic"
|
||||
|
||||
依赖 pdftotext(poppler,优先);没有则回退 pypdf(pip install pypdf)。
|
||||
抽取后是"原文草稿",我再人工补小标题/生词/等级。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import datetime as _dt
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
ACTIONS = ROOT / "actions"
|
||||
|
||||
|
||||
def extract_pdf(pdf: Path) -> str:
|
||||
if shutil.which("pdftotext"):
|
||||
proc = subprocess.run(
|
||||
["pdftotext", "-layout", str(pdf), "-"],
|
||||
capture_output=True, text=True, encoding="utf-8", errors="replace",
|
||||
)
|
||||
if proc.returncode == 0 and proc.stdout.strip():
|
||||
return proc.stdout
|
||||
try:
|
||||
import pypdf # type: ignore
|
||||
except ImportError:
|
||||
sys.exit("找不到 pdftotext(poppler),也没装 pypdf。请二选一安装。")
|
||||
reader = pypdf.PdfReader(str(pdf))
|
||||
return "\n".join((page.extract_text() or "") for page in reader.pages)
|
||||
|
||||
|
||||
def clean(text: str) -> str:
|
||||
text = text.replace("\ufffd", "") # 替换字符
|
||||
lines = [ln.rstrip() for ln in text.splitlines()]
|
||||
kept: list[str] = []
|
||||
blanks = 0
|
||||
for ln in lines:
|
||||
if not ln.strip():
|
||||
blanks += 1
|
||||
if blanks > 1:
|
||||
continue
|
||||
else:
|
||||
blanks = 0
|
||||
# 丢掉只有引号/标点的残留行(PDF 抽取常见噪音)
|
||||
if ln.strip() and not re.search(r"[A-Za-z0-9\u4e00-\u9fff]", ln):
|
||||
continue
|
||||
kept.append(ln)
|
||||
return "\n".join(kept).strip() + "\n"
|
||||
|
||||
|
||||
def default_slug(pdf: Path) -> str:
|
||||
slug = re.sub(r"[^\w\-]+", "-", pdf.stem, flags=re.UNICODE).strip("-").lower()
|
||||
return slug or "material"
|
||||
|
||||
|
||||
def main() -> None:
|
||||
ap = argparse.ArgumentParser(description="PDF → actions/*.md")
|
||||
ap.add_argument("pdf", help="PDF 路径")
|
||||
ap.add_argument("--slug", help="文件名 slug(默认取 PDF 文件名)")
|
||||
ap.add_argument("--level", default="待定", help="CEFR 等级")
|
||||
ap.add_argument("--title", help="素材标题(默认取 PDF 文件名)")
|
||||
ap.add_argument("--date", default=_dt.date.today().isoformat(), help="日期 YYYY-MM-DD")
|
||||
args = ap.parse_args()
|
||||
|
||||
pdf = Path(args.pdf)
|
||||
if not pdf.is_file():
|
||||
sys.exit(f"文件不存在: {pdf}")
|
||||
|
||||
slug = args.slug or default_slug(pdf)
|
||||
title = args.title or pdf.stem
|
||||
body = clean(extract_pdf(pdf))
|
||||
|
||||
ACTIONS.mkdir(exist_ok=True)
|
||||
out = ACTIONS / f"{args.date}-{slug}.md"
|
||||
out.write_text(
|
||||
f"""# Material — {args.date} · {slug}
|
||||
|
||||
- **source**: 用户 PDF · `{pdf.name}` · {title}
|
||||
- **level**: {args.level}
|
||||
- **duration**: 待补
|
||||
- **pdf**: `{pdf}`
|
||||
|
||||
---
|
||||
|
||||
## 原文(自动抽取草稿,待人工整理)
|
||||
|
||||
{body}
|
||||
""",
|
||||
encoding="utf-8",
|
||||
)
|
||||
print(f"已写出: {out.relative_to(ROOT)}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user