public List <FarmManure> GetFarmManures() { FarmData userData = _ctx.HttpContext.Session.GetObjectFromJson <FarmData>("FarmData"); YearData yd = userData.years.FirstOrDefault(y => y.year == userData.farmDetails.year); if (yd.farmManures == null) { yd.farmManures = new List <FarmManure>(); } foreach (var fm in yd.farmManures) { if (!fm.customized) { Manure man = _sd.GetManure(fm.manureId.ToString()); fm.ammonia = man.ammonia; fm.dmid = man.dmid; fm.manure_class = man.manure_class; fm.moisture = man.moisture; fm.name = man.name; fm.nitrate = (decimal?)null; fm.nitrogen = man.nitrogen; fm.nminerizationid = man.nminerizationid; fm.phosphorous = man.phosphorous; fm.potassium = man.potassium; fm.solid_liquid = man.solid_liquid; } } return(yd.farmManures); }
public NutrientInputs GetNutrientInputs(NutrientInputs nutrientInputs) { FarmManure mymanure = _ud.GetFarmManure(Convert.ToInt32(manure)); ConversionFactor _cf = _sd.GetConversionFactor(); decimal potassiumAvailabilityFirstYear = _cf.potassiumAvailabilityFirstYear; decimal potassiumAvailabilityLongTerm = _cf.potassiumAvailabilityLongTerm; decimal potassiumKtoK2Oconversion = _cf.potassiumKtoK2Oconversion; decimal phosphorousAvailabilityFirstYear = _cf.phosphorousAvailabilityFirstYear; decimal phosphorousAvailabilityLongTerm = _cf.phosphorousAvailabilityLongTerm; decimal phosphorousPtoP2O5Kconversion = _cf.phosphorousPtoP2O5Kconversion; decimal lbPerTonConversion = _cf.lbPerTonConversion; decimal tenThousand = 10000; // get conversion factor for selected units to lb/ac Unit myunit = _sd.GetUnit(applicationRateUnits); decimal conversion = myunit.conversion_lbton; // for solid manures specified in cubic yards per ac, convert application rate to tons/ac if (myunit.id == 6 && mymanure.solid_liquid.ToUpper() == "SOLID") { Manure manure = _sd.GetManure(mymanure.manureId.ToString()); applicationRate = applicationRate * manure.cubic_Yard_Conversion; } // get potassium first year nutrientInputs.K2O_FirstYear = Convert.ToInt32(decimal.Multiply(applicationRate, mymanure.potassium) * lbPerTonConversion * potassiumKtoK2Oconversion * potassiumAvailabilityFirstYear * conversion); // get potassium long term nutrientInputs.K2O_LongTerm = Convert.ToInt32(decimal.Multiply(applicationRate, mymanure.potassium) * lbPerTonConversion * potassiumKtoK2Oconversion * potassiumAvailabilityLongTerm * conversion); // get phosphorous first year nutrientInputs.P2O5_FirstYear = Convert.ToInt32(decimal.Multiply(applicationRate, mymanure.phosphorous) * lbPerTonConversion * phosphorousPtoP2O5Kconversion * phosphorousAvailabilityFirstYear * conversion); // get phosphorous long term nutrientInputs.P2O5_LongTerm = Convert.ToInt32(decimal.Multiply(applicationRate, mymanure.phosphorous) * lbPerTonConversion * phosphorousPtoP2O5Kconversion * phosphorousAvailabilityLongTerm * conversion); // get N values // Organic N% = Total N% - NH4-N ppm / 10,000 decimal organicN = mymanure.nitrogen - (Convert.ToDecimal(mymanure.ammonia) / tenThousand); NOrganicMineralizations nOrganicMineralizations = new NOrganicMineralizations(); int regionid = _ud.FarmDetails().farmRegion.Value; Region region = _sd.GetRegion(regionid); nOrganicMineralizations = GetNMineralization(mymanure.id, region.locationid); nOrganicMineralizations.OrganicN_FirstYear = firstYearOrganicNAvailablityPct / 100; // get data from screen //decimal ammoniaRetention = GetAmmoniaRetention(mymanure.id, Convert.ToInt32(applicationSeason)); decimal ammoniaRetention = ammoniaNRetentionPct / 100; // get data from screen // N 1st year lb/ton = [NH4-N ppm/10,000 * NH4 retention + NO3-N/10,000 + Organic N % * 1st yr Mineralization] * 20 decimal a = decimal.Divide(mymanure.ammonia, tenThousand) * ammoniaRetention; decimal b1 = decimal.Multiply(organicN, nOrganicMineralizations.OrganicN_FirstYear); //E07US20 decimal c1 = a + b1 + Convert.ToDecimal(mymanure.nitrate) / tenThousand; decimal N_Firstyear = decimal.Multiply(c1, lbPerTonConversion); nutrientInputs.N_FirstYear = Convert.ToInt32(applicationRate * N_Firstyear * conversion); // same for long term decimal b2 = decimal.Multiply(organicN, nOrganicMineralizations.OrganicN_LongTerm); //E07US20 decimal c2 = a + b2 + Convert.ToDecimal(mymanure.nitrate) / tenThousand; decimal N_LongTerm = decimal.Multiply(c2, lbPerTonConversion); nutrientInputs.N_LongTerm = Convert.ToInt32(applicationRate * N_LongTerm * conversion); return(nutrientInputs); }
public static string GetManure(Manure manure) { return(m_Manure[(int)manure]); }
public NutrientInputs GetNutrientInputs( FarmManure farmManure, Region region, decimal applicationRate, string applicationRateUnits, decimal ammoniaNRetentionPct, decimal firstYearOrganicNAvailablityPct) { var nutrientInputs = new NutrientInputs(); var _cf = _sd.GetConversionFactor(); decimal potassiumAvailabilityFirstYear = _cf.PotassiumAvailabilityFirstYear; decimal potassiumAvailabilityLongTerm = _cf.PotassiumAvailabilityLongTerm; decimal potassiumKtoK2Oconversion = _cf.PotassiumKtoK2OConversion; decimal phosphorousAvailabilityFirstYear = _cf.PhosphorousAvailabilityFirstYear; decimal phosphorousAvailabilityLongTerm = _cf.PhosphorousAvailabilityLongTerm; decimal phosphorousPtoP2O5Kconversion = _cf.PhosphorousPtoP2O5Conversion; decimal lbPerTonConversion = _cf.PoundPerTonConversion; decimal tenThousand = 10000; // get conversion factor for selected units to lb/ac Unit myunit = _sd.GetUnit(applicationRateUnits); decimal conversion = myunit.ConversionlbTon; // for solid manures specified in cubic yards per ac, convert application rate to tons/ac if (myunit.Id == 6 && farmManure.SolidLiquid.ToUpper() == "SOLID") { Manure manure = _sd.GetManure(farmManure.ManureId); applicationRate = applicationRate * manure.CubicYardConversion; } // get potassium first year nutrientInputs.K2O_FirstYear = Convert.ToInt32(decimal.Multiply(applicationRate, farmManure.Potassium) * lbPerTonConversion * potassiumKtoK2Oconversion * potassiumAvailabilityFirstYear * conversion); // get potassium long term nutrientInputs.K2O_LongTerm = Convert.ToInt32(decimal.Multiply(applicationRate, farmManure.Potassium) * lbPerTonConversion * potassiumKtoK2Oconversion * potassiumAvailabilityLongTerm * conversion); // get phosphorous first year nutrientInputs.P2O5_FirstYear = Convert.ToInt32(decimal.Multiply(applicationRate, farmManure.Phosphorous) * lbPerTonConversion * phosphorousPtoP2O5Kconversion * phosphorousAvailabilityFirstYear * conversion); // get phosphorous long term nutrientInputs.P2O5_LongTerm = Convert.ToInt32(decimal.Multiply(applicationRate, farmManure.Phosphorous) * lbPerTonConversion * phosphorousPtoP2O5Kconversion * phosphorousAvailabilityLongTerm * conversion); // get N values // Organic N% = Total N% - NH4-N ppm / 10,000 decimal organicN = farmManure.Nitrogen - Convert.ToDecimal(farmManure.Ammonia) / tenThousand; NOrganicMineralizations nOrganicMineralizations = new NOrganicMineralizations(); nOrganicMineralizations = GetNMineralization(farmManure, region.LocationId); nOrganicMineralizations.OrganicN_FirstYear = firstYearOrganicNAvailablityPct / 100; // get data from screen //decimal ammoniaRetention = GetAmmoniaRetention(mymanure.id, Convert.ToInt32(applicationSeason)); decimal ammoniaRetention = ammoniaNRetentionPct / 100; // get data from screen // N 1st year lb/ton = [NH4-N ppm/10,000 * NH4 retention + NO3-N/10,000 + Organic N % * 1st yr Mineralization] * 20 decimal a = decimal.Divide(farmManure.Ammonia, tenThousand) * ammoniaRetention; decimal b1 = decimal.Multiply(organicN, nOrganicMineralizations.OrganicN_FirstYear); //E07US20 decimal c1 = a + b1 + Convert.ToDecimal(farmManure.Nitrate) / tenThousand; decimal N_Firstyear = decimal.Multiply(c1, lbPerTonConversion); nutrientInputs.N_FirstYear = Convert.ToInt32(applicationRate * N_Firstyear * conversion); // same for long term decimal b2 = decimal.Multiply(organicN, nOrganicMineralizations.OrganicN_LongTerm); //E07US20 decimal c2 = a + b2 + Convert.ToDecimal(farmManure.Nitrate) / tenThousand; decimal N_LongTerm = decimal.Multiply(c2, lbPerTonConversion); nutrientInputs.N_LongTerm = Convert.ToInt32(applicationRate * N_LongTerm * conversion); return(nutrientInputs); }