Skip to main content

calculateDose

@svenvw/fdm-source


@svenvw/fdm-source / fdm-calculator/src / calculateDose

Function: calculateDose()

calculateDose(__namedParameters): object

Defined in: fdm-calculator/src/doses/calculate-dose.ts:37

Calculates the cumulative nutrient doses from a series of fertilizer applications.

This function processes an array of fertilizer applications, matching each with its corresponding fertilizer definition to calculate the dose of each nutrient. The nutrient rates are converted from grams or milligrams per kilogram to kilograms per kilogram and then multiplied by the application amount to determine the dose in kg/ha.

Parameters

__namedParameters

applications

FertilizerApplication[]

fertilizers

Fertilizer[]

Returns

object

An object containing:

  • dose: An object with the total cumulative doses for all nutrients in kg/ha.
  • applications: An array of objects, each detailing the individual nutrient doses for each fertilizer application.

applications

applications: Dose[]

dose

dose: Dose

Throws

If any application amount or nutrient rate is negative, ensuring data integrity.

Example

import { calculateDose } from "./calculate-dose";

const applications = [
{ p_app_id: "app1", p_id: "fert1", p_app_amount: 100 },
{ p_app_id: "app2", p_id: "fert2", p_app_amount: 50 },
];

const fertilizers = [
{ p_id: "fert1", p_n_rt: 100, p_p_rt: 50, p_k_rt: 30, p_n_wc: 0.5, p_s_rt: 20, p_mg_rt: 10 },
{ p_id: "fert2", p_n_rt: 200, p_p_rt: 0, p_k_rt: 60, p_n_wc: 1.0, p_cu_rt: 5, p_zn_rt: 3 },
];

const result = calculateDose({ applications, fertilizers });
console.log(result.dose);
// Expected output: { p_dose_n: 20, p_dose_nw: 15, p_dose_p: 5, p_dose_k: 6, p_dose_s: 2, p_dose_mg: 1, ... }
console.log(result.applications);
// Expected output: [ { p_app_id: "app1", p_dose_n: 10, ... }, { p_app_id: "app2", p_dose_n: 10, ... } ]