feat: mark four agenda windows on the overview timeline
总览时间轴此前只有条目自己的时钟区间,与运维页「当前时间段」、归档里的 窗口快照三者口径各说各的。现在统一走 agenda_contracts.window_for_minutes。 窗口标记放在时间列的色条上,不用整行底色——整行底色与透明度已经被 lifecycle 占用(is-current 用 background、is-completed 用 opacity、is-change 用 background), 再拿整行表示窗口会撞语义,尤其「深夜」与「已完成」都偏灰无法区分。 另加窗口分组小标,色觉障碍/打印/换肤时不依赖颜色也能读。 agenda_contracts 新增 window_for_minutes 与 WINDOW_SLUGS,页面与归档共用同一判定。 新增 5 项回归,含与 window_for_datetime 全天 24 小时逐点一致性校验。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
这个提交存在于:
父节点
fa0241ff99
当前提交
eb8b1dd3b1
共有 5 个文件被更改,包括 173 次插入 和 3 次删除
|
|
@ -37,6 +37,27 @@ WINDOW_DEFINITIONS = (
|
||||||
("晚上", 18 * 60, 22 * 60),
|
("晚上", 18 * 60, 22 * 60),
|
||||||
)
|
)
|
||||||
WINDOW_NAMES = {item[0] for item in WINDOW_DEFINITIONS}
|
WINDOW_NAMES = {item[0] for item in WINDOW_DEFINITIONS}
|
||||||
|
# 渲染层用的窗口标识(CSS 类名/主题变量都用它,避免把中文名写进样式表)
|
||||||
|
WINDOW_SLUGS = {"深夜": "late_night", "早晨": "morning", "下午": "afternoon", "晚上": "evening"}
|
||||||
|
|
||||||
|
|
||||||
|
def window_for_minutes(minutes: Any) -> str:
|
||||||
|
"""把「当日分钟数」归入四段式窗口。
|
||||||
|
|
||||||
|
页面时间轴按分钟排段,没有 datetime 可用;跨零点的段会带 +1440 偏移,先取模。
|
||||||
|
深夜跨零点(22:00-06:00),所以它的判定要拆成两截。
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
value = int(minutes) % (24 * 60)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
return ""
|
||||||
|
for name, start, end in WINDOW_DEFINITIONS:
|
||||||
|
if start < end:
|
||||||
|
if start <= value < end:
|
||||||
|
return name
|
||||||
|
elif value >= start or value < end:
|
||||||
|
return name
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def timezone_or_default(timezone_name: Any = "Asia/Shanghai") -> ZoneInfo:
|
def timezone_or_default(timezone_name: Any = "Asia/Shanghai") -> ZoneInfo:
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ from quart import request, send_file
|
||||||
|
|
||||||
from .constants import DEFAULT_DAILY_PLAN_ITEMS, PAGE_FONT_NAMES, PAGE_THEME_NAMES, PLUGIN_NAME, _REASON_TEXT
|
from .constants import DEFAULT_DAILY_PLAN_ITEMS, PAGE_FONT_NAMES, PAGE_THEME_NAMES, PLUGIN_NAME, _REASON_TEXT
|
||||||
from .config_migration import _ensure_config_parent_dir
|
from .config_migration import _ensure_config_parent_dir
|
||||||
|
from .agenda_contracts import WINDOW_SLUGS, window_for_minutes
|
||||||
from .helpers import _flat_get, _normalize_timezone_name, _redact_outbound_secrets, _safe_int, _set_into_config, _set_today_key_timezone, _strip_internal_message_blocks, _text_looks_garbled, _text_similarity, _today_key
|
from .helpers import _flat_get, _normalize_timezone_name, _redact_outbound_secrets, _safe_int, _set_into_config, _set_today_key_timezone, _strip_internal_message_blocks, _text_looks_garbled, _text_similarity, _today_key
|
||||||
from .page_api_users_groups import PrivateCompanionPageApiUsersGroupsMixin
|
from .page_api_users_groups import PrivateCompanionPageApiUsersGroupsMixin
|
||||||
from .planning import evaluate_daily_plan_quality, generate_daily_plan, generate_detail_enhancement
|
from .planning import evaluate_daily_plan_quality, generate_daily_plan, generate_detail_enhancement
|
||||||
|
|
@ -18663,6 +18664,10 @@ class PrivateCompanionPageApi(PrivateCompanionPageApiUsersGroupsMixin):
|
||||||
{
|
{
|
||||||
"key": str(key),
|
"key": str(key),
|
||||||
"window": segment.get("window", str(key)),
|
"window": segment.get("window", str(key)),
|
||||||
|
# 四段式窗口。此前时间轴只有条目自己的时钟区间,
|
||||||
|
# 与运维页「当前时间段」、归档里的窗口快照三者口径各说各的。
|
||||||
|
"agenda_window": window_for_minutes(segment.get("start")),
|
||||||
|
"agenda_window_slug": WINDOW_SLUGS.get(window_for_minutes(segment.get("start")), ""),
|
||||||
"start": segment.get("start", 99999),
|
"start": segment.get("start", 99999),
|
||||||
"end": segment.get("end", 99999),
|
"end": segment.get("end", 99999),
|
||||||
"lifecycle": lifecycle,
|
"lifecycle": lifecycle,
|
||||||
|
|
@ -18706,6 +18711,8 @@ class PrivateCompanionPageApi(PrivateCompanionPageApiUsersGroupsMixin):
|
||||||
{
|
{
|
||||||
"key": key,
|
"key": key,
|
||||||
"window": f"{self.plugin._minutes_to_hhmm(start)}-{self.plugin._minutes_to_hhmm(end)}",
|
"window": f"{self.plugin._minutes_to_hhmm(start)}-{self.plugin._minutes_to_hhmm(end)}",
|
||||||
|
"agenda_window": window_for_minutes(start),
|
||||||
|
"agenda_window_slug": WINDOW_SLUGS.get(window_for_minutes(start), ""),
|
||||||
"start": start,
|
"start": start,
|
||||||
"end": end,
|
"end": end,
|
||||||
"lifecycle": self.plugin._plan_item_runtime_status(plan, item, index),
|
"lifecycle": self.plugin._plan_item_runtime_status(plan, item, index),
|
||||||
|
|
|
||||||
|
|
@ -8390,9 +8390,21 @@ function renderDashboardLifeDesk(overview = {}) {
|
||||||
item,
|
item,
|
||||||
}));
|
}));
|
||||||
const entries = [...scheduleEntries, ...changeEntries].sort((left, right) => left.sort - right.sort);
|
const entries = [...scheduleEntries, ...changeEntries].sort((left, right) => left.sort - right.sort);
|
||||||
|
// 四段式分组小标:不依赖颜色也能读懂(色觉障碍、打印、换肤时颜色语义会失效)。
|
||||||
|
// 只在窗口发生变化时插一条,日程条目本身的结构不变。
|
||||||
|
let lastAgendaWindow = "";
|
||||||
timelineRoot.innerHTML = entries.length ? entries.map((entry) => {
|
timelineRoot.innerHTML = entries.length ? entries.map((entry) => {
|
||||||
|
let windowHeading = "";
|
||||||
|
if (entry.kind === "schedule") {
|
||||||
|
const agendaWindow = String(entry.segment?.agenda_window || "");
|
||||||
|
if (agendaWindow && agendaWindow !== lastAgendaWindow) {
|
||||||
|
lastAgendaWindow = agendaWindow;
|
||||||
|
const slug = String(entry.segment?.agenda_window_slug || "");
|
||||||
|
windowHeading = `<li class="life-timeline-window is-window-${escapeHtml(slug)}" role="presentation"><span>${escapeHtml(agendaWindow)}</span></li>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (entry.kind === "change") {
|
if (entry.kind === "change") {
|
||||||
return `
|
return windowHeading + `
|
||||||
<li class="life-timeline-row is-change">
|
<li class="life-timeline-row is-change">
|
||||||
<time class="life-timeline-time is-change-time"><strong>${escapeHtml(entry.item.label)}</strong></time>
|
<time class="life-timeline-time is-change-time"><strong>${escapeHtml(entry.item.label)}</strong></time>
|
||||||
<div class="life-timeline-content">
|
<div class="life-timeline-content">
|
||||||
|
|
@ -8410,8 +8422,9 @@ function renderDashboardLifeDesk(overview = {}) {
|
||||||
const windowMatch = windowText.match(/^(\d{1,2}:\d{2})\s*[-~至]\s*(\d{1,2}:\d{2})$/);
|
const windowMatch = windowText.match(/^(\d{1,2}:\d{2})\s*[-~至]\s*(\d{1,2}:\d{2})$/);
|
||||||
const startText = windowMatch ? windowMatch[1] : windowText;
|
const startText = windowMatch ? windowMatch[1] : windowText;
|
||||||
const endText = windowMatch ? windowMatch[2] : "";
|
const endText = windowMatch ? windowMatch[2] : "";
|
||||||
return `
|
const windowSlug = String(segment.agenda_window_slug || "");
|
||||||
<li class="life-timeline-row is-${escapeHtml(lifecycle)}${isCurrent ? " is-current" : ""}"${isCurrent ? ' aria-current="step"' : ""}>
|
return windowHeading + `
|
||||||
|
<li class="life-timeline-row is-${escapeHtml(lifecycle)}${isCurrent ? " is-current" : ""}${windowSlug ? ` is-window-${escapeHtml(windowSlug)}` : ""}"${isCurrent ? ' aria-current="step"' : ""}>
|
||||||
<time class="life-timeline-time">
|
<time class="life-timeline-time">
|
||||||
<strong>${escapeHtml(startText)}</strong>
|
<strong>${escapeHtml(startText)}</strong>
|
||||||
${endText ? `<small>至 ${escapeHtml(endText)}</small>` : ""}
|
${endText ? `<small>至 ${escapeHtml(endText)}</small>` : ""}
|
||||||
|
|
|
||||||
|
|
@ -3087,3 +3087,78 @@ small {
|
||||||
border-bottom: 0;
|
border-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ── 四段式窗口标记(深夜/早晨/下午/晚上)────────────────────────────────
|
||||||
|
放在时间列的色条上,而不是整行底色:整行底色与透明度已经被 lifecycle 占用
|
||||||
|
(.is-current 用 background、.is-completed 用 opacity、.is-change 用 background),
|
||||||
|
再拿整行表示窗口会和它们撞语义——尤其「深夜」与「已完成」都偏灰,无法区分。
|
||||||
|
颜色一律走变量,页面有 28 套主题,写死色值换肤后会失真。 */
|
||||||
|
:root {
|
||||||
|
--window-late-night: #4c5aa8;
|
||||||
|
--window-morning: #4aa3d8;
|
||||||
|
--window-afternoon: #e08a3c;
|
||||||
|
--window-evening: #a9663c;
|
||||||
|
}
|
||||||
|
|
||||||
|
.life-timeline-row.is-window-late_night,
|
||||||
|
.life-timeline-window.is-window-late_night { --timeline-window-color: var(--window-late-night); }
|
||||||
|
.life-timeline-row.is-window-morning,
|
||||||
|
.life-timeline-window.is-window-morning { --timeline-window-color: var(--window-morning); }
|
||||||
|
.life-timeline-row.is-window-afternoon,
|
||||||
|
.life-timeline-window.is-window-afternoon { --timeline-window-color: var(--window-afternoon); }
|
||||||
|
.life-timeline-row.is-window-evening,
|
||||||
|
.life-timeline-window.is-window-evening { --timeline-window-color: var(--window-evening); }
|
||||||
|
|
||||||
|
.life-timeline-row[class*="is-window-"] .life-timeline-time {
|
||||||
|
position: relative;
|
||||||
|
padding-left: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.life-timeline-row[class*="is-window-"] .life-timeline-time::before {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
top: 2px;
|
||||||
|
bottom: 2px;
|
||||||
|
left: 0;
|
||||||
|
width: 3px;
|
||||||
|
border-radius: 2px;
|
||||||
|
background: var(--timeline-window-color, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 已完成整行会被调淡,色条跟着淡下去即可,不额外补偿——
|
||||||
|
否则「已完成」这个状态反而被窗口色盖过去。 */
|
||||||
|
|
||||||
|
/* 分组小标:不依赖颜色也能读出当前是哪一段 */
|
||||||
|
.life-timeline-window {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
margin: 16px 0 4px;
|
||||||
|
padding: 0 2px;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
letter-spacing: .12em;
|
||||||
|
color: var(--muted);
|
||||||
|
list-style: none;
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.life-timeline-window:first-child { margin-top: 2px; }
|
||||||
|
|
||||||
|
.life-timeline-window::before {
|
||||||
|
content: "";
|
||||||
|
flex: 0 0 auto;
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--timeline-window-color, var(--line-soft));
|
||||||
|
}
|
||||||
|
|
||||||
|
.life-timeline-window::after {
|
||||||
|
content: "";
|
||||||
|
flex: 1 1 auto;
|
||||||
|
height: 1px;
|
||||||
|
background: linear-gradient(to right, var(--line-soft), transparent);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""四段式窗口归类回归。
|
||||||
|
|
||||||
|
总览时间轴、运维页「当前时间段」、归档里的窗口快照此前各算各的,
|
||||||
|
现在统一走 agenda_contracts.window_for_minutes。
|
||||||
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
|
|
||||||
|
from agenda_contracts import WINDOW_DEFINITIONS, WINDOW_SLUGS, window_for_datetime, window_for_minutes
|
||||||
|
|
||||||
|
TZ = timezone(timedelta(hours=8))
|
||||||
|
|
||||||
|
|
||||||
|
class WindowForMinutesTests(unittest.TestCase):
|
||||||
|
def test_each_window_boundary(self):
|
||||||
|
cases = [
|
||||||
|
(0, "深夜"), (5 * 60 + 59, "深夜"), (22 * 60, "深夜"), (23 * 60 + 59, "深夜"),
|
||||||
|
(6 * 60, "早晨"), (11 * 60 + 59, "早晨"),
|
||||||
|
(12 * 60, "下午"), (17 * 60 + 59, "下午"),
|
||||||
|
(18 * 60, "晚上"), (21 * 60 + 59, "晚上"),
|
||||||
|
]
|
||||||
|
for minutes, expected in cases:
|
||||||
|
with self.subTest(minutes=minutes):
|
||||||
|
self.assertEqual(window_for_minutes(minutes), expected)
|
||||||
|
|
||||||
|
def test_cross_midnight_offset_is_normalised(self):
|
||||||
|
"""跨零点的段带 +1440 偏移,必须先取模再归类。"""
|
||||||
|
self.assertEqual(window_for_minutes(24 * 60 + 30), "深夜")
|
||||||
|
self.assertEqual(window_for_minutes(24 * 60 + 7 * 60), "早晨")
|
||||||
|
|
||||||
|
def test_invalid_input_returns_empty(self):
|
||||||
|
for value in (None, "", "abc", object()):
|
||||||
|
self.assertEqual(window_for_minutes(value), "")
|
||||||
|
|
||||||
|
def test_every_window_has_a_slug(self):
|
||||||
|
for name, _start, _end in WINDOW_DEFINITIONS:
|
||||||
|
self.assertIn(name, WINDOW_SLUGS)
|
||||||
|
self.assertRegex(WINDOW_SLUGS[name], r"^[a-z_]+$")
|
||||||
|
|
||||||
|
def test_agrees_with_window_for_datetime(self):
|
||||||
|
"""与既有的 datetime 版判定必须一致,否则页面和归档又会各说各的。"""
|
||||||
|
for hour in range(24):
|
||||||
|
for minute in (0, 30, 59):
|
||||||
|
moment = datetime(2026, 7, 27, hour, minute, tzinfo=TZ)
|
||||||
|
expected = window_for_datetime(moment)[0]
|
||||||
|
with self.subTest(t=f"{hour:02d}:{minute:02d}"):
|
||||||
|
self.assertEqual(window_for_minutes(hour * 60 + minute), expected)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
正在加载…
添加表格
在新工单中引用