예제 #1
0
        /// <summary>
        /// Processes the data in accordance with the formulas.
        /// </summary>
        private RatingsStorage?AppraiseThings()
        {
            RatingsStorage?ratingsStorage = null;

            try
            {
                IReadOnlyList <RawDataContainer> results =
                    DataBaseManager.GetResultsFromDbWithAdditionalInfo();
                ProcessedDataContainer ratings = AppraisersManager.GetAllRatings(results);

                ratingsStorage = ratings.RatingsStorage;
                if (ratings.Data.Count == 0)
                {
                    GlobalMessageHandler.OutputMessage(
                        "Appraisers have not calculated ratings. Result is empty."
                        );
                    _status = ServiceStatus.Nothing;
                }
                else
                {
                    DataBaseManager.DeleteResultAndRatings();
                    DataBaseManager.PutRatingsToDb(ratings);

                    GlobalMessageHandler.OutputMessage(
                        "Appraisers have calculated ratings successfully."
                        );
                    _status = ServiceStatus.Ok;
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Exception occured during appraising work.");
                _status = ServiceStatus.AppraiseError;
            }

            return(ratingsStorage);
        }
예제 #2
0
        public void PutRatingsToDb(ProcessedDataContainer ratings)
        {
            foreach (Rating rating in ratings.RatingsStorage.GetAllRatings())
            {
                if (!_ratingRepository.Contains(rating.RatingId))
                {
                    _ratingRepository.InsertItem(rating);
                }
            }

            foreach (IReadOnlyList <ResultInfo> datum in ratings.Data)
            {
                // Skip empty collections of data.
                if (datum.IsNullOrEmpty())
                {
                    continue;
                }

                foreach (ResultInfo info in datum)
                {
                    _resultRepository.InsertItem(info);
                }
            }
        }