Skip to content

A dataset measure cannot render as a percent: the console's scale heuristic reports a rate of exactly 1 as 1.0% #101

Description

@os-warren

Found while adding duly_duty_health.on_time_rate in #52. The rate ships as a bare fraction (format: '0.00'0.94) because every percent spelling is either inert or wrong at the one value that matters most.

Measured, in the browser, against the demo's 0.94

measure format tile renders
(absent) 0.94
'percent' 1
'0.00' 0.94 — what ships

'percent' is the obvious spelling and it is silently wrong. The console treats format as a numeral pattern, not a keyword (@object-ui/core, utils/dataset-format.ts#formatMeasure): decimals come from format.split('.')[1]?.match(/0/g)?.length ?? 0, and percent mode turns on only for a literal %. So 'percent' means "zero decimals, not a percent", and 0.94 rounds to 1.

Why '0.0%' is not the answer either

Percent mode scales by a heuristic, because a measure — unlike a field — has no declared percentScale to hand:

export function percentDisplayValue(value: number): number {
  return value > -1 && value < 1 ? value * 100 : value;
}

A ratio of exactly 1 is outside that window, so a 100%-on-time period renders as 1.0%. The function's own docblock records the same defect for fields (objectui#3136), which was fixed there by letting the server declare the scale — DatasetMeasureSchema has no such key, so the fix did not reach measures.

An on-time rate of 1.0 is not an edge case: it is the number a small tenant sees most often, and the one a customer is proudest of. Reporting it as 1% is the worst available failure.

What would close it

A dataset measure needs to say that its value is a fraction — the same thing percentScale: 'fraction' says for a field. Then format: '0%' on a derived ratio would be safe and this app would show 94% / 100% instead of 0.94 / 1.00.

Two halves, and they live upstream:

  1. @objectstack/specDatasetMeasureSchema gains the annotation (it is z.strictObject, so an app cannot pass one through today).
  2. objectuiformatMeasure already prefers a declared scale over the heuristic; it just needs the measure's.

Filed here rather than upstream because I could not verify which upstream repo owns the pair from this checkout. Worth re-filing as objectstack-ai/objectstack + objectstack-ai/objectui when someone can.

Not blocking

duly_duty_health reads 0.94 today under a tile titled "On-time rate", with the denominator stated in its description. Unambiguous, and never a wrong number — just not the 94% it should be.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions