/// <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); }
/// <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); }
/// <summary> /// Calculates rating which depends on final and initial price. /// </summary> /// <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 SteamGameInfo)) { throw new ArgumentException( $"Element type is invalid for appraiser with type {TypeId.FullName}" ); } var converted = rawData.Select(e => (SteamGameInfo)e); foreach (SteamGameInfo entityInfo in converted) { double ratingValue = decimal.ToDouble(entityInfo.Price) - entityInfo.VoteAverage; 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); }