コード例 #1
0
 internal void SetConversionFactors()
 {
     if (!ConversionFactorsSet)
     {
         DegreesFactor        = new ConversionFactor(Degrees.HalfTurn, HalfTurn);
         RadiansFactor        = new ConversionFactor(Radians.HalfTurn, HalfTurn);
         GradiansFactor       = new ConversionFactor(Gradians.HalfTurn, HalfTurn);
         ConversionFactorsSet = true;
     }
 }
コード例 #2
0
 public UserUnit(string name, ConversionFactor numeratorPrefixes, ConversionFactor denominatorPrefixes, decimal multiplier, decimal offset, DimensionVector dv)
 {
     NumeratorName = name;
     Numerator.Add(this);
     NumeratorPrefix   = numeratorPrefixes;
     DenominatorPrefix = denominatorPrefixes;
     Multiplier        = multiplier;
     Offset            = offset;
     DimensionVector   = dv;
 }
コード例 #3
0
        public override string GetStepParameters()
        {
            var parameters = new List <string>();

            parameters.Add(Dimensions != null ? Dimensions.ToStepValue() : "$");
            parameters.Add(UnitType.ToStepValue());
            parameters.Add(Name != null ? Name.ToStepValue() : "$");
            parameters.Add(ConversionFactor != null ? ConversionFactor.ToStepValue() : "$");

            return(string.Join(", ", parameters.ToArray()));
        }
コード例 #4
0
        // default for % Crude Protien = crop.cropremovalfactor_N * 0.625 [N to protien conversion] * 0.5 [unit conversion]
        public decimal GetCrudeProtienByCropId(int cropid)
        {
            ConversionFactor _cf  = _sd.GetConversionFactor();
            Crop             crop = _sd.GetCrop(cropid);
            decimal          crfN;

            decimal.TryParse(crop.CropRemovalFactorNitrogen.ToString(), out crfN);
            decimal cp = crfN * _cf.NitrogenProteinConversion * _cf.UnitConversion;

            return(cp);
        }
コード例 #5
0
        public override int GetHashCode()
        {
            unchecked
            {
                int hashCode = Value.GetHashCode();
                hashCode = (hashCode * 397) ^ EqualityComparer <TUnit> .Default.GetHashCode(Unit);

                hashCode = (hashCode * 397) ^ ConversionFactor.GetHashCode();
                hashCode = (hashCode * 397) ^ (Abbreviation != null ? Abbreviation.GetHashCode() : 0);
                return(hashCode);
            }
        }
コード例 #6
0
        // default for % Crude Protien = crop.cropremovalfactor_N * 0.625 [N to protien conversion] * 0.5 [unit conversion]
        public decimal GetCrudeProtienByCropId(int _cropid)
        {
            ConversionFactor _cf = _sd.GetConversionFactor();

            decimal cp   = 0;
            decimal crfN = 0;
            Crop    crop = _sd.GetCrop(_cropid);

            decimal.TryParse(crop.cropremovalfactor_N.ToString(), out crfN);
            cp = crfN * _cf.n_protein_conversion * _cf.unit_conversion;

            return(cp);
        }
コード例 #7
0
        public ActionResult FieldDetail(string name, string target, string cntl, string actn, string currFld)
        {
            FieldDetailViewModel fvm = new FieldDetailViewModel();

            ConversionFactor cf = _sd.GetConversionFactor();

            fvm.selPrevYrManureOptions = _sd.GetPrevManureApplicationInPrevYears();

            fvm.target    = target;
            fvm.actn      = actn;
            fvm.cntl      = cntl;
            fvm.currFld   = currFld;
            fvm.placehldr = _sd.GetUserPrompt("fieldcommentplaceholder");

            if (!string.IsNullOrEmpty(name))
            {
                Field fld = _ud.GetFieldDetails(name);
                fvm.currFieldName = fld.fieldName;
                fvm.fieldName     = fld.fieldName;
                fvm.fieldArea     = fld.area.ToString("G29");
                fvm.fieldComment  = fld.comment;
                fvm.fieldId       = fld.id;
                // retrofit old saved NMP files
                if (String.IsNullOrEmpty(fld.prevYearManureApplicationFrequency))
                {
                    // set to default (no manure applied in the last two years)
                    fvm.selPrevYrManureOption = cf.DefaultApplicationOfManureInPrevYears;
                }
                else
                {
                    fvm.selPrevYrManureOption = fld.prevYearManureApplicationFrequency;
                }
                fvm.act = "Edit";
            }
            else
            {
                fvm.act = "Add";
            }
            return(PartialView("FieldDetail", fvm));
        }
コード例 #8
0
ファイル: Seed.cs プロジェクト: Jesma89/ProyectoCalculin
        CrearListaFactores()
        {
            var listaMonedasOrigen  = CrearListaMonedas();
            var listaMonedasDestino = CrearListaMonedas();
            var listaFactores       = new List <ConversionFactor>();

            foreach (var monedaOrigen in listaMonedasOrigen)
            {
                foreach (var monedaDestino in listaMonedasDestino)
                {
                    if (monedaOrigen.Abreviatura == monedaDestino.Abreviatura)
                    {
                        continue;
                    }

                    var factor = new ConversionFactor(monedaOrigen.Id, monedaDestino.Id, ObtenerAleatorio());
                    listaFactores.Add(factor);
                }
            }


            return(null);
        }
コード例 #9
0
        // This processing detemines the N P K values in lb per acre for the fertilizer select and appricatio rate/density etc.
        public FertilizerNutrients GetFertilizerNutrients()
        {
            FertilizerNutrients fn = new FertilizerNutrients();

            // get the fertilizer N P K % values from fertlizer look up
            //  for dry fertilizers
            //      N (lb/ac) = Application rate converted to lb/ac * N %
            //      P and K same as above
            //  for wet fertilizers
            //      N (lb/ac) = Application rate converted to lb/ac * N% * Density converted to lb / imp gallons
            //

            decimal applicationRateConversion = 0;
            decimal densityInSelectedUnit     = 0;
            decimal densityUnitConversion     = 0;

            Fertilizer _fertilizer = _sd.GetFertilizer(FertilizerId.ToString());

            if ((CustomFertilizer && FertilizerType == "dry") || (!CustomFertilizer && _fertilizer.dry_liquid == "dry"))
            {
                densityUnitConversion = 1;
                switch (ApplicationRateUnits)
                {
                case 1:   // application rate in lb/ac no conversion required
                    applicationRateConversion = 1;
                    break;

                case 2:   // application rate in kg/ha, convert to lb/ac
                    ConversionFactor _cf = _sd.GetConversionFactor();
                    applicationRateConversion = _cf.kgperha_lbperac_conversion;
                    break;

                case 7:   // application rate in lb/100 ft squared, convert to lb/ac
                    ConversionFactor _cf1 = _sd.GetConversionFactor();
                    applicationRateConversion = _cf1.lbper1000ftsquared_lbperac_conversion;
                    break;
                }
            }
            else //use liquid fertilizer
            {
                FertilizerUnit _fU = _sd.GetFertilizerUnit(ApplicationRateUnits);
                applicationRateConversion = _fU.conv_to_impgalperac;
                if (CustomFertilizer)
                {
                    densityInSelectedUnit = Density;
                }
                else
                {
                    LiquidFertilizerDensity _lfd = _sd.GetLiquidFertilizerDensity(FertilizerId, DensityUnits);
                    densityInSelectedUnit = _lfd.value;
                }
                DensityUnit _du = _sd.GetDensityUnit(DensityUnits);
                densityUnitConversion = _du.convfactor * densityInSelectedUnit;
            }

            fn.fertilizer_N    = ApplicationRate * decimal.Divide(userN, 100) * applicationRateConversion * densityUnitConversion;
            fn.fertilizer_P2O5 = ApplicationRate * decimal.Divide(userP2o5, 100) * applicationRateConversion * densityUnitConversion;
            fn.fertilizer_K2O  = ApplicationRate * decimal.Divide(userK2o, 100) * applicationRateConversion * densityUnitConversion;

            return(fn);
        }
コード例 #10
0
        public List <BalanceMessages> DetermineBalanceMessages(string fieldName)
        {
            List <BalanceMessages> messages = new List <BalanceMessages>();
            bool            legume          = false;
            string          message         = string.Empty;
            BalanceMessages bm = new BalanceMessages();


            //get soil test values
            ConversionFactor _cf = _sd.GetConversionFactor();

            //get the chemical balances
            ChemicalBalances cb = GetChemicalBalances(fieldName);

            //determine if a legume is included in the crops
            List <FieldCrop> fieldCrops = _ud.GetFieldCrops(fieldName);

            if (fieldCrops.Count > 0)
            {
                foreach (var _crop in fieldCrops)
                {
                    Crop crop = _sd.GetCrop(Convert.ToInt16(_crop.cropId));
                    if (crop.n_recommcd == 1) //is a legume
                    {
                        legume = true;
                    }
                }

                if (legume)
                {
                    // get sum of agronomic N for manure, fertilizer and other for field
                    // sum the above number with the crop removal N
                    // use the resulting number to determine message
                    int LegumeAgronomicN = GetLegumeAgronomicN(fieldName);
                    int LegumeRemovalN   = GetLegumeRemovalN(fieldName);
                    bm = _sd.GetMessageByChemicalBalance("AgrN", LegumeAgronomicN + LegumeRemovalN, legume);
                    if (bm != null)
                    {
                        messages.Add(bm);
                    }
                }
                else
                {
                    bm = _sd.GetMessageByChemicalBalance("AgrN", chemicalBalances.balance_AgrN, legume);
                    if (bm != null)
                    {
                        messages.Add(bm);
                    }
                }

                bm = _sd.GetMessageByChemicalBalance("AgrP2O5", chemicalBalances.balance_AgrP2O5, legume);
                if (bm != null)
                {
                    messages.Add(bm);
                }

                bm = _sd.GetMessageByChemicalBalance("AgrK2O", chemicalBalances.balance_AgrK2O, legume);
                if (bm != null)
                {
                    messages.Add(bm);
                }

                bm = _sd.GetMessageByChemicalBalance("CropN", chemicalBalances.balance_CropN, legume);
                if (bm != null)
                {
                    messages.Add(bm);
                }

                bm = _sd.GetMessageByChemicalBalance("CropP2O5", chemicalBalances.balance_CropP2O5, legume);
                if (bm != null)
                {
                    messages.Add(bm);
                }

                bm = _sd.GetMessageByChemicalBalance("CropK2O", chemicalBalances.balance_CropK2O, legume);
                if (!string.IsNullOrEmpty(bm.Chemical))
                {
                    messages.Add(bm);
                }

                bm = _sd.GetMessageByChemicalBalance("AgrP2O5CropP2O5", chemicalBalances.balance_AgrP2O5, chemicalBalances.balance_CropP2O5, "CropP2O5");
                if (bm != null)
                {
                    messages.Add(bm);
                }
            }
            return(messages);
        }
コード例 #11
0
ファイル: IFC C XML.cs プロジェクト: wsy8648/GeometryGymIFC
 internal override void SetXML(XmlElement xml, BaseClassIfc host, Dictionary <int, XmlElement> processed)
 {
     base.SetXML(xml, host, processed);
     xml.SetAttribute("Name", Name);
     xml.AppendChild(ConversionFactor.GetXML(xml.OwnerDocument, "ConversionFactor", this, processed));
 }
コード例 #12
0
        public CropRequirementRemoval GetCropRequirementRemoval(
            int cropid,
            decimal yield,
            decimal?crudeProtien,
            bool?coverCropHarvested,
            int nCredit,
            int regionId,
            Field field)
        {
            ConversionFactor _cf = _sd.GetConversionFactor();

            var  crr  = new CropRequirementRemoval();
            Crop crop = _sd.GetCrop(cropid);

            decimal n_removal;

            //      For testing we're using Soil Test Kelowna of 65ppm, should actually by 100+ (say 101)
            //
            //      Nutrient removal
            //          P2O5 = crop.cropremovalfactor_P2O5 * yield
            //          K2O = crop.cropremovalfactor_K2O * yield
            //          N = crop.cropremovalfactor_N * yield
            //          if crude_protien exists and is not default
            //                  crop.cropremovalfactor_N = (crude protien / (0.625 * 0.5))
            //                  N = crop.cropremovalfactor_N * yield
            //           else
            //                  N = crop.cropremovalfactor_N * yield
            //
            //      Note for Cover crops (only)
            //          if Cover Crop harvested
            //              don't change numbers
            //          if Cover crop not harvested
            //              set all removal amts to zero

            if (!crudeProtien.HasValue || crudeProtien.HasValue && crudeProtien.Value == 0)
            {
                decimal tmpDec;
                if (decimal.TryParse(crop.CropRemovalFactorNitrogen.ToString(), out tmpDec))
                {
                    n_removal = tmpDec * yield;
                }
                else
                {
                    n_removal = 0;
                }
            }
            else
            {
                n_removal = decimal.Divide(Convert.ToDecimal(crudeProtien), _cf.NitrogenProteinConversion * _cf.UnitConversion) * yield;
            }

            crr.P2O5_Removal = Convert.ToInt32(crop.CropRemovalFactorP2O5 * yield);
            crr.K2O_Removal  = Convert.ToInt32(crop.CropRemovalFactorK2O * yield);
            crr.N_Removal    = Convert.ToInt32(n_removal);

            if (coverCropHarvested.HasValue && coverCropHarvested.Value == false)
            {
                crr.P2O5_Removal = 0;
                crr.K2O_Removal  = 0;
                crr.N_Removal    = 0;
            }

            //      Crop Requirement
            //          P205
            //              get region.soil_test_phospherous_region_cd
            //              get phosphorous_crop_group_region_cd  = crop_stp_regioncd(cropid, region.soil_test_phospherous_region_cd)
            //              get stp_kelowna_range.id usign default ST Kelowna (65) between range_low and range_high
            //              get P2O5 recommedation  = stp_recommend(stp_kelowna_range.id, region.soil_test_phospherous_region_cd, phosphorous_crop_group_region_cd)
            //
            //          same as above for K2O
            //
            //          For N
            //          Look up crop.n_recommcd
            //          if 0 or 1
            //              N = crop.n_recomm_lbperac
            //          if 2
            //              same as N removal
            //          if 3
            //              get default yield = cropyield(cropid, locationid)
            //              N = (yield / default yield) * crop.n_recomm_lbperac

            var region = _sd.GetRegion(regionId);

            if (field.SoilTest == null)
            {
                field.SoilTest = new SoilTest();
                var dt = _sd.GetDefaultSoilTest();
                field.SoilTest.valNO3H           = dt.Nitrogen;
                field.SoilTest.ValP              = dt.Phosphorous;
                field.SoilTest.valK              = dt.Potassium;
                field.SoilTest.valPH             = dt.pH;
                field.SoilTest.ConvertedKelownaK = dt.ConvertedKelownaK;
                field.SoilTest.ConvertedKelownaP = dt.ConvertedKelownaP;
            }

            int _STP = field.SoilTest.ConvertedKelownaP;

            if (_STP == 0)
            {
                _STP = _cf.DefaultSoilTestKelownaPhosphorous;
            }

            int _STK = field.SoilTest.ConvertedKelownaK;

            if (field.SoilTest.ConvertedKelownaK == 0)
            {
                _STK = _cf.DefaultSoilTestKelownaPotassium;
            }

            // p2o5 recommend calculations
            CropSoilTestPhosphorousRegion cropSTPRegionCd   = _sd.GetCropSTPRegionCd(cropid, region.SoilTestPhosphorousRegionCd);
            int?phosphorous_crop_group_region_cd            = cropSTPRegionCd.PhosphorousCropGroupRegionCode;
            SoilTestPhosphorousKelownaRange sTPKelownaRange = _sd.GetSTPKelownaRangeByPpm(_STP);
            int stp_kelowna_range_id = sTPKelownaRange.Id;

            if (phosphorous_crop_group_region_cd == null)
            {
                crr.P2O5_Requirement = 0;
            }
            else
            {
                SoilTestPhosphorousRecommendation sTPRecommend = _sd.GetSTPRecommend(stp_kelowna_range_id, region.SoilTestPhosphorousRegionCd, Convert.ToInt16(phosphorous_crop_group_region_cd));
                crr.P2O5_Requirement = Convert.ToInt32(Convert.ToDecimal(sTPRecommend.P2O5RecommendationKilogramPerHectare) * _cf.KilogramPerHectareToPoundPerAcreConversion);
            }

            // k2o recommend calculations
            CropSoilTestPotassiumRegion cropSTKRegionCd   = _sd.GetCropSTKRegionCd(cropid, region.SoilTestPotassiumRegionCd);
            int?potassium_crop_group_region_cd            = cropSTKRegionCd?.PotassiumCropGroupRegionCode;
            SoilTestPotassiumKelownaRange sTKKelownaRange = _sd.GetSTKKelownaRangeByPpm(_STK);
            int stk_kelowna_range_id = sTKKelownaRange.Id;

            if (potassium_crop_group_region_cd == null)
            {
                crr.K2O_Requirement = 0;
            }
            else
            {
                SoilTestPotassiumRecommendation sTKRecommend = _sd.GetSTKRecommend(stk_kelowna_range_id, region.SoilTestPotassiumRegionCd, Convert.ToInt16(potassium_crop_group_region_cd));
                crr.K2O_Requirement = Convert.ToInt32(Convert.ToDecimal(sTKRecommend.K2ORecommendationKilogramPerHectare) * _cf.KilogramPerHectareToPoundPerAcreConversion);
            }

            // n recommend calculations -note the excel n_recommd are zero based, the static data is 1 based
            switch (crop.NitrogenRecommendationId)
            {
            case 1:
                crr.N_Requirement = Convert.ToInt16(crop.NitrogenRecommendationPoundPerAcre);
                break;

            case 2:
                crr.N_Requirement = Convert.ToInt16(crop.NitrogenRecommendationPoundPerAcre);
                break;

            case 3:
                crr.N_Requirement = crr.N_Removal;
                break;

            case 4:
                CropYield cropYield = _sd.GetCropYield(cropid, region.LocationId);
                if (cropYield?.Amount != null)
                {
                    crr.N_Requirement = Convert.ToInt16(decimal.Divide(yield, Convert.ToDecimal(cropYield.Amount)) * crop.NitrogenRecommendationPoundPerAcre);
                }
                else
                {
                    crr.N_Requirement = 0;
                }
                break;
            }

            // if a previous crop has been ploughed dowm account for the N in the field (passed in as a credit)
            crr.N_Requirement = crr.N_Requirement - nCredit;

            // only reduce to 0
            crr.N_Requirement = crr.N_Requirement < 0 ? 0 : crr.N_Requirement;

            return(crr);
        }
コード例 #13
0
        public bool Equals(CalcLoadTypeDto other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(_lti.Equals(other._lti) && Name == other.Name && UnitOfPower == other.UnitOfPower && UnitOfSum == other.UnitOfSum && ConversionFactor.Equals(other.ConversionFactor) && ShowInCharts == other.ShowInCharts && Guid == other.Guid && FileName == other.FileName);
        }
コード例 #14
0
ファイル: YTYData.cs プロジェクト: clintkautz/BinManager
        public Dictionary <string, string> ToStringDict()
        {
            Dictionary <string, string> dict = new Dictionary <string, string>();

            string cropYear;

            if (CropYear == 0)
            {
                cropYear = "0";
            }
            else
            {
                cropYear = CropYear.ToString();
            }
            dict.Add("cropYear", cropYear);

            string crop;

            if (Crop == null)
            {
                crop = string.Empty;
            }
            else
            {
                crop = Crop.ToString();
            }
            dict.Add("crop", crop);

            string grainHeight;

            if (GrainHeight == 0)
            {
                grainHeight = "0";
            }
            else
            {
                grainHeight = GrainHeight.ToString();
            }
            dict.Add("grainHeight", grainHeight);

            string grainHopperHeight;

            if (GrainHopperHeight == 0)
            {
                grainHopperHeight = "0";
            }
            else
            {
                grainHopperHeight = GrainHopperHeight.ToString();
            }
            dict.Add("grainHopperHeight", grainHopperHeight);

            string coneHeight;

            if (ConeHeight == 0)
            {
                coneHeight = "0";
            }
            else
            {
                coneHeight = ConeHeight.ToString();
            }
            dict.Add("coneHeight", coneHeight);

            string totalVolume;

            if (TotalVolume == 0)
            {
                totalVolume = "0";
            }
            else
            {
                totalVolume = TotalVolume.ToString("#,###.##");
            }
            dict.Add("totalVolume", totalVolume);

            string moistureOfGrain;

            if (MoistureOfGrain == 0)
            {
                moistureOfGrain = "0";
            }
            else
            {
                moistureOfGrain = MoistureOfGrain.ToString();
            }
            dict.Add("moistureOfGrain", moistureOfGrain);

            string moistureFactor;

            if (MoistureFactor == 0)
            {
                moistureFactor = "0";
            }
            else
            {
                moistureFactor = MoistureFactor.ToString();
            }
            dict.Add("moistureFactor", moistureFactor);

            string testWeight;

            if (TestWeight == 0)
            {
                testWeight = "0";
            }
            else
            {
                testWeight = TestWeight.ToString();
            }
            dict.Add("testWeight", testWeight);

            string packFactor;

            if (PackFactor == 0)
            {
                packFactor = "0";
            }
            else
            {
                packFactor = PackFactor.ToString();
            }
            dict.Add("packFactor", packFactor);

            string dockagePercent;

            if (DockagePercent == 0)
            {
                dockagePercent = "0";
            }
            else
            {
                dockagePercent = DockagePercent.ToString();
            }
            dict.Add("dockagePercent", dockagePercent);

            string dockageFactor;

            if (DockageFactor == 0)
            {
                dockageFactor = "0";
            }
            else
            {
                dockageFactor = DockageFactor.ToString();
            }
            dict.Add("dockageFactor", dockageFactor);

            string conversionFactor;

            if (ConversionFactor == 0)
            {
                conversionFactor = "0";
            }
            else
            {
                conversionFactor = ConversionFactor.ToString();
            }
            dict.Add("conversionFactor", conversionFactor);

            string shellFactor;

            if (ShellFactor == 0)
            {
                shellFactor = "0";
            }
            else
            {
                shellFactor = ShellFactor.ToString();
            }
            dict.Add("shellFactor", shellFactor);

            string totalDeductionVolume;

            if (TotalDeductionVolume == 0)
            {
                totalDeductionVolume = "0";
            }
            else
            {
                totalDeductionVolume = TotalDeductionVolume.ToString();
            }
            dict.Add("totalDeductionVolume", totalDeductionVolume);

            string notes;

            if (Notes == null)
            {
                notes = string.Empty;
            }
            else
            {
                notes = Notes.ToString();
            }
            dict.Add("notes", notes);

            return(dict);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        public List <BalanceMessages> DetermineBalanceMessages(Field field, int farmRegionId, string year)
        {
            List <BalanceMessages> messages = new List <BalanceMessages>();
            bool            legume          = false;
            string          message         = string.Empty;
            BalanceMessages bm = new BalanceMessages();

            //get soil test values
            ConversionFactor cf = _sd.GetConversionFactor();

            //get the chemical balances
            ChemicalBalances cb = GetChemicalBalances(field, farmRegionId, year);

            //determine if a legume is included in the crops
            var fieldCrops = field.Crops;

            if (fieldCrops.Count > 0)
            {
                foreach (var _crop in fieldCrops)
                {
                    Crop crop = _sd.GetCrop(Convert.ToInt16(_crop.cropId));
                    if (crop.NitrogenRecommendationId == 1) // no nitrogen need to be added
                    {
                        legume = true;
                    }
                }

                if (legume)
                {
                    // get sum of agronomic N for manure, fertilizer and other for field
                    // sum the above number with the crop removal N
                    // use the resulting number to determine message
                    long LegumeAgronomicN = GetLegumeAgronomicN(field);
                    int  LegumeRemovalN   = GetLegumeRemovalN(field);
                    bm = _sd.GetMessageByChemicalBalance("AgrN", LegumeAgronomicN + LegumeRemovalN, legume);
                    if (bm != null)
                    {
                        messages.Add(bm);
                    }
                }
                else
                {
                    bm = _sd.GetMessageByChemicalBalance("AgrN", chemicalBalances.balance_AgrN, legume);
                    if (bm != null)
                    {
                        messages.Add(bm);
                    }
                }

                bm = _sd.GetMessageByChemicalBalance("AgrP2O5", chemicalBalances.balance_AgrP2O5, legume);
                if (bm != null)
                {
                    messages.Add(bm);
                }

                bm = _sd.GetMessageByChemicalBalance("AgrK2O", chemicalBalances.balance_AgrK2O, legume);
                if (bm != null)
                {
                    messages.Add(bm);
                }

                bm = _sd.GetMessageByChemicalBalance("CropN", chemicalBalances.balance_CropN, legume);
                if (bm != null)
                {
                    messages.Add(bm);
                }

                bm = _sd.GetMessageByChemicalBalance("CropP2O5", chemicalBalances.balance_CropP2O5, legume);
                if (bm != null)
                {
                    messages.Add(bm);
                }

                bm = _sd.GetMessageByChemicalBalance("CropK2O", chemicalBalances.balance_CropK2O, legume);
                if (!string.IsNullOrEmpty(bm?.Chemical))
                {
                    messages.Add(bm);
                }

                bm = _sd.GetMessageByChemicalBalance("AgrP2O5CropP2O5", chemicalBalances.balance_AgrP2O5, chemicalBalances.balance_CropP2O5, "CropP2O5");
                if (bm != null)
                {
                    messages.Add(bm);
                }
            }
            return(messages);
        }
コード例 #17
0
        // This processing detemines the N P K values in lb per acre for the fertilizer select and appricatio rate/density etc.
        public FertilizerNutrients GetFertilizerNutrients(int FertilizerId,
                                                          string fertilizerType,
                                                          decimal applicationRate,
                                                          int applicationRateUnits,
                                                          decimal density,
                                                          int densityUnits,
                                                          decimal userN,
                                                          decimal userP2o5,
                                                          decimal userK2o,
                                                          bool customFertilizer)
        {
            var fn = new FertilizerNutrients();

            // get the fertilizer N P K % values from fertlizer look up
            //  for dry fertilizers
            //      N (lb/ac) = Application rate converted to lb/ac * N %
            //      P and K same as above
            //  for wet fertilizers
            //      N (lb/ac) = Application rate converted to lb/ac * N% * Density converted to lb / imp gallons
            //

            decimal applicationRateConversion = 0;
            decimal densityInSelectedUnit     = 0;
            decimal densityUnitConversion     = 0;

            Fertilizer _fertilizer = _sd.GetFertilizer(FertilizerId.ToString());

            if (customFertilizer && fertilizerType == "dry" || !customFertilizer && _fertilizer.DryLiquid == "dry")
            {
                densityUnitConversion = 1;
                switch (applicationRateUnits)
                {
                case 1:     // application rate in lb/ac no conversion required
                    applicationRateConversion = 1;
                    break;

                case 2:     // application rate in kg/ha, convert to lb/ac
                    ConversionFactor _cf = _sd.GetConversionFactor();
                    applicationRateConversion = _cf.KilogramPerHectareToPoundPerAcreConversion;
                    break;

                case 7:     // application rate in lb/100 ft squared, convert to lb/ac
                    ConversionFactor _cf1 = _sd.GetConversionFactor();
                    applicationRateConversion = _cf1.PoundPer1000FtSquaredToPoundPerAcreConversion;
                    break;
                }
            }
            else //use liquid fertilizer
            {
                FertilizerUnit _fU = _sd.GetFertilizerUnit(applicationRateUnits);
                applicationRateConversion = _fU.ConversionToImperialGallonsPerAcre;
                if (customFertilizer)
                {
                    densityInSelectedUnit = density;
                }
                else
                {
                    LiquidFertilizerDensity _lfd = _sd.GetLiquidFertilizerDensity(FertilizerId, densityUnits);
                    densityInSelectedUnit = _lfd.Value;
                }
                DensityUnit _du = _sd.GetDensityUnit(densityUnits);
                densityUnitConversion = _du.ConvFactor * densityInSelectedUnit;
            }

            fn.fertilizer_N    = applicationRate * decimal.Divide(userN, 100) * applicationRateConversion * densityUnitConversion;
            fn.fertilizer_P2O5 = applicationRate * decimal.Divide(userP2o5, 100) * applicationRateConversion * densityUnitConversion;
            fn.fertilizer_K2O  = applicationRate * decimal.Divide(userK2o, 100) * applicationRateConversion * densityUnitConversion;

            return(fn);
        }
コード例 #18
0
 protected override void setJSON(JObject obj, BaseClassIfc host, SetJsonOptions options)
 {
     base.setJSON(obj, host, options);
     base.setAttribute(obj, "Name", Name);
     obj["ConversionFactor"] = ConversionFactor.getJson(this, options);
 }
コード例 #19
0
        public CropRequirementRemoval GetCropRequirementRemoval()
        {
            decimal n_removal = 0;

            ConversionFactor _cf = _sd.GetConversionFactor();

            CropRequirementRemoval crr = new CropRequirementRemoval();
            Crop crop = _sd.GetCrop(cropid);

            //      For testing we're using Soil Test Kelowna of 65ppm, should actually by 100+ (say 101)
            //
            //      Nutrient removal
            //          P2O5 = crop.cropremovalfactor_P2O5 * yield
            //          K2O = crop.cropremovalfactor_K2O * yield
            //          N = crop.cropremovalfactor_N * yield
            //          if crude_protien exists and is not default
            //                  crop.cropremovalfactor_N = (crude protien / (0.625 * 0.5))
            //                  N = crop.cropremovalfactor_N * yield
            //           else
            //                  N = crop.cropremovalfactor_N * yield
            //
            //      Note for Cover crops (only)
            //          if Cover Crop harvested
            //              don't change numbers
            //          if Cover crop not harvested
            //              set all removal amts to zero

            if (!crudeProtien.HasValue || (crudeProtien.HasValue && crudeProtien.Value == 0))
            {
                decimal tmpDec;
                if (decimal.TryParse(crop.cropremovalfactor_N.ToString(), out tmpDec))
                {
                    n_removal = tmpDec * yield;
                }
                else
                {
                    n_removal = 0;
                }
            }
            else
            {
                n_removal = decimal.Divide(Convert.ToDecimal(crudeProtien), (_cf.n_protein_conversion * _cf.unit_conversion)) * yield;
            }

            crr.P2O5_Removal = Convert.ToInt32(crop.cropremovalfactor_P2O5 * yield);
            crr.K2O_Removal  = Convert.ToInt32(crop.cropremovalfactor_K2O * yield);
            crr.N_Removal    = Convert.ToInt32(n_removal);

            if (coverCropHarvested.HasValue && coverCropHarvested.Value == false)
            {
                crr.P2O5_Removal = 0;
                crr.K2O_Removal  = 0;
                crr.N_Removal    = 0;
            }


            //      Crop Requirement
            //          P205
            //              get region.soil_test_phospherous_region_cd
            //              get phosphorous_crop_group_region_cd  = crop_stp_regioncd(cropid, region.soil_test_phospherous_region_cd)
            //              get stp_kelowna_range.id usign default ST Kelowna (65) between range_low and range_high
            //              get P2O5 recommedation  = stp_recommend(stp_kelowna_range.id, region.soil_test_phospherous_region_cd, phosphorous_crop_group_region_cd)
            //
            //          same as above for K2O
            //
            //          For N
            //          Look up crop.n_recommcd
            //          if 0 or 1
            //              N = crop.n_recomm_lbperac
            //          if 2
            //              same as N removal
            //          if 3
            //              get default yield = cropyield(cropid, locationid)
            //              N = (yield / default yield) * crop.n_recomm_lbperac

            int    regionid = _ud.FarmDetails().farmRegion.Value;
            Region region   = _sd.GetRegion(regionid);

            Field fld = _ud.GetFieldDetails(fieldName);

            if (fld.soilTest == null)
            {
                fld.soilTest = new SoilTest();
                DefaultSoilTest dt = _sd.GetDefaultSoilTest();
                fld.soilTest.valNO3H           = dt.nitrogen;
                fld.soilTest.ValP              = dt.phosphorous;
                fld.soilTest.valK              = dt.potassium;
                fld.soilTest.valPH             = dt.pH;
                fld.soilTest.ConvertedKelownaK = dt.convertedKelownaK;
                fld.soilTest.ConvertedKelownaP = dt.convertedKelownaP;
            }

            int _STP = fld.soilTest.ConvertedKelownaP;

            if (_STP == 0)
            {
                _STP = _cf.defaultSoilTestKelownaP;
            }

            int _STK = fld.soilTest.ConvertedKelownaK;

            if (fld.soilTest.ConvertedKelownaK == 0)
            {
                _STK = _cf.defaultSoilTestKelownaK;
            }

            // p2o5 recommend calculations
            CropSTPRegionCd cropSTPRegionCd = _sd.GetCropSTPRegionCd(cropid, region.soil_test_phospherous_region_cd);
            int?            phosphorous_crop_group_region_cd = cropSTPRegionCd.phosphorous_crop_group_region_cd;
            STPKelownaRange sTPKelownaRange      = _sd.GetSTPKelownaRangeByPpm(_STP);
            int             stp_kelowna_range_id = sTPKelownaRange.id;

            if (phosphorous_crop_group_region_cd == null)
            {
                crr.P2O5_Requirement = 0;
            }
            else
            {
                STPRecommend sTPRecommend = _sd.GetSTPRecommend(stp_kelowna_range_id, region.soil_test_phospherous_region_cd, Convert.ToInt16(phosphorous_crop_group_region_cd));
                crr.P2O5_Requirement = Convert.ToInt32(Convert.ToDecimal(sTPRecommend.p2o5_recommend_kgperha) * _cf.kgperha_lbperac_conversion);
            }

            // k2o recommend calculations
            CropSTKRegionCd cropSTKRegionCd = _sd.GetCropSTKRegionCd(cropid, region.soil_test_potassium_region_cd);
            int?            potassium_crop_group_region_cd = cropSTKRegionCd.potassium_crop_group_region_cd;
            STKKelownaRange sTKKelownaRange      = _sd.GetSTKKelownaRangeByPpm(_STK);
            int             stk_kelowna_range_id = sTKKelownaRange.id;

            if (potassium_crop_group_region_cd == null)
            {
                crr.K2O_Requirement = 0;
            }
            else
            {
                STKRecommend sTKRecommend = _sd.GetSTKRecommend(stk_kelowna_range_id, region.soil_test_potassium_region_cd, Convert.ToInt16(potassium_crop_group_region_cd));
                crr.K2O_Requirement = Convert.ToInt32(Convert.ToDecimal(sTKRecommend.k2o_recommend_kgperha) * _cf.kgperha_lbperac_conversion);
            }

            // n recommend calculations -note the excel n_recommd are zero based, the static data is 1 based
            switch (crop.n_recommcd)
            {
            case 1:
                crr.N_Requirement = Convert.ToInt16(crop.n_recomm_lbperac);
                break;

            case 2:
                crr.N_Requirement = Convert.ToInt16(crop.n_recomm_lbperac);
                break;

            case 3:
                crr.N_Requirement = crr.N_Removal;
                break;

            case 4:
                CropYield cropYield = _sd.GetCropYield(cropid, region.locationid);
                if (cropYield.amt != null)
                {
                    crr.N_Requirement = Convert.ToInt16(decimal.Divide(yield, Convert.ToDecimal(cropYield.amt)) * crop.n_recomm_lbperac);
                }
                else
                {
                    crr.N_Requirement = 0;
                }
                break;
            }

            // if a previous crop has been ploughed dowm account for the N in the field (passed in as a credit)
            crr.N_Requirement = crr.N_Requirement - nCredit;

            // only reduce to 0
            crr.N_Requirement = (crr.N_Requirement < 0) ? 0 : crr.N_Requirement;

            return(crr);
        }
コード例 #20
0
 protected override void setJSON(JObject obj, BaseClassIfc host, HashSet <int> processed)
 {
     base.setJSON(obj, host, processed);
     base.setAttribute(obj, "Name", Name);
     obj["ConversionFactor"] = ConversionFactor.getJson(this, processed);
 }
コード例 #21
0
        }//beforeDeleteNode()

        protected override void afterPopulateProps()
        {
            ConversionFactor.SetOnPropChange(OnConversionFactorPropChange);
            Aliases.SetOnPropChange(onAliasesPropChange);
            Name.SetOnPropChange(OnNamePropChange);
        }//afterPopulateProps()
