# Scales and measuring

> scale().from().through().to(), given().measure(), and ranking with a scale.

A scale is a degree, not a probability. It describes ordered situations and the model returns a position along them. It is kept distinct from predicates on purpose: “how much does this disrupt work” is a different question from “is this disruptive”.

## Defining one

```ts
import { scale } from "jevlish";
import type { Ticket } from "./support.js";


// A degree, not a probability. Levels are ordered situations; the model
// returns a position along them. Two to ten levels.
export const disruption = scale<Ticket>("how much the reported problem disrupts the customer's work")
  .from("Work continues normally; the problem affects appearance only")
  .through("The task remains possible through a workaround")
  .to("The task cannot be completed")
  .named("disruption");


disruption.levels.length; // 3
disruption.top; // 2: scores run from 0 to top
```

`.from(lowest)` starts the levels, `.through(level)` adds intermediate ones (repeatable), and `.to(highest)` finishes. A scale needs at least two levels and supports at most ten. Each level is a description of a situation, not a number; the numbers are positions, 0 through `scale.top`.

A scale compiles to a Jev Score question with the levels as its criteria.

## Measuring one subject

`given(x).measure(scale)` resolves to a `Judgment<Measurement>`.

```ts
import { given } from "jevlish";
import { ticket } from "./support.js";
import { disruption } from "./vocabulary.js";


const measurement = await given(ticket)
  .seenAs((t) => ({ subject: t.subject, body: t.body }))
  .measure(disruption);


if (measurement.status === "decided") {
  const { score, normalized, level, levelDescription, confidence } = measurement.value;
  score; // expected position, 0 .. disruption.top
  normalized; // score / top
  level; // the most likely level's index
  levelDescription; // that level's text
  confidence; // what the policy compared against policy.score.minConfidence
}
```

A decided measurement carries:

* `score`: the expected position on the scale, a real number from 0 to `top`.
* `normalized`: `score / top`, from 0 to 1.
* `level` and `levelDescription`: the most likely level and its text.
* `confidence` and `probabilities`: what the policy compared against `policy.score.minConfidence`, and the distribution behind it.

The judgment is `uncertain` when confidence misses the threshold.

## Ranking with a scale

`from(items).rankedBy(scale, order)` measures each accepted item and sorts by `score`. See [Filtering and ranking](/Jevlish/guides/from/#ranking).

## Inside `ask`

A scale can be one of the questions in `given(x).ask({ ... })`, alongside conditions and Choices; it produces a `Judgment<Measurement>` under its key. See [Asking several questions](/Jevlish/guides/ask/).