public IEnumerable <RecommendationSimple> GetRecommendationSimplesByScenarioIdAndProcessors(Guid scenarioId, IEnumerable <string> processors)
 {
     lock (_session)
     {
         List <RecommendationSimple> results = _session
                                               .GetAllWithTransform <Recommendation, RecommendationSimple_Transformer, RecommendationSimple>(
             recommendation =>
             recommendation.ScenarioId == scenarioId &&
             recommendation.Processor.In(processors),
             indexName: Recommendations_Default.DefaultIndexName, isMapReduce: false);
         return(results);
     }
 }
Exemple #2
0
        public IEnumerable <Scenario> GetByPassId(int passId)
        {
            lock (_session)
            {
                var scenariosWithPassId = _session.GetAllWithTransform <Scenario, ScenariosWithPassId_Transformer, ScenariosWithPassIdTransformerResult>(scenario => scenario.Id != Guid.Empty,
                                                                                                                                                         indexName: Scenarios_Default.DefaultIndexName, isMapReduce: false).ToList();

                var scenarioIdsForPassId = scenariosWithPassId.Where(swp => swp.PassId == passId).Select(swp => swp.ScenarioId).Distinct();
                if (scenarioIdsForPassId.Any())
                {
                    var scenarios = _session.Query <Scenario>().Where(s => s.Id.In(scenarioIdsForPassId));
                    return(scenarios);
                }
                return(new List <Scenario>());
            }
        }
Exemple #3
0
 private IEnumerable <FunctionalAreaFaultTypes_Transformer.Result> FunctionalAreaFaultTypesTransformerResult(
     Func <FunctionalAreaFaultTypes_Transformer.Result, bool> condition) => _session
 .GetAllWithTransform <FunctionalArea, FunctionalAreaFaultTypes_Transformer,
                       FunctionalAreaFaultTypes_Transformer.Result>(f => f.Id != Guid.Empty,
                                                                    FunctionalAreas_Default.DefaultIndexName, false)
 .Where(condition);
Exemple #4
0
        /// <summary>
        /// Checks the Demographic/SalesArea/ScheduleDay where there are not ratings prediction for all 96 slots in a day (4 x 24).
        /// Checks that there are the expected number of documents for each date and sales area in the run.
        /// </summary>
        /// <param name="fromDateTime"></param>
        /// <param name="toDateTime"></param>
        /// <param name="salesAreaNames"></param>
        /// <param name="demographicsNames"></param>
        /// <param name="noOfRatingPredictionsPerScheduleDayAreaDemo"></param>
        /// <returns>List of messages for any errors in the document collection </returns>
        public List <RatingsPredictionValidationMessage> Validate_RatingsPredictionSchedules(DateTime fromDateTime, DateTime toDateTime,
                                                                                             IEnumerable <string> salesAreaNames, IEnumerable <string> demographicsExtRefs, int noOfRatingPredictionsPerScheduleDayAreaDemo)
        {
            TimeSpan spanOfDays    = toDateTime.Date - fromDateTime.Date;
            int      noOfDaysInRun = spanOfDays.Days + 1; //inclusive of fromDate

            var messages = new List <RatingsPredictionValidationMessage>();

            lock (_session)
            {
                //get all the ratingspredictionschedules documents (transformed group of salesArea,scheduledDay,demographic - count) by date range of run and all the sales areas passed in
                //added 1 day to toDateTime in order to overcome the wierd comparison result of [schedule.ScheduleDay <= toDateTime.Date] where the last day of data was missing
                var allRatingsScheduleInDateRange = _session.GetAllWithTransform <RatingsPredictionSchedule, RatingsPredictionSchedule_TransformerRating,
                                                                                  RatingsPredictionSchedule_TransformerRating.Result>
                                                        (schedule => schedule.ScheduleDay >= fromDateTime.Date && schedule.ScheduleDay <= toDateTime.Date.AddDays(1) && schedule.SalesArea.In(salesAreaNames),
                                                        indexName: RatingsPredictionsSchedules_BySalesAreaScheduleDay.DefaultIndexName, isMapReduce: false);

                //then filter by the demographics enabled for gameplan
                var allRatingsScheduleForDemographicsEnabled = allRatingsScheduleInDateRange.Where(r => r.Demographic.In(demographicsExtRefs)).ToList();

                //check that we have 96 (4 x 24) ratings for each day for each sales area, report where we dont
                //(this could be less than 96 where individual ratings are missing from a document or more than 96 say 192 for duplicate documents)
                var _incorrectRatings = allRatingsScheduleForDemographicsEnabled.Where(r => r.Count != noOfRatingPredictionsPerScheduleDayAreaDemo).ToList();
                foreach (var item in _incorrectRatings)
                {
                    messages.Add(new RatingsPredictionValidationMessage {
                        Message = $"Count: {item.Count} for Demographic: {item.Demographic}, incorrect in Sales Area: " +
                                  $"{item.SalesArea}, in Schedule Day: {item.ScheduleDay.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)}"
                    });
                }

                // check for missing whole documents by date and sales area from the above in memory collection
                var missingRatingPredictionDays = new List <string>();
                foreach (string salesAreaName in salesAreaNames)
                {
                    for (int i = 0; i < noOfDaysInRun; i++)
                    {
                        var ratingsScheduleForThisDay = allRatingsScheduleForDemographicsEnabled.Where(r =>
                                                                                                       r.SalesArea == salesAreaName &&
                                                                                                       r.ScheduleDay == fromDateTime.Date.AddDays(i)).ToList();

                        if (ratingsScheduleForThisDay.Count == 0)
                        {
                            missingRatingPredictionDays.Add(fromDateTime.Date.AddDays(i).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture));
                        }
                    }

                    if (missingRatingPredictionDays.Any())
                    {
                        messages.Add(new RatingsPredictionValidationMessage
                        {
                            SeverityLevel = ValidationSeverityLevel.Warning,
                            Message       = $"Missing Schedule Days: {string.Join(", ", missingRatingPredictionDays)} for the following Sales Area: {salesAreaName}"
                        });

                        missingRatingPredictionDays.Clear();
                    }
                }

                return(messages);
            }
        }