372 lines
18 KiB
Python
372 lines
18 KiB
Python
#!/usr/bin/env python3
|
||
"""生成 lpt-android 目标态线框(.svg)。
|
||
|
||
取值来自 lpt-android/.agents/roles/design-system.md:
|
||
主色 #237556(深色 #7FD8B4)、页底 #F7FBF8 / #111A16、面 #FFFFFF / #1B2A23、
|
||
输入框底 #F1F6F3 / #22332B、描边 #C6D6CD / #33453D、次要字 #4B6156 / #B3C7BD、
|
||
提醒条 #FFF8E1/#856404、错误 #B62324、强调底 #EEF9F3。
|
||
一屏一份文件;画布 360×800(=真机 1080×2400 的 dp)。改文案或布局改这里,重跑:
|
||
|
||
python3 docs/diagrams/android-ui/_build_wireframes.py
|
||
|
||
不生成二进制;产物是同目录的 .svg,由 index.html 引用。
|
||
"""
|
||
|
||
import os
|
||
|
||
W, H, PAD, GUTTER = 360, 800, 16, 24
|
||
FONT = "'Noto Sans CJK SC','Source Han Sans SC','PingFang SC','Microsoft YaHei',system-ui,sans-serif"
|
||
MONO = "'JetBrains Mono','SF Mono',Menlo,Consolas,monospace"
|
||
|
||
LIGHT = dict(bg="#F7FBF8", surface="#FFFFFF", inset="#F1F6F3", text="#16241C", sec="#4B6156",
|
||
primary="#237556", on_primary="#FFFFFF", border="#C6D6CD", accent="#EEF9F3",
|
||
warn_bg="#FFF8E1", warn="#856404", err="#B62324", err_bg="#FDECEA",
|
||
skeleton="#E4EDE8")
|
||
DARK = dict(bg="#111A16", surface="#1B2A23", inset="#22332B", text="#E4EFE9", sec="#B3C7BD",
|
||
primary="#7FD8B4", on_primary="#111A16", border="#33453D", accent="#17332A",
|
||
warn_bg="#3A3220", warn="#FFD08A", err="#F85149", err_bg="#3A1F1F",
|
||
skeleton="#2C3E36")
|
||
|
||
OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)))
|
||
|
||
|
||
def esc(s):
|
||
return (s.replace("&", "&").replace("<", "<").replace(">", ">"))
|
||
|
||
|
||
def rect(x, y, w, h, fill, r=0, stroke=None, sw=1, dash=None):
|
||
s = f'<rect x="{x}" y="{y}" width="{w}" height="{h}" rx="{r}" fill="{fill}"'
|
||
if stroke:
|
||
s += f' stroke="{stroke}" stroke-width="{sw}"'
|
||
if dash:
|
||
s += f' stroke-dasharray="{dash}"'
|
||
return s + "/>"
|
||
|
||
|
||
def line(x1, y1, x2, y2, color, sw=1, dash=None):
|
||
s = f'<line x1="{x1}" y1="{y1}" x2="{x2}" y2="{y2}" stroke="{color}" stroke-width="{sw}"'
|
||
if dash:
|
||
s += f' stroke-dasharray="{dash}"'
|
||
return s + "/>"
|
||
|
||
|
||
def text(x, y, s, size=14, color="#000", anchor="start", weight=400, family=None, opacity=None):
|
||
extra = f' font-family="{family}"' if family else ""
|
||
extra += f' font-weight="{weight}"'
|
||
if opacity is not None:
|
||
extra += f' opacity="{opacity}"'
|
||
return (f'<text x="{x}" y="{y}" font-size="{size}" fill="{color}" text-anchor="{anchor}"'
|
||
f'{extra}>{esc(s)}</text>')
|
||
|
||
|
||
def button(x, y, w, h, label, p, kind="primary", size=14):
|
||
out = []
|
||
if kind == "primary":
|
||
out.append(rect(x, y, w, h, p["primary"], 8))
|
||
out.append(text(x + w / 2, y + h / 2 + 5, label, size, p["on_primary"], "middle", 500))
|
||
elif kind == "outlined":
|
||
out.append(rect(x, y, w, h, p["surface"], 8, p["primary"], 1))
|
||
out.append(text(x + w / 2, y + h / 2 + 5, label, size, p["primary"], "middle", 500))
|
||
elif kind == "text":
|
||
out.append(text(x + w / 2, y + h / 2 + 5, label, size, p["primary"], "middle", 500))
|
||
return out
|
||
|
||
|
||
def status_bar(p, y=0):
|
||
out = [text(PAD + 4, y + 19, "9:41", 11, p["text"], weight=500)]
|
||
out.append(rect(W - 58, y + 13, 12, 9, p["sec"], 1))
|
||
out.append(rect(W - 44, y + 16, 8, 6, p["sec"], 1))
|
||
out.append(rect(W - 33, y + 12, 15, 10, "none", 2, p["sec"], 1))
|
||
out.append(rect(W - 31, y + 14, 11, 6, p["sec"], 1))
|
||
return out
|
||
|
||
|
||
def header(p, title, back=None, action=None):
|
||
"""页头:标题 22sp;可带左侧返回与右侧唯一动作。"""
|
||
out = []
|
||
x = PAD
|
||
if back:
|
||
out.append(text(PAD, 62, back, 14, p["primary"]))
|
||
x = PAD + 56
|
||
out.append(text(x, 64, title, 22, p["text"]))
|
||
if action:
|
||
out.append(text(W - PAD, 62, action, 14, p["primary"], "end"))
|
||
return out
|
||
|
||
|
||
# ---------------------------------------------------------------- 任务页
|
||
|
||
TASKS = [
|
||
("LLM 模型部署实践", "vLLM 与 PagedAttention 的部署实验", "3.75"),
|
||
("k8s 的使用", "把 LPT 系统迁移到 k8s 中", "3.15"),
|
||
("功能测试", "复习功能的测试学习任务", "2.45"),
|
||
("Whisper 模型学习与应用", "数据集、微调与领域模型", "2.35"),
|
||
("网络通讯加密与应用", "TLS 握手与证书链排查", "2.10"),
|
||
]
|
||
|
||
|
||
def screen_tasks(p, with_search=True):
|
||
out = header(p, "学习任务", action="设置")
|
||
# 进行中会话:独立成块,整块可点,不带箭头
|
||
out.append(rect(PAD, 88, W - 2 * PAD, 64, p["accent"], 12))
|
||
out.append(text(PAD + 16, 113, "有一次学习正在进行", 14, p["text"]))
|
||
out.append(text(PAD + 16, 133, "LLM 模型部署实践 · 已学 12:30", 12, p["sec"]))
|
||
out.append(text(W - PAD - 16, 117, "回到会话", 14, p["primary"], "end", 500))
|
||
y = 168
|
||
if with_search:
|
||
out.append(rect(PAD, y, W - 2 * PAD, 40, p["inset"], 8))
|
||
out.append(f'<circle cx="{PAD + 24}" cy="{y + 20}" r="6" fill="none" stroke="{p["sec"]}" stroke-width="1.5"/>')
|
||
out.append(line(PAD + 28.5, y + 24.5, PAD + 32, y + 28, p["sec"], 1.5))
|
||
out.append(text(PAD + 42, y + 25, "搜索任务名称或描述", 14, p["sec"]))
|
||
y += 56
|
||
for name, desc, prio in TASKS:
|
||
out.append(rect(PAD, y, W - 2 * PAD, 104, p["surface"], 8, p["border"], 1))
|
||
out.append(text(PAD + 16, y + 28, name, 14, p["text"]))
|
||
out.append(text(PAD + 16, y + 50, desc, 12, p["sec"]))
|
||
out.append(text(PAD + 16, y + 86, f"优先级 {prio}", 12, p["sec"], family=MONO))
|
||
out.append(text(PAD + 216, y + 86, "报告", 12, p["sec"]))
|
||
out.append(text(W - PAD - 16, y + 86, "开始学习", 14, p["primary"], "end", 500))
|
||
y += 120
|
||
return out
|
||
|
||
|
||
def screen_tasks_empty(p):
|
||
out = header(p, "学习任务", action="设置")
|
||
out.append(text(W / 2, 392, "还没有学习任务", 14, p["text"], "middle"))
|
||
out.append(text(W / 2, 416, "任务在网页端新建,建好后回来刷新", 12, p["sec"], "middle"))
|
||
out.extend(button(W / 2 - 60, 440, 120, 40, "刷新列表", p, "outlined"))
|
||
return out
|
||
|
||
|
||
def screen_tasks_loading(p):
|
||
out = header(p, "学习任务", action="设置")
|
||
y = 96
|
||
for i in range(3):
|
||
out.append(rect(PAD, y, W - 2 * PAD, 104, p["inset"], 8))
|
||
out.append(rect(PAD + 16, y + 20, 140, 12, p["skeleton"], 4))
|
||
out.append(rect(PAD + 16, y + 44, 220, 10, p["skeleton"], 4))
|
||
out.append(rect(PAD + 16, y + 76, 72, 10, p["skeleton"], 4))
|
||
y += 120
|
||
return out
|
||
|
||
|
||
def screen_tasks_error(p):
|
||
out = header(p, "学习任务", action="设置")
|
||
out.append(rect(PAD, 196, W - 2 * PAD, 152, p["surface"], 12, p["border"], 1))
|
||
out.append(text(PAD + 16, 232, "任务列表没加载出来", 14, p["text"]))
|
||
out.append(text(PAD + 16, 258, "网络断开,或服务器没有响应", 12, p["err"]))
|
||
out.append(text(PAD + 16, 282, "恢复网络后重新加载,列表不会丢", 12, p["sec"]))
|
||
out.extend(button(PAD + 16, 296, 120, 40, "重新加载", p, "outlined"))
|
||
return out
|
||
|
||
|
||
# ---------------------------------------------------------------- 会话页
|
||
|
||
def screen_session(p, mode="ongoing"):
|
||
# 会话页顶栏不放「学习会话」这种复述性页标题:任务是逐屏变化的,任务名就是标题
|
||
out = [text(PAD, 62, "‹ 任务", 14, p["primary"])]
|
||
out.append(text(PAD + 56, 54, "LLM 模型部署实践", 16, p["text"]))
|
||
out.append(text(PAD + 56, 74, "S-20261119-01", 12, p["sec"]))
|
||
y = 96
|
||
if mode == "paused":
|
||
out.append(rect(PAD, y, W - 2 * PAD, 44, p["warn_bg"], 8))
|
||
out.append(text(PAD + 16, y + 27, "已暂停,继续后接着计时", 12, p["warn"]))
|
||
y += 56
|
||
elif mode == "due":
|
||
out.append(rect(PAD, y, W - 2 * PAD, 60, p["warn_bg"], 8))
|
||
out.append(text(PAD + 16, y + 25, "本轮时间已到,先暂停休息", 12, p["warn"]))
|
||
out.append(text(PAD + 16, y + 44, "会话不会自己结束", 12, p["warn"]))
|
||
y += 72
|
||
out.append(rect(PAD, y, W - 2 * PAD, 152, p["surface"], 12))
|
||
countdown = "00:00" if mode == "due" else "12:34"
|
||
out.append(text(W / 2, y + 34, f"本轮还剩 {countdown}", 14,
|
||
p["warn"] if mode == "due" else p["sec"], "middle"))
|
||
out.append(text(W / 2, y + 92, "25:30", 44, p["sec"] if mode == "paused" else p["primary"],
|
||
"middle", 700, MONO))
|
||
out.append(text(W / 2, y + 120, "有效学习时间", 12, p["sec"], "middle"))
|
||
y += 168
|
||
out.extend(button(PAD, y, W - 2 * PAD, 48, "继续" if mode == "paused" else "暂停", p, "primary"))
|
||
y += 56
|
||
out.extend(button(PAD, y, W - 2 * PAD, 48, "结束学习", p, "outlined"))
|
||
y += 56
|
||
out.append(text(W / 2, y + 16, "显示悬浮窗", 14, p["primary"], "middle"))
|
||
y += 40
|
||
# 学习预期
|
||
out.append(rect(PAD, y, W - 2 * PAD, 112, p["surface"], 12))
|
||
out.append(text(PAD + 16, y + 28, "学习预期", 14, p["text"]))
|
||
out.append(text(W - PAD - 16, y + 28, "修改", 12, p["primary"], "end"))
|
||
out.append(text(PAD + 16, y + 54, "理解 vLLM 的 PagedAttention 与连续批处理,", 12, p["sec"]))
|
||
out.append(text(PAD + 16, y + 74, "并跑通一次并发压测", 12, p["sec"]))
|
||
y += 128
|
||
# 知识碎片
|
||
out.append(rect(PAD, y, W - 2 * PAD, 176 if mode != "ongoing" else 208, p["surface"], 12))
|
||
out.append(text(PAD + 16, y + 28, "知识碎片(3)" if mode == "ongoing" else "知识碎片(2)",
|
||
14, p["text"]))
|
||
out.append(rect(PAD + 16, y + 40, 232, 40, p["inset"], 8))
|
||
out.append(text(PAD + 30, y + 65, "记一条…", 14, p["sec"]))
|
||
out.append(text(W - PAD - 16, y + 65, "记录", 14, p["primary"], "end", 500))
|
||
out.append(text(PAD + 16, y + 108, "1.", 12, p["sec"]))
|
||
out.append(text(PAD + 34, y + 108, "PagedAttention 把 KV cache 按页切", 14, p["text"]))
|
||
out.append(text(PAD + 16, y + 134, "2.", 12, p["sec"]))
|
||
out.append(text(PAD + 34, y + 134, "连续批处理提升吞吐,延迟换吞吐", 14, p["text"]))
|
||
if mode == "ongoing":
|
||
out.append(text(PAD + 16, y + 160, "3.", 12, p["sec"]))
|
||
out.append(text(PAD + 34, y + 160, "抢占会让请求重算,代价是解码时间", 14, p["text"]))
|
||
if mode == "ongoing":
|
||
out.append(text(W / 2, y + 178, "查看全部 3 条", 12, p["primary"], "middle"))
|
||
return out
|
||
|
||
|
||
# ---------------------------------------------------------------- 报告页
|
||
|
||
def screen_reports(p, expanded=False):
|
||
out = header(p, "学习报告", back="‹ 任务")
|
||
out.append(text(PAD + 56, 82, "LLM 模型部署实践", 12, p["sec"]))
|
||
y = 96
|
||
out.append(rect(PAD, y, W - 2 * PAD, 132, p["surface"], 8, p["border"], 1))
|
||
out.append(text(PAD + 16, y + 26, "S-20261114-03", 12, p["sec"]))
|
||
out.append(text(W - PAD - 16, y + 26, "11-14 21:30", 12, p["sec"], "end", family=MONO))
|
||
out.append(text(PAD + 16, y + 54, "把 PagedAttention 与连续批处理跑通,", 14, p["text"]))
|
||
out.append(text(PAD + 16, y + 74, "对比了两种并发配置的吞吐", 14, p["text"]))
|
||
out.append(text(PAD + 16, y + 106, "展开全文", 12, p["primary"]))
|
||
out.append(text(PAD + 88, y + 106, "查看本次碎片", 12, p["sec"]))
|
||
y += 148
|
||
h = 300 if expanded else 132
|
||
out.append(rect(PAD, y, W - 2 * PAD, h, p["surface"], 8, p["border"], 1))
|
||
out.append(text(PAD + 16, y + 26, "S-20261113-02", 12, p["sec"]))
|
||
out.append(text(W - PAD - 16, y + 26, "11-13 20:10", 12, p["sec"], "end", family=MONO))
|
||
out.append(text(PAD + 16, y + 54, "复习了 vLLM 的调度器源码,", 14, p["text"]))
|
||
out.append(text(PAD + 16, y + 74, "补了 3 条碎片", 14, p["text"]))
|
||
if expanded:
|
||
out.append(text(PAD + 16, y + 110, "本次预期", 12, p["sec"]))
|
||
out.append(text(PAD + 16, y + 132, "看懂调度器怎么决定这一批跑哪些请求", 14, p["text"]))
|
||
out.append(text(PAD + 16, y + 166, "预期达成判断", 12, p["sec"]))
|
||
out.append(text(PAD + 16, y + 188, "部分达成:调度策略看懂了,抢占逻辑还没", 14, p["text"]))
|
||
out.append(text(PAD + 16, y + 222, "自由总结", 12, p["sec"]))
|
||
out.append(text(PAD + 16, y + 244, "下次从抢占与重算那条路径接着看", 14, p["text"]))
|
||
out.append(text(PAD + 16, y + 276, "收起全文", 12, p["primary"]))
|
||
else:
|
||
out.append(text(PAD + 16, y + 106, "展开全文", 12, p["primary"]))
|
||
out.append(text(PAD + 88, y + 106, "查看本次碎片", 12, p["sec"]))
|
||
y += h + 16
|
||
out.append(text(W / 2, y + 20, "加载更多(3/12)", 12, p["primary"], "middle"))
|
||
return out
|
||
|
||
|
||
# ---------------------------------------------------------------- 设置页 / 权限引导
|
||
|
||
def permission_rows(p, y):
|
||
"""一行一条权限:左边「是什么 + 为什么」,右边「现在什么状态 + 怎么开」。"""
|
||
out = []
|
||
rows = [
|
||
("悬浮窗权限", "在其他应用之上显示计时浮窗", "已授权", True),
|
||
("通知权限", "前台服务要有一条常驻通知", "未授权", False),
|
||
("电池优化白名单", "长时间学习时不被系统冻结计时", "未授权", False),
|
||
]
|
||
for name, why, state, granted in rows:
|
||
out.append(text(PAD + 16, y + 26, name, 14, p["text"]))
|
||
out.append(text(PAD + 16, y + 48, why, 12, p["sec"]))
|
||
out.append(text(W - PAD - 16, y + 26, state, 12,
|
||
p["primary"] if granted else p["err"], "end"))
|
||
if not granted:
|
||
out.append(text(W - PAD - 16, y + 49, "去开启", 12, p["primary"], "end"))
|
||
y += 64
|
||
return out
|
||
|
||
|
||
def screen_settings(p):
|
||
out = header(p, "设置", back="‹ 任务")
|
||
y = 96
|
||
out.append(rect(PAD, y, W - 2 * PAD, 232, p["surface"], 12))
|
||
out.append(text(PAD + 16, y + 28, "权限", 14, p["text"]))
|
||
out.extend(permission_rows(p, y + 44))
|
||
y += 248
|
||
out.append(rect(PAD, y, W - 2 * PAD, 56, p["surface"], 12))
|
||
out.append(text(PAD + 16, y + 34, "小米 / MIUI 额外设置", 14, p["text"]))
|
||
out.append(text(W - PAD - 16, y + 34, "展开", 12, p["primary"], "end"))
|
||
y += 72
|
||
out.append(rect(PAD, y, W - 2 * PAD, 112, p["surface"], 12))
|
||
out.append(text(PAD + 16, y + 28, "服务器地址", 14, p["text"]))
|
||
out.append(text(W - PAD - 16, y + 28, "修改", 12, p["primary"], "end"))
|
||
out.append(text(PAD + 16, y + 56, "https://lpt-dev.cat-shark.xyz/api", 12, p["sec"], family=MONO))
|
||
out.append(text(PAD + 16, y + 82, "换环境时改这里,改完重新登录", 12, p["sec"]))
|
||
y += 136
|
||
out.append(text(W / 2, y + 24, "退出登录", 14, p["err"], "middle"))
|
||
return out
|
||
|
||
|
||
def screen_permissions_gate(p):
|
||
out = header(p, "权限与后台", back="‹ 任务", action="稍后")
|
||
y = 96
|
||
out.append(rect(PAD, y, W - 2 * PAD, 232, p["surface"], 12))
|
||
out.append(text(PAD + 16, y + 28, "能不能跨应用计时,取决于这三项", 14, p["text"]))
|
||
out.extend(permission_rows(p, y + 44))
|
||
y += 248
|
||
out.append(rect(PAD, y, W - 2 * PAD, 88, p["surface"], 12))
|
||
out.append(text(PAD + 16, y + 26, "小米 / MIUI 额外设置", 14, p["text"]))
|
||
out.append(text(PAD + 16, y + 50, "自启动、后台弹出界面、省电策略无限制", 12, p["sec"]))
|
||
out.append(text(W - PAD - 16, y + 26, "展开", 12, p["primary"], "end"))
|
||
out.extend(button(PAD, H - 88, W - 2 * PAD, 48, "已完成,去学习任务", p, "primary"))
|
||
return out
|
||
|
||
|
||
# ---------------------------------------------------------------- 登录页
|
||
|
||
def screen_login(p):
|
||
out = []
|
||
out.append(text(PAD + 8, 268, "LPT 学习", 28, p["text"]))
|
||
for label, value, y in (("账号", "admin", 312), ("密码", "••••••••••", 384)):
|
||
out.append(rect(PAD + 8, y, W - 2 * PAD - 16, 56, p["surface"], 8, p["border"], 1))
|
||
out.append(text(PAD + 24, y + 22, label, 12, p["sec"]))
|
||
out.append(text(PAD + 24, y + 43, value, 14, p["text"]))
|
||
out.extend(button(PAD + 8, 464, W - 2 * PAD - 16, 48, "登录", p, "primary"))
|
||
out.append(text(W / 2, 544, "修改 API 地址", 14, p["primary"], "middle"))
|
||
return out
|
||
|
||
|
||
# ---------------------------------------------------------------- 组装
|
||
|
||
def compose(frames, dark_border=False):
|
||
n = len(frames)
|
||
width = W * n + GUTTER * (n - 1)
|
||
parts = [f'<svg xmlns="http://www.w3.org/2000/svg" width="{width}" height="{H}" '
|
||
f'viewBox="0 0 {width} {H}" font-family="{FONT}">',
|
||
'<defs><clipPath id="fc"><rect x="0" y="0" '
|
||
f'width="{W}" height="{H}"/></clipPath></defs>']
|
||
for i, (dark, content) in enumerate(frames):
|
||
p = DARK if dark else LIGHT
|
||
dx = i * (W + GUTTER)
|
||
parts.append(f'<g transform="translate({dx},0)">')
|
||
parts.append(rect(0, 0, W, H, p["bg"]))
|
||
parts.extend(status_bar(p))
|
||
parts.append('<g clip-path="url(#fc)">')
|
||
parts.extend(content(p))
|
||
parts.append("</g>")
|
||
parts.append(rect(0.5, 0.5, W - 1, H - 1, "none", 0,
|
||
"#33453D" if dark else "#C6D6CD", 1))
|
||
parts.append("</g>")
|
||
parts.append("</svg>")
|
||
return "\n".join(parts)
|
||
|
||
|
||
FILES = {
|
||
"tasks.svg": [(False, screen_tasks)],
|
||
"tasks-dark.svg": [(True, screen_tasks)],
|
||
"tasks-states.svg": [(False, screen_tasks_empty), (False, screen_tasks_loading),
|
||
(False, screen_tasks_error)],
|
||
"session.svg": [(False, screen_session)],
|
||
"session-states.svg": [(False, lambda p: screen_session(p, "paused")),
|
||
(False, lambda p: screen_session(p, "due"))],
|
||
"reports.svg": [(False, screen_reports),
|
||
(False, lambda p: screen_reports(p, expanded=True))],
|
||
"settings.svg": [(False, screen_settings), (False, screen_permissions_gate)],
|
||
"login.svg": [(False, screen_login)],
|
||
}
|
||
|
||
if __name__ == "__main__":
|
||
for name, frames in FILES.items():
|
||
svg = compose(frames)
|
||
with open(os.path.join(OUT, name), "w", encoding="utf-8") as f:
|
||
f.write(svg + "\n")
|
||
print(f"wrote {name} ({len(frames)} frame(s), {len(svg)} bytes)")
|