feat: establish coffee game and grinder baseline

This commit is contained in:
Yanchen
2026-11-11 14:08:47 +08:00
commit 890f3fa5f3
220 changed files with 8361 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>精华与浓度 · 咖啡机手感实验</title>
<link rel="stylesheet" href="../assets/lab.css?v=20261107-2">
<script src="../assets/instruments.js?v=20261107-2" defer></script>
<script src="../assets/machine.js?v=20261107-2" defer></script>
<script src="../assets/controls.js?v=20261107-2" defer></script>
<script src="page.js?v=20261107-2" defer></script>
</head>
<body>
<header class="lab-header">
<a class="lab-brand" href="../?v=20261107-2"><span class="brand-mark">PC</span><span class="brand-copy">咖啡机<small>手感实验</small></span></a>
<nav class="module-nav" aria-label="测试模块"><a href="../temperature/?v=20261107-2">01 水温</a><a href="../flow/?v=20261107-2">02 水流</a><a href="./?v=20261107-2" aria-current="page">03 萃取</a></nav>
</header>
<main class="workspace">
<section class="recipe-bar" aria-label="配方与制杯操作">
<div class="recipe-picker" role="group" aria-label="配方"><button type="button" data-recipe="B1" aria-pressed="true">B1</button><button type="button" data-recipe="B2" aria-pressed="false">B2</button></div>
<div class="recipe-targets"><span>水温 T <strong id="tempTarget">92 ± 1°C</strong></span><span>预浸泡 I <strong id="preTarget">6–9 s</strong></span><span>精华 <strong id="essenceRequirement">≥100%</strong></span><span>参考量 <strong id="referenceVolumeTarget">300 mL</strong></span><span>浓度目标 <strong id="concentrationGoal">1.00×</strong></span></div>
<div class="session-actions"><button class="action-button primary" id="loadButton" type="button">装粉并锁定</button><button class="action-button" id="handleButton" type="button" disabled>取下手柄</button><button class="action-button" id="resetButton" type="button">复位</button></div>
</section>
<div class="instrument-grid extraction-grid">
<section class="instrument-card"><div class="instrument-heading"><h2>出水口温度</h2><span>T_s · 2 s</span></div><svg id="temperatureGauge"></svg></section>
<section class="instrument-card"><div class="instrument-heading"><h2>沸水阀</h2><span>100°C</span></div><svg id="hotValve"></svg><div class="control-readout"><span>开度 <output id="hotValveValue">60%</output></span><span>q<sub>h</sub> <output id="hotFlowValue">0.010</output><small>mL/s</small></span></div></section>
<section class="instrument-card"><div class="instrument-heading"><h2>萃取水流</h2><span>q</span></div><svg id="flowGauge"></svg><div class="instrument-reading"><output id="flowValue">0.00</output><span>mL/s</span></div></section>
<section class="instrument-card"><div class="instrument-heading"><h2>水流拨杆</h2><span>连续开度</span></div><svg id="flowLever"></svg><div class="control-readout"><span>开度 <output id="flowLeverValue">0%</output></span><span>q <output id="waterFlowValue">0.00</output><small>mL/s</small></span></div></section>
<section class="instrument-card timing-card">
<div class="instrument-heading"><h2>双阶段与萃取得分</h2><span id="sessionStatus">待装粉</span></div>
<div class="dual-timers">
<div class="timer-block" id="preTimer" data-label="预浸泡"><div class="timer-heading"><span>预浸泡 I</span><small>首次接触水开始</small></div><div class="timer-value"><output data-time>00.0</output><span>s</span></div><div class="timer-track"><span class="timer-target-band" data-target-band></span><span class="timer-marker" data-time-marker></span></div><div class="timer-labels"><span>0</span><span data-target>6–9 s</span><span data-max>12 s</span></div></div>
<div class="timer-block"><div class="timer-heading"><span>萃取进水</span><small>过程数据 · 不直接评分</small></div><div class="timer-value"><output id="processTime">00.0</output><span>s</span></div><div class="process-note">只记录实际进水时间</div></div>
</div>
<div class="extraction-metrics">
<div class="metric-block" id="essenceMetric"><div class="metric-heading"><span>精华收集 R</span><output data-value>0%</output></div><div class="metric-track"><span data-fill></span><i data-marker></i></div><div class="metric-detail"><span data-detail>0.0 / 10</span><span data-target>≥100%</span></div></div>
<div class="metric-block" id="concentrationMetric"><div class="metric-heading"><span>相对浓度 C</span><output data-value>0.00×</output></div><div class="metric-track"><span data-fill></span><i data-marker></i></div><div class="metric-detail"><span data-detail>等待出液</span><span data-target>目标 1.00×</span></div></div>
</div>
<div class="liquid-status"><div class="liquid-meter"><div class="liquid-label"><span>粉饼吸水</span><output id="saturationValue">0.0 / 60 mL</output></div><div class="meter"><span id="saturationMeter"></span></div></div><div class="liquid-meter"><div class="liquid-label"><span>饮料量</span><output id="volumeValue">0.0 mL</output></div><div class="meter output"><span id="volumeMeter"></span></div></div></div>
<div class="liquid-label total-time"><span>总冲泡时间(含关水间隙)</span><output id="totalTime">0.0 s</output></div>
<div class="score-line"><span>萃取得分 E</span><output id="extractionScore">0.0</output></div>
<p class="instrument-feedback" id="sessionFeedback" role="status">装粉后,推杆开始进水</p>
<details class="review-details" id="reviewDetails" hidden><summary>查看 T / I / E 分项</summary><div class="review-scores"><span>T<output id="temperatureScore">—</output></span><span>I<output id="preinfusionScore">—</output></span><span>E<output id="reviewExtractionScore">—</output></span></div></details>
</section>
</div>
</main>
</body>
</html>
+173
View File
@@ -0,0 +1,173 @@
(() => {
const { Gauge, TimerScale, MetricBar, clamp } = window.Lab;
const { RotaryValve, FlowLever } = window.MachineControls;
const M = window.CoffeeMachine;
const byId = id => document.getElementById(id);
const machine = { ...M.defaults };
const temperatureGauge = new Gauge(byId("temperatureGauge"), {
min: 0, max: 100, target: M.recipes.B1.targetTemp,
tolerance: M.recipes.B1.tempTolerance, unit: "°C", label: "T_s"
});
const flowGauge = new Gauge(byId("flowGauge"), { min: 0, max: machine.maxFlow, unit: "mL/s", label: "q" });
const preTimer = new TimerScale(byId("preTimer"), { max: 12 });
const essenceMetric = new MetricBar(byId("essenceMetric"), { max: 100 });
const concentrationMetric = new MetricBar(byId("concentrationMetric"), { max: 2 });
let recipeName = "B1";
let session = null;
let sensorTemperature = M.temperature(machine, 0.6);
let accumulator = 0;
let previousFrame = performance.now();
const fixedStep = 1 / 120;
const hotValve = new RotaryValve(byId("hotValve"), {
value: 0.6,
label: "沸水阀 · 只调节混水温度",
onChange: readout
});
const flowLever = new FlowLever(byId("flowLever"), {
value: 0,
label: "萃取水流拨杆 · 精华收集与相对浓度",
onChange: readout
});
const isActive = () => Boolean(session && ["ready", "preinfusion", "extraction"].includes(session.phase));
const activeRecipe = () => session ? session.recipe : M.recipes[recipeName];
function configureRecipe() {
const recipe = activeRecipe();
document.querySelectorAll("[data-recipe]").forEach(button => {
button.setAttribute("aria-pressed", String(button.dataset.recipe === recipeName));
button.disabled = isActive();
});
byId("tempTarget").textContent = `${recipe.targetTemp} ± ${recipe.tempTolerance}°C`;
byId("preTarget").textContent = `${recipe.preMin}–${recipe.preMax} s`;
byId("essenceRequirement").textContent = `≥${Math.round(recipe.minEssenceRatio * 100)}%`;
byId("referenceVolumeTarget").textContent = `${recipe.referenceVolume} mL`;
byId("concentrationGoal").textContent = "1.00×";
temperatureGauge.setTarget(recipe.targetTemp, recipe.tempTolerance);
preTimer.setTarget(recipe.preMin, recipe.preMax);
essenceMetric.setTarget(recipe.minEssenceRatio * 100, `≥${Math.round(recipe.minEssenceRatio * 100)}%`);
concentrationMetric.setTarget(1, "目标 1.00×");
}
function readout() {
const phase = session ? session.phase : "empty";
const recipe = activeRecipe();
const q = M.flow(machine, flowLever.value);
const waterIn = session ? session.waterIn : 0;
const volume = session ? session.volume : 0;
const scores = session ? session.scores() : null;
const ratio = scores ? scores.essenceRatio : 0;
const concentration = scores ? scores.concentration : 0;
temperatureGauge.update(sensorTemperature);
flowGauge.update(q);
byId("hotValveValue").textContent = `${Math.round(hotValve.value * 100)}%`;
byId("hotFlowValue").textContent = M.hotFlow(machine, hotValve.value).toFixed(3);
byId("flowValue").textContent = q.toFixed(2);
byId("flowLeverValue").textContent = `${Math.round(flowLever.value * 100)}%`;
byId("waterFlowValue").textContent = q.toFixed(2);
preTimer.update(session ? session.preTime ?? session.elapsed : 0, phase === "preinfusion");
byId("processTime").textContent = (session ? session.extractionTime : 0).toFixed(1).padStart(4, "0");
essenceMetric.update(ratio * 100, `${Math.round(ratio * 100)}%`);
essenceMetric.setDetail(`${(session ? session.essenceCollected : 0).toFixed(1)} / ${recipe.essenceCapacity}`);
concentrationMetric.update(concentration, `${concentration.toFixed(2)}×`);
concentrationMetric.setDetail(volume > 0 ? `${volume.toFixed(1)} mL` : "等待出液");
byId("saturationValue").textContent = `${waterIn.toFixed(1)} / ${machine.saturation} mL`;
byId("saturationMeter").style.width = `${clamp(0, 100, waterIn / machine.saturation * 100)}%`;
byId("volumeValue").textContent = `${volume.toFixed(1)} mL`;
byId("volumeMeter").style.width = `${clamp(0, 100, volume / (recipe.referenceVolume * 1.5) * 100)}%`;
byId("totalTime").textContent = `${(session ? session.elapsed : 0).toFixed(1)} s`;
byId("extractionScore").textContent = scores ? scores.extraction.toFixed(1) : "0.0";
document.querySelectorAll("[data-recipe]").forEach(button => { button.disabled = isActive(); });
const status = {
empty: "待装粉", ready: "等待进水",
preinfusion: q > 0 ? "预浸泡" : "I继续 · 关水",
extraction: q > 0 ? "萃取进水" : "萃取暂停",
complete: "本杯完成", aborted: "已放弃"
};
byId("sessionStatus").textContent = status[phase];
byId("loadButton").disabled = isActive();
byId("loadButton").textContent = ["complete", "aborted"].includes(phase) ? "再做一杯" : "装粉并锁定";
byId("handleButton").disabled = !session || !["preinfusion", "extraction"].includes(phase) || (phase === "extraction" && q > 0);
byId("handleButton").textContent = phase === "extraction" && q > 0 ? "先关水" : phase === "complete" ? "已取手柄" : "取下手柄";
const feedback = {
empty: "装粉后,推杆开始进水",
ready: "手柄已锁定 · 等待进水",
preinfusion: q > 0 ? "粉饼吸水中 · I继续" : "停止吸水 · I继续",
extraction: q > 0 ? "精华收集中 · 关注相对浓度" : "暂停进水 · 精华与出液暂停;取手柄结束",
aborted: "粉饼未饱和 · 取手柄放弃本杯"
};
byId("reviewDetails").hidden = phase !== "complete";
if (phase === "complete") {
const entries = [
{ label: "水温", key: "T", score: scores.temperature },
{ label: "预浸泡", key: "I", score: scores.preinfusion },
{ label: "精华与浓度", key: "E", score: scores.extraction }
];
const focus = entries.reduce((worst, entry) => entry.score < worst.score ? entry : worst);
byId("sessionFeedback").textContent = `本杯完成 · 重点关注 ${focus.label} ${focus.key} ${focus.score.toFixed(1)}`;
byId("temperatureScore").textContent = scores.temperature.toFixed(1);
byId("preinfusionScore").textContent = scores.preinfusion.toFixed(1);
byId("reviewExtractionScore").textContent = scores.extraction.toFixed(1);
} else {
byId("sessionFeedback").textContent = feedback[phase];
}
}
function loadSession() {
session = new M.BrewSession(machine, M.recipes[recipeName], sensorTemperature);
session.load();
flowLever.setValue(0, false);
accumulator = 0;
configureRecipe();
readout();
}
function resetSession() {
session = null;
flowLever.setValue(0, false);
accumulator = 0;
configureRecipe();
readout();
}
document.querySelectorAll("[data-recipe]").forEach(button => {
button.addEventListener("click", () => {
if (isActive()) return;
recipeName = button.dataset.recipe;
session = null;
configureRecipe();
readout();
});
});
byId("loadButton").addEventListener("click", loadSession);
byId("handleButton").addEventListener("click", () => {
if (!session) return;
session.removeHandle(flowLever.value);
readout();
});
byId("resetButton").addEventListener("click", resetSession);
function frame(now) {
const frameTime = Math.min(0.1, Math.max(0, (now - previousFrame) / 1000));
previousFrame = now;
if (isActive()) {
accumulator += frameTime;
while (accumulator >= fixedStep && isActive()) {
session.step(flowLever.value, hotValve.value, fixedStep);
accumulator -= fixedStep;
}
sensorTemperature = session.sensorTemperature;
} else {
sensorTemperature = M.probeStep(machine, sensorTemperature, hotValve.value, frameTime);
}
readout();
requestAnimationFrame(frame);
}
document.addEventListener("visibilitychange", () => { previousFrame = performance.now(); });
configureRecipe();
readout();
requestAnimationFrame(frame);
})();