Esempio n. 1
0
        public RatingResult Compute(IList <RestaurantReview> reviews)
        {
            var result = new RatingResult();

            if (reviews.Any())
            {
                var counter = 0;
                var total   = 0;

                for (int i = 0; i < reviews.Count; i++)
                {
                    if (i < reviews.Count / 2)
                    {
                        total   += reviews[i].Rating * 2;
                        counter += 2;
                    }
                    else
                    {
                        total += reviews[i].Rating;
                        counter++;
                    }
                }

                result.Rating = total / counter;
            }
            else
            {
                result.Rating = null;
            }

            return(result);
        }
        public RatingResult Compute(IList <RestaurantReview> reviews)
        {
            var result = new RatingResult();

            if (reviews.Any())
            {
                result.Rating = reviews.Average(r => r.Rating);
            }
            else
            {
                result.Rating = null;
            }

            return(result);
        }