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 zerobradford_factor(10)→ spells 1, days 10, score 10 one ten-day spell scores 10bradford_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.
pub fn bradford_factor(spell_days: &[i64]) -> BradfordFactor
| spell_days | int[] | days lost in each separate spell of absence within the rolling period, one entry per spell |
| returns | BradfordFactor |
The type it declares, generated into your project
/// The score and the two numbers it comes from.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BradfordFactor {
/// S, the number of spells
pub spells: i64,
/// D, the total days absent
pub days: i64,
/// S x S x D
pub score: i64,
}
Your code names it in one line, in the file that uses it
fune!(hr.absence-bradford-factor@^1); // then call bradford_factor(…)
Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
use super::funejson::Value; ← the fune runtime: the JSON value the test vectors use; fune build keeps it only where a signature takes one
/// B = S x S x D over the spells given.
///
/// # Panics
/// Panics if a spell is shorter than one day.
pub fn bradford_factor(spell_days: &[i64]) -> BradfordFactor {
let mut days = 0;
for &d in spell_days {
if d < 1 {
panic!("each spell must be at least one whole day, received {}", d);
}
days += d;
}
let spells = spell_days.len() as i64;
BradfordFactor { spells, days, score: spells * spells * days }
}
pub fn fune_vector(args: &[Value]) -> Value {
let spells: Vec<i64> = args[0]
.as_arr()
.iter()
.map(|v| match v {
Value::Float(f) => panic!("each spell must be at least one whole day, received {}", f),
other => other.as_i64(),
})
.collect();
let b = bradford_factor(&spells);
Value::obj(vec![
("spells", Value::Int(b.spells)),
("days", Value::Int(b.days)),
("score", Value::Int(b.score)),
])
}Install
fune build
With that line in your source, in a Rust project (language rust in fune.project), fune build resolves it and nothing else, pins them in fune.lock, downloads only the Rust 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. A crate’s build.rs runs it before every compile. Or pin a range in fune.project and build in one step:
fune add hr.absence-bradford-factor
The manifest, vectors and README with only the Rust implementation. Install it without the registry with fune add ./hr.absence-bradford-factor-1.0.0-rust.fune, or fetch it from a terminal with fune pull hr.absence-bradford-factor@1.0.0:rust.
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.
| Case | Arguments | Expected | |
|---|---|---|---|
| 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
| Path | Bytes |
|---|---|
| README.md | 943 |
| impl/python.py | 533 |
| impl/rust.rs | 991 |
| impl/typescript.ts | 497 |
| vectors.json | 1,168 |