Beispiel #1
0
        private void OnCLEMInitialiseResource(object sender, EventArgs e)
        {
            // setup price list
            // initialise herd price list
            PriceList = new List <AnimalPriceValue>();

            foreach (AnimalPricing priceGroup in Apsim.Children(this, typeof(AnimalPricing)))
            {
                SirePrice = priceGroup.BreedingSirePrice;
                foreach (AnimalPriceEntry price in Apsim.Children(priceGroup, typeof(AnimalPriceEntry)))
                {
                    AnimalPriceValue val = new AnimalPriceValue();
                    val.Age           = price.Age;
                    val.PurchaseValue = price.PurchaseValue;
                    val.Gender        = price.Gender;
                    val.Breed         = this.Breed;
                    val.SellValue     = price.SellValue;
                    val.Style         = priceGroup.PricingStyle;
                    PriceList.Add(val);
                }
            }
            PriceList = PriceList.OrderBy(a => a.Age).ToList();

            // get advanced conception parameters
            List <RuminantConceptionAdvanced> concepList = Apsim.Children(this, typeof(RuminantConceptionAdvanced)).Cast <RuminantConceptionAdvanced>().ToList();

            if (concepList.Count == 1)
            {
                AdvancedConceptionParameters = concepList.FirstOrDefault();
            }
        }
Beispiel #2
0
 /// <summary>
 /// Get value of a specific individual
 /// </summary>
 /// <returns>value</returns>
 public double ValueofIndividual(Ruminant ind, bool PurchasePrice)
 {
     if (PricingAvailable())
     {
         // ordering now done when the list is created for speed
         //AnimalPriceValue getvalue = PriceList.Where(a => a.Age < ind.Age).OrderBy(a => a.Age).LastOrDefault();
         AnimalPriceValue getvalue = PriceList.Where(a => a.Age <= ind.Age).LastOrDefault();
         if (getvalue == null)
         {
             getvalue = PriceList.OrderBy(a => a.Age).FirstOrDefault();
             Summary.WriteWarning(this, "No pricing was found for indiviudal [" + ind.HerdName + "] of age [" + ind.Age + "]");
             Summary.WriteWarning(this, "Using pricing for individual of age [" + getvalue.Age + "]");
         }
         if (PurchasePrice)
         {
             return(getvalue.PurchaseValue * ((getvalue.Style == PricingStyleType.perKg) ? ind.Weight : 1.0));
         }
         else
         {
             return(getvalue.SellValue * ((getvalue.Style == PricingStyleType.perKg) ? ind.Weight : 1.0));
         }
     }
     else
     {
         return(0);
     }
 }