Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix[AGRI-NMP-721]: Fertigation Calculation Fixes #722

Merged
merged 8 commits into from
Jan 30, 2025
2 changes: 1 addition & 1 deletion app/Agri.Data/SeedData/FertigationData.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
"Id": 6,
"FertilizerId": 6,
"SolubilityUnitId": 3,
"Value": 15.86,
"Value": 19.02,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to the solubility of Ammonium nitrate to 19.02 as per Ahmed's correction in the fert ppt

"StaticDataVersionId": 14
},
{
Expand Down
54 changes: 39 additions & 15 deletions app/Server/src/SERVERAPI/Controllers/NutrientsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -797,15 +797,36 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm)
fgvm.manualEntry);

Field field = _ud.GetFieldDetails(fgvm.fieldName);
// Get the selected unit's conversion factor
FertilizerUnit _fU = _sd.GetFertilizerUnit(Convert.ToInt32(fgvm.selProductRateUnitOption));
// Convert the rate to imp gal
decimal convertedProductRate = Convert.ToDecimal(fgvm.productRate) * _fU.ConversionToImperialGallonsPerAcre;

//Total Product Volume per fertigation
fgvm.totProductVolPerFert = Math.Round((field.Area * convertedProductRate), 1); // convert to int/string? Error messages?
// Method to get conversion factor based on user's selected unit for product rate
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change total product units and conversion factor based on users application rate units

decimal conversionFactor = 1m;
switch(fgvm.selProductRateUnitOption) {
case "5": // imp gal to US gallon/ac
conversionFactor = 1.2m;
break;
case "3": // imp gal to L/ac
conversionFactor = 4.546m;
break;
case "4": // Imp. gallon/ac
break;
case "6": // imp gal to L/ha
conversionFactor = 2.471m;
break;
}

// Convert the rate based on the selected unit
decimal selectedProductRate = convertedProductRate * conversionFactor;

//Total Product Volume per fertigation
fgvm.totProductVolPerFert = Math.Round(field.Area * selectedProductRate, 1); // convert to int/string? Error messages?

// Total product volume per growing season calc
// Product Rate x Fertigation area x fert per season
fgvm.totProductVolPerSeason = Math.Round((field.Area * convertedProductRate * fgvm.eventsPerSeason), 1); // convert to int/string? Error messages?
fgvm.totProductVolPerSeason = Math.Round(field.Area * selectedProductRate, 1) * fgvm.eventsPerSeason; // convert to int/string? Error messages?

decimal injectionRateConversion = 0;
switch (fgvm.selInjectionRateUnitOption)
Expand Down Expand Up @@ -833,14 +854,14 @@ public IActionResult FertigationDetails(FertigationDetailsViewModel fgvm)
fgvm.fertigationTime = Math.Round(fertTimeVal, 0);

//Applied nutrients per fertigation
fgvm.calcN = Convert.ToInt32(fertilizerNutrients.fertilizer_N).ToString();
fgvm.calcP2o5 = Convert.ToInt32(fertilizerNutrients.fertilizer_P2O5).ToString();
fgvm.calcK2o = Convert.ToInt32(fertilizerNutrients.fertilizer_K2O).ToString();
fgvm.calcN = (Convert.ToInt32(fertilizerNutrients.fertilizer_N)/100).ToString();
fgvm.calcP2o5 = (Convert.ToInt32(fertilizerNutrients.fertilizer_P2O5)/100).ToString();
fgvm.calcK2o = (Convert.ToInt32(fertilizerNutrients.fertilizer_K2O)/100).ToString();

//Total Applied Nutrients
fgvm.calcTotalN = Convert.ToString(Convert.ToInt32(fertilizerNutrients.fertilizer_N) * Convert.ToInt32(fgvm.eventsPerSeason));
fgvm.calcTotalK2o = Convert.ToString(Convert.ToInt32(fertilizerNutrients.fertilizer_P2O5) * Convert.ToInt32(fgvm.eventsPerSeason));
fgvm.calcTotalP2o5 = Convert.ToString(Convert.ToInt32(fertilizerNutrients.fertilizer_K2O) * Convert.ToInt32(fgvm.eventsPerSeason));
fgvm.calcTotalN = Convert.ToString(Convert.ToInt32(fertilizerNutrients.fertilizer_N)/100 * Convert.ToInt32(fgvm.eventsPerSeason));
Copy link
Contributor Author

@lunamoonmoon lunamoonmoon Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction to Applied Nutrients calculation, was N * tank vol / fert area now N/100 * amount to dissolve / fert area

fgvm.calcTotalK2o = Convert.ToString(Convert.ToInt32(fertilizerNutrients.fertilizer_P2O5)/100 * Convert.ToInt32(fgvm.eventsPerSeason));
fgvm.calcTotalP2o5 = Convert.ToString(Convert.ToInt32(fertilizerNutrients.fertilizer_K2O)/100 * Convert.ToInt32(fgvm.eventsPerSeason));

fgvm.btnText = fgvm.id == null ? "Add to Field" : "Update Field";
}
Expand Down Expand Up @@ -1039,17 +1060,20 @@ private void SolidFertigationCalculation(FertigationDetailsViewModel fgvm){

fgvm.fertigationTime = Math.Round(tankVolume / convertedInjectionRate, 0);


if (amountToDissolve <= tankVolume * solInWater/1000){
//convert tankVolume from imp gal to litres
//convert amountToDissolve from lbs to kgs
if ((amountToDissolve * 0.45359237m) <= ((tankVolume * 4.54609m) * solInWater / 1000 * 0.65m))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per Ahmed fert ppt changed solubility assessment to "Multilply by 0.65 ("amountToDissolve <= tankVolume * solInWater/1000 * 0.65") to give room to error in solubility such as using colder water etc."

{
fgvm.dryAction = "Soluble";
}
else{
else
{
fgvm.dryAction = "Reduce the amount to dissolve";
}

fgvm.calcN = Convert.ToString(Math.Round(Convert.ToDecimal(fgvm.nutrientConcentrationN) * tankVolume / fertArea, 2));
fgvm.calcK2o = Convert.ToString(Math.Round(Convert.ToDecimal(fgvm.nutrientConcentrationK2O) * tankVolume / fertArea, 2));
fgvm.calcP2o5 = Convert.ToString(Math.Round(Convert.ToDecimal(fgvm.nutrientConcentrationP205) * tankVolume / fertArea, 2));
fgvm.calcN = Convert.ToString(Math.Round(Convert.ToDecimal(fgvm.nutrientConcentrationN) * amountToDissolve / fertArea, 2));
fgvm.calcK2o = Convert.ToString(Math.Round(Convert.ToDecimal(fgvm.nutrientConcentrationK2O) * amountToDissolve / fertArea, 2));
fgvm.calcP2o5 = Convert.ToString(Math.Round(Convert.ToDecimal(fgvm.nutrientConcentrationP205) * amountToDissolve / fertArea, 2));

fgvm.totN = Convert.ToString(Math.Round(Convert.ToDecimal(fgvm.calcN) * fgvm.eventsPerSeason, 2));
fgvm.totK2o = Convert.ToString(Math.Round(Convert.ToDecimal(fgvm.calcK2o) * fgvm.eventsPerSeason, 2));
Expand Down