getDyna
@nmi-agro/fdm-source / fdm-calculator/src / getDyna
Variable: getDyna
constgetDyna:any
Defined in: fdm-calculator/src/mineralization/dyna.ts:179
DB-backed cached version of requestDyna.
Uses withCalculationCache from @nmi-agro/fdm-core to persist results in
the FDM database. The cache key is derived from a hash of the input (excluding
nmiApiKey which is redacted). The cache is automatically invalidated when
the request body changes (e.g. when soil data, cultivations, or fertilizer
applications are updated) or when the package version changes.
Because the DYNA model simulates the full rotation, a single cached result
covers all years in the rotation. The caller should filter the returned
calculationDyna array to the target calendar year before displaying.
Signature: (fdm: FdmType, input: DynaComputeInput) => Promise<DynaResult>
Cache parameters:
- Function name:
"requestDyna" - Version:
pkg.calculatorVersion(invalidates on package upgrades) - Sensitive keys:
["nmiApiKey"](redacted from cache key hash)
Example
import { getDyna } from "@nmi-agro/fdm-calculator"
const result = await getDyna(fdm, {
b_id: "field_abc",
nmiApiKey: env.NMI_API_KEY,
requestBody: buildDynaRequest(
field, soilData, cultivations, fertilizers,
"arable", timeframe, cropProperties
),
})
// Filter to current year before rendering:
const yearData = result.calculationDyna.filter(
d => new Date(d.b_date_calculation).getFullYear() === 2026
)