feat: establish coffee game and grinder baseline
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<!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="./?v=20261107-2" aria-current="page">02 水流</a><a href="../extraction/?v=20261107-2">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>预浸泡 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 flow-grid">
|
||||
<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><p class="instrument-feedback" id="scoreFeedback" hidden></p>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,148 @@
|
||||
(() => {
|
||||
const { Gauge, TimerScale, MetricBar, clamp } = window.Lab;
|
||||
const { FlowLever } = window.MachineControls;
|
||||
const M = window.CoffeeMachine;
|
||||
const byId = id => document.getElementById(id);
|
||||
const machine = { ...M.defaults };
|
||||
const gauge = 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 accumulator = 0;
|
||||
let previousFrame = performance.now();
|
||||
const fixedStep = 1 / 120;
|
||||
const lever = 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];
|
||||
const referenceValve = () => M.idealValve(machine, activeRecipe().targetTemp);
|
||||
|
||||
function configureRecipe() {
|
||||
const recipe = activeRecipe();
|
||||
document.querySelectorAll("[data-recipe]").forEach(button => {
|
||||
button.setAttribute("aria-pressed", String(button.dataset.recipe === recipeName));
|
||||
button.disabled = isActive();
|
||||
});
|
||||
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×";
|
||||
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, lever.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;
|
||||
gauge.update(q);
|
||||
byId("flowValue").textContent = q.toFixed(2);
|
||||
byId("flowLeverValue").textContent = `${Math.round(lever.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 ? "精华收集中 · 关注相对浓度" : "暂停进水 · 精华与出液暂停;取手柄结束",
|
||||
complete: "本杯完成 · 手柄已取下",
|
||||
aborted: "粉饼未饱和 · 取手柄放弃本杯"
|
||||
};
|
||||
byId("sessionFeedback").textContent = feedback[phase];
|
||||
const scoreFeedback = byId("scoreFeedback");
|
||||
scoreFeedback.hidden = phase !== "complete";
|
||||
if (phase === "complete") {
|
||||
scoreFeedback.textContent = `R ${Math.round(scores.essenceRatio * 100)}% · C ${scores.concentration.toFixed(2)}×`;
|
||||
}
|
||||
}
|
||||
|
||||
function loadSession() {
|
||||
session = new M.BrewSession(machine, M.recipes[recipeName]);
|
||||
session.load();
|
||||
lever.setValue(0, false);
|
||||
accumulator = 0;
|
||||
configureRecipe();
|
||||
readout();
|
||||
}
|
||||
|
||||
function resetSession() {
|
||||
session = null;
|
||||
lever.setValue(0, false);
|
||||
accumulator = 0;
|
||||
configureRecipe();
|
||||
readout();
|
||||
}
|
||||
|
||||
document.querySelectorAll("[data-recipe]").forEach(button => {
|
||||
button.addEventListener("click", () => {
|
||||
if (session && !["complete", "aborted"].includes(session.phase)) return;
|
||||
recipeName = button.dataset.recipe;
|
||||
session = null;
|
||||
configureRecipe();
|
||||
readout();
|
||||
});
|
||||
});
|
||||
byId("loadButton").addEventListener("click", loadSession);
|
||||
byId("handleButton").addEventListener("click", () => {
|
||||
if (!session) return;
|
||||
session.removeHandle(lever.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(lever.value, referenceValve(), fixedStep);
|
||||
accumulator -= fixedStep;
|
||||
}
|
||||
}
|
||||
readout();
|
||||
requestAnimationFrame(frame);
|
||||
}
|
||||
|
||||
document.addEventListener("visibilitychange", () => { previousFrame = performance.now(); });
|
||||
configureRecipe();
|
||||
readout();
|
||||
requestAnimationFrame(frame);
|
||||
})();
|
||||
Reference in New Issue
Block a user