/// <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)); }
/// <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)); }
/// <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)); }
/// <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); }