コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ClientFlightPlacement" /> class.
        /// </summary>
        /// <param name="client">the client</param>
        /// <param name="flight">the flight</param>
        /// <param name="placement">the placement</param>
        /// <param name="placementSequence">the placementSequence</param>
        /// <param name="rules">the rules</param>
        /// <param name="rankingGroupId">the rankingGroupId</param>
        /// <param name="rankingGroupVersion">the rankingGroupVersion</param>
        public ClientFlightPlacement(Client client, Flight flight, string placement, byte placementSequence, XElement rules, string rankingGroupId, int rankingGroupVersion)
        {
            ClientId          = client.Id;
            ClientAppId       = client.App;
            FlightId          = flight.Id;
            FlightVersion     = flight.Version;
            Placement         = placement;
            Key               = GetKey(Client.GetKey(ClientId, ClientAppId), Flight.GetKey(FlightId, FlightVersion), Placement);
            PlacementSequence = placementSequence;
            Rules             = rules;

            DealsCountForRandomization = QueryRanking.DefaultDealsCountForRandomization;
            var dealsCountForRandomizationNode = Rules.Descendants("DealsCountForRandomization").FirstOrDefault();

            if (dealsCountForRandomizationNode != null)
            {
                int dealsCountForRandomization;
                var randomizeResultsValue = dealsCountForRandomizationNode.Attribute("Value").Value;
                if (int.TryParse(randomizeResultsValue, out dealsCountForRandomization))
                {
                    DealsCountForRandomization = dealsCountForRandomization;
                }
                else
                {
                    Log.Error("Incorrect NumberOfTopDealsToRandomize value in configuration: {0}", randomizeResultsValue);
                }
            }

            FallbackToOnlineDeals = true;
            var fallbackToOnlineDealsNode = Rules.Descendants("FallbackToOnlineDeals").FirstOrDefault();

            if (fallbackToOnlineDealsNode != null)
            {
                bool fallbackToOnlineDeals;
                var  fallbackToOnlineDealsValue = fallbackToOnlineDealsNode.Attribute("Value").Value;
                if (bool.TryParse(fallbackToOnlineDealsValue, out fallbackToOnlineDeals))
                {
                    FallbackToOnlineDeals = fallbackToOnlineDeals;
                }
                else
                {
                    Log.Error("Incorrect FallbackToOnlineDeals value in configuration: {0}", fallbackToOnlineDealsValue);
                }
            }

            var countNode = Rules.Descendants("DefaultDealsCount").FirstOrDefault();

            DefaultDealsCount   = countNode == null ? (byte)50 : byte.Parse(countNode.Value);
            RankingGroupId      = rankingGroupId;
            RankingGroupVersion = rankingGroupVersion;
            RankingGroupKey     = RankingGroup.GetKey(RankingGroupId, RankingGroupVersion);
        }
コード例 #2
0
        /// <summary>
        /// Gets Rank Weight
        /// </summary>
        /// <param name="rankingGroup">the rule</param>
        /// <param name="providerId">provider id</param>
        /// <param name="subProviderId">sub provider id</param>
        /// <param name="categories">category names</param>
        /// <param name="dealtype">the deal type</param>
        /// <returns>rank weight</returns>
        private static double GetRankWeight(RankingGroup rankingGroup, string providerId, string subProviderId, IList <string> categories, int dealtype)
        {
            var subProviderKey = string.IsNullOrEmpty(subProviderId) ? null : providerId + "/" + subProviderId.ToLower();

            var wP = rankingGroup.DefaultProviderWeight;

            foreach (var exception in rankingGroup.ExceptionProviderWeights)
            {
                if (string.Equals(exception.Provider, providerId, StringComparison.OrdinalIgnoreCase)
                    ||
                    (subProviderId != null && string.Equals(exception.Provider, subProviderKey, StringComparison.OrdinalIgnoreCase)))
                {
                    wP = exception.Weight;
                    break;
                }
            }

            var wC = rankingGroup.DefaultCategoryWeight;

            foreach (var exception in rankingGroup.ExceptionCategoryWeights)
            {
                if (categories.Any(_ => string.Equals(exception.Category, _, StringComparison.OrdinalIgnoreCase)))
                {
                    wC = exception.Weight;
                    break;
                }
            }

            var wDt = rankingGroup.DefaultDealTypeWeight;

            foreach (var exception in rankingGroup.ExceptionDealTypeWeights)
            {
                if (exception.DealType == dealtype)
                {
                    wDt = exception.Weight;
                    break;
                }
            }

            return(wP * wC * wDt);
        }
コード例 #3
0
        /// <summary>
        /// Checks whether Campaign Rule is Satisfied
        /// </summary>
        /// <param name="deal">the deal</param>
        /// <param name="rankingGroup">the rule</param>
        /// <returns>value indicating whether rule is satisfied</returns>
        private static bool AreRankingGroupRulesSatisfied(Deal deal, RankingGroup rankingGroup)
        {
            var res = false;

            if (deal.DealType != DealType.CardLinkDeal // don't go through checks for card link deals
                &&
                (rankingGroup.ImageHeight != null ||
                 rankingGroup.PriceMinimum != null ||
                 rankingGroup.DiscountMinimum != null ||
                 rankingGroup.Categories.Any() ||
                 rankingGroup.Keywords.Any() ||
                 rankingGroup.ProblematicDealTitlePatterns.Any()))
            {
                do
                {
                    // check image dimensions
                    if (rankingGroup.ImageHeight != null && deal.Images == null)
                    {
                        break;
                    }

                    if (rankingGroup.ImageHeight != null
                        &&
                        !deal.Images.Any(_ => _.ImageStatus == ImageStatusType.GoodImage &&
                                         _.Height >= rankingGroup.ImageHeight &&
                                         _.Width >= rankingGroup.ImageWidth))
                    {
                        break;
                    }

                    // check value
                    if (rankingGroup.PriceMinimum != null && deal.Price < rankingGroup.PriceMinimum)
                    {
                        break;
                    }

                    if (deal.DealInfo == null)
                    {
                        break;
                    }

                    if (rankingGroup.DiscountMinimum != null &&
                        deal.DealInfo.VoucherDiscountPercent < rankingGroup.DiscountMinimum)
                    {
                        break;
                    }

                    // check content
                    if (rankingGroup.Categories.Any()
                        &&
                        !deal.Categories.Any(_ => rankingGroup.Categories.Any(rc => string.Equals(rc, _.CategoryName))))
                    {
                        break;
                    }

                    if (rankingGroup.Keywords.Any())
                    {
                        if (!rankingGroup.Keywords.Any(_ => deal.Description.Contains(_) || deal.Title.Contains(_)))
                        {
                            break;
                        }
                    }

                    if (rankingGroup.ProblematicDealTitlePatterns.Any() && deal.Title != null)
                    {
                        // match title or businessname
                        if (
                            rankingGroup.ProblematicDealTitlePatterns.Any(
                                _ => ((new Regex(_, RegexOptions.IgnoreCase)).IsMatch(deal.Title)
                                      ||
                                      (deal.Business != null &&
                                       new Regex(_, RegexOptions.IgnoreCase).IsMatch(deal.Business.Name)))))
                        {
                            break;
                        }
                    }

                    res = true;
                }while (false);
            }
            else
            {
                res = true;
            }

            return(res);
        }