From 244b1f73cac3198889f6dbe257f352dbc6e6f372 Mon Sep 17 00:00:00 2001 From: Yoav Date: Wed, 18 Nov 2026 14:13:19 +0200 Subject: [PATCH] Make Lab Code Practice exercise-first --- README.md | 2 +- site/_quarto.yml | 38 +- site/assets/notebook-lab.js | 675 +++++++++++++++++++++++++------- site/assets/notebook-lessons.js | 52 ++- site/assets/style.css | 228 +++++------ site/assets/ui.js | 14 +- site/git-playground.qmd | 6 +- site/index.qmd | 68 ++-- site/notebook-lab.qmd | 120 +++--- site/resources.qmd | 16 +- site/workshop.qmd | 2 +- 11 files changed, 813 insertions(+), 408 deletions(-) diff --git a/README.md b/README.md index 2411ea6..eb85d7e 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ For a copy hosted in another repository, enable Pages with GitHub Actions and up ## Design and teaching decisions -A slate-and-blue design, clear sans-serif typography, restrained surfaces, and a scientific illustration give the workshop a consistent visual identity. The notebook lab groups files into keyboard-accessible tabs with a task rail, kernel toolbar, line-number gutters, output panels, and nearby check feedback. The Git room has a live mission checklist, per-file controls, and an optional terminal. Narrow screens stack the workspaces and collapse detailed instructions. Modules share objectives, research examples, exercises with hints and revealed explanations, takeaways, and onward links. Introductory Python syntax is assumed. Optional explanations address tooling and package mechanics; extensions address scientific and maintenance tradeoffs. Semantic HTML, visible focus, reduced-motion support, responsive layouts, and text alternatives complement Quarto's built-in navigation. +A slate-and-blue design, clear sans-serif typography, restrained surfaces, and a scientific illustration give the workshop a consistent visual identity. The homepage links directly to four guided notebook exercises followed by Git practice. The notebook guide presents one action at a time, with Python loading on the first run, feedback beside the current step, and an overview for jumping to any step. Keyboard-accessible file tabs, execution history, and exports are available in the workspace. The Git room has a live mission checklist, per-file controls, and an optional terminal. Narrow screens stack the instructions and workspace. Modules share objectives, research examples, exercises with hints and revealed explanations, takeaways, and onward links. Introductory Python syntax is assumed. Optional explanations address tooling and package mechanics; extensions address scientific and maintenance tradeoffs. Semantic HTML, visible focus, reduced-motion support, responsive layouts, and text alternatives complement Quarto's built-in navigation. The simulator is bounded to two teaching files, five local branches, and 50 commits. It never executes Git or modifies a real filesystem. Real Git commands and scientific decision-making remain explicit in the Git lab. Mission progress carries across mission switches during a visit and resets on reload. Python source edits, predictions, and personal handoff notes are saved in localStorage when available. Kernel variables are temporary. Both lab notebooks and handoff notes can be exported. No account is required. diff --git a/site/_quarto.yml b/site/_quarto.yml index 5f767d6..9447881 100644 --- a/site/_quarto.yml +++ b/site/_quarto.yml @@ -18,20 +18,20 @@ website: title: "research / code" background: light right: - - text: "90-minute workshop" - href: workshop.qmd - - text: "Get the materials ↗" + - text: "Notebook practice" + href: notebook-lab.qmd + - text: "Git practice" + href: git-playground.qmd + - text: "Lessons & materials" href: resources.qmd sidebar: style: docked background: light collapse-level: 2 contents: - - text: "Overview" - href: index.qmd - - text: "Setup & prerequisites" - href: setup.qmd - - section: "THE LEARNING PATH" + - text: "Lessons & materials" + href: resources.qmd + - section: "LESSONS" contents: - text: "01 · Clean code & naming" href: modules/01-foundations.qmd @@ -45,23 +45,19 @@ website: href: modules/05-git.qmd - text: "06 · Reproducible together" href: modules/06-reproducibility.qmd - - section: "LABS & PRACTICE" + - section: "WORKSHOP MATERIALS" contents: - - text: "Notebook lab" - href: notebook-lab.qmd - - text: "Git practice room" - href: git-playground.qmd - - text: "Handoff & practice" - href: practice.qmd - - text: "The Git lab" + - text: "Local setup" + href: setup.qmd + - text: "Git lab on your computer" href: git-lab.qmd - - text: "Workshop run sheet" + - text: "Personal handoff plan" + href: practice.qmd + - text: "Facilitator schedule" href: workshop.qmd - - text: "Downloads & reference" - href: resources.qmd page-footer: - left: "Research / Code · A workshop for the curious lab" - right: "Synthetic data. Real research habits. · November 2026" + left: "Research / Code" + right: "Workshop exercises use synthetic data." format: html: theme: diff --git a/site/assets/notebook-lab.js b/site/assets/notebook-lab.js index 00a5a31..4a91b89 100644 --- a/site/assets/notebook-lab.js +++ b/site/assets/notebook-lab.js @@ -1,139 +1,538 @@ -import {lessons,notebookExport} from './notebook-lessons.js'; -const root=document.querySelector('[data-notebook-lab]'); -if(root) { - const q=s=>root.querySelector(s); - const BASE_CONFIG='[paths]\ndata = "../data/raw/trials.csv"\noutput = "../results/baseline"\n\n[preprocessing]\nmin_rt_s = 0.2\nmax_rt_s = 2.0\n'; - const storageKey='research-code-notebook-v1'; - let saved={}; - try{saved=JSON.parse(localStorage.getItem(storageKey)||'{}');}catch{saved={};} - let lesson,worker,ready=false,busy=false,sequence=0,execution=0,pending=new Map(); - const message=text=>{q('[data-kernel-status]').textContent=text;q('[data-kernel-status]').closest('.kernel-line').dataset.state=busy?'busy':ready?'ready':'idle';}; - const sources=()=>[...root.querySelectorAll('[data-cell-code]')].map(e=>e.value); - const workspace=()=>({'helpers.py':q('[data-helper]').value,'config/analysis.toml':q('[data-config]').value}); - function persist(){ - if(!lesson)return; - saved[lesson.id]={sources:sources(),helper:q('[data-helper]').value,config:q('[data-config]').value,prediction:q('[data-prediction]').value}; - try{localStorage.setItem(storageKey,JSON.stringify(saved));}catch{message('Browser storage is unavailable. Download your notebook to keep edits.');} - } - function invalidate(){delete q('[data-mission-result]').dataset.state;q('[data-mission-result]').textContent='Edits changed the saved procedure. Rerun and check it again.';for(const output of root.querySelectorAll('[data-cell-output]')){if(output.textContent)output.dataset.stale='true';}persist();} - function controls(){ - q('[data-kernel-status]').closest('.kernel-line').dataset.state=busy?'busy':ready?'ready':'idle'; - for(const b of root.querySelectorAll('[data-run-cell],[data-run-all],[data-check-mission],[data-save-file],[data-scenario],[data-solution],[data-reset-lesson]'))b.disabled=busy; - q('[data-start-python]').disabled=busy||ready; - q('[data-stop-python]').disabled=!worker; - for(const e of root.querySelectorAll('[data-cell-code],[data-helper],[data-config]'))e.readOnly=busy; - } - function terminate(reason='Kernel restarted. Run cells again; previous variables and virtual files were cleared.'){ - worker?.terminate();worker=null;ready=false;execution=0; - for(const request of pending.values()){clearTimeout(request.timer);request.reject(new Error(reason));}pending.clear(); - q('[data-variables]').textContent='No live variables. Start Python and run a cell.'; - for(const c of root.querySelectorAll('[data-cell-count]'))c.textContent='In [ ]'; - for(const o of root.querySelectorAll('[data-cell-output]'))if(o.textContent)o.dataset.stale='true'; - message(reason);controls(); - } - function request(action,values={},timeout=15000){ - const id=++sequence; - return new Promise((resolve,reject)=>{ - const timer=setTimeout(()=>{terminate('Execution timed out. The worker was stopped; restart and rerun your cells.');},timeout); - pending.set(id,{resolve,reject,timer}); - worker.postMessage({id,action,...values}); - }); - } - async function start(){ - if(ready)return; - worker?.terminate(); - worker=new Worker(new URL('./python-worker.js',import.meta.url),{type:'module'}); - worker.onmessage=({data})=>{ - if(data.type==='status'){message(data.text);return;} - const item=pending.get(data.id);if(!item)return; - clearTimeout(item.timer);pending.delete(data.id); - if(data.error)item.reject(new Error(data.error));else item.resolve(JSON.parse(data.result)); - }; - worker.onerror=event=>terminate(`Python could not load: ${event.message}. Check that the site runtime was built, then try Start Python.`); - controls();message('Starting Python. The first load includes local WebAssembly, pandas, and Matplotlib…'); - const versions=await request('init',{files:workspace()},120000); - ready=true; - message(`Ready · Python ${versions.python} · pandas ${versions.pandas} · NumPy ${versions.numpy} · Matplotlib ${versions.matplotlib}. This browser environment differs from the local dependency lock.`); - controls(); - } - function output(result,container){ - container.replaceChildren();delete container.dataset.stale;container.dataset.error=String(Boolean(result.error)); - const text=document.createElement('pre');text.textContent=[result.stdout,result.stderr,result.error].filter(Boolean).join('\n')||'(No output; the cell may still have changed Python state.)';container.append(text); - for(const png of result.figures){const img=document.createElement('img');img.src=`data:image/png;base64,${png}`;img.alt='Scientific figure generated by this Python cell';container.append(img);} - q('[data-variables]').textContent=result.variables.map(v=>`${v.name}: ${v.value}`).join('\n')||'No user variables.'; - return !result.error; - } - async function runCell(index){ - await start();const cell=root.querySelector(`[data-cell="${index}"]`); - cell.querySelector('[data-cell-count]').textContent=`In [${++execution}]`; - const result=await request('run',{code:cell.querySelector('[data-cell-code]').value}); - q('[data-execution-log]').textContent+=`In [${execution}] → cell ${index+1}${result.error?' · error':''}\n`; - return output(result,cell.querySelector('[data-cell-output]')); - } - async function runAll(fresh=false){ - if(fresh)terminate('Fresh kernel requested. Reloading the current workspace files…'); - for(let i=0;il.id===id)||lessons[0]; - const work=saved[lesson.id];q('[data-lab-title]').textContent=lesson.title;q('[data-lab-goal]').textContent=lesson.goal; - q('[data-lab-steps]').replaceChildren(...lesson.steps.map(text=>{const li=document.createElement('li');li.textContent=text;return li;})); - q('[data-lab-hint]').textContent=lesson.hint;q('[data-lab-explanation]').textContent=lesson.explanation; - q('[data-prediction]').value=work?.prediction||''; - q('[data-helper]').value=work?.helper||lesson.helper||'def clean_trials(trials, min_rt_s=0.2, max_rt_s=2.0):\n return trials.loc[trials.reaction_time.between(min_rt_s, max_rt_s)].copy()\n'; - q('[data-config]').value=work?.config||BASE_CONFIG; - q('[data-execution-log]').textContent='';q('[data-mission-result]').textContent='Not checked yet.';delete q('[data-mission-result]').dataset.state; - q('[data-cells]').replaceChildren(...lesson.cells.map((spec,i)=>{ - const cell=document.createElement('section');cell.className='live-cell';cell.dataset.cell=i; - const bar=document.createElement('div');bar.className='cell-toolbar'; - const count=document.createElement('span');count.dataset.cellCount='';count.textContent='In [ ]'; - const label=document.createElement('label');label.htmlFor=`python-cell-${i}`;label.textContent=`${i+1}. ${spec.title}`; - const button=document.createElement('button');button.type='button';button.dataset.runCell=i;button.textContent=`Run cell ${i+1}`; - const editor=document.createElement('textarea');editor.id=`python-cell-${i}`;editor.dataset.cellCode='';editor.className='code-editor';editor.spellcheck=false;editor.rows=Math.min(14,Math.max(4,spec.code.split('\n').length));editor.value=work?.sources?.[i]??spec.code; - const result=document.createElement('div');result.className='cell-output';result.dataset.cellOutput='';result.setAttribute('aria-live','polite'); - bar.append(count,label,button);cell.append(bar,editor,result);return cell; - })); - for(const b of root.querySelectorAll('[data-scenario]'))b.setAttribute('aria-pressed',String(b.dataset.scenario===lesson.id)); - controls();root.dispatchEvent(new CustomEvent('workshop:lesson',{detail:{id:lesson.id}})); - } - root.addEventListener('input',event=>{if(event.target.matches('[data-cell-code],[data-helper],[data-config]'))invalidate();else if(event.target.matches('[data-prediction]'))persist();}); - root.addEventListener('keydown',event=>{ - if(event.target.matches('[data-cell-code]')&&event.key==='Enter'&&event.shiftKey){event.preventDefault();act(()=>runCell(Number(event.target.closest('[data-cell]').dataset.cell)));} - // Keep Tab as normal keyboard navigation; no editor focus trap. - }); - root.addEventListener('click',event=>{ - const b=event.target.closest('button');if(!b)return; - if(b.matches('[data-run-cell]'))act(()=>runCell(Number(b.dataset.runCell))); - else if(b.matches('[data-start-python]'))act(start); - else if(b.matches('[data-run-all]'))act(()=>runAll(b.dataset.runAll==='fresh')); - else if(b.matches('[data-stop-python]')){terminate('Stopped. The kernel and its variables were cleared; source edits are preserved.');} - else if(b.matches('[data-scenario]'))choose(b.dataset.scenario); - else if(b.matches('[data-check-mission]'))act(async()=>{ - if(lesson.freshCheck&&!await runAll(true)){q('[data-mission-result]').dataset.state='error';q('[data-mission-result]').textContent='Fresh run stopped at an error. Fix the cell, then check again.';return;} - await start();const result=await request('run',{code:lesson.check}); - q('[data-mission-result]').dataset.state=result.error?'error':'passed'; - q('[data-mission-result]').textContent=result.error?result.error:`Passed · ${result.stdout}\nExplain: ${lesson.explanation}`; - }); - else if(b.matches('[data-save-file]'))act(async()=>{await start();const path=b.dataset.saveFile;await request('save',{path,content:workspace()[path]});message(`Saved ${path} to the virtual workspace. Rerun imports/config loading and dependent cells; existing names do not update automatically.`);}); - else if(b.matches('[data-solution]')){ - const solution=lesson.solution; - solution.cells?.forEach((code,i)=>{root.querySelector(`[data-cell="${i}"] [data-cell-code]`).value=code;}); - if(solution.helper)q('[data-helper]').value=solution.helper;if(solution.config)q('[data-config]').value=solution.config; - persist();delete q('[data-mission-result]').dataset.state;terminate('Worked solution loaded into the editors. Start a fresh run to test it.');q('[data-mission-result]').textContent='Solution is visible. Predict what it changes, then run and check.'; - } else if(b.matches('[data-reset-lesson]')){delete saved[lesson.id];lesson=null;choose(root.querySelector('[data-scenario][aria-pressed=true]').dataset.scenario);persist();} - else if(b.matches('[data-download]')){ - const kind=b.dataset.download; - const text=kind==='notebook'?JSON.stringify(notebookExport(lesson,sources()),null,2):kind==='helper'?q('[data-helper]').value:q('[data-config]').value; - const url=URL.createObjectURL(new Blob([text],{type:kind==='notebook'?'application/x-ipynb+json':'text/plain'})); - const a=document.createElement('a');a.href=url;a.download=kind==='notebook'?`workshop-${lesson.id}.ipynb`:kind==='helper'?'helpers.py':'analysis.toml';a.click();setTimeout(()=>URL.revokeObjectURL(url),1000); - } - }); - const initial=location.hash.slice(1);choose(lessons.some(l=>l.id===initial)?initial:'state'); - window.addEventListener('beforeunload',()=>{persist();worker?.terminate();}); +import {lessons, notebookExport} from './notebook-lessons.js'; +import {tabs} from './ui.js'; + +const root = document.querySelector('[data-notebook-lab]'); +const q = selector => root.querySelector(selector); +const selectPane = tabs(root, '[data-workspace-tabs]'); +const filePaths = {helper: 'helpers.py', config: 'config/analysis.toml'}; +const baseConfig = '[paths]\ndata = "../data/raw/trials.csv"\noutput = "../results/baseline"\n\n[preprocessing]\nmin_rt_s = 0.2\nmax_rt_s = 2.0\n'; +const baseHelper = 'def clean_trials(trials, min_rt_s=0.2, max_rt_s=2.0):\n return trials.loc[trials.reaction_time.between(min_rt_s, max_rt_s)].copy()\n'; +const storageKey = 'research-code-notebook-v1'; +const guide = q('[data-guide-action]'); +const feedback = q('[data-guide-feedback]'); +const stepPanel = q('#current-step'); +const executedSources = new Map(); +const pending = new Map(); + +let saved; +try { + saved = JSON.parse(localStorage.getItem(storageKey) || '{}') || {}; +} catch { + saved = {}; } + +let lesson; +let stepIndex = 0; +let files; +let errorCell; +let worker; +let ready = false; +let busy = false; +let sequence = 0; +let execution = 0; + +const currentStep = () => lesson.steps[stepIndex]; +const cellAt = index => q(`[data-cell="${index}"]`); +const cellEditor = index => cellAt(index).querySelector('[data-cell-code]'); +const fileEditor = file => q(`[data-${file}]`); +const sources = () => [...root.querySelectorAll('[data-cell-code]')].map(editor => editor.value); +const focusStep = () => stepPanel.focus(); + +function persist() { + saved[lesson.id] = { + sources: sources(), + helper: fileEditor('helper').value, + config: fileEditor('config').value, + prediction: q('[data-prediction]').value, + files + }; + try { + localStorage.setItem(storageKey, JSON.stringify(saved)); + } catch { + q('.lab-footnote').textContent = 'Browser storage is unavailable. Export your work to keep a copy.'; + } +} + +function message(text) { + q('[data-kernel-status]').textContent = text; +} + +function controls() { + q('.kernel-line').dataset.state = busy ? 'busy' : ready ? 'ready' : 'idle'; + for (const button of root.querySelectorAll('[data-run-cell], [data-run-all], [data-guide-action], [data-save-file], [data-scenario], [data-solution], [data-reset-lesson], [data-step-index]')) { + button.disabled = busy; + } + q('[data-stop-python]').hidden = !busy || !worker; + for (const editor of root.querySelectorAll('[data-cell-code], [data-helper], [data-config]')) { + editor.readOnly = busy; + } +} + +function markOutputsStale() { + for (const output of root.querySelectorAll('[data-cell-output]:not(:empty)')) { + output.dataset.stale = 'true'; + } +} + +function terminate(reason) { + worker?.terminate(); + worker = null; + ready = false; + execution = 0; + executedSources.clear(); + for (const request of pending.values()) { + clearTimeout(request.timer); + request.reject(new Error(reason)); + } + pending.clear(); + q('[data-variables]').textContent = 'No live variables.'; + q('[data-execution-log]').textContent = 'No cells run yet.'; + for (const count of root.querySelectorAll('[data-cell-count]')) count.textContent = 'In [ ]'; + markOutputsStale(); + message(reason); + controls(); +} + +function request(action, values = {}, timeout = 15000) { + const id = ++sequence; + return new Promise((resolve, reject) => { + const timer = setTimeout(() => { + terminate(action === 'init' ? 'Python took too long to load.' : 'Python stopped because the action timed out.'); + }, timeout); + pending.set(id, {resolve, reject, timer}); + worker.postMessage({id, action, ...values}); + }); +} + +async function start() { + if (ready) return; + const activeWorker = new Worker(new URL('./python-worker.js', import.meta.url), {type: 'module'}); + worker = activeWorker; + worker.onmessage = ({data}) => { + if (worker !== activeWorker) return; + if (data.type === 'status') { + message(data.text); + return; + } + const item = pending.get(data.id); + if (!item) return; + clearTimeout(item.timer); + pending.delete(data.id); + if (data.error) item.reject(new Error(data.error)); + else item.resolve(JSON.parse(data.result)); + }; + worker.onerror = () => { + if (worker === activeWorker) terminate('Python could not load. Reload the page if retrying does not help.'); + }; + controls(); + message('Loading Python and scientific packages…'); + const projectFiles = Object.fromEntries(Object.entries(filePaths).map(([file, path]) => [path, files[file]])); + await request('init', {files: projectFiles}, 120000); + ready = true; +} + +function guideLabel(step) { + if (step.label) return step.label; + switch (step.action) { + case 'edit-cell': return `Edit cell ${step.cell + 1}`; + case 'edit-file': return `Open ${filePaths[step.file].split('/').at(-1)}`; + case 'run-cell': return `Run cell ${step.cell + 1}`; + case 'run-all': return 'Run all cells'; + case 'fresh-run': return 'Restart & run all'; + case 'check': return 'Check your work'; + case 'continue': return 'Continue'; + } +} + +function renderOutputLink() { + const button = q('[data-view-output]'); + const outputIndex = errorCell ?? currentStep()?.output ?? lesson.steps.at(-1).output; + const output = cellAt(outputIndex)?.querySelector('[data-cell-output]'); + button.hidden = !output?.childElementCount; + if (!button.hidden) { + button.dataset.viewOutput = outputIndex; + button.textContent = `View cell ${outputIndex + 1} output`; + } +} + +function showFeedback(text = '', state = '', trace = '', cell) { + feedback.textContent = text; + feedback.dataset.state = state; + errorCell = cell; + q('[data-error-details]').open = false; + q('[data-error-details]').hidden = !trace; + q('[data-error-trace]').textContent = trace; + renderOutputLink(); +} + +function showStep(index, switchPane = true) { + stepIndex = index; + const step = currentStep(); + const completed = !step; + const lastExercise = lesson === lessons.at(-1); + q('[data-step-progress]').textContent = completed ? 'Exercise complete' : `Step ${index + 1} of ${lesson.steps.length}`; + q('[data-step-instruction]').textContent = completed ? lesson.explanation : step.instruction; + q('[data-step-prediction]').hidden = !step?.predict; + guide.hidden = completed && lastExercise; + q('[data-continue-git]').hidden = !completed || !lastExercise; + if (!guide.hidden) guide.textContent = completed ? 'Next notebook exercise' : guideLabel(step); + for (const [i, button] of [...root.querySelectorAll('[data-step-index]')].entries()) { + if (i === index) button.setAttribute('aria-current', 'step'); + else button.removeAttribute('aria-current'); + } + const targetCell = step?.cell ?? step?.output; + for (const cell of root.querySelectorAll('[data-cell]')) { + cell.toggleAttribute('data-step-cell', Number(cell.dataset.cell) === targetCell); + } + if (switchPane) selectPane(step?.file || 'notebook'); + renderOutputLink(); +} + +function advance(action, target) { + const step = currentStep(); + if (!step) return; + const matches = step.action === action + || (action === 'run-cell' && step.action === 'edit-cell') + || (action === 'fresh-run' && step.action === 'run-all'); + if (!matches || (step.cell ?? step.file) !== target) return; + showStep(stepIndex + 1); + focusStep(); +} + +async function act(action) { + if (busy) return; + busy = true; + controls(); + showFeedback(); + try { + await action(); + if (ready) message('Python ready.'); + if (feedback.dataset.state === 'error') focusStep(); + } catch (error) { + if (worker) terminate('The Python session was cleared.'); + showFeedback(`${error.message} Run again to start a fresh Python session.`, 'error'); + focusStep(); + } finally { + busy = false; + controls(); + persist(); + if (location.hash !== `#${lesson.id}`) chooseFromLocation(); + } +} + +function showOutput(result, container) { + const text = document.createElement('pre'); + text.textContent = [result.stdout, result.stderr, result.error].filter(Boolean).join('\n') || 'Finished with no printed output.'; + container.replaceChildren(text); + delete container.dataset.stale; + container.dataset.error = String(Boolean(result.error)); + for (const png of result.figures) { + const img = document.createElement('img'); + img.src = `data:image/png;base64,${png}`; + img.alt = 'Scientific figure generated by this Python cell'; + container.append(img); + } + q('[data-variables]').textContent = result.variables.map(variable => `${variable.name}: ${variable.value}`).join('\n') || 'No user variables.'; +} + +function errorSummary(trace) { + return trace.trim().split('\n').at(-1); +} + +async function runCell(index, recovery = 'Fix this cell and run it again.') { + await start(); + message(`Running cell ${index + 1}…`); + const cell = cellAt(index); + const code = cellEditor(index).value; + const count = ++execution; + cell.querySelector('[data-cell-count]').textContent = `In [${count}]`; + const result = await request('run', {code}); + const log = q('[data-execution-log]'); + if (count === 1) log.textContent = ''; + log.textContent += `In [${count}] → cell ${index + 1}${result.error ? ' · error' : ''}\n`; + showOutput(result, cell.querySelector('[data-cell-output]')); + if (result.error) { + executedSources.delete(index); + showFeedback(`Cell ${index + 1}: ${errorSummary(result.error)} ${recovery}`, 'error', result.error, index); + return false; + } + executedSources.set(index, code); + renderOutputLink(); + return true; +} + +async function runAll(fresh = false, recovery = 'Fix this cell, then run all cells again.') { + selectPane('notebook'); + if (fresh) terminate('Starting a fresh Python session…'); + for (let index = 0; index < lesson.cells.length; index++) { + if (!await runCell(index, recovery)) return false; + } + return true; +} + +async function saveFile(file) { + const content = fileEditor(file).value; + if (content !== files[file]) { + if (ready) await request('save', {path: filePaths[file], content}); + files[file] = content; + executedSources.clear(); + markOutputsStale(); + } + showFeedback(`Saved ${filePaths[file]}.`, 'success'); + advance('edit-file', file); +} + +async function checkLesson() { + if (lesson.file && fileEditor(lesson.file).value !== files[lesson.file]) { + showFeedback(`Save ${filePaths[lesson.file]} before checking.`, 'error'); + return; + } + if (lesson.freshCheck) { + if (!await runAll(true, lesson.recovery)) return; + } else if (!ready || sources().some((code, index) => executedSources.get(index) !== code)) { + showFeedback('Use Run all cells in Notebook tools to run the current notebook, then check again.', 'error'); + return; + } + message('Checking your work…'); + const result = await request('run', {code: lesson.check}); + if (result.error) { + showFeedback(`${errorSummary(result.error)} ${lesson.recovery}`, 'error', result.error); + return; + } + advance('check'); + showFeedback(result.stdout.trim(), 'success'); +} + +function renderCells(work) { + q('[data-cells]').replaceChildren(...lesson.cells.map((spec, index) => { + const cell = document.createElement('section'); + cell.className = 'live-cell'; + cell.dataset.cell = index; + const bar = document.createElement('div'); + bar.className = 'cell-toolbar'; + const count = document.createElement('span'); + count.dataset.cellCount = ''; + count.textContent = 'In [ ]'; + const label = document.createElement('label'); + label.htmlFor = `python-cell-${index}`; + label.textContent = `${index + 1}. ${spec.title}`; + const button = document.createElement('button'); + button.type = 'button'; + button.dataset.runCell = index; + button.textContent = `Run cell ${index + 1}`; + const editor = document.createElement('textarea'); + editor.id = label.htmlFor; + editor.dataset.cellCode = ''; + editor.className = 'code-editor'; + editor.spellcheck = false; + editor.rows = Math.min(14, Math.max(4, spec.code.split('\n').length)); + editor.value = work?.sources?.[index] ?? spec.code; + const output = document.createElement('div'); + output.className = 'cell-output'; + output.dataset.cellOutput = ''; + output.tabIndex = -1; + output.setAttribute('aria-label', `Cell ${index + 1} output`); + bar.append(count, label, button); + cell.append(bar, editor, output); + return cell; + })); +} + +function choose(id, {navigate = false, reset = false} = {}) { + const next = lessons.find(item => item.id === id) || lessons[0]; + if (busy || (next === lesson && !reset)) return; + if (lesson && !reset) persist(); + lesson = next; + if (navigate) history.pushState(null, '', `#${lesson.id}`); + terminate('Python starts when you run code.'); + const work = reset ? undefined : saved[lesson.id]; + fileEditor('helper').value = work?.helper ?? lesson.helper ?? baseHelper; + fileEditor('config').value = work?.config ?? baseConfig; + // Older drafts stored the file text only, and used it on the next fresh session. + files = { + helper: work?.files?.helper ?? fileEditor('helper').value, + config: work?.files?.config ?? fileEditor('config').value + }; + q('[data-prediction]').value = work?.prediction ?? ''; + q('[data-exercise-progress]').textContent = `Exercise ${lessons.indexOf(lesson) + 1} of ${lessons.length} · ${lesson.minutes}`; + q('[data-lab-title]').textContent = lesson.title; + q('[data-lab-goal]').textContent = lesson.goal; + q('[data-lab-hint]').textContent = lesson.hint; + q('[data-lab-explanation]').textContent = lesson.explanation; + q('[data-solution]').hidden = !Object.keys(lesson.solution).length; + for (const panel of root.querySelectorAll('[data-mission-instructions], [data-hint-panel], [data-solution-panel], .workspace-options')) { + panel.open = false; + } + for (const button of root.querySelectorAll('[data-scenario]')) { + button.setAttribute('aria-pressed', String(button.dataset.scenario === lesson.id)); + } + q('[data-lab-steps]').replaceChildren(...lesson.steps.map((step, index) => { + const item = document.createElement('li'); + const button = document.createElement('button'); + button.type = 'button'; + button.dataset.stepIndex = index; + button.className = 'text-action'; + button.textContent = step.instruction; + item.append(button); + return item; + })); + renderCells(work); + showStep(0); + const changedCells = work?.sources?.some((code, index) => code !== lesson.cells[index]?.code); + const changedFiles = fileEditor('helper').value !== (lesson.helper ?? baseHelper) || fileEditor('config').value !== baseConfig; + if (reset) showFeedback('Starter code restored.'); + else if (changedCells || changedFiles || work?.prediction) { + const baseline = (changedCells || changedFiles) && lesson.baseline ? ` ${lesson.baseline}` : ''; + showFeedback(`Draft restored. Python variables start empty.${baseline}`); + } else showFeedback(); + controls(); + root.dispatchEvent(new Event('workshop:lesson')); + if (navigate || reset) q('[data-lab-title]').focus(); +} + +function loadSolution() { + if (!window.confirm('Replace the exercise code with the worked solution? Your prediction will be kept.')) return; + const solution = lesson.solution; + solution.cells?.forEach((code, index) => { cellEditor(index).value = code; }); + for (const file of Object.keys(filePaths)) { + if (solution[file]) fileEditor(file).value = solution[file]; + } + terminate('Python will start fresh on the next run.'); + const next = lesson.steps.findIndex(step => step.action === 'edit-file' || step.action === 'fresh-run'); + showStep(next); + showFeedback('Worked solution loaded. Follow the current step to try it.'); + persist(); + root.dispatchEvent(new Event('workshop:lesson')); + focusStep(); +} + +function download(kind) { + const notebook = kind === 'notebook'; + const text = notebook ? JSON.stringify(notebookExport(lesson, sources()), null, 2) : fileEditor(kind).value; + const url = URL.createObjectURL(new Blob([text], {type: notebook ? 'application/x-ipynb+json' : 'text/plain'})); + const link = document.createElement('a'); + link.href = url; + link.download = notebook ? `workshop-${lesson.id}.ipynb` : filePaths[kind].split('/').at(-1); + link.click(); + setTimeout(() => URL.revokeObjectURL(url), 1000); +} + +function performGuideAction() { + const step = currentStep(); + if (!step) { + choose(lessons[lessons.indexOf(lesson) + 1].id, {navigate: true}); + return; + } + switch (step.action) { + case 'continue': + showFeedback(); + advance('continue'); + break; + case 'edit-cell': + selectPane('notebook'); + cellEditor(step.cell).focus(); + break; + case 'edit-file': + selectPane(step.file); + fileEditor(step.file).focus(); + break; + case 'run-cell': + runSingleCell(step.cell); + break; + case 'run-all': + case 'fresh-run': + runNotebook(step.action === 'fresh-run'); + break; + case 'check': + act(checkLesson); + break; + } +} + +function runNotebook(fresh) { + act(async () => { + if (await runAll(fresh)) advance(fresh ? 'fresh-run' : 'run-all'); + }); +} + +function runSingleCell(index) { + act(async () => { + if (await runCell(index)) advance('run-cell', index); + }); +} + +root.addEventListener('input', event => { + if (event.target.matches('[data-cell-code], [data-helper], [data-config]')) { + markOutputsStale(); + showFeedback(); + if (!currentStep()) { + showStep(lesson.steps.length - 1, false); + showFeedback(lesson.freshCheck ? 'Code changed. Run the fresh check again.' : 'Code changed. Run it again before checking.'); + } + } + if (event.target.matches('textarea')) persist(); +}); + +root.addEventListener('keydown', event => { + if (event.target.matches('[data-cell-code]') && event.key === 'Enter' && event.shiftKey) { + event.preventDefault(); + runSingleCell(Number(event.target.closest('[data-cell]').dataset.cell)); + } +}); + +root.addEventListener('click', event => { + if (event.target.closest('.back-to-step')) { + event.preventDefault(); + focusStep(); + return; + } + const button = event.target.closest('button'); + if (!button) return; + if (button.hasAttribute('data-stop-python')) { + terminate('Python stopped. Your code is still in the editors.'); + return; + } + if (button.hasAttribute('data-view-output')) { + selectPane('notebook'); + cellAt(Number(button.dataset.viewOutput)).querySelector('[data-cell-output]').focus(); + return; + } + if (busy) return; + if (button === guide) performGuideAction(); + else if (button.hasAttribute('data-step-index')) { + q('[data-mission-instructions]').open = false; + showFeedback(); + showStep(Number(button.dataset.stepIndex)); + focusStep(); + } else if (button.hasAttribute('data-run-cell')) runSingleCell(Number(button.dataset.runCell)); + else if (button.hasAttribute('data-run-all')) { + q('.workspace-options').open = false; + runNotebook(button.dataset.runAll === 'fresh'); + } else if (button.hasAttribute('data-save-file')) act(() => saveFile(button.dataset.saveFile)); + else if (button.hasAttribute('data-inspect')) { + q('.workspace-options').open = false; + selectPane('inspect'); + q('#tab-inspect').focus(); + } else if (button.hasAttribute('data-scenario')) choose(button.dataset.scenario, {navigate: true}); + else if (button.hasAttribute('data-solution')) loadSolution(); + else if (button.hasAttribute('data-reset-lesson')) { + if (window.confirm('Restore starter code and clear the prediction for this exercise?')) { + choose(lesson.id, {reset: true}); + persist(); + } + } else if (button.hasAttribute('data-download')) download(button.dataset.download); +}); + +function chooseFromLocation() { + const id = location.hash.slice(1); + if (id && !lessons.some(item => item.id === id)) return; + if (busy) { + terminate('Python stopped because you opened another exercise.'); + return; + } + choose(id); +} + +choose(location.hash.slice(1)); +window.addEventListener('popstate', chooseFromLocation); +window.addEventListener('hashchange', chooseFromLocation); diff --git a/site/assets/notebook-lessons.js b/site/assets/notebook-lessons.js index 0ac04ec..039bf29 100644 --- a/site/assets/notebook-lessons.js +++ b/site/assets/notebook-lessons.js @@ -1,7 +1,17 @@ export const lessons = [ - {id:'state',title:'1 · Expose hidden state',minutes:'8 min', - goal:'Predict a result before running it. Change the threshold without rerunning its dependents, then diagnose the stale table.', - steps:['Run all three cells to establish the 3,761-trial baseline.','Change min_rt_s to 0.6 in cell 1 and run only cell 1. Then run cell 3.','Predict the retained count, inspect the live variables, and check the mission. Why do the policy and table disagree?','Restart & Run All, then check again. Explain which dependency was missing.'], + {id:'state',title:'Run notebook cells',minutes:'8 min', + goal:'See how running cells out of order can leave a result out of date.', + steps:[ + {action:'run-all',instruction:'Run all cells with the original minimum of 0.2 seconds and note the retained count.'}, + {action:'continue',output:2,predict:true,instruction:'Look at the retained count in cell 3. What do you expect to happen if you change the minimum but leave the filtering cell alone?'}, + {action:'edit-cell',cell:0,instruction:'In cell 1, change min_rt_s from 0.2 to 0.6. Run just cell 1 to apply the new setting.'}, + {action:'run-cell',cell:2,instruction:'Run cell 3 to print the new setting beside the retained count. Leave cell 2 alone for now.'}, + {action:'continue',output:2,instruction:'Compare cell 3 with the baseline. Why did the setting change while the retained count stayed the same?'}, + {action:'fresh-run',instruction:'Restart Python and run all cells in order so cell 2 recalculates the table with the new minimum.'}, + {action:'check',output:2,instruction:'Look at the new count in cell 3. Check that it agrees with the 0.6-second rule.'} + ], + baseline:'For the original baseline, set min_rt_s to 0.2 in cell 1.', + recovery:'Set min_rt_s to 0.6 in cell 1, then use Restart & run all in Notebook tools and check again.', hint:'A name assigned in cell 2 still refers to the old filtered table. Editing or executing cell 1 does not recompute cell 2.', explanation:'The filter depends on min_rt_s at execution time. At 0.6 s a fresh run retains 3,461 trials. A saved output does not prove its dependent cells used the displayed configuration.', cells:[{title:'Load inputs and choose the policy',code:`import pandas as pd @@ -26,9 +36,14 @@ raw_trials = pd.read_csv("data/raw/trials.csv") min_rt_s = 0.6 max_rt_s = 2.0 print(f"Current policy: {min_rt_s}–{max_rt_s} seconds")`]}}, - {id:'refactor',title:'2 · Extract a function into a module',minutes:'12 min', - goal:'Replace an unfinished helper with a reusable RT filter, import it, and prove that the refactor preserves the scientific result.', - steps:['Read the helpers.py editor below. Implement clean_trials with explicit second-based bounds and a returned copy.','Save the module to the browser workspace. Run the import and analysis cells.','Check inclusive boundaries, error retention, raw-table immutability, and the full condition summary.','Change the helper and observe that old imported names require the import cell to run again.'], + {id:'refactor',title:'Extract a Python function',minutes:'12 min',file:'helper', + goal:'Move the reaction-time filter into a reusable function and verify that the results match.', + steps:[ + {action:'edit-file',file:'helper',instruction:'In helpers.py, replace the unfinished line in clean_trials. Return a new table with all trials inside the inclusive bounds, including incorrect responses. Then save the file.'}, + {action:'run-all',instruction:'Run the notebook to import your saved function and use it to calculate the condition summary.'}, + {action:'check',output:1,instruction:'Check that the function includes both boundary values, retains errors, leaves the input intact, and reproduces the summary.'} + ], + recovery:'Review clean_trials and save helpers.py. Run all cells again to import the updated function, then retry the check.', hint:'Use trials.loc[trials.reaction_time.between(min_rt_s, max_rt_s)].copy(). Keep both correct and incorrect trials. Saving a file does not rerun an existing import binding.', explanation:'The extraction has one responsibility: select rows from explicit inputs. The notebook owns file loading and policy. Boundary and summary checks catch plausible scientific regressions.', helper:`def clean_trials(trials, min_rt_s=0.2, max_rt_s=2.0): @@ -59,11 +74,18 @@ print("Boundary, error-retention, input-immutability, and summary checks passed. solution:{helper:`def clean_trials(trials, min_rt_s=0.2, max_rt_s=2.0): """Return a new table within inclusive RT bounds (seconds), including errors.""" return trials.loc[trials.reaction_time.between(min_rt_s, max_rt_s)].copy()`}}, - {id:'config',title:'3 · Make configuration drive the result',minutes:'10 min', - goal:'Edit a real TOML file and make its validated values control the same analysis. Keep code and scientific policy separate.', - steps:['Run the baseline with config/analysis.toml.','Edit the TOML minimum to 0.6 and choose a separate output directory. Save the file, then rerun the cells.','Temporarily misspell min_rt_s, observe the validation error, and repair it.','Check the mission and explain why moving a value into configuration does not justify the exclusion rule.'], + {id:'config',title:'Change a setting',minutes:'10 min',file:'config', + goal:'Change the analysis using a settings file and give the alternative run its own output location.', + steps:[ + {action:'run-all',instruction:'Run all cells and note the retained count with the original minimum of 0.2 seconds.'}, + {action:'edit-file',file:'config',instruction:'In analysis.toml, set min_rt_s to 0.6 and change output to "../results/sensitivity". Save the file so the notebook can read it.'}, + {action:'run-all',instruction:'Rerun the notebook to load the saved settings and count the trials under the new rule.'}, + {action:'check',output:1,instruction:'Check the new trial count and output location. What does recording the new rule help your labmate verify?'} + ], + baseline:'For the original baseline, save min_rt_s = 0.2 and output = "../results/baseline" in analysis.toml.', + recovery:'Set min_rt_s to 0.6 and output to "../results/sensitivity", then save analysis.toml and run all cells again.', hint:'Change the file, not a hardcoded number in the filter call. load_config resolves paths relative to the TOML file and rejects missing/unknown keys.', - explanation:'Both entry points can load the same reviewed settings. Explicit effective values and independent output directories protect the baseline; configuration remains a scientific decision that needs review.', + explanation:'A shared settings file records the choices behind the result and gives the alternative run its own output path. After the check, try misspelling min_rt_s, saving, and rerunning to see how the loader catches a typo.', cells:[{title:'Load and inspect the run specification',code:`from experiment.config import load_config from experiment.preprocessing import load_trials, filter_trials from experiment.analysis import participant_summary, condition_summary @@ -87,9 +109,13 @@ output = "../results/sensitivity" min_rt_s = 0.6 max_rt_s = 2.0 `}}, - {id:'handoff',title:'4 · Reproduce the figure from a fresh kernel',minutes:'10 min',freshCheck:true, - goal:'Complete the analysis without relying on previous cells or another exercise. Pass a fresh-kernel handoff check and export your notebook.', - steps:['Run the baseline, inspect participant metrics, and display the real Matplotlib figure.','Explain why the plotting function receives computed probabilities rather than filtering trials.','Use Check mission: it restarts the kernel and runs the saved cells in order before checking the result.','Download the notebook and your helper/config files. Apply one of these changes to your own research project.'], + {id:'handoff',title:'Reproduce a figure',minutes:'10 min',file:'config',freshCheck:true, + goal:'Reproduce the baseline figure from the notebook you would give a labmate.', + steps:[ + {action:'continue',predict:true,instruction:'Read the three cells. What needs to be available for this notebook to produce the figure in a fresh Python session?'}, + {action:'check',label:'Run and check figure',output:2,instruction:'Start a fresh Python session, run every cell in order, and check that the participant summaries and figure match the baseline.'} + ], + recovery:'Fix the first cell with an error and retry. If you changed analysis.toml, save the baseline settings before running the check.', hint:'Every input must be created by these saved cells. Use the installed experiment modules in the virtual project, with config/analysis.toml.', explanation:'A fresh-kernel run tests the saved procedure rather than a lucky session state. Numeric equivalence and a real plot support the handoff; scientific interpretation still requires judgment.', cells:[{title:'Declare all dependencies and inputs',code:`from experiment.config import load_config diff --git a/site/assets/style.css b/site/assets/style.css index 9330bff..de800d0 100644 --- a/site/assets/style.css +++ b/site/assets/style.css @@ -26,7 +26,7 @@ p {line-height:1.75;} .navbar-container {max-width:1680px;width:100%;margin:auto;} .navbar .navbar-brand,.navbar .nav-link {color:var(--ink)!important;} .navbar .nav-link {font-size:.78rem;font-weight:600;padding:.55rem .8rem!important;} -.navbar .navbar-nav .nav-item:last-child .nav-link {border:1px solid var(--line);border-radius:7px;background:var(--paper);} +.navbar .navbar-nav .nav-link.active {background:var(--pale);color:var(--accent)!important;border-radius:7px;} .navbar-brand {padding:0;margin-right:2rem;} #quarto-sidebar {background:var(--paper)!important;border:0;padding:1.8rem .75rem 1rem;} .sidebar-item {margin:.18rem 0;} @@ -55,7 +55,6 @@ main {padding-top:1.3rem;min-width:0;} .eyebrow,.panel-eyebrow {font-size:.61rem;font-weight:750;letter-spacing:.12em;color:var(--muted);text-transform:uppercase;} .panel-eyebrow {display:flex;gap:.45rem;align-items:center;} .small-note {font-size:.72rem;line-height:1.7;color:var(--muted);} -.status-pill {display:inline-flex;align-items:center;gap:.4rem;padding:.3rem .6rem;border-radius:6px;background:var(--pale);color:var(--accent);font-size:.67rem;font-weight:650;white-space:nowrap;} .status-dot {display:inline-block;flex-shrink:0;width:6px;height:6px;border-radius:50%;background:var(--success);} .ui-icon {width:16px;height:16px;flex-shrink:0;vertical-align:middle;} [data-icon] {display:inline-flex;align-items:center;vertical-align:middle;} @@ -64,55 +63,44 @@ main {padding-top:1.3rem;min-width:0;} .button-primary:hover {background:#1d4ed8;} .button-secondary {background:var(--surface);border-color:var(--line);color:var(--ink);} .button-secondary:hover {background:var(--pale);border-color:var(--accent);} -.hero-actions {display:flex;gap:.7rem;align-items:center;flex-wrap:wrap;margin:1.7rem 0 1rem;} button:disabled {opacity:.42;cursor:not-allowed!important;} /* Homepage */ -.workshop-badge {display:inline-flex;align-items:center;gap:.55rem;font-size:.63rem;font-weight:650;color:var(--muted);margin:1rem 0 1.5rem;} -.badge-dot {height:6px;width:6px;border-radius:50%;background:#2563eb;} -.hero {display:grid;grid-template-columns:1.05fr 1fr;gap:3rem;align-items:center;margin-bottom:2.5rem;} -.hero h1 {font:780 clamp(2.7rem,4.2vw,4.4rem)/1.07 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;letter-spacing:-.065em;margin:0 0 1.25rem;max-width:13ch;} -.hero h1 em {font-style:normal;color:var(--accent);} -.hero .eyebrow {color:var(--accent);margin-bottom:1rem;} -.hero .intro {font-size:.94rem;line-height:1.85;max-width:46ch;color:var(--muted);} -.hero .small-note {font-size:.66rem;} -.research-card {background:var(--surface);border:1px solid var(--line);border-radius:14px;box-shadow:0 14px 45px #142e5810;overflow:hidden;} -.card-top {display:flex;align-items:center;justify-content:space-between;gap:1rem;padding:.9rem 1.1rem;border-bottom:1px solid var(--line);font:.67rem ui-monospace,SFMono-Regular,Consolas,monospace;color:var(--muted);} -.window-dots {display:flex;gap:4px;align-items:center;} -.window-dots span {width:6px;height:6px;border-radius:50%;background:var(--line);} -.card-top>div {display:flex;gap:.7rem;align-items:center;} -.research-card .figure {padding:1.1rem .7rem .3rem;margin:0;background:#fff;} -.research-card img {width:100%;height:auto;display:block;} -.card-caption {display:flex;justify-content:space-between;gap:1rem;font-size:.65rem;color:var(--muted);padding:.7rem 1.1rem;border-top:1px solid var(--line);} -.card-code {background:#121e32;color:#d7e5f7;padding:1rem 1.1rem;font:.69rem/1.9 ui-monospace,SFMono-Regular,Consolas,monospace;} -.code-comment {color:#91a4bf;}.code-accent {color:#8db8ff;} -.meta-strip {display:grid;grid-template-columns:repeat(4,1fr);border:1px solid var(--line);border-radius:10px;background:var(--surface);margin:1rem 0 2.8rem;} -.meta-strip span {font-size:.68rem;color:var(--muted);padding:1rem 1.1rem;border-right:1px solid var(--line);} -.meta-strip span:last-child {border:0;} -.meta-strip b {display:block;font-size:1.2rem;font-weight:750;color:var(--ink);margin-bottom:.15rem;letter-spacing:-.04em;} -.section-head {display:flex;justify-content:space-between;align-items:baseline;gap:1rem;margin-top:2.5rem;} -.section-head h2 {font-size:1.55rem;margin:0;}.section-head p {font-size:.7rem;color:var(--muted);} -.journey {display:grid;grid-template-columns:repeat(5,1fr);gap:1rem;margin:1.3rem 0 2.5rem;} -.journey-step {position:relative;border-top:2px solid var(--line);padding:.9rem 0;} -.journey-step:last-child {border-color:var(--accent);} -.journey-step span {font:.62rem ui-monospace,monospace;color:var(--accent);display:block;margin-bottom:.4rem;} -.journey-step strong {font-size:.77rem;display:block;line-height:1.5;} -.journey-step small {display:block;font-size:.65rem;color:var(--muted);margin-top:.3rem;} -.quick-labs {display:grid;grid-template-columns:1fr 1fr;gap:1rem;margin:1.5rem 0 2rem;} -.quick-lab {display:grid;grid-template-columns:40px 1fr 20px;gap:1rem;align-items:center;background:var(--surface);border:1px solid var(--line);border-radius:11px;padding:1.3rem;text-decoration:none;color:var(--ink);transition:border-color .15s,box-shadow .15s;} -.quick-lab:hover {border-color:var(--accent);box-shadow:var(--shadow);color:var(--ink);} -.quick-lab .lab-card-icon {display:flex;align-items:center;justify-content:center;width:40px;height:40px;background:var(--pale);color:var(--accent);border-radius:10px;} -.quick-lab .lab-card-icon .ui-icon {width:20px;height:20px;} -.quick-lab h3 {font-size:.93rem;margin:0 0 .35rem;}.quick-lab p {font-size:.75rem;color:var(--muted);line-height:1.65;margin:0;} -.quick-lab .eyebrow {font-size:.53rem;color:var(--accent);margin-bottom:.35rem;display:block;} -.module-list {display:grid;grid-template-columns:repeat(2,1fr);gap:1rem;margin:1.3rem 0;} -.module-card {display:grid;grid-template-columns:34px 1fr;gap:.9rem;padding:1.3rem;background:var(--surface);border:1px solid var(--line);border-radius:10px;color:var(--ink);text-decoration:none;transition:border-color .15s,box-shadow .15s;} -.module-card:hover {color:var(--ink);border-color:#a3bff5;box-shadow:var(--shadow);} -.module-number {display:flex;align-items:center;justify-content:center;width:32px;height:32px;border:1px solid var(--line);border-radius:8px;font:.65rem ui-monospace,monospace;color:var(--muted);} -.module-card h3 {font-size:.91rem;margin:0 0 .5rem;letter-spacing:-.02em;} -.module-card p {font-size:.75rem;color:var(--muted);line-height:1.7;margin:0 0 1rem;} -.module-card small {font-size:.57rem;font-weight:600;letter-spacing:.04em;color:var(--accent);} -.feature-ribbon {display:flex;justify-content:space-between;align-items:center;gap:1.5rem;margin:2.5rem 0 1.5rem;padding:1.6rem;background:var(--pale);border:1px solid var(--line);border-radius:12px;} -.feature-ribbon p {font-size:.8rem;margin:0;color:var(--muted);}.feature-ribbon strong {display:block;font-size:1rem;color:var(--ink);margin-bottom:.3rem;} +main:has(>.practice-home) {max-width:1120px;width:100%;margin:clamp(.8rem,4vw,3.2rem) auto 2rem;} +main:has(>.practice-home) .quarto-title-block {margin:0 0 1.2rem;} +main:has(>.practice-home) .quarto-title h1 {font-size:clamp(2.7rem,5.3vw,5.2rem);font-weight:780;line-height:1.02;letter-spacing:-.065em;margin:0;max-width:12ch;} +.practice-intro .intro {font-size:clamp(.96rem,1.5vw,1.15rem);color:var(--muted);line-height:1.65;max-width:35ch;margin:0 0 1.45rem;} +.practice-intro .button-primary {font-size:.94rem;padding:.8rem 1rem;min-height:48px;} +.practice-intro .small-note {max-width:40ch;font-size:.81rem;margin:.85rem 0 0;} +.practice-path {border:1px solid var(--line);border-radius:var(--radius);background:var(--surface);box-shadow:var(--shadow);padding:.4rem 0;min-width:0;} +.practice-path h2 {font-size:1.18rem;margin:0;padding:.9rem 1.1rem .55rem;} +.practice-exercises {list-style:none;counter-reset:exercise;padding:0;margin:0;} +.practice-exercises li {counter-increment:exercise;max-width:none;border-top:1px solid var(--line);} +.practice-exercises a {display:grid;grid-template-columns:2rem minmax(0,1fr) auto;align-items:center;gap:.75rem;padding:.75rem 1.05rem;text-decoration:none;color:var(--ink);} +.practice-exercises a:hover {background:var(--pale);} +.practice-exercises a:focus-visible {outline-offset:-4px;} +.practice-exercises a::before {content:counter(exercise);display:grid;place-items:center;width:2rem;height:2rem;border-radius:.55rem;background:var(--pale);color:var(--accent);font-size:.78rem;font-weight:700;} +.practice-exercises a [data-icon] {color:var(--accent);} +.practice-exercises strong,.practice-exercises a div span {display:block;} +.practice-exercises strong {font-size:.92rem;} +.practice-exercises a div span {color:var(--muted);font-size:.8rem;line-height:1.45;margin-top:.18rem;} +.practice-reference {display:flex;flex-wrap:wrap;gap:.65rem 1.35rem;border-top:1px solid var(--line);padding-top:1rem;font-size:.85rem;} +.practice-page-intro {font-size:.92rem;color:var(--muted);margin:0 0 1rem;} +@media(min-width:825px) { + main:has(>.practice-home) { + display:grid;grid-template-columns:minmax(0,.9fr) minmax(0,1fr);grid-template-rows:1fr auto auto 1fr auto; + grid-template-areas:". exercises" "heading exercises" "intro exercises" ". exercises" "references references"; + column-gap:clamp(2rem,6vw,6.5rem); + } + main:has(>.practice-home) .quarto-title-block {grid-area:heading;} + .practice-home {display:contents;} + .practice-intro {grid-area:intro;} + .practice-path {grid-area:exercises;} + .practice-reference {grid-area:references;margin-top:1.7rem;} +} +@media(max-width:824px) { + .practice-home .practice-path {margin-top:1.6rem;} + .practice-reference {margin-top:1.2rem;} +} /* Reading, exercises, and reference pages */ .lesson-meta {display:inline-block;background:var(--pale);padding:.5rem .7rem;border-radius:6px;color:var(--accent);font-size:.66rem;margin-bottom:1rem;} .callout {background:var(--surface);border-color:var(--line);border-radius:9px;box-shadow:none;} @@ -152,7 +140,6 @@ details[open]>summary {margin-bottom:.8rem;}details>*:last-child {margin-bottom: .checklist label {display:block;font-size:.85rem;line-height:1.7;margin:.8rem 0;}.checklist input {margin-right:.6rem;accent-color:#2563eb;}.checklist-output {font-size:.8rem;color:var(--success);font-weight:650;} .download-grid {display:grid;grid-template-columns:1fr 1fr;gap:1rem;}.download-grid a {background:var(--surface);border:1px solid var(--line);border-radius:10px;padding:1.4rem;text-decoration:none;font-weight:650;font-size:.87rem;}.download-grid small {display:block;font-size:.73rem;color:var(--muted);font-weight:400;margin-top:.5rem;} /* Interactive workspace foundations */ -.lab-intro {display:flex;align-items:center;flex-wrap:wrap;gap:.6rem 1.2rem;font-size:.67rem;color:var(--muted);margin:.5rem 0 1.5rem;} .interactive-lab {margin:1.2rem 0 2rem;min-width:0;} .interactive-lab :is(button,input,select,textarea),.practice-plan :is(button,input,textarea) {font:inherit;color:var(--ink);background:var(--surface);border:1px solid var(--line);border-radius:6px;max-width:100%;} .interactive-lab button,.practice-plan button {display:inline-flex;align-items:center;justify-content:center;gap:.4rem;min-height:34px;padding:.45rem .7rem;font-size:.7rem;font-weight:600;line-height:1.5;cursor:pointer;transition:background .12s,border-color .12s;} @@ -169,34 +156,52 @@ details[open]>summary {margin-bottom:.8rem;}details>*:last-child {margin-bottom: .interactive-lab h2 {font-size:1rem;margin:0 0 .7rem;line-height:1.5;letter-spacing:-.025em;} .interactive-lab h3 {font-size:.8rem;letter-spacing:-.015em;} /* Notebook mission navigation + task rail */ -.lab-missions {display:grid;grid-template-columns:repeat(4,1fr);gap:0;background:var(--surface);border:1px solid var(--line);border-radius:10px;padding:5px;margin-bottom:1.2rem;} -.lab-missions button {display:flex;align-items:center;justify-content:flex-start;gap:.7rem;background:transparent;border-color:transparent;padding:.7rem;min-width:0;text-align:left;border-radius:7px;font-size:.73rem;} -.lab-missions button small {display:block;color:var(--muted);font-size:.59rem;font-weight:400;margin-top:.15rem;} -.step-number {display:flex;align-items:center;justify-content:center;flex-shrink:0;width:27px;height:27px;background:var(--paper);border:1px solid var(--line);border-radius:7px;color:var(--muted);font:.6rem ui-monospace,monospace;} -.lab-missions button[aria-pressed=true] {background:var(--pale);color:var(--accent);border-color:transparent;} +.lab-missions {display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:.25rem;background:var(--surface);border:1px solid var(--line);border-radius:10px;padding:.3rem;margin-bottom:1rem;} +.lab-missions button {justify-content:flex-start;gap:.6rem;background:transparent;border-color:transparent;padding:.6rem;min-width:0;text-align:left;font-size:.81rem;min-height:44px;scroll-margin-top:165px;} +.step-number {display:grid;place-items:center;flex-shrink:0;width:1.65rem;height:1.65rem;background:var(--paper);border:1px solid var(--line);border-radius:.4rem;color:var(--muted);font-size:.72rem;} +.lab-missions button[aria-pressed=true] {background:var(--pale);color:var(--accent);} .lab-missions button[aria-pressed=true] .step-number {background:#2563eb;color:#fff;border-color:#2563eb;} -.lab-layout {display:grid;grid-template-columns:242px minmax(0,1fr);gap:1.2rem;align-items:start;} -.mission-card {background:var(--surface);border:1px solid var(--line);border-radius:10px;padding:1.2rem;position:sticky;top:88px;box-shadow:var(--shadow);} -.mission-card h2 {font-size:1rem;line-height:1.5;margin:.75rem 0;} -.mission-card>p {font-size:.8rem;color:var(--muted);line-height:1.8;} -.mission-card details {padding:.65rem 0;background:transparent;border:0;border-bottom:1px solid var(--line);border-radius:0;margin:0;} -.mission-card summary {font-size:.71rem;color:var(--ink);} -.mission-card details p,.mission-card li {font-size:.75rem;line-height:1.85;color:var(--muted);} -.mission-card ol {padding-left:1.1rem;margin:.7rem 0 .2rem;}.mission-card li {margin-bottom:.6rem;padding-left:.15rem;} -.mission-card .small-note {font-size:.62rem;margin:.8rem 0 0;} -.mission-actions {display:flex;align-items:center;gap:.5rem;flex-wrap:wrap;margin-top:1rem;} -.mission-card .mission-actions {flex-direction:column;align-items:stretch;gap:.3rem;}.mission-card .mission-actions button {width:100%;} +.lab-layout {display:grid;grid-template-columns:minmax(235px,290px) minmax(0,1fr);gap:1rem;align-items:start;} +body:has(.notebook-lab) main,body:has(.git-dojo) main {width:100%;max-width:1160px;margin-inline:auto;} +.mission-card {min-width:0;background:var(--surface);border:1px solid var(--line);border-radius:10px;padding:1rem;box-shadow:var(--shadow);} +.mission-card h2 {font-size:1.24rem;line-height:1.25;margin:.3rem 0 .55rem;scroll-margin-top:95px;} +.mission-card>p:not(.exercise-progress) {font-size:.84rem;color:var(--muted);line-height:1.6;} +.exercise-progress {font-size:.74rem;font-weight:650;color:var(--muted);margin:0;} +.notebook-step {background:var(--pale);border:1px solid var(--line);border-radius:8px;padding:.85rem;scroll-margin-top:95px;} +.step-instruction {font-size:.87rem;line-height:1.55;margin:.35rem 0 .7rem;} +.notebook-step textarea {box-sizing:border-box;} +.mission-actions {display:flex;align-items:flex-start;gap:.4rem;flex-wrap:wrap;} +.notebook-step .mission-actions button,.notebook-step .button-primary {font-size:.78rem;min-height:40px;} +.notebook-step [data-view-output] {text-decoration:underline;color:var(--accent);} +.mission-card details {padding:.55rem 0;background:transparent;border:0;border-bottom:1px solid var(--line);border-radius:0;margin:0;} +.mission-card details:last-child {border-bottom:0;padding-bottom:0;} +.mission-card summary {font-size:.78rem;color:var(--ink);} +.mission-card details p,.mission-card li {font-size:.8rem;line-height:1.5;color:var(--muted);} +.mission-card ol {padding-left:1.1rem;margin:.5rem 0 0;} +.mission-card li button {display:block;text-align:left;font-size:.77rem;margin:.1rem 0;} +.mission-card li button[aria-current=step] {background:var(--pale);color:var(--accent);} +.guide-feedback {margin:.55rem 0 0;font-size:.79rem;line-height:1.5;overflow-wrap:anywhere;} +.guide-feedback:empty {display:none;} +.guide-feedback[data-state=success] {color:var(--success);} +.guide-feedback[data-state=error] {border-inline-start:3px solid #c4504e;padding-inline-start:.55rem;} +.notebook-step .error-details {border:0;padding:.4rem 0 0;} +.error-details pre {max-height:12rem;overflow:auto;} /* Notebook editor */ .notebook-workspace,.git-workspace {min-width:0;background:var(--surface);border:1px solid var(--line);border-radius:10px;overflow:hidden;box-shadow:var(--shadow);} -.workspace-heading {display:flex;align-items:center;justify-content:space-between;gap:.7rem;padding:.9rem 1rem;border-bottom:1px solid var(--line);font-size:.69rem;color:var(--muted);} +.workspace-heading {display:flex;align-items:center;justify-content:space-between;gap:.7rem;padding:.8rem 1rem;border-bottom:1px solid var(--line);font-size:.8rem;color:var(--muted);} .workspace-heading>div {display:flex;gap:.5rem;align-items:center;min-width:0;flex-wrap:wrap;} -.workspace-heading strong {color:var(--ink);font-weight:650;}.workspace-icon {color:var(--accent);}.workspace-separator {color:var(--muted);} -.language-badge {color:var(--muted);background:var(--paper);padding:.2rem .5rem;border:1px solid var(--line);border-radius:5px;font:.6rem ui-monospace,monospace;} -.workspace-toolbar {display:flex;align-items:center;flex-wrap:wrap;gap:.4rem;padding:.75rem 1rem;} -.workspace-toolbar .stop-action {margin-left:auto;}.workspace-toolbar .stop-action:not(:disabled) {color:#d24a58;} -.kernel-line {display:flex;align-items:flex-start;gap:.5rem;padding:.1rem 1rem .7rem;color:var(--muted);} -.kernel-line .status-dot {margin-top:.4rem;background:#98a6bc;}.kernel-line[data-state=ready] .status-dot {background:var(--success);}.kernel-line[data-state=busy] .status-dot {background:#e6ad4a;} -.kernel-line p {font-size:.59rem;line-height:1.7;margin:0;max-width:none;} +.workspace-heading strong {color:var(--ink);font-weight:650;} +.workspace-icon {color:var(--accent);} +.workspace-options {padding:0;margin:0;border:0;background:transparent;} +.workspace-options summary {font-size:.78rem;color:var(--accent);} +.workspace-options[open] .lab-controls {margin:0;} +.workspace-heading:has(.workspace-options[open]) {align-items:flex-start;} +.kernel-line {display:flex;align-items:center;gap:.45rem;margin-top:.65rem;color:var(--muted);} +.kernel-line .status-dot {background:#98a6bc;} +.kernel-line[data-state=ready] .status-dot {background:var(--success);} +.kernel-line[data-state=busy] .status-dot {background:#b7791c;} +.kernel-line p {font-size:.75rem;line-height:1.4;margin:0;} +.kernel-line .stop-action {color:var(--ink);margin-left:auto;} .lab-tabs {display:flex;align-items:stretch;overflow-x:auto;background:var(--paper);border-top:1px solid var(--line);border-bottom:1px solid var(--line);padding:0 .6rem;gap:.1rem;} .lab-tabs button {flex-shrink:0;border:0;border-radius:0;background:transparent;color:var(--muted);padding:.8rem .75rem;font-size:.65rem;font-weight:500;position:relative;min-height:42px;} .lab-tabs button[aria-selected=true] {color:var(--accent);background:var(--surface);font-weight:650;} @@ -216,6 +221,8 @@ kbd {font-size:.58rem;background:var(--paper);color:var(--muted);border:1px soli .code-editor:focus-visible {outline:0;box-shadow:inset 0 0 0 2px #6395f5;} .editor-frame {--gutter:36px;position:relative;display:block;padding-left:var(--gutter);background:var(--code-bg);min-width:0;} .interactive-lab .line-gutter {position:absolute;inset:0 auto 0 0;width:var(--gutter);box-sizing:border-box;color:var(--muted);opacity:.65;text-align:right;border-right:1px solid var(--line);padding:1rem .45rem;font:.78rem/1.85 ui-monospace,SFMono-Regular,Consolas,monospace;white-space:pre;overflow:hidden;user-select:none;max-height:100%;} +.live-cell[data-step-cell] {border-color:var(--accent);} +.code-editor,.cell-output {scroll-margin-top:95px;} .cell-output:empty {display:none;} .cell-output:not(:empty) {padding:.8rem 1rem;border-top:1px solid var(--line);} .cell-output:not(:empty):before {content:'OUTPUT';display:block;margin-bottom:.4rem;font-size:.5rem;font-weight:700;letter-spacing:.1em;color:var(--muted);} @@ -227,17 +234,12 @@ kbd {font-size:.58rem;background:var(--paper);color:var(--muted);border:1px soli .file-heading button {font-size:.65rem;}.file-guidance {font-size:.71rem;color:var(--muted);padding:0 1rem .9rem;line-height:1.8;margin:0;} .file-pane .editor-frame {border-top:1px solid var(--line);} .inspector-grid {padding:1.2rem;}.inspector-grid h3 {margin:0 0 .4rem;}.inspector-grid p {font-size:.68rem;color:var(--muted);}.inspector-grid pre {padding:.8rem;background:var(--code-bg);border:1px solid var(--line);border-radius:7px;min-height:120px;} -.workspace-bottom {display:flex;align-items:center;justify-content:space-between;gap:1rem;padding:.7rem 1rem;border-top:1px solid var(--line);font-size:.58rem;color:var(--muted);} -.workspace-bottom>span {display:flex;align-items:center;gap:.4rem;} -.download-menu {position:relative;background:transparent;border:0;padding:0;margin:0;} -.download-menu summary {font-size:.63rem;list-style:none;display:flex;align-items:center;gap:.4rem;white-space:nowrap;} -.download-menu[open]>summary {margin:0;} -.download-menu .lab-controls {position:absolute;bottom:1.7rem;right:0;z-index:5;width:180px;background:var(--surface);border:1px solid var(--line);border-radius:8px;padding:.5rem;box-shadow:0 6px 20px #00000016;} -.download-menu button {width:100%;justify-content:flex-start;font-size:.65rem;border:0;} -.mission-result-panel {padding:1rem 1.2rem;margin-top:1.2rem;border:1px solid var(--line);border-radius:9px;background:var(--surface);} -.mission-result-panel .panel-eyebrow {margin-bottom:.45rem;}.mission-feedback {font-size:.72rem;line-height:1.8;color:var(--muted);} -.mission-feedback[data-state=passed] {color:var(--success);}.mission-feedback[data-state=error] {color:#c43b4c;} -.lab-footnote {margin-top:1rem;font-size:.64rem;} +.workspace-bottom {display:flex;align-items:flex-start;justify-content:space-between;gap:.6rem;padding:.75rem 1rem;border-top:1px solid var(--line);font-size:.77rem;} +.download-menu {background:transparent;border:0;padding:0;margin:0;} +.download-menu summary {font-size:.77rem;color:var(--accent);} +.download-menu .lab-controls {margin:0;} +.lab-footnote {margin-top:1rem;font-size:.76rem;} +.notebook-reference {font-size:.82rem;} /* Git practice room */ .git-dojo {margin:1rem 0 1.5rem;} .git-layout {display:grid;grid-template-columns:minmax(200px,235px) minmax(0,1fr);align-items:start;gap:1rem;} @@ -341,50 +343,32 @@ kbd {font-size:.58rem;background:var(--paper);color:var(--muted);border:1px soli } /* Personal handoff worksheet */ .practice-plan input:not([type=checkbox]),.practice-plan textarea {display:block;width:100%;}.practice-plan label {font-size:.8rem;margin:1rem 0 .5rem;}.practice-plan label:has(input[type=checkbox]) {font-size:.8rem;font-weight:400;line-height:1.8;}.practice-plan input[type=checkbox] {margin-right:.6rem;accent-color:#2563eb;}.practice-plan button {margin-top:1rem;}.practice-plan [role=status] {font-size:.73rem;color:var(--muted);margin:1rem 0 0;} -/* Wide layouts use the space for tools, while articles keep a reading measure. */ -@media(min-width:1200px) { - body:has(.interactive-lab) .page-columns,body:has(.hero) .page-columns { - grid-template-columns:[screen-start] 20px [screen-start-inset] 0 [page-start] 0 [page-start-inset] 204px [body-start-outset] 28px [body-start] 0 [body-content-start] minmax(0,1fr) [body-content-end] 0 [body-end] 28px [body-end-outset] 0 [page-end-inset] 0 [page-end] 0 [screen-end-inset] 20px [screen-end]; - } +@media(min-width:825px) { + .mission-card {position:sticky;top:85px;max-height:calc(100dvh - 103px);overflow-y:auto;scrollbar-width:thin;} } -@media(min-width:1500px) {.lab-layout {grid-template-columns:270px minmax(0,1fr);}} -@media(max-width:1199px) { - .lab-layout {grid-template-columns:1fr;}.mission-card {position:static;}.mission-card .mission-actions {flex-direction:row;}.mission-card .mission-actions button {width:auto;} - .mission-card {padding:1rem 1.2rem;}.mission-card>p {max-width:100%;}.mission-card details {padding:.5rem 0;}.mission-card h2 {margin:.5rem 0;}.mission-card .mission-actions {margin-top:.7rem;}.mission-card>.small-note {display:none;} - .hero {gap:1.8rem;}.hero h1 {font-size:3.2rem;}.quick-lab {padding:1.1rem;gap:.7rem;} +@media(max-width:824px) { + .lab-layout {grid-template-columns:minmax(0,1fr);gap:.75rem;} } @media(max-width:991px) { - .lab-missions button small {display:none;} - .quarto-title h1 {font-size:2rem;}.navbar {padding:.8rem 1rem;}.navbar .navbar-nav .nav-item:last-child .nav-link {border:0;background:transparent;} + .quarto-title h1 {font-size:2rem;} + .navbar {padding:.8rem 1rem;} } @media(max-width:767px) { body {font-size:15px;}.quarto-title h1 {font-size:1.85rem;}.quarto-title .subtitle {font-size:.9rem;}main {padding-top:.8rem;} - .hero {grid-template-columns:1fr;gap:1.8rem;}.hero h1 {font-size:3.1rem;max-width:16ch;}.hero .intro {max-width:100%;font-size:.9rem;}.research-card {max-width:100%;}.workshop-badge {font-size:.57rem;} - .meta-strip {grid-template-columns:1fr 1fr;}.meta-strip span {padding:.8rem;}.meta-strip span:nth-child(2) {border-right:0;}.meta-strip span:nth-child(-n+2) {border-bottom:1px solid var(--line);} - .journey {grid-template-columns:1fr;gap:.5rem;}.journey-step {display:grid;grid-template-columns:26px 1fr;gap:.2rem;border:0;border-left:2px solid var(--line);padding:.7rem 0 .7rem 1rem;}.journey-step span {grid-row:span 2;margin:0;}.journey-step strong {font-size:.78rem;}.journey-step small {margin:0;} - .module-list,.quick-labs,.download-grid {grid-template-columns:1fr;}.section-head {display:block;}.section-head p {margin-top:.5rem;}.feature-ribbon {display:block;padding:1.2rem;}.feature-ribbon .button-primary {margin-top:1rem;} - .lab-intro {font-size:.6rem;gap:.5rem .7rem;margin:.7rem 0 1rem;}.lab-missions {grid-template-columns:1fr 1fr;gap:3px;}.lab-missions button {padding:.55rem .5rem;font-size:.66rem;}.step-number {height:24px;width:24px;font-size:.55rem;} - .mission-card {padding:1rem;}.mission-card h2 {font-size:.92rem;}.lab-layout,.git-layout {gap:.8rem;} - .interactive-lab button {min-height:38px;}.workspace-toolbar {padding:.7rem;gap:.35rem;}.workspace-toolbar button {font-size:.62rem;padding:.4rem .55rem;}.workspace-toolbar .stop-action {margin-left:0;} - .workspace-heading {padding:.8rem .7rem;font-size:.63rem;}.workspace-heading .workspace-separator,.workspace-heading .workspace-separator+span {display:none;} - .lab-tabs {padding:0 .3rem;}.lab-tabs button {padding:.7rem .6rem;font-size:.61rem;}.lab-tabs .ui-icon {height:13px;width:13px;} - .editor-caption {font-size:.55rem;padding:.6rem .7rem;}.editor-caption>span:last-child {display:none;} - [data-cells] {padding:.6rem;}.cell-toolbar {padding:.5rem .6rem;gap:.4rem;flex-wrap:wrap;}.cell-toolbar label {font-size:.63rem;min-width:110px;}.cell-toolbar button {font-size:.58rem;min-height:29px;}.cell-toolbar [data-cell-count] {font-size:.55rem;} - .interactive-lab .code-editor,.interactive-lab .line-gutter {font-size:.66rem;}.editor-frame {--gutter:28px;}.interactive-lab .code-editor {padding:.8rem .6rem;}.interactive-lab .line-gutter {padding:.8rem .3rem;} - .cell-output:not(:empty) {padding:.7rem;}.cell-output pre {font-size:.61rem;}.file-heading {padding:.8rem;align-items:flex-start;}.file-heading label {font-size:.7rem;}.file-heading button {font-size:.61rem;}.file-guidance {font-size:.66rem;padding:0 .8rem .8rem;} - .workspace-bottom {padding:.7rem;gap:.6rem;align-items:flex-start;}.workspace-bottom>span {font-size:.53rem;line-height:1.7;}.workspace-bottom>span .ui-icon {display:none;}.download-menu summary {font-size:.58rem;}.kernel-line {padding:0 .7rem .7rem;}.kernel-line p {font-size:.54rem;} - .inspector-grid,.lab-columns {grid-template-columns:1fr;gap:.5rem;}.mission-result-panel {padding:.9rem;}.mission-result-panel pre {font-size:.62rem;} + .download-grid {grid-template-columns:1fr;} + .lab-missions {grid-template-columns:repeat(2,minmax(0,1fr));} + .lab-missions button {padding:.45rem;font-size:.74rem;} + .interactive-lab button {min-height:38px;} + .workspace-heading {padding:.7rem;} + .workspace-heading:has(.workspace-options[open]) {flex-wrap:wrap;} + .lab-tabs {padding:0 .3rem;}.lab-tabs button {padding:.7rem .6rem;font-size:.68rem;}.lab-tabs .ui-icon {height:13px;width:13px;} + .editor-caption {padding:.6rem .7rem;}.editor-caption>span:last-child {display:none;} + [data-cells] {padding:.6rem;}.cell-toolbar {padding:.5rem .6rem;gap:.4rem;flex-wrap:wrap;}.cell-toolbar label {font-size:.72rem;min-width:110px;} + .interactive-lab .code-editor,.interactive-lab .line-gutter {font-size:.72rem;}.editor-frame {--gutter:28px;}.interactive-lab .code-editor {padding:.8rem .6rem;}.interactive-lab .line-gutter {padding:.8rem .3rem;} + .cell-output:not(:empty) {padding:.7rem;}.file-heading {padding:.8rem;align-items:flex-start;}.file-guidance {padding:0 .8rem .8rem;} + .workspace-bottom {padding:.7rem;} + .inspector-grid,.lab-columns {grid-template-columns:1fr;gap:.5rem;} .schedule-block {grid-template-columns:74px 1fr;gap:.8rem;}.schedule-time {font-size:.6rem;padding:.4rem .2rem;}.schedule-block p {font-size:.8rem;} .table td,.table th {padding:.6rem!important;}.columns {display:block;}.columns>.column {width:100%!important;} } @media(prefers-reduced-motion:reduce) {* {scroll-behavior:auto!important;transition:none!important;}} - -.check-summary {font-size:.65rem;text-align:center;text-decoration:none;line-height:1.7;}.check-summary[data-state=passed] {color:var(--success);}.check-summary[data-state=error] {color:#c43b4c;} -@media(min-width:1200px){.mission-card {max-height:calc(100dvh - 110px);overflow-y:auto;scrollbar-width:thin;}} -/* Keep the editor beside its brief in narrow desktop panels; phones stack. */ -@media(min-width:700px) and (max-width:1199px) { - .lab-layout {grid-template-columns:210px minmax(0,1fr);gap:.9rem;} - .mission-card {position:sticky;top:88px;max-height:calc(100dvh - 110px);overflow-y:auto;scrollbar-width:thin;padding:1rem;} - .mission-card .mission-actions {flex-direction:column;align-items:stretch;} - .mission-card .mission-actions button {width:100%;} -} diff --git a/site/assets/ui.js b/site/assets/ui.js index 23d4212..a0e58d3 100644 --- a/site/assets/ui.js +++ b/site/assets/ui.js @@ -40,11 +40,6 @@ export function tabs(root,selector,onSelect){ } const notebook=document.querySelector('[data-notebook-lab]'); if(notebook){ - const select=tabs(notebook,'[data-workspace-tabs]'); - const feedback=notebook.querySelector('[data-mission-result]'),summary=notebook.querySelector('[data-check-summary]'); - new MutationObserver(()=>{const state=feedback.dataset.state;summary.hidden=!state;summary.dataset.state=state||'';summary.textContent=state==='passed'?'Passed · view feedback':'Check failed · view feedback';}).observe(feedback,{childList:true}); - const instructions=notebook.querySelector('[data-mission-instructions]'); - if(instructions)instructions.open=matchMedia('(min-width:1200px)').matches; const decorate=()=>{ for(const editor of notebook.querySelectorAll('.code-editor:not([data-lines-ready])')){ editor.dataset.linesReady=''; @@ -57,13 +52,6 @@ if(notebook){ }; const syncGutters=()=>{for(const editor of notebook.querySelectorAll('.code-editor')){const gutter=editor.closest('.editor-frame')?.querySelector('.line-gutter');if(gutter)gutter.textContent=Array.from({length:editor.value.split('\n').length},(_,i)=>i+1).join('\n');}}; new MutationObserver(()=>{decorate();icons(notebook);}).observe(notebook.querySelector('[data-cells]'),{childList:true}); - notebook.addEventListener('workshop:lesson',e=>{ - decorate();syncGutters();select(e.detail.id==='refactor'?'helper':e.detail.id==='config'?'config':'notebook'); - }); - notebook.addEventListener('click',e=>{ - const b=e.target.closest('button');if(!b)return; - if(b.matches('[data-run-cell],[data-run-all],[data-check-mission]'))select('notebook'); - if(b.matches('[data-solution]'))queueMicrotask(syncGutters); - },{capture:true}); + notebook.addEventListener('workshop:lesson',()=>{decorate();syncGutters();}); decorate(); } diff --git a/site/git-playground.qmd b/site/git-playground.qmd index d604538..033eadc 100644 --- a/site/git-playground.qmd +++ b/site/git-playground.qmd @@ -1,10 +1,14 @@ --- -title: "Git practice room" +title: "Git practice" toc: false +sidebar: false +page-navigation: false +page-layout: full --- ```{=html}
+

Practice making and sharing a change in a simulated repository. Start by choosing which edits belong in one commit.

diff --git a/site/index.qmd b/site/index.qmd index 5c01f4c..800c8b5 100644 --- a/site/index.qmd +++ b/site/index.qmd @@ -1,55 +1,33 @@ --- -title: "" -pagetitle: "Research / Code · A practical Python & Git workshop" -title-block-style: none +title: "Lab Code Practice" toc: false +sidebar: false +page-navigation: false +page-layout: full --- ```{=html} -
THE NEUROSCIENCE LAB WORKSHOP · NOVEMBER 2026
-
-
FROM EXPLORATION TO REPRODUCTION
-

Your next analysis.
Built to last.

-

Keep the curiosity of a notebook. Add clear functions, explicit choices, and a workflow your lab can reproduce. Learn it all through one motion-perception experiment.

- -

You know basic Python. We'll take it from there.
No installation needed for the browser labs.

-
motion-perception / results
Reproduced
-
Synthetic motion discrimination: participant accuracy is higher in the clear condition than in the noisy condition. Error bars show approximate participant uncertainty.
-
24 synthetic participantsOne experiment. Three code stages.
-
# Same settings. Notebook or script.
from experiment.config import load_config
config = load_config("config/analysis.toml")
-
-
6 modulesOne connected learning path2 live labsLearn by changing real examples90 minutesA guided workshop for your lab100% syntheticReal habits, teaching data
-

Less setup. More discovery.

Jump in and make a change.

- -

One project. A better workflow.

Follow the analysis as it evolves.

-
-
01ExploreAsk a question in a notebook
-
02ExtractGive repeated logic a function
-
03OrganizeShare code and configuration
-
04ReviewMake every change explainable
-
05ReproduceLet a labmate run it again
+
+
+

Run and improve a Python notebook, reproduce the result, and use Git to share a change with your lab.

+Start notebook practice +

The first exercise takes about 8 minutes. Basic Python is enough, and everything runs in your browser.

-``` - -## Built around the work you already do -You already write Python and pandas analyses. Here, you'll improve their names, responsibilities, configuration, and reproducibility. Git starts from first principles. We follow a fully synthetic visual motion discrimination experiment: load trials, apply an explicit exclusion rule, compare conditions, and generate a scientific figure. - -The core lessons take about three hours. The [90-minute workshop](workshop.qmd) selects the essentials; the live labs and [personal handoff plan](practice.qmd) let you practice further. +
+

Exercises

+
    +
  1. Run notebook cellsFind out why changing one cell can leave a result out of date.
  2. +
  3. Extract a Python functionMove a filter into a helper file and check that the results match.
  4. +
  5. Change a settingUse a configuration file to rerun the analysis with a different threshold.
  6. +
  7. Reproduce a figureRun from a fresh Python session to see what a labmate would get.
  8. +
  9. Practice GitChoose what goes into a commit, then practice branches and review.
  10. +
+
-```{=html} -

The learning path

Go in order, or return to what you need.

- -

Take the workflow back to your lab.Three working notebooks, a tested Python package, and synthetic data. Yours to explore and adapt.

Get the materials
-

Local setup instructions · 90-minute workshop run sheet · Make a handoff plan

``` diff --git a/site/notebook-lab.qmd b/site/notebook-lab.qmd index 0701457..cd843e3 100644 --- a/site/notebook-lab.qmd +++ b/site/notebook-lab.qmd @@ -1,39 +1,67 @@ --- -title: "Notebook lab" -subtitle: "A real Python workspace for better research code." +title: "Notebook practice" toc: false +sidebar: false +page-navigation: false +page-layout: full --- ```{=html} -
Interactive workspace4 missions · ~40 minutesNo installation needed
-