/// <summary>
        /// Extracts additional values to rating calculation from <see cref="RawDataContainer" />.
        /// </summary>
        /// <param name="rawDataContainer">
        /// The object which contains values to normalize properties.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="rawDataContainer" /> is <c>null</c> .
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Popularity characteristics do not contains in <paramref name="rawDataContainer" />.
        /// </exception>
        public void PrepareCalculation(RawDataContainer rawDataContainer)
        {
            rawDataContainer.ThrowIfNull(nameof(rawDataContainer));

            _basicAppraisal.PrepareCalculation(rawDataContainer);
            _metascoreMMD = rawDataContainer.GetParameter(nameof(OmdbMovieInfo.Metascore));
        }
Esempio n. 2
0
        /// <summary>
        /// Extracts additional values to rating calculation from <see cref="RawDataContainer" />.
        /// </summary>
        /// <param name="rawDataContainer">
        /// The object which contains values to normalize properties.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="rawDataContainer" /> is <c>null</c> .
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Vote count characteristics do not contains in <paramref name="rawDataContainer" />. -or-
        /// Vote average characteristics do not contains in <paramref name="rawDataContainer" />.
        /// </exception>
        public void PrepareCalculation(RawDataContainer rawDataContainer)
        {
            rawDataContainer.ThrowIfNull(nameof(rawDataContainer));

            _voteCountMMD   = rawDataContainer.GetParameter(nameof(BasicInfo.VoteCount));
            _voteAverageMMD = rawDataContainer.GetParameter(nameof(BasicInfo.VoteAverage));
        }
        /// <summary>
        /// Extracts additional values to rating calculation from <see cref="RawDataContainer" />.
        /// </summary>
        /// <param name="rawDataContainer">
        /// The object which contains values to normalize properties.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="rawDataContainer" /> is <c>null</c> .
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Popularity characteristics do not contains in <paramref name="rawDataContainer" />.
        /// </exception>
        public void PrepareCalculation(RawDataContainer rawDataContainer)
        {
            rawDataContainer.ThrowIfNull(nameof(rawDataContainer));

            _basicAppraisal.PrepareCalculation(rawDataContainer);
            _priceMMD = rawDataContainer.GetParameter(nameof(SteamGameInfo.Price));
        }
Esempio n. 4
0
        /// <summary>
        /// Extracts additional values to rating calculation from <see cref="RawDataContainer" />.
        /// </summary>
        /// <param name="rawDataContainer">
        /// The object which contains values to normalize properties.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="rawDataContainer" /> is <c>null</c> .
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Popularity characteristics do not contains in <paramref name="rawDataContainer" />.
        /// </exception>
        public void PrepareCalculation(RawDataContainer rawDataContainer)
        {
            rawDataContainer.ThrowIfNull(nameof(rawDataContainer));

            _basicAppraisal.PrepareCalculation(rawDataContainer);
            _popularityMMD = rawDataContainer.GetParameter(nameof(TmdbMovieInfo.Popularity));
        }
Esempio n. 5
0
        internal static IReadOnlyList <ResultInfo> CreateExpectedValueForBasicInfo(Guid ratingId,
                                                                                   RawDataContainer rawDataContainer, params BasicInfo[] items)
        {
            rawDataContainer.ThrowIfNull(nameof(rawDataContainer));
            items.ThrowIfNull(nameof(items));

            return(CreateExpectedValueForBasicInfo(ratingId, rawDataContainer,
                                                   items.AsEnumerable()));
        }
Esempio n. 6
0
        /// <summary>
        /// Makes prior analysis through prepare stage for strategy and then uses it to calculate
        /// ratings.
        /// </summary>
        /// <param name="rawDataContainer">
        /// The entities to appraise with additional parameters.
        /// </param>
        /// <param name="outputResults">The flag to define need to output.</param>
        /// <returns>Collection of result object (data object with rating).</returns>
        /// <remarks>
        /// Entities collection must be unique because rating calculation errors can occur in such
        /// situations.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="rawDataContainer" /> is <c>null</c>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="rawDataContainer" /> contains instances of invalid type for this
        /// appraiser.
        /// </exception>
        public IReadOnlyList <ResultInfo> GetRatings(RawDataContainer rawDataContainer,
                                                     bool outputResults)
        {
            rawDataContainer.ThrowIfNull(nameof(rawDataContainer));

            CheckRatingId();

            var ratings = new List <ResultInfo>();
            IReadOnlyList <BasicInfo> rawData = rawDataContainer.RawData;

            if (!rawData.Any())
            {
                return(ratings);
            }

            // Check if list have proper type.
            IReadOnlyList <T> converted = rawData.Select(e =>
            {
                if (!(e is T result))
                {
                    throw new ArgumentException(
                        $"Element \"{e.Title}\" (ID = {e.ThingId.ToString()}) type " +
                        $"\"{e.GetType().FullName}\" is invalid for appraiser with type " +
                        $"\"{TypeId.FullName}\"."
                        );
                }
                return(result);
            }).ToList();

            _appraisal.PrepareCalculation(rawDataContainer);

            foreach (T entityInfo in converted)
            {
                double ratingValue = _appraisal.CalculateRating(entityInfo);

                var resultInfo = new ResultInfo(entityInfo.ThingId, ratingValue, RatingId);
                ratings.Add(resultInfo);

                if (outputResults)
                {
                    GlobalMessageHandler.OutputMessage($"Appraised {resultInfo} by {Tag}.");
                }
            }

            ratings.Sort((x, y) => y.RatingValue.CompareTo(x.RatingValue));
            return(ratings);
        }
Esempio n. 7
0
        internal static IReadOnlyList <ResultInfo> CreateExpectedValueForBasicInfo(Guid ratingId,
                                                                                   RawDataContainer rawDataContainer, IEnumerable <BasicInfo> items)
        {
            rawDataContainer.ThrowIfNull(nameof(rawDataContainer));
            items.ThrowIfNull(nameof(items));

            var appraisal = new BasicAppraisal();

            appraisal.PrepareCalculation(rawDataContainer);

            var expectedValue = new List <ResultInfo>();

            foreach (BasicInfo item in items)
            {
                double expectedRating = appraisal.CalculateRating(item);
                var    expectedItem   = new ResultInfo(item.ThingId, expectedRating, ratingId);

                expectedValue.Add(expectedItem);
            }

            return(expectedValue);
        }