aggregateNormsToFarmLevel
@svenvw/fdm-source / fdm-calculator/src / aggregateNormsToFarmLevel
Function: aggregateNormsToFarmLevel()
aggregateNormsToFarmLevel(
input):AggregatedNormsToFarmLevel
Defined in: fdm-calculator/src/norms/farm.ts:87
Aggregates the norm values from individual fields to the farm level. This function takes the output per field of the norm calculation, multiplies each norm by the field's area, and sums these values across all fields to provide total norms for the farm.
The result are three numbers (manure, nitrogen, phosphate) expressed as totals, not per hectare.
Parameters
input
InputAggregateNormsToFarmLevel
An array of field data, each containing field ID, area, and calculated norms.
Returns
An object containing the total aggregated norms for manure, nitrogen, and phosphate for the farm.
Example
const fieldData = [
{
b_id: "field1",
b_area: 10, // hectares
norms: {
manure: { normValue: 100, normSource: "Source A" }, // kg N/ha
nitrogen: { normValue: 150, normSource: "Source B" }, // kg N/ha
phosphate: { normValue: 50, normSource: "Source C" }, // kg P2O5/ha
},
},
{
b_id: "field2",
b_area: 5, // hectares
norms: {
manure: { normValue: 90, normSource: "Source A" }, // kg N/ha
nitrogen: { normValue: 140, normSource: "Source B" }, // kg N/ha
phosphate: { normValue: 45, normSource: "Source C" }, // kg P2O5/ha
},
},
];
const aggregatedNorms = aggregateNormsToFarmLevel(fieldData);
// aggregatedNorms will be:
// {
// manure: (100 * 10) + (90 * 5) = 1000 + 450 = 1450,
// nitrogen: (150 * 10) + (140 * 5) = 1500 + 700 = 2200,
// phosphate: (50 * 10) + (45 * 5) = 500 + 225 = 725,
// }