Exemplo n.º 1
0
 /// <summary>
 /// A common method to get the labour resource requests from the activity.
 /// </summary>
 /// <returns></returns>
 protected List<ResourceRequest> GetLabourResourcesNeededForActivity()
 {
     List<ResourceRequest> labourResourceRequestList = new List<ResourceRequest>();
     foreach (LabourRequirement item in FindAllChildren<LabourRequirement>())
     {
         GetDaysLabourRequiredReturnArgs daysResult = GetDaysLabourRequired(item);
         if (daysResult.DaysNeeded > 0)
         {
             foreach (LabourFilterGroup fg in item.FindAllChildren<LabourFilterGroup>())
             {
                 int numberOfPpl = 1;
                 if (item.ApplyToAll)
                     // how many matches
                     numberOfPpl = fg.Filter(Resources.FindResourceGroup<Labour>().Items).Count();
                 for (int i = 0; i < numberOfPpl; i++)
                 {
                     labourResourceRequestList.Add(new ResourceRequest()
                     {
                         AllowTransmutation = true,
                         Required = daysResult.DaysNeeded,
                         ResourceType = typeof(Labour),
                         ResourceTypeName = "",
                         ActivityModel = this,
                         FilterDetails = new List<object>() { fg },
                         Category = daysResult.Category,
                         RelatesToResource = daysResult.RelatesToResource
                     }
                     ); ;
                 }
             }
         }
     }
     return labourResourceRequestList;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Determine the labour required for this activity based on LabourRequired items in tree
        /// </summary>
        /// <param name="requirement">Labour requirement model</param>
        /// <returns></returns>
        public override GetDaysLabourRequiredReturnArgs GetDaysLabourRequired(LabourRequirement requirement)
        {
            IEnumerable <Ruminant> herd = CurrentHerd(false);
            double daysNeeded           = 0;
            var    returnArgs           = new GetDaysLabourRequiredReturnArgs(daysNeeded, TransactionCategory, this.PredictedHerdName);

            if (requirement.UnitType == LabourUnitType.Fixed)
            {
                returnArgs.DaysNeeded = requirement.LabourPerUnit;
            }
            else
            {
                foreach (RuminantGroup item in filterGroups)
                {
                    int head = item.Filter(GetIndividuals <Ruminant>(GetRuminantHerdSelectionStyle.NotMarkedForSale).Where(a => a.Weaned == false)).Count();
                    switch (requirement.UnitType)
                    {
                    case LabourUnitType.Fixed:
                        break;

                    case LabourUnitType.perHead:
                        daysNeeded += head * requirement.LabourPerUnit;
                        break;

                    case LabourUnitType.perUnit:
                        double numberUnits = head / requirement.UnitSize;
                        if (requirement.WholeUnitBlocks)
                        {
                            numberUnits += Math.Ceiling(numberUnits);
                        }

                        daysNeeded = numberUnits * requirement.LabourPerUnit;
                        break;

                    default:
                        throw new Exception(String.Format("LabourUnitType {0} is not supported for {1} in {2}", requirement.UnitType, requirement.Name, this.Name));
                    }
                }
            }
            return(returnArgs);
        }
Exemplo n.º 3
0
        /// <summary>
        /// A common method to get the labour resource requests from the activity.
        /// </summary>
        /// <returns></returns>
        protected List <ResourceRequest> GetLabourResourcesNeededForActivity()
        {
            List <ResourceRequest> labourResourceRequestList = new List <ResourceRequest>();

            foreach (LabourRequirement item in Children.Where(a => a.GetType() == typeof(LabourRequirement) | a.GetType().IsSubclassOf(typeof(LabourRequirement))))
            {
                GetDaysLabourRequiredReturnArgs daysResult = GetDaysLabourRequired(item);
                if (daysResult.DaysNeeded > 0)
                {
                    foreach (LabourFilterGroup fg in item.Children.OfType <LabourFilterGroup>())
                    {
                        int numberOfPpl = 1;
                        if (item.ApplyToAll)
                        {
                            // how many matches
                            numberOfPpl = (Resources.GetResourceGroupByType(typeof(Labour)) as Labour).Items.Filter(fg).Count();
                        }
                        for (int i = 0; i < numberOfPpl; i++)
                        {
                            labourResourceRequestList.Add(new ResourceRequest()
                            {
                                AllowTransmutation = true,
                                Required           = daysResult.DaysNeeded,
                                ResourceType       = typeof(Labour),
                                ResourceTypeName   = "",
                                ActivityModel      = this,
                                FilterDetails      = new List <object>()
                                {
                                    fg
                                },
                                Category          = daysResult.Category,
                                RelatesToResource = daysResult.RelatesToResource
                            }
                                                          );;
                        }
                    }
                }
            }
            return(labourResourceRequestList);
        }