コード例 #22
0
ファイル: YTYData.cs プロジェクト: clintkautz/BinManager
        public List <string> ToStringList()
        {
            List <string> list = new List <string>();

            string cropYear;

            if (CropYear == 0)
            {
                cropYear = "0";
            }
            else
            {
                cropYear = CropYear.ToString();
            }
            list.Add("CropYear: " + cropYear);

            string crop;

            if (Crop == null)
            {
                crop = string.Empty;
            }
            else
            {
                crop = Crop.ToString();
            }
            list.Add("Crop: " + crop);

            string grainHeight;

            if (GrainHeight == 0)
            {
                grainHeight = "0";
            }
            else
            {
                grainHeight = GrainHeight.ToString();
            }
            list.Add("Grain Height: " + grainHeight);

            string hopperHeight;

            if (GrainHopperHeight == 0)
            {
                hopperHeight = "0";
            }
            else
            {
                hopperHeight = GrainHopperHeight.ToString();
            }
            list.Add("Grain Hopper Height: " + hopperHeight.ToString());

            string coneHeight;

            if (ConeHeight == 0)
            {
                coneHeight = "0";
            }
            else
            {
                coneHeight = ConeHeight.ToString();
            }
            list.Add("Cone Height: " + coneHeight);

            string totalVolume;

            if (TotalVolume == 0)
            {
                totalVolume = "0";
            }
            else
            {
                totalVolume = TotalVolume.ToString("#,###.##");
            }
            list.Add("Total Volume: " + totalVolume);

            string moistureOfGrain;

            if (MoistureOfGrain == 0)
            {
                moistureOfGrain = "0";
            }
            else
            {
                moistureOfGrain = MoistureOfGrain.ToString();
            }
            list.Add("Moisture Of Grain: " + moistureOfGrain);

            string moistureFactor;

            if (MoistureFactor == 0)
            {
                moistureFactor = "0";
            }
            else
            {
                moistureFactor = MoistureFactor.ToString();
            }
            list.Add("Moisture Factor: " + moistureFactor);

            string testWeight;

            if (TestWeight == 0)
            {
                testWeight = "0";
            }
            else
            {
                testWeight = TestWeight.ToString();
            }
            list.Add("Test Weight: " + testWeight);

            string packFactor;

            if (PackFactor == 0)
            {
                packFactor = "0";
            }
            else
            {
                packFactor = PackFactor.ToString();
            }
            list.Add("Pack Factor: " + packFactor);

            string dockagePercent;

            if (DockagePercent == 0)
            {
                dockagePercent = "0";
            }
            else
            {
                dockagePercent = DockagePercent.ToString();
            }
            list.Add("Dockage Percent: " + dockagePercent);

            string dockageFactor;

            if (DockageFactor == 0)
            {
                dockageFactor = "0";
            }
            else
            {
                dockageFactor = DockageFactor.ToString();
            }
            list.Add("Dockage Factor: " + dockageFactor);

            string conversionFactor;

            if (ConversionFactor == 0)
            {
                conversionFactor = "0";
            }
            else
            {
                conversionFactor = ConversionFactor.ToString();
            }
            list.Add("Conversion Factor: " + conversionFactor);

            string shellFactor;

            if (ShellFactor == 0)
            {
                shellFactor = "0";
            }
            else
            {
                shellFactor = ShellFactor.ToString();
            }
            list.Add("Shell Factor: " + shellFactor);

            string totalDeductionVolume;

            if (TotalDeductionVolume == 0)
            {
                totalDeductionVolume = "0";
            }
            else
            {
                totalDeductionVolume = TotalDeductionVolume.ToString();
            }
            list.Add("Total Deduction Volume: " + totalDeductionVolume);

            string notes;

            if (Notes == null)
            {
                notes = string.Empty;
            }
            else
            {
                notes = Notes.ToString();
            }
            list.Add("Notes: " + notes);

            return(list);
        }
コード例 #23
0
 protected bool Equals(NumericValue <TUnit> other)
 {
     return(Value.Equals(other.Value) && (Unit.GetType() == other.Unit.GetType()) && ConversionFactor.Equals(other.ConversionFactor) && string.Equals(Abbreviation, other.Abbreviation));
 }