Purpose: Build a calculator that, when given a fertilizer name and applied weight…
- User
Purpose: Build a calculator that, when given a fertilizer name and applied weight (kg/ha), returns the kilograms per hectare of elemental Nitrogen (N), Phosphorus (P) and Sulfur (S) contributed by that fertilizer based on the conversion factors below. The app should accept common fertilizer names (see mapping) and handle case-insensitive matches and common synonyms. biblio.iita
Conversion-data (use these exact numeric fractions/percentages):
DAP: Ammonium (N): 0.18 (fraction of product that is ammonium-N). Phosphorus (P): 0.46 × 0.43 (product P factor; compute as 0.46*0.43). ifdc
Urea: total N = 0.46 (fraction). digitalcommons.usu
NPK (example blend given): total N = 19% (0.19) composed as Urea 10.5% (0.105), Ammoniacal 4.5% (0.045), Nitrate 4.0% (0.04). Use these subcomponents only if breakdown by form is needed. biblio.iita
20.20.0.13: Ammonium (N): 0.20, Phosphate (P): 0.20, Sulphate (S): 0.13. [user data]
10.26.26: Ammonium (N): 0.10, Phosphate (P): 0.26. [user data]
Zinc Sulphate (21%): Sulphate (S): 0.21. [user data]
Ammonium sulphate: Ammonium (N): 0.21, Sulphate (S): 0.24. [user data]
Magnesium sulphate: Sulphate (S): 0.12. [user data]
Functional requirements:
Input: fertilizer name (text), weight applied (numeric, kg/ha). Accept synonyms, e.g., "diammonium phosphate", "DAP", "map" (if present), "urea", "ammonium sulfate", "znso4", "20-20-0-13", etc. biblio.iita
Output (display): kg N / ha, kg P / ha, kg S / ha, and if available show breakdown by chemical forms (urea‑N, ammoniacal‑N, nitrate‑N) and percentage of product used. biblio.iita
Unit handling: input weight assumed kg/ha; if user provides kg (total) include an option to convert to kg/ha by entering area (ha). Provide quick conversion helper: lb/acre ↔ kg/ha. pubs.ext.vt
Calculation rules: multiply input weight (kg/ha) by the appropriate fraction for each nutrient to get kg nutrient/ha. Example: for urea, kg N/ha = applied_kg_per_ha * 0.46. For DAP P, first compute 0.46*0.43 then multiply by applied weight to get kg P/ha. pubs.ext.vt
Robustness: return 0.0 for nutrients not present in mapping; warn if fertilizer name is unmapped and offer to accept user-provided fractions for N, P, S. Provide a small editable database UI for adding new fertilizers and their fractions. biblio.iita
UI suggestions:
Simple form: fertilizer name (autocomplete from mapping), applied weight (kg/ha), optional area (ha) if user enters total kg. Show results in numeric and percent-of-product terms (e.g., "kg N/ha (this equals applied_kg * fraction)"). Include a "show calculation" toggle to display the multiplication. pubs.ext.vt
Example calculations (for test cases):
Urea, 100 kg/ha → N = 100 * 0.46 = 46 kg N/ha. digitalcommons.usu
DAP, 100 kg/ha → Ammonium-N = 100 * 0.18 = 18 kg N/ha; P fraction = 0.46*0.43 = 0.1978 so P = 19.78 kg P/ha. [user data] ifdc
Assistant
Now the calculation logic, unit conversion helpers, CSV export, and built-in unit tests:
Now update the page title and build:
Build succeeded ✅. The Fertilizer Nutrient Calculator is complete. Here's what was built:
Files
- — The nutrient-fraction database with all 8 mappings (DAP with P = 0.46 × 0.43 = 0.1978, Urea 0.46 N, NPK 19 with urea/ammoniacal/nitrate sub-fractions, 20-20-0-13, 10-26-26, zinc/ammonium/magnesium sulphates), extensive synonyms ("diammonium phosphate", "znso4", "(NH4)2SO4", "epsom", "46-0-0", etc.), plus case-insensitive normalization, substring matching, and Levenshtein-based fuzzy matching (typos like "ureaa" or "amonium sulfate" still resolve).
- User
in NPK , Phosporus content is also present which is 19%
Assistant
I'll update the NPK 19 entry to include the 19% Phosphorus fraction, and update the unit tests accordingly.
Now update the unit tests to verify the NPK 19 phosphorus value:
Done ✅. NPK 19 now includes Phosphorus at 19% (fraction 0.19):
- Database updated: NPK 19 is now
{N: 0.19, P: 0.19, S: 0}— its note reads "Total N 19% (urea-N 10.5% + ammoniacal-N 4.5% + nitrate-N 4.0%) · P 19%". Also added "19-19-19" and "19.19.19" as synonyms since it's an N-P balanced blend. - New unit test added:
NPK 19, 100 kg/ha → P = 19.00 kg/ha— the test badge now shows ✓ 21/21.
Example: entering "NPK 19" at 100 kg/ha now returns N: 19.00 kg/ha, P: 19.00 kg/ha, S: 0.00 kg/ha, with the nitrogen breakdown (urea-N 10.50, ammoniacal-N 4.50, nitrate-N 4.00) still shown.
Files built:
src/data/fertilizers.ts,src/utils/calc.ts- Database updated: NPK 19 is now
- User
phosphorus in NPK is from phoshate
Assistant
I'll mark the P in NPK 19 (and other P-containing fertilizers) as coming from the phosphate form, and show that in the chemical-form breakdown just like the nitrogen forms.
Now add the phosphate form to NPK 19 and the other phosphate-based fertilizers:
Now update the calculation engine to include Phosphate-P in the form breakdown:
Update the results panel header since the breakdown now includes phosphorus forms too, and add a unit test:
Done ✅. Phosphorus is now explicitly attributed to the phosphate form:
- NPK 19: P 19% is now recorded as phosphate-P (
pBreakdown: { phosphate: 0.19 }), with its note updated to "P 19% from phosphate". For 100 kg/ha, the chemical-form breakdown now shows: Urea-N 10.50, Ammoniacal-N 4.50, Nitrate-N 4.00, Phosphate-P 19.00 kg/ha. - Consistency: DAP (0.1978), 20-20-0-13 (0.20), and 10-26-26 (0.26) also mark their P as phosphate-P, matching the original spec's "Phosphate (P)" labeling.
- UI: the results panel section is now titled "Breakdown by chemical form" (covering both N and P forms), and each form still shows its % of product and the multiplication when "Show calculation" is on.
- NPK 19: P 19% is now recorded as phosphate-P (