Skip to content
Astera Technology

Capture a stable device value with its unit

Admit the stable message before normalising its magnitude.

Download complete case notes and answer keys ↓

Set the decision and its input

The literal grammar uses U or S, two decimal places and kg or g. Base messages are unstable1.20kg then stable1.25kg. The stated rule selects the first stable message:1,250,000mg with source unit kg. Taking the first readable number captures an ineligible unstable reading.

Filled local test worksheet
CaseInput JSON
Base test{"messages":["U|1.20|kg","S|1.25|kg"]}
Download editable CSV ↓

Run the supplied comparison

The programme parses the supplied strings and scales integer hundredths. It does not connect to a real scale, establish calibration or invent a device stability tolerance.

Faulty and required outputs
PathOutput JSON
Faulty path{"stableCaptured":false,"milligrams":1200000,"sourceUnit":"kg"}
Required path{"stableCaptured":true,"milligrams":1250000,"sourceUnit":"kg"}
Download editable CSV ↓
Complete local Node24.14.1 programme
import assert from 'node:assert/strict';

const run=function run(i,corrected=true){
    const messages=i.messages.map(s=>{const match=/^([US])\|(\d+)\.(\d{2})\|(kg|g)$/.exec(s);if(!match)throw new Error('Outside the literal device grammar');return {stable:match[1]==='S',hundredths:Number(match[2])*100+Number(match[3]),unit:match[4]};});
    const captured=corrected?messages.find(m=>m.stable):messages[0];if(!captured)return {held:true,reason:'no-stable-reading'};
    return {stableCaptured:captured.stable,milligrams:captured.hundredths*(captured.unit==='kg'?10000:10),sourceUnit:captured.unit};
  };
const cases=[{"input":{"messages":["U|1.20|kg","S|1.25|kg"]},"corrected":false,"expected":{"stableCaptured":false,"milligrams":1200000,"sourceUnit":"kg"}},{"input":{"messages":["U|1.20|kg","S|1.25|kg"]},"corrected":true,"expected":{"stableCaptured":true,"milligrams":1250000,"sourceUnit":"kg"}},{"input":{"messages":["S|1250.00|g"]},"corrected":true,"expected":{"stableCaptured":true,"milligrams":1250000,"sourceUnit":"g"}},{"input":{"messages":["U|1.20|kg"]},"corrected":true,"expected":{"held":true,"reason":"no-stable-reading"}}];
for(const test of cases){const actual=await run(test.input,test.corrected);assert.deepEqual(actual,test.expected);console.log(actual);}
Download runnable example ↓

Choose from the boundary evidence

Stable1250.00g yields the same milligrams while retaining g. An all-U sequence is held as no-stable-reading.

  1. Parse the stated grammar
  2. Select a stable message
  3. Retain unit and scaled value

Hold absent stability evidence rather than use the last unstable number.

Editable boundary inputs and outputs
ConditionInput JSONExpected output JSON
stable gram representation{"messages":["S|1250.00|g"]}{"stableCaptured":true,"milligrams":1250000,"sourceUnit":"g"}
no stable message{"messages":["U|1.20|kg"]}{"held":true,"reason":"no-stable-reading"}
Download editable CSV ↓

Which base reading is eligible?

Show the worked answer

Stable1.25kg. The earlier1.20kg remains ineligible under the supplied stable-flag rule.

Related resources