Functional Weave
Code in Rust

agri.stocking-rate@1.0.1

README.md

3,102 bytes · view raw

# agri.stocking-rate

Livestock units (LU) and the stocking rate in LU per hectare, from head counts
by category and a published table of livestock unit coefficients.
`stockingRate("eurostat", [{category: "dairy-cows", count: 100},
{category: "bovine-1-to-2-years", count: 80}], 120)` is 156 LU, 1.3 LU/ha.

## Two tables, deliberately separate

A livestock unit is a convention, not a measurement, and the published tables
disagree (a goat is 0.1 LU to Eurostat and 0.12 LU to Countryside
Stewardship), so the caller names the scheme and each category belongs to one:

- `eurostat`: the EU livestock unit (LSU) coefficients used in farm
  statistics, from the reference of a dairy cow = 1 LSU. 21 categories:
  bovine animals by age and type, sheep, goats, equidae, pigs, poultry, breeding
  rabbits.
- `uk-countryside-stewardship`: the grazing livestock unit table Defra and the
  RPA use to set and check stocking in England's Countryside Stewardship
  agreements: cattle over 2 years 1.0, 6 months to 2 years 0.6, lowland ewe
  and lamb or ram 0.12, hill ewe and lamb, store lamb or hogg/teg 0.08, horse
  1.0, pony or donkey 0.8, goat 0.12. Cattle under 6 months are not in the
  table, so there is no category for them.

Category codes are listed in `data/livestock-units.json`, with each row's
full name and source. The data has no `effective` dates: these are reference
conventions rather than rules with commencement dates, and a revised table
will be published as a new version of this capability.

## Exactness

Coefficients are held in thousandths of an LU, so each line and the total are
exact (0.027 LU piglets included) and only the rate per hectare is rounded,
once, half up to 0.01 LU/ha. The area is taken to 0.0001 ha (1 m²). Adding
float coefficients drifts: 3 x 0.7 is 2.0999999999999996, which puts three
yearlings on 12 ha at 0.17 LU/ha rather than 0.18.

It does not judge whether a rate is too high: limits differ by scheme option,
land type and season.

## Limits

Counts are whole numbers from 0 to 10,000,000; area more than 0 and at most
1,000,000 ha, and at least 0.0001 ha after rounding. An empty list is 0 LU.

## Sources

- Eurostat, "Glossary: Livestock unit (LSU)",
  https://ec.europa.eu/eurostat/statistics-explained/index.php?title=Glossary:Livestock_unit_(LSU)
  (coefficients checked against the page, September 2026).
- Defra and Rural Payments Agency, "Countryside Stewardship Higher Tier
  manual for agreements starting on 1 January 2023", Annex 8C "Convert
  livestock numbers into Livestock Units",
  https://www.gov.uk/government/publications/countryside-stewardship-higher-tier-manual-for-agreements-starting-on-1-january-2023/annex-8c-convert-livestock-numbers-into-livestock-units
  (the same table is Annex 6C of the Mid Tier manual).

## Notices

Contains public sector information licensed under the Open Government
Licence v3.0 (https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/).

Source: Eurostat; Defra and the Rural Payments Agency.

1.0.1 adds its attribution notices (NOTICE). The code and the tests are unchanged.