Skip to main content

collectInputForOrganicMatterBalance

@svenvw/fdm-source


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

Function: collectInputForOrganicMatterBalance()

collectInputForOrganicMatterBalance(fdm, principal_id, b_id_farm, timeframe, b_id?): Promise<OrganicMatterBalanceInput>

Defined in: fdm-calculator/src/balance/organic-matter/input.ts:40

Alpha

Collects all necessary input data from an FDM instance to calculate the organic matter balance for a farm or a specific field.

This function acts as a data-gathering layer, interacting with the FDM core to fetch all records required for the organic matter balance calculation. It retrieves data for a given farm and timeframe, including field details, cultivation history, soil analyses, and fertilizer applications. It also fetches the complete fertilizer and cultivation catalogues for the farm to provide necessary details for the calculations (e.g., EOM values).

The collected data is then structured into an OrganicMatterBalanceInput object, which can be directly passed to the main calculateOrganicMatterBalance function.

Parameters

fdm

FdmType

The FDM instance, used for all database interactions.

principal_id

PrincipalId

The ID of the user or service principal requesting the data, for authorization purposes.

b_id_farm

farmsTypeSelect

The unique identifier for the farm.

timeframe

Timeframe

The time period (start and end dates) for which to collect the data.

b_id?

any

Optional. If provided, the data collection will be limited to this specific field ID. Otherwise, data for all fields in the farm will be collected.

Returns

Promise<OrganicMatterBalanceInput>

A promise that resolves with a single OrganicMatterBalanceInput object containing all the structured data for the calculation.

Throws

Throws an error if any of the database queries fail or if a specified field is not found.