コード例 #1
0
 private void OnCLEMDoCutAndCarry(object sender, EventArgs e)
 {
     // get resources needed such as labour before DoActivity
     // when not going to a GrazeFoodStore that uses CLEMUpdatePasture
     if (LinkedResourceItem.GetType() != typeof(GrazeFoodStoreType))
     {
         GetResourcesRequiredForActivity();
     }
 }
コード例 #2
0
 private void OnCLEMUpdatePasture(object sender, EventArgs e)
 {
     if (LinkedResourceItem.GetType() == typeof(GrazeFoodStoreType))
     {
         if (this.TimingOK)
         {
             Status = ActivityStatus.NotNeeded;
             DoActivity();
         }
     }
 }
コード例 #3
0
        private void OnCLEMDoCutAndCarry(object sender, EventArgs e)
        {
            int year  = Clock.Today.Year;
            int month = Clock.Today.Month;

            if (NextHarvest != null)
            {
                //if this month is a harvest month for this crop
                if ((year == NextHarvest.HarvestDate.Year) && (month == NextHarvest.HarvestDate.Month))
                {
                    if (this.TimingOK)
                    {
                        double totalamount;
                        if (IsTreeCrop)
                        {
                            totalamount = NextHarvest.AmtKg * TreesPerHa * parentManagementActivity.Area * UnitsToHaConverter * (PercentKept / 100);
                        }
                        else
                        {
                            totalamount = NextHarvest.AmtKg * parentManagementActivity.Area * UnitsToHaConverter * (PercentKept / 100);
                        }

                        if (totalamount > 0)
                        {
                            //if Npct column was not in the file
                            if (double.IsNaN(NextHarvest.Npct))
                            {
                                //Add without adding any new nitrogen.
                                //The nitrogen value for this feed item in the store remains the same.
                                LinkedResourceItem.Add(totalamount, this.Name, "Harvest");
                            }
                            else
                            {
                                FoodResourcePacket packet = new FoodResourcePacket()
                                {
                                    Amount   = totalamount,
                                    PercentN = NextHarvest.Npct
                                };
                                LinkedResourceItem.Add(packet, this.Name, "Harvest");
                            }
                        }
                        SetStatusSuccess();
                    }
                    HarvestData.RemoveAt(0);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Method used to perform activity if it can occur as soon as resources are available.
        /// </summary>
        public override void DoActivity()
        {
            int year  = Clock.Today.Year;
            int month = Clock.Today.Month;

            AmountHarvested           = 0;
            AmountAvailableForHarvest = 0;

            if (NextHarvest != null)
            {
                //if this month is a harvest month for this crop
                if ((year == NextHarvest.HarvestDate.Year) && (month == NextHarvest.HarvestDate.Month))
                {
                    if (this.TimingOK)
                    {
                        if (IsTreeCrop)
                        {
                            AmountHarvested = NextHarvest.AmtKg * TreesPerHa * parentManagementActivity.Area * UnitsToHaConverter * ProportionKept;
                        }
                        else
                        {
                            AmountHarvested = NextHarvest.AmtKg * parentManagementActivity.Area * UnitsToHaConverter * ProportionKept;
                        }

                        AmountAvailableForHarvest = AmountHarvested;
                        // reduce amount by limiter if present.
                        if (limiter != null)
                        {
                            double canBeCarried = limiter.GetAmountAvailable(Clock.Today.Month);
                            AmountHarvested = Math.Max(AmountHarvested, canBeCarried);

                            // now modify by labour limits as this is the amount labour was calculated for.
                            double labourLimit = this.LabourLimitProportion;
                            AmountHarvested *= labourLimit;

                            if (labourLimit < 1)
                            {
                                this.Status = ActivityStatus.Partial;
                            }

                            // now limit further by fees not paid
                            double financeLimit = this.LimitProportion(typeof(Finance));


                            limiter.AddWeightCarried(AmountHarvested);
                        }

                        if (AmountHarvested > 0)
                        {
                            double percentN = 0;
                            // if no nitrogen provided form file
                            if (double.IsNaN(NextHarvest.Npct))
                            {
                                if (LinkedResourceItem.GetType() == typeof(GrazeFoodStoreType))
                                {
                                    // grazed pasture with no N read assumes the green biomass N content
                                    percentN = (LinkedResourceItem as GrazeFoodStoreType).GreenNitrogen;
                                }
                            }
                            else
                            {
                                percentN = NextHarvest.Npct;
                            }

                            if (percentN == 0)
                            {
                                //Add without adding any new nitrogen.
                                //The nitrogen value for this feed item in the store remains the same.
                                LinkedResourceItem.Add(AmountHarvested, this, addReason);
                            }
                            else
                            {
                                FoodResourcePacket packet = new FoodResourcePacket()
                                {
                                    Amount   = AmountHarvested,
                                    PercentN = percentN
                                };
                                if (LinkedResourceItem.GetType() == typeof(GrazeFoodStoreType))
                                {
                                    packet.DMD = (LinkedResourceItem as GrazeFoodStoreType).EstimateDMD(packet.PercentN);
                                }
                                LinkedResourceItem.Add(packet, this, addReason);
                            }
                            SetStatusSuccess();
                        }
                        else
                        {
                            if (Status == ActivityStatus.Success)
                            {
                                Status = ActivityStatus.NotNeeded;
                            }
                        }
                    }
                }
                else
                {
                    this.Status = ActivityStatus.NotNeeded;
                }
            }
            else
            {
                this.Status = ActivityStatus.NotNeeded;
            }
        }