/// <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> /// Makes prior analysis through normalizers and calculates ratings based on average vote /// and vote count. /// </summary> /// <param name="rawDataContainer">Entities to appraise with additional parameters.</param> /// <param name="outputResults">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> public virtual ResultList GetRatings(RawDataContainer rawDataContainer, bool outputResults) { CheckRatingId(); var ratings = new ResultList(); IReadOnlyList <BasicInfo> rawData = rawDataContainer.GetData(); if (rawData.IsNullOrEmpty()) { return(ratings); } MinMaxDenominator voteCountMMD = rawDataContainer.GetParameter("VoteCount"); MinMaxDenominator voteAverageMMD = rawDataContainer.GetParameter("VoteAverage"); foreach (BasicInfo entityInfo in rawData) { double ratingValue = CalculateRating(entityInfo, voteCountMMD, voteAverageMMD); var resultInfo = new ResultInfo(entityInfo.ThingId, ratingValue, RatingId); ratings.Add(resultInfo); if (outputResults) { GlobalMessageHandler.OutputMessage(resultInfo.ToString()); } } ratings.Sort((x, y) => y.RatingValue.CompareTo(x.RatingValue)); return(ratings); }
/// <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); _priceMMD = rawDataContainer.GetParameter(nameof(SteamGameInfo.Price)); }
/// <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)); }
/// <inheritdoc /> /// <remarks> /// Considers popularity value in addition to average vote and vote count. /// </remarks> /// <exception cref="ArgumentException"> /// <paramref name="rawDataContainer" /> contains instances of invalid type for this /// appraiser. /// </exception> public override ResultList GetRatings(RawDataContainer rawDataContainer, bool outputResults) { CheckRatingId(); var ratings = new ResultList(); IReadOnlyList <BasicInfo> rawData = rawDataContainer.GetData(); if (rawData.IsNullOrEmpty()) { return(ratings); } // Check if list have proper type. if (!rawData.All(e => e is TmdbMovieInfo)) { throw new ArgumentException( $"Element type is invalid for appraiser with type {TypeId.FullName}" ); } MinMaxDenominator voteCountMMD = rawDataContainer.GetParameter("VoteCount"); MinMaxDenominator voteAverageMMD = rawDataContainer.GetParameter("VoteAverage"); MinMaxDenominator popularityMMD = rawDataContainer.GetParameter("Popularity"); var converted = rawData.Select(e => (TmdbMovieInfo)e); foreach (TmdbMovieInfo entityInfo in converted) { double ratingValue = CalculateRating(entityInfo, voteCountMMD, voteAverageMMD, popularityMMD); 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); }