Chapter 1 · Session 15
Measures before widgets
A dashboard exists because someone makes a decision with it. Before any widget, every number gets a written definition: the decision it serves, its formula, the table it comes from, its unit, its owner and what happens when it is red. Anything the platform does not record yet is written down as not measured, never estimated.
30 min2 stepsNo code yetAbout 2½ hours hands-on in all
By the end of this chapter you can
- Trace every measure back to a decision in your intent and forward to an action.
- Have Claude Code draft docs/measures.md from the tables you already have, with a list of what is not measured yet.
- Check each measure with its owner and work one by hand, so the tests have a number to prove.
Start from the decision, not the data
If you start from the data ("we have holds, inspections and die changes, let's chart them") you get a screen full of charts nobody acts on. Start from the decision in docs/INTENT.md instead, and walk the chain below for each person who will read the dashboard. If you cannot name the action a red number triggers, the widget does not belong.
| Every measure has | Stamping plant example | Why it is there |
|---|---|---|
| Decision | Quality lead: hold or release the new lot? | Ties the number to the intent |
| Definition and formula | Lots whose latest decision is hold, and how long each has waited | Everyone, and Claude Code, counts the same way |
| Source | holds, through the lot_status view | Proves the platform already records it |
| Unit and period | Lots, now | Stops a shift being compared with a week |
| Owner | Quality lead | Someone answers for it |
| Target and red when | None waiting; red when one has waited over 4 hours | Says when to act |
| Action when red | Decide the oldest waiting lot first | No action, no widget |
| Stale after | 15 minutes without a newer row | Says when the number can no longer be trusted |
Have Claude Code draft docs/measures.md
15 minutesWhy
A measure written down before any code is a measure everyone computes the same way: you, the owner, the tests and Claude Code. Drafting it from your existing tables also shows at once which measures the platform can honestly show today and which it cannot, so nothing on the dashboard has to be filled in by guesswork.
Do this
Read docs/INTENT.md, docs/SCHEMA-PLAN.md, docs/workflow-1-fields.md, docs/matrix.json and the files in supabase/migrations/. Do not write any SQL or code.
On a new branch dashboard/measures, write docs/measures.md for someone who does not write code:
1. For each role in docs/matrix.json that makes or supports the decision in the intent, the decisions they make each shift and the questions they need answered first.
2. Up to six measures per role. For each: id (naming standard), title, the decision it serves, definition in plain words, formula, source tables (only tables that exist), unit and period, owner (a role), target, red when, the action when red, leading or lagging, and stale after (how old the newest source row may be before the number is not trusted).
3. A machine-readable block (a fenced json block) with the same fields per measure, so tests can read it.
4. "Not measured yet": every measure someone would want that our tables cannot compute today (for example OEE, which needs planned time, run time and part counts), with the data it would need and which session or workflow could bring it. Never propose estimating or defaulting one.
5. "Questions for the owners".
Open a pull request titled "Dashboard: measures" and show me the link.You will see recreated screen
- A complete definition: decision, formula, source, unit, owner, red when and action.
- The most important list on the page. Whatever is here never appears on a widget as a number.
Check it worked
The pull request has one new file. Every measure names its source tables (all of which exist), a unit, an owner and an action when red; there is a json block, a Not measured yet list and a Questions list.
If it goes wrong
It proposes OEE, scrap cost or energy from tables you do not have
Say: Move every measure whose data no table holds to Not measured yet, with the data it would need. Never estimate one. On our platform a report guessed revenue from headcount; the customer had never given it.
A measure has no action when red
Say: Drop any measure with no action when red, or ask its owner in the Questions section what they would do. A number nobody acts on still costs attention every day.
It wrote SQL or a widget anyway
Say: Remove the code. I need the definitions in plain English first, as asked.
Check each measure with its owner, and work one by hand
20 minutesWhy
The owner knows what the number is for: whether a hold counts from the decision or from the die change, whether four hours is the right limit. Working one measure by hand on a few made-up rows gives a number that is right because you counted it, so the tests can prove the database computes the same, not just something plausible.
Do this
Sit with the quality lead and the area supervisor and read docs/measures.md on GitHub. For each measure ask: What do you do when this is red? Is this how you would count it? Answer the questions. Then work the pass rate by hand on eight made-up lots: write each lot, whether its first piece was inside limits, and the result (here 7 of 8: 87.5%, red). Then:
The owners read docs/measures.md:
1. <paste their answer to each question>
They also changed: <paste anything else, in their words>.
Update the file. Add a section "Worked by hand" with this example, which the tests must reproduce exactly:
<paste your eight lots and the result, for example: 8 lots on Press 3, lots 1 to 8, lot 6 out of limits on flange height; first_piece_pass = 7 of 8 = 87.5%, red>
Add "Checked with the quality lead and the area supervisor on <today's date>" at the top, and push to the same pull request.Owner two approves; merge.
You will see recreated screen
| Measure | Owner | Unit | Red when | Stale after |
|---|---|---|---|---|
| Lots on hold now | Quality lead | lots | one waits over 4 h | 15 min |
| First-piece pass rate, 7 days | Quality lead | % (with count) | below 90% | 60 min |
| Die change to release, median | Area supervisor | minutes | over 30 | 60 min |
| Die change minutes, median | Maintenance lead | minutes | over 45 | 24 h |
- The sign-off: who agreed each definition, and when.
- The number the tests must reproduce. You counted it; the database must agree.
Check it worked
docs/measures.md is merged on main, signed off by the owners with a date, with a hand-worked example and no open questions.
Fastest path
Work the example on paper with the owner during the meeting. They will spot a counting rule (does a correction count as a first piece?) faster than any review.
If it goes wrong
The owner asks for twenty measures
Ask which decision each extra one changes. Keep six; put the rest in a monthly report, or under Not measured yet if the data does not exist.
The owner wants a number you do not record, "just roughly"
Write it under Not measured yet with what would be needed. A rough number on a dashboard is read as a measured one by everyone who did not hear the word roughly.
Use the standard definitions, and only for data you have
Manufacturing already agrees on how to compute its common measures. ISO 22400-2 defines key performance indicators for manufacturing operations (availability, quality ratio, scrap ratio, OEE and others) with formulas, units and the times and quantities each is built from [1], in terms that line up with the ISA-95 model your names follow [2]. Overall equipment effectiveness multiplies three factors, and the lowest factor says where to look [3]:
| Factor | Formula | Example shift |
|---|---|---|
| Availability | run time ÷ planned time = 387 ÷ 450 | 86.0% |
| Performance | total parts ÷ (run time × ideal rate) = 6,966 ÷ 7,740 | 90.0% |
| Quality | good parts ÷ total parts = 6,757 ÷ 6,966 | 97.0% |
| OEE | 0.860 × 0.900 × 0.970 | 75.1% |
A lagging measure says what already happened (last week's pass rate). A leading one moves first (lots waiting on a decision now). Pair each lagging measure with a leading one so the owner has time to act, and watch for numbers that mislead: an average that hides one bad shift, a percentage without its count ("50% failed" of two lots), a target that people learn to move instead of the work.
Knowledge check
A manager asks for a widget showing 'all the press data'. What do you ask first?
Knowledge check
The dashboard needs OEE, but no table holds run time or part counts. What goes on the dashboard?
References
- ISO 22400-2:2014, Key performance indicators (KPIs) for manufacturing operations management, Part 2: Definitions and descriptions. https://www.iso.org/standard/54497.html
- ISA: ISA-95 standard, Enterprise-Control System Integration. https://www.isa.org/standards-and-publications/isa-standards/isa-95-standard
- Vorne: Calculating OEE. https://www.oee.com/calculating-oee/
Chapter 2 · Session 15
Widgets that show only what was measured
Each measure becomes a database view that keeps your access rules, and each widget is a few lines of configuration drawn by one component. The component has five honest states, and every widget carries its source and the time of its newest data. Then you hunt for any number on any screen that nobody measured.
45 min3 steps5 honest statesA test for every widget
By the end of this chapter you can
- Have Claude Code write one view per measure, with security_invoker, and tests that reproduce the hand-worked number.
- Build one widget component with five states (live, no data, stale, not enough data, could not load) and a test per widget.
- Find and remove every displayed number that is hard-coded, generated or defaulted.
The number nobody measured
We shipped invented numbers more than once. A savings counter that ticked up by itself, labelled as the ledger. A control chart that drew twelve hard-coded points and graded them "In control" on 87 screens. Seven users on an admin page who did not exist. A sensor that could not be read, shown as 0, which is a real reading. Each time, an agent had filled an empty place so the screen looked finished. The fix is a rule and a design: every displayed number comes from a stored or measured value, and "no data" is a visible state, never a number.
| State | When | What the widget shows |
|---|---|---|
| Live | Rows in the period, newest within stale after | The value, its count, its source and "as of 06:52" |
| No data | No rows in the period | "No first-piece results in the last 7 days": never 0 |
| Stale | Newest row older than stale after | Grey, the last value, "as of 03:10, not updating" |
| Not enough data | Fewer rows than the measure needs (a control chart needs 20) | "12 of 20 lots: limits not yet computed" |
| Could not load | The view failed or was refused | "Could not load" and the time it tried: never a remembered or default value |
A view is a saved query that reads like a table. Created with security_invoker = true, it runs with the rights of the person asking, so the row-level security on the tables underneath still applies [1][2]. Without it, a view runs with its owner's rights and can show every site's rows to everyone; Supabase's Security Advisor flags such a view as an error [3].
One prompt: the measure views and their tests
20 minutesWhy
Computing each measure once, in the database, means every screen and every test gets the same number, and the access rules apply to it automatically. Tests that reproduce your hand-worked number prove the formula; tests from another site prove the view opened no new path to the data. Writing them in the same pull request means no measure ever exists untested.
Do this
Read docs/measures.md (signed off) and the existing migrations and tests.
On a new branch dashboard/views:
1. Create a NEW migration (npx supabase migration new measure_views) with one view per measure in the json block, named measure_<id>, each created with (security_invoker = true). Each returns site_id, any grouping columns, value, n (how many rows it counted) and as_of (the time of the newest source row). When there are no rows, the view returns no row: no coalesce to 0, no default.
2. pgTAP tests in supabase/tests/measures.test.sql: for the "Worked by hand" example, insert exactly those rows in a transaction and check the view returns exactly that value and count; check a user from another site gets no rows; check every measure_ view has security_invoker on; check each view returns no row when its tables are empty.
3. Do not change any table, policy or existing test.
Push, open a pull request titled "Dashboard: measure views", wait for every check, and fix any failure before you report. Tell me, for each view, the value it returned for the worked example.You will see recreated screen
- value, n and as_of: the number, how many rows it stands on, and how fresh it is.
- Your hand-worked 87.5%, proven; and no row, not 0, when there is nothing to count.
Check it worked
The pull request is green, every view has security_invoker, and Claude Code's values for the worked example match the ones you counted. Owner two approves; merge. After the deploy run, rerun the Security Advisor for acme-platform-prod: no errors.
Fastest path
Asking for the worked-example values in the summary lets you check the formula in ten seconds, without reading the SQL.
If it goes wrong
The Security Advisor shows Security Definer View
A view runs with its owner's rights and ignores the access rules. Say: Write a new migration that recreates view <view name> with security_invoker = true, and add a test that a user from another site gets no rows from it.
A view uses coalesce(..., 0) or returns 0 when nothing happened
Say: No data must return no row, not 0. Remove the default and add a test that the view is empty when its tables are. A zero on a dashboard is read as "nothing went wrong".
The test value differs from yours by a little
Do not accept "close enough". Ask: Show me the rows the view counted for the worked example, one per line, and say which rule decided each. Usually it is a counting rule (a correction, a lot with two first pieces) the owner must settle, and you write the answer into docs/measures.md.
The widget component, the widgets file, and a test per widget
20 minutesWhy
One component drawing every widget means one place to get the five states, the source line and the freshness right, and a new widget becomes a few reviewable lines instead of a new page. A test per widget, in every state, makes a widget that would show a made-up number fail the build instead of reaching the manager.
Do this
Read docs/measures.md and the views from "Dashboard: measure views". This version of Next.js differs from older guides: read the relevant guide in node_modules/next/dist/docs/ before writing any page or component code.
On a new branch dashboard/widgets:
1. One widget component that draws a widget from configuration and reads only from its measure_ view, as the signed-in person. Five states: live (value, count, "Source: view and tables", "as of" time), no data (says what is missing, in words), stale (grey, last value, "as of", "not updating"), not enough data (for control charts, fewer than 20 points), could not load (says so). It never shows 0, a sample or a remembered value in place of data. Colour only when red, always with a word.
2. lib/dashboard/widgets.json: one entry per measure: id (must match docs/measures.md), title, view, visual (tile, line, pareto, control chart, table), refresh seconds, stale after (from docs/measures.md), drill (the page a tap opens), roles. No values: targets and limits come from docs/measures.md.
3. Tests, per widget: the worked example shows the hand-worked number; no rows shows the no-data message; an old as_of (fixed clock) shows stale; another site sees no data; a role not listed does not see the widget. Plus guard tests: every widget id exists in the docs/measures.md json block with formula, source, unit and owner; no widget entry holds a value; the component never renders 0 for a missing value.
4. For each new test, show me it failing with the feature broken on purpose, then passing.
Push, open a pull request titled "Dashboard: widgets", wait for every check and the preview, fix any failure, and report.You will see recreated screen
- Red first, then green: a test that cannot fail proves nothing.
- Open the preview on your phone before approving.
You will see recreated screen
- Live: value, count, a word beside the colour, the source and the time.
- Nothing to show is said in words. Here it is good news, and still not a 0.
- Stale: grey, the last value and its time, so nobody acts on it as if it were now.
- Not enough data: control limits from fewer than 20 points would mislead.
Check it worked
The pull request is green with a test per widget per state, each shown failing first; lib/dashboard/widgets.json holds no values; the preview shows each widget with its source and as-of time. Owner two approves; merge.
If it goes wrong
A test only checks that a word appears in the component's code
It will pass while the widget is broken; we found three such tests in one night's work. Say: Rewrite every widget test to render the widget with data from the view and check what it shows.
A widget test was loosened or skipped to get to green
Say: Never edit, skip or loosen a test to make something pass. Restore the test, show me why it fails, and stop if you think the test is wrong. Check the Files changed tab for edited tests before reading the summary.
The component shows a value while the view is still loading, then changes
That first value is invented. Say: While loading, show a loading state with no number. A value may only appear once the view has answered.
Hunt down every number nobody measured
10 minutesWhy
The widgets are now honest, but the screens from Sessions 12 to 14 were built before this rule existed, and an agent filling an empty place is the commonest way an invented number gets in. A single sweep finds them; a line in CLAUDE.md and the guard tests keep them out of every later session, including the overnight builds in Session 17.
Do this
On a new branch dashboard/no-invented-numbers:
Search every screen, chart, widget and report in the app for values that are hard-coded, generated, guessed or defaulted, including 0 or an empty string used for "unknown", sample or placeholder data, and numbers in components that do not come from a query. List each one with its file and line and where its value comes from. Do not group them: check each one separately.
Replace every one that is not a stored or measured value with an explicit "No data", "Not measured" or "Not updating" state. Targets and limits may stay only if they match docs/measures.md.
Add this line to CLAUDE.md: "No displayed number may come from a typed-in, generated, guessed or defaulted value. No data is a visible state, never a number. Every widget names its source and its as-of time."
Push, open a pull request titled "Dashboard: no invented numbers", wait for every check, and report what you found, item by item.You will see recreated screen
- Item by item. A sample array behind a trend is exactly what we found graded "In control" on 87 screens.
- The rule every later prompt and agent reads first.
Check it worked
The pull request lists every finding separately with its file and line, the CLAUDE.md rule is on main, and every check is green. Merge it.
If it goes wrong
Claude Code says the findings are false positives and changes nothing
Some may be; a group is never all false. Say: For each item separately, show me where its value comes from and what the screen shows with an empty table. We once saw a group of warnings dismissed together; some of them were real and were exposing customer data in production.
It reports nothing found
Test the search: Add a hard-coded 42 to one widget on this branch, run your search again, and show me it is found. Then remove it. A search that cannot find a planted number cannot be trusted to find a real one.
Knowledge check
Why are measure views created with security_invoker = true?
Knowledge check
A view has no rows for the last 7 days. What should the widget show?
References
- PostgreSQL Documentation: CREATE VIEW (security_invoker). https://www.postgresql.org/docs/current/sql-createview.html
- Supabase Docs: Row Level Security. https://supabase.com/docs/guides/database/postgres/row-level-security
- Supabase Docs: Database advisors. https://supabase.com/docs/guides/database/database-advisors
- Supabase Docs: Testing your database (pgTAP). https://supabase.com/docs/guides/database/testing
Chapter 3 · Session 15
The dashboard, on the floor
One dashboard per role, read in five seconds on a phone or from across the room. Grey is normal, colour means act, a control chart tells signal from noise, and every widget says how fresh it is. Then it ships through the pipeline and you check the live one tells the truth.
30 min2 stepsEnds with a gateThe five-second test
By the end of this chapter you can
- Lay out each role's dashboard with the measure tied to the main decision first, on a wall and on a phone.
- Use colour only for trouble, always with a word, and read an individuals control chart.
- Ship the dashboard through the Session 11 pipeline and check every live widget shows a measured value or an honest state.
One role, one screen, five seconds
Each role gets its own dashboard, answering its own questions. Test it the simple way: show it to the person for five seconds, hide it, and ask what they would do next. If they cannot say, the layout is wrong, not the person. Most important top left; widgets for the same decision together; the same scale every day; on a phone, one column in the same order, 44 px targets, as Session 12 set out [1].
Choose each widget's picture from the question it answers. People judge positions along a common scale (bars, dots on a line) far more accurately than angles, areas or shades, which is why sorted bars and plain lines beat pies, round gauges and 3-D effects [6].
Control rooms learned the colour lesson the hard way. ISA-101, the standard for operator displays in process automation, describes screens where normal states are muted and bright colour is kept for abnormal conditions, so the eye goes straight to what needs attention [2]. Never use colour alone: add a word or a shape, so people who cannot tell the colours apart, and screens in bright light, still carry the message [3].
Signal or noise
Every process varies. React to every dip and you change things that were fine, adding variation. An individuals control chart draws limits from the process's own variation: the mean plus and minus 2.66 times the average moving range (the average difference between one point and the next). The 2.66 is 3 ÷ 1.128, which turns the average moving range into three estimated standard deviations [4]. React to a point outside a limit, or to a run of eight on one side of the mean; otherwise, watch.
Lay out each role's dashboard, and test it on a phone
20 minutesWhy
The same six widgets in the wrong order are read wrongly every shift. Putting the main decision first, keeping normal grey and colour for red with a word, and running the five-second test with the real person on a phone is how you know the dashboard changes a decision rather than decorating a wall.
Do this
On a new branch dashboard/layout, using only the widget component and lib/dashboard/widgets.json:
- One dashboard per role in docs/measures.md, on the manager view from Session 13 (its address is in lib/access/routes.ts) and the supervisor's view. Most important first, as docs/measures.md orders them; widgets for the same decision together.
- Normal values in the page's neutral colours. Colour only when a measure is red, always with a word or shape beside it ("Over 4 h").
- On a phone, one column in the same order, 44 px targets, no sideways scrolling. A tap opens the widget's drill page.
- Phone tests at 360 and 390 px for each role's dashboard.
Push, open a pull request titled "Dashboard: layout", wait for every check and the preview, and give me the preview address.Open the preview on your phone, signed in as a test quality lead. Then show it to the real quality lead for five seconds, hide it, and ask what they would do next. Write their answer in the pull request.
You will see recreated screen
- The only colour on the screen, with a word and a shape: the one thing to act on now.
- A signal, not a dip: a point outside limits computed from at least 20 lots.
Check it worked
The pull request is green with phone tests for each role; on your phone the order matches docs/measures.md, only red measures have colour, each with a word; and the quality lead said what they would do after five seconds. Owner two approves; merge.
Fastest path
Do the five-second test on the preview, before merging. Moving a widget is one line in lib/dashboard/widgets.json now, and a whole meeting after go-live.
If it goes wrong
The "last 8 hours" and "this shift" widgets on the preview all say No data
The made-up data in the development project has aged: it was written relative to the day it was seeded, and we measured our newest seeded batch at 10.9 days old eleven days later. The widgets are right to say so. Re-run the development seed (scripts/seed-dev, Session 6) against acme-platform-dev only, yourself, and check the newest row is less than an hour old. Never change a widget's period to make it show something.
Some widgets show today and others a fortnight ago
Some tables were re-seeded and others not, or the seed read the clock more than once. Ask: Check that the seed reads the clock once and shifts every table by the same offset, so the newest record is now and the gaps between records are unchanged. Add a test for it.
A tap on a widget opens a 404
Say: Sign in as each role on the preview, tap every widget and follow its drill link. Report every 404 or error and fix it. A link that compiles is not a link that works.
Ship it, and check the live dashboard tells the truth
10 minutesWhy
The preview runs on made-up data; production runs on the plant's. After the pipeline ships the dashboard, the live widgets must show either a number measured from real records or an honest state. A widget that shows a number on production that you cannot trace to a real record is the defect this whole session exists to prevent.
Do this
https://github.com/acme-ops/acme-platform/actions
The deploy run for the layout merge must be green, with any new migrations applied.
https://acme-platform.vercel.app/manager
The live dashboard on your phone, signed in as yourself. Check each widget against the table below.
https://supabase.com/dashboard/project/abcdefghijklmnopqrst/advisors/security
The Security Advisor for the live project: Rerun linter. No errors.
For any live number you doubt, ask Claude Code to trace it, without touching production:
On the live dashboard, the widget "<title>" shows <value> as of <time>. Using only the view's definition and docs/measures.md, tell me which tables and which kind of rows that number is computed from, and what I should look up in the Supabase Table Editor to check it by hand. Do not connect to or change the live project.You will see recreated screen
- Real and current: as of minutes ago.
- Only Press 3 uses the screen so far (Session 14). The other presses say so, in words.
- Production has fewer lots than the preview. The widget waits for 20 before drawing limits.
Check it worked
The deploy run is green, the Security Advisor shows no errors, and every live widget shows either a value you can trace to real records, with its source and as-of time, or an honest state in words. No number on the live dashboard is a sample, a default or a guess.
If it goes wrong
A live widget shows a number you cannot trace to any real record
Stop and treat it as a defect, not a curiosity. Check that no made-up row reached production: made-up data is marked as made up (Session 6) and must never be in acme-platform-prod. If it is, tell owner two, and follow docs/runbook.md.
Every live widget says Not updating
The newest real row is older than its stale after. Ask the floor whether the screens are being used; if records are stuck in a device's outbox, the widget is right to say so. Do not lengthen stale after to make it look live.
The production deploy shows Canceled
A newer merge replaced it within a minute. A canceled deploy that a newer ready deploy replaced is not a failure. Check the newest production deployment is Ready and came from git.
Knowledge check
On the quality lead's dashboard, what colour is a measure that is inside its limits?
Knowledge check
A widget's newest row is 3 hours old and its stale after is 60 minutes. What does it show?
References
- W3C: Understanding WCAG 2.2, Success Criterion 2.5.5 Target Size (Enhanced). https://www.w3.org/WAI/WCAG22/Understanding/target-size-enhanced.html
- ISA: ISA-101, Human-Machine Interfaces for Process Automation Systems. https://www.isa.org/standards-and-publications/isa-standards/isa-101-standards
- W3C: Understanding WCAG 2.2, Success Criterion 1.4.1 Use of Color. https://www.w3.org/WAI/WCAG22/Understanding/use-of-color.html
- NIST/SEMATECH e-Handbook of Statistical Methods: Individuals control charts. https://www.itl.nist.gov/div898/handbook/pmc/section3/pmc322.htm
- NIST/SEMATECH e-Handbook of Statistical Methods: What are control charts?. https://www.itl.nist.gov/div898/handbook/pmc/section3/pmc31.htm
- Cleveland, W. S. and McGill, R. (1984). Graphical perception. Journal of the American Statistical Association 79 (387). https://doi.org/10.1080/01621459.1984.10478080
Chapter 4 · 12 questions · 80% passes
Final assessment
Twelve questions across the session. Score 80% (10 of 12) to pass. Your LMS records your score and each answer; you can review the chapters and try again.
15 min12 questions≈ 15 minutesRetake allowed
Your result
CivOps AI Academy
Widgets and the Dashboard: Only Measured Numbers, With Where They Come From
Element F14 complete · Learner
Your LMS records this completion. For the CivOps Foundation certificate, finish the Foundation Course at https://civops.io/learn.