# PatternRule

Industry: Workforce

A count of rests by class inside a window: "at least 4 weekly rests in any 4 weeks, at least 2 of them regular".

```ts
import type { PatternRule } from "@northguild/gmt";
```

## Members

| Member | Type | Description |
| --- | --- | --- |
| `label` | `string` | The caller's name for the rule. The report is keyed by it; labels must be unique. |
| `severity?` | `"violation"` \| `"advisory"` ([`DutySeverity`](/gmt/reference/types/DutySeverity/)) | Whether a failure is a violation or an advisory. |
| `kind` | `"pattern"` | Selects this rule kind. |
| `period` | [`Period`](/gmt/reference/types/Period/) | The unit the window is counted in. |
| `lookback` | `number` | How many periods the window covers, an integer from 1 to 10,000. Times a count `period`, it is 10,000 at most. |
| `classes` | `object[]` | The classes of rest, each named for `require`. |
| `classes[].label` | `string` | The class's name, unique within the rule. |
| `classes[].statuses` | `S[]` | The statuses a run of this class is made of. |
| `classes[].minimum` | `string` | The shortest run of this class, a positive ISO 8601 duration of exact time. |
| `require` | `object[]` | The count each class needs. |
| `require[].label` | `string` | The class, one of the labels in `classes`. |
| `require[].atLeast` | `number` | The fewest runs of that class the window must hold, a non-negative integer. |

## Definition

```ts
type PatternRule<S extends string = string> = {
  /** The caller's name for the rule. The report is keyed by it; labels must be unique. */
  label: string;
  /**
   * Whether a failure is a violation or an advisory.
   *
   * @defaultValue `"violation"`.
   */
  severity?: DutySeverity;
  /** Selects this rule kind. */
  kind: "pattern";
  /** The unit the window is counted in. */
  period: Period;
  /**
   * How many periods the window covers, an integer from 1 to 10,000. Times a count `period`, it is
   * 10,000 at most.
   */
  lookback: number;
  /** The classes of rest, each named for `require`. */
  classes: {
    /** The class's name, unique within the rule. */
    label: string;
    /** The statuses a run of this class is made of. */
    statuses: S[];
    /** The shortest run of this class, a positive ISO 8601 duration of exact time. */
    minimum: string;
  }[];
  /** The count each class needs. */
  require: {
    /** The class, one of the labels in `classes`. */
    label: string;
    /** The fewest runs of that class the window must hold, a non-negative integer. */
    atLeast: number;
  }[];
};
```

## Used by

- [`dutyViolations`](/gmt/reference/workforce/calculate/dutyViolations/)
- [`evaluateDutyLog`](/gmt/reference/workforce/calculate/evaluateDutyLog/)

## Source

[types/duty.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/types/duty.ts)
