# OccurrenceCapRule

Industry: Workforce

A cap on how many local periods hold a status: "night duty no more often than every third night", "duty started on at most 6 of any 7 days".

```ts
import type { OccurrenceCapRule } 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` | `"occurrenceCap"` | Selects this rule kind. |
| `statuses` | `S[]` | The statuses that occur. |
| `per` | [`LocalPeriod`](/gmt/reference/types/LocalPeriod/) | The local period occurrences are counted by. |
| `lookback` | `number` | How many periods the window covers, an integer from 1 to 10,000. Times the count in `per`, it is 10,000 at most. |
| `maximum` | `number` | The most periods allowed to hold an occurrence, a non-negative integer. |
| `byInitiationDate?` | `boolean` | Whether a run counts only in the period it starts in, so that two tours starting on one date count once and a night shift counts on the date it began. |

## Definition

```ts
type OccurrenceCapRule<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: "occurrenceCap";
  /** The statuses that occur. */
  statuses: S[];
  /** The local period occurrences are counted by. */
  per: LocalPeriod;
  /**
   * How many periods the window covers, an integer from 1 to 10,000. Times the count in `per`, it
   * is 10,000 at most.
   */
  lookback: number;
  /** The most periods allowed to hold an occurrence, a non-negative integer. */
  maximum: number;
  /**
   * Whether a run counts only in the period it starts in, so that two tours starting on one date
   * count once and a night shift counts on the date it began.
   *
   * @defaultValue `false`. A run counts in every period it touches.
   */
  byInitiationDate?: boolean;
};
```

## 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)
