Ejemplo n.º 1
0
 private void OnCLEMStartOfTimeStep(object sender, EventArgs e)
 {
     // get next harvest and store previous harvest
     while (HarvestData.Count() > 0 && Clock.Today.Year * 100 + Clock.Today.Month > HarvestData.First().Year * 100 + HarvestData.First().Month)
     {
         PreviousHarvest = HarvestData.FirstOrDefault();
         HarvestData.RemoveAt(0);
     }
     NextHarvest = HarvestData.FirstOrDefault();
 }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
0
        private void OnCLEMStartOfTimeStep(object sender, EventArgs e)
        {
            // if harvest tags provided for this crop then they will be used to define previous, next etc

            // while date month > harvest record look for previous and delete past events

            if (HarvestData.Count() > 0)
            {
                int clockYrMth = CalculateYearMonth(Clock.Today);
                int position; // passed -1, current 0, future 1
                do
                {
                    int harvestYrMth = CalculateYearMonth(HarvestData.First().HarvestDate);
                    position = (clockYrMth > harvestYrMth) ? -1 : ((clockYrMth == harvestYrMth) ? 0 : 1);

                    // check for valid sequence
                    if (HarvestTagsUsed && HarvestData.FirstOrDefault().HarvestType != "")
                    {
                        if (previousTag == HarvestData.FirstOrDefault().HarvestType)
                        {
                            string warn = $"Invalid sequence of HarvetTags detected in [a={this.Name}]\r\nEnsure tags are ordered first, last in sequence.";
                            if (!Warnings.Exists(warn))
                            {
                                Summary.WriteWarning(this, warn);
                                Warnings.Add(warn);
                            }
                        }
                        previousTag = HarvestData.FirstOrDefault().HarvestType;
                    }


                    switch (position)
                    {
                    case -1:
                        if (HarvestTagsUsed)
                        {
                            switch (HarvestData.FirstOrDefault().HarvestType)
                            {
                            case "first":
                                if (!performedHarvest)
                                {
                                    InsideMultiHarvestSequence  = true;
                                    StartCurrentSequenceHarvest = HarvestData.FirstOrDefault();
                                    EndCurrentSequenceHarvest   = HarvestData.Where(a => a.HarvestType == "last").FirstOrDefault();
                                }
                                break;

                            case "last":
                                // hit tagged last to delete as we've passed this date so out of multi harvest sequence
                                InsideMultiHarvestSequence = false;
                                PreviousHarvest            = HarvestData.FirstOrDefault();
                                break;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            PreviousHarvest = HarvestData.FirstOrDefault();
                        }
                        HarvestData.RemoveAt(0);
                        break;

                    case 0:
                        performedHarvest = true;
                        if (HarvestTagsUsed)
                        {
                            switch (HarvestData.FirstOrDefault().HarvestType)
                            {
                            case "first":
                                // hit tagged first for current time step
                                InsideMultiHarvestSequence  = true;
                                StartCurrentSequenceHarvest = HarvestData.FirstOrDefault();
                                PreviousHarvest             = null;
                                EndCurrentSequenceHarvest   = HarvestData.Where(a => a.HarvestType == "last").FirstOrDefault();
                                break;

                            default:
                                NextHarvest     = HarvestData.FirstOrDefault();
                                PreviousHarvest = null;
                                break;
                            }
                        }
                        else
                        {
                            NextHarvest     = HarvestData.FirstOrDefault();
                            PreviousHarvest = null;
                        }
                        break;

                    case 1:
                        if (HarvestTagsUsed)
                        {
                            switch (HarvestData.FirstOrDefault().HarvestType)
                            {
                            case "first":
                                // hit tagged first for next harvest
                                NextHarvest = HarvestData.FirstOrDefault();
                                break;

                            default:
                                NextHarvest = HarvestData.FirstOrDefault();
                                break;
                            }
                        }
                        else
                        {
                            NextHarvest = HarvestData.FirstOrDefault();
                        }
                        break;

                    default:
                        break;
                    }
                } while (HarvestData.Count > 0 && position == -1);
            }
        }