Пример #1
0
        //This is temporary solution to identify DayPart by it's DOW and Time
        //Example of dowTimeString: "2100-2659(Mon-Fri)"
        //Will be removed in scope of technical debt (XGGT-16613) and DayParts will receive identifier guid
        public static DayPart GetDayPartByDowTimeString(List <DayPart> dayParts, string dowTimeString)
        {
            if (dayParts is null || dowTimeString is null ||
                dowTimeString == "NotSupplied" || dowTimeString.Length < 18)
            {
                return(null);
            }

            var AgFromTime = dowTimeString.Substring(0, 4);

            var AgToTime = dowTimeString.Substring(5, 4);

            var firstDOW = dowTimeString.Substring(10, 3);

            var lastDOW = dowTimeString.Substring(14, 3);

            var fromTime = AgConversions.ParseTotalHHMMSSFormat(AgFromTime + "00", false).ToString(@"hh\:mm");

            var toTime = AgConversions.ParseTotalHHMMSSFormat(AgToTime + "59", false).ToString(@"hh\:mm");

            return(dayParts.Where(d
                                  => d.Timeslices.Any(t => t.FromTime == fromTime && t.ToTime == toTime &&
                                                      t.DowPattern.Contains(firstDOW) && t.DowPattern.Contains(lastDOW)))
                   .FirstOrDefault());
        }
Пример #2
0
        public TenantSettingsProfile()
        {
            CreateMap <TenantSettings, TenantSettingsEntity>()
            .ForMember(dest => dest.PeakStartTime,
                       opt => opt.MapFrom(src => AgConversions.ParseHHMMSSFormat(src.PeakStartTime)))
            .ForMember(dest => dest.PeakEndTime,
                       opt => opt.MapFrom(src => AgConversions.ParseHHMMSSFormat(src.PeakEndTime)))
            .ForMember(dest => dest.MidnightStartTime,
                       opt => opt.MapFrom(src => AgConversions.ParseTotalHHMMSSFormat(src.MidnightStartTime, true)))
            .ForMember(dest => dest.MidnightEndTime,
                       opt => opt.MapFrom(src => AgConversions.ParseTotalHHMMSSFormat(src.MidnightEndTime, true)))
            .ReverseMap()
            .ForMember(dest => dest.PeakStartTime,
                       opt => opt.MapFrom(src => AgConversions.ToAgTimeAsHHMMSS(src.PeakStartTime)))
            .ForMember(dest => dest.PeakEndTime,
                       opt => opt.MapFrom(src => AgConversions.ToAgTimeAsHHMMSS(src.PeakEndTime)))
            .ForMember(dest => dest.MidnightStartTime,
                       opt => opt.MapFrom(src => AgConversions.ToAgTimeAsTotalHHMMSS(src.MidnightStartTime)))
            .ForMember(dest => dest.MidnightEndTime,
                       opt => opt.MapFrom(src => AgConversions.ToAgTimeAsTotalHHMMSS(src.MidnightEndTime)));

            CreateMap <RunRestrictions, RunRestrictionsEntity>()
            .ReverseMap();

            CreateMap <MinimumRunSizeDocumentRestriction, MinimumRunSizeDocumentRestrictionEntity>()
            .ReverseMap();

            CreateMap <MinimumDocumentRestriction, MinimumDocumentRestrictionEntity>()
            .ReverseMap();

            CreateMap <RunEventSettings, RunEventSettingsEntity>()
            .ReverseMap();

            CreateMap <HTTPNotificationSettings, HTTPNotificationSettingsEntity>()
            .ReverseMap();

            CreateMap <HTTPMethodSettings, HTTPMethodSettingsEntity>()
            .ReverseMap();

            CreateMap <Feature, FeatureEntity>()
            .ForMember(dest => dest.IdValue, opt => opt.MapFrom(src => src.Id))
            .ForMember(dest => dest.Id, opt => opt.Ignore())
            .ReverseMap()
            .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.IdValue))
            .ForMember(dest => dest.Settings,
                       opt => opt.MapFrom(src => src.Settings.ToDictionary(x => x.Key, x => (object)x.Value)))
            ;

            CreateMap <WebhookSettings, WebhookSettingsEntity>()
            .ReverseMap();
        }
        /// <summary>Generates the report data.</summary>
        /// <param name="source">The source.</param>
        /// <returns></returns>
        public IReadOnlyCollection <RecommendationExtendedModel> GenerateReportData(IReadOnlyCollection <Recommendation> source)
        {
            if ((source?.Count ?? 0) == 0)
            {
                return(Array.Empty <RecommendationExtendedModel>());
            }

            PrepareRelatedData(source);

            var tenantSettings = ResolveTenantSettings();
            var startDayOfWeek = tenantSettings?.StartDayOfWeek ?? DayOfWeek.Monday;

            var peakStartTime     = AgConversions.ParseTotalHHMMSSFormat(tenantSettings?.PeakStartTime ?? DefaultTimeFormat);
            var peakEndTime       = AgConversions.ParseTotalHHMMSSFormat(tenantSettings?.PeakEndTime ?? DefaultTimeFormat);
            var midnightStartTime = new TimeSpan(0, 0, 0);
            var midnightEndTime   = new TimeSpan(6, 0, 0);

            return(source
                   .AsParallel()
                   .Select(item =>
            {
                var recommendationExtendedModel = new RecommendationExtendedModel();
                _ = _mapper.Map(item, recommendationExtendedModel);

                recommendationExtendedModel.StartDayOfWeek = startDayOfWeek.ToString();
                recommendationExtendedModel.WeekCommencingDate =
                    GetWeekCommencingDate(startDayOfWeek, item.StartDateTime);
                recommendationExtendedModel.DayPart = GetDayPart(item.StartDateTime, peakStartTime, peakEndTime,
                                                                 midnightStartTime, midnightEndTime);
                recommendationExtendedModel.StartDate = item.StartDateTime.Date;
                recommendationExtendedModel.StartTime = item.StartDateTime.TimeOfDay;
                recommendationExtendedModel.EndDate = item.EndDateTime.Date;
                recommendationExtendedModel.EndTime = item.EndDateTime.TimeOfDay;
                recommendationExtendedModel.SpotLengthInSec = item.SpotLength.TotalSeconds;

                if (String.Equals(item.Processor, SmoothProcessorName, StringComparison.OrdinalIgnoreCase))
                {
                    recommendationExtendedModel.ExternalBreakNo = String.IsNullOrEmpty(item.ExternalBreakNo)
                            ? Globals.UnplacedBreakString
                            : recommendationExtendedModel.ExternalBreakNo;
                }

                var campaign = ResolveCampaign(item);
                if (!(campaign is null))
                {
                    recommendationExtendedModel.SalesAreaGroupName = campaign.SalesAreaCampaignTarget?
                                                                     .Select(sact => sact.SalesAreaGroup)
                                                                     .FirstOrDefault(sag => sag?.SalesAreas?.Any(sa => sa.Equals(item.SalesArea)) ?? false)
                                                                     ?.GroupName;
                }

                if (recommendationExtendedModel.SalesAreaGroupName is null)
                {
                    var salesArea = ResolveSalesArea(item);
                    recommendationExtendedModel.SalesAreaGroupName = salesArea?.TargetAreaName;
                }

                var demographic = ResolveDemographic(item);
                if (!(demographic is null))
                {
                    recommendationExtendedModel.DemographicName = demographic.Name;
                }

                var product = ResolveProduct(item);
                if (!(product is null))
                {
                    recommendationExtendedModel.ClientName = product.AgencyName;
                    recommendationExtendedModel.ProductName = product.Name;

                    var childClash = ResolveClash(item);
                    if (!(childClash is null))
                    {
                        recommendationExtendedModel.ClashName = childClash.Description;

                        var parentClash = ResolveParentClash(item);
                        if (!(parentClash is null))
                        {
                            recommendationExtendedModel.ParentClashName = parentClash.Description;
                        }
                    }
                }

                return recommendationExtendedModel;
            }).ToArray());
        }