Ejemplo n.º 1
0
        //RAISE
        private void Raise(SourceSug suggestion, Result results)
        {
            if (!suggestion.Event_Date.HasValue)
            {
                throw new ArgumentNullException(nameof(suggestion.Event_Date));
            }

            var runRule = false;

            //Event within 7 days
            if (suggestion.EventDateWithin(SevenDays))
            {
                if (
                    //Change < $10 and sug has RAISE for past 2 days
                    (suggestion.ChangeLower(LowestChange) && HasForPast(TwoDays, suggestion))
                    //Change $10 ‐ $30 and sug has RAISE $10‐$30 for past 1 days
                    || (suggestion.ChangeHigher(LowestChange) && suggestion.ChangeLowerOrEquals(HighestChange) &&
                        HasForPast(OneDay, suggestion, LowestChange, HighestChange))
                    //Change > $30
                    || suggestion.ChangeHigher(HighestChange))
                {
                    runRule = true;
                }
            }
            //Event 7-30 days
            else if (suggestion.EventDateFromTo(SevenDays, ThirtyDays))
            {
                if (
                    //Change < $10 and sug has RAISE for past 4 days
                    (suggestion.ChangeLower(LowestChange) && HasForPast(FourDays, suggestion))
                    //Change $10 ‐ $30 and sug has RAISE $10‐$30 for past 3 days
                    || (suggestion.ChangeHigherOrEquals(LowestChange) && suggestion.ChangeLowerOrEquals(HighestChange) &&
                        HasForPast(ThreeDays, suggestion, LowestChange, HighestChange))
                    //Change > $30 and sug has RAISE +/‐ $10 for past 2 days
                    || (suggestion.ChangeHigher(HighestChange) && HasForPast(TwoDays, suggestion, LowestChange)))
                {
                    runRule = true;
                }
            }
            //Event > 30 days
            else
            {
                if (
                    //Change < $10 and sug has RAISE for past 6 days
                    (suggestion.ChangeLower(LowestChange) && HasForPast(SixDays, suggestion))
                    //Change $10 ‐ $30 and sug has RAISE $10‐$30 for past 5 days
                    || (suggestion.ChangeHigher(LowestChange) && suggestion.ChangeLowerOrEquals(HighestChange) &&
                        HasForPast(FiveDays, suggestion, LowestChange, HighestChange))
                    //Change > $30 and sug has RAISE +/‐ $10 for past 4 days
                    || (suggestion.ChangeHigher(HighestChange) && HasForPast(FourDays, suggestion, LowestChange)))
                {
                    runRule = true;
                }
            }
            SaveResultToDatabase(suggestion, results, runRule);
        }
Ejemplo n.º 2
0
        //LOWER
        private void Lower(SourceSug sug, Result results)
        {
            if (sug == null)
            {
                throw new ArgumentNullException(nameof(sug));
            }

            sug.CheckRequiredFields(price: false, sugPrice: true, runDate: false, eventDate: false);

            //Any listings that are suggested for lower than $30 should be priced at $30, don’t run rule
            if (sug.SugPrice < MinPrice)
            {
                sug.Price = MinPrice;

                SaveResultToDatabase(sug, results, runRule: true);

                OnEventHappened(SuggestionRulesStrings.Lower + ": SugPrice is lower than " + MinPrice + "$! Price was set to " + MinPrice + "$.");
                return;
            }

            sug.CheckRequiredFields(price: true, sugPrice: false, runDate: false, eventDate: true);

            var runRule = false;

            //Event within 7 days
            if (sug.EventDateWithin(SevenDays))
            {
                if (
                    //Change < $10 and sug has LOWER for past 2 days
                    (sug.ChangeLower(LowestChange) && HasForPast(TwoDays, sug))
                    //Change $10 ‐ $30 and sug has LOWER $10‐$30 for past 3 days
                    || (sug.ChangeHigherOrEquals(LowestChange) && sug.ChangeLowerOrEquals(HighestChange) &&
                        HasForPast(ThreeDays, sug, LowestChange, HighestChange)))
                {
                    runRule = true;
                }
            }
            //Event 7‐30 days
            else if (sug.EventDateFromTo(SevenDays, ThirtyDays))
            {
                if (
                    //Change < $10 and sug has LOWER for past 3 days
                    (sug.ChangeLower(LowestChange) && HasForPast(ThreeDays, sug))
                    //Change $10 ‐ $30 and sug has LOWER $10‐$30 for past 4 days
                    || (sug.ChangeHigherOrEquals(LowestChange) && sug.ChangeLowerOrEquals(HighestChange) &&
                        HasForPast(FourDays, sug, LowestChange, HighestChange))
                    //Change > $30 and sug has LOWER +/‐ $10 for past 7 days
                    || (sug.ChangeHigher(HighestChange) && HasForPast(SevenDays, sug, LowestChange)))
                {
                    runRule = true;
                }
            }
            //Event > 30 days
            else
            {
                if (
                    //Change < $10 and sug has LOWER for past 5 days
                    (sug.ChangeLower(LowestChange) && HasForPast(FiveDays, sug))
                    //Change $10 ‐ $30 and sug has LOWER $10‐$30 for past 7 days
                    || (sug.ChangeHigherOrEquals(LowestChange) && sug.ChangeLowerOrEquals(HighestChange) &&
                        HasForPast(SevenDays, sug, LowestChange, HighestChange))
                    //Change > $30 and sug has LOWER +/‐ $10 for past 10 days
                    || (sug.ChangeHigher(HighestChange) && HasForPast(TenDays, sug, LowestChange)))
                {
                    runRule = true;
                }
            }
            SaveResultToDatabase(sug, results, runRule);
        }