Functional Weave
Code in Python

hr.absence-bradford-factor

Bradford factor for a set of absence spells: spells squared times total days, which weights frequent short absences.

1.0.0 · published 2026-10-03 by charlie · Anterra

Pinned by 10 tests, run in TypeScript, Python and Rust.

What it does

The Bradford factor is B = S² × D, where S is the number of separate spells of absence and D is the total days absent, both over one rolling period (commonly 52 weeks). Squaring the spell count is the point: ten one-day absences (10² × 10 = 1000) score a hundred times one ten-day absence (1² × 10 = 10), because frequent short absences disrupt work more.

The caller decides what a spell is (consecutive days off for the same reason are one spell) and which period to look at, and passes the days lost in each spell. An empty list is a score of 0. A spell of zero or fewer days is an error rather than something silently counted as a spell.

For example

  • bradford_factor() → spells 0, days 0, score 0 no absence scores zero
  • bradford_factor(10) → spells 1, days 10, score 10 one ten-day spell scores 10
  • bradford_factor(2, 2, 2, 2, 2) → spells 5, days 10, score 250 five two-day spells score 250

The function

The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.

def bradford_factor(spell_days: Sequence[int]) -> BradfordFactor
spell_daysint[]days lost in each separate spell of absence within the rolling period, one entry per spell
returnsBradfordFactor

The type it declares, generated into your project

@dataclass(frozen=True)
class BradfordFactor:
    """The score and the two numbers it comes from."""

    #: S, the number of spells
    spells: int
    #: D, the total days absent
    days: int
    #: S x S x D
    score: int

Your code names it in one line, in the file that uses it

from fune.hr.absence_bradford_factor import bradford_factor  # hr.absence-bradford-factor@^1
impl/python.py · 14 lines · open · raw
from typing import Sequence

from .hr_absence_bradford_factor_types import BradfordFactor


def bradford_factor(spell_days: Sequence[int]) -> BradfordFactor:
    """B = S x S x D over the spells given."""
    days = 0
    for d in spell_days:
        if isinstance(d, bool) or not isinstance(d, int) or d < 1:
            raise ValueError("each spell must be at least one whole day, received %s" % (d,))
        days += d
    spells = len(spell_days)
    return BradfordFactor(spells=spells, days=days, score=spells * spells * days)

Install

fune build

With that line in your source, in a Python project (language python in fune.project), fune build resolves it and nothing else, pins them in fune.lock, downloads only the Python package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:

fune add hr.absence-bradford-factor
Download for Python hr.absence-bradford-factor-1.0.0-python.fune · 4,669 bytes sha256 03361022355437797f0b769dfe21d39c08386ccb8201ccd402804befacfe7313

The manifest, vectors and README with only the Python implementation. Install it without the registry with fune add ./hr.absence-bradford-factor-1.0.0-python.fune, or fetch it from a terminal with fune pull hr.absence-bradford-factor@1.0.0:python.

The whole function, every language, is one file too: hr.absence-bradford-factor-1.0.0.fune, 6,247 bytes, sha256 2a1f3a106d2a361a144113adb6e481be6a0e58e4c254009219961a1e8d166876. It installs into a project of any language.

Customise it in your app

The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.

before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.

# fune: before hr.absence-bradford-factor

after — your function gets the result and the arguments, and returns the final result.

# fune: after hr.absence-bradford-factor

replace — it requires no other capability, so there is no dependency to replace.

step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show hr.absence-bradford-factor --steps.

# fune: step hr.absence-bradford-factor after <n|label>

Tests

A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.

CaseArgumentsExpected
no absence scores zero → spells 0, days 0, score 0
one ten-day spell scores 10 10 → spells 1, days 10, score 10
five two-day spells score 250 2, 2, 2, 2, 2 → spells 5, days 10, score 250
ten one-day spells score 1000: same days, a hundred times the score 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 → spells 10, days 10, score 1,000
mixed spells 3, 2, 1 → spells 3, days 6, score 54
a single day off 1 → spells 1, days 1, score 1
a long-term absence plus a short one 60, 1 → spells 2, days 61, score 244
a zero-day spell is an error 2, 0 → error: at least one whole day
a negative spell is an error -1 → error: at least one whole day
a half-day spell is an error 1.5 → error: at least one whole day

More from the author

It is a management heuristic, not a legal test. Absences related to disability, pregnancy or other protected characteristics should not be scored against someone (Equality Act 2010); this function cannot know which those are, so filter them out before calling it.

Files

PathBytes
README.md943
impl/python.py533
impl/rust.rs991
impl/typescript.ts497
vectors.json1,168