예제 #1
0
        /// <summary>
        /// Returns the Where clause for specified rating filter.
        /// </summary>
        /// <param name="Query">The video selection query to filter.</param>
        /// <param name="item">The rating filter to apply.</param>
        /// <param name="ratingRatio">The rating ratio.</param>
        /// <param name="context">The data context to the database.</param>
        /// <returns>The Where clause to apply to the query.</returns>
        public static Expression <Func <Media, bool> > GetFilterClause(IQueryable <Media> Query, SearchRatingSetting item, double ratingRatio, Entities context)
        {
            Expression <Func <Media, bool> > Result;

            if (item.Category == "Length")
            {
                Result = (v => context.CompareValues(v.Length, item.Operator, item.Value * 60));
            }
            else if (item.Category == "Height")
            {
                Result = (v => context.CompareValues(v.Height, item.Operator, item.Value));
            }
            else if (item.Category == "Preference")
            {
                Result = (v => context.CompareValues(v.Preference, item.Operator, item.Value));
            }
            else if (item.Category == "Highest")
            {
                Result = (v => context.CompareValues(v.MediaRatings.Max(r => r.DbGetValue(r.Height, r.Depth, ratingRatio)), item.Operator, item.Value));
            }
            else if (item.Category.StartsWith("!Physical") || item.Category.StartsWith("!Emotional") || item.Category.StartsWith("!Spiritual"))
            {
                // All other polarity energies smaller than...
                string ItemCategory = item.Category.Substring(1);
                Result = (v =>
                          !(from r in v.MediaRatings
                            let val = r.DbGetValue(r.Height, r.Depth, ratingRatio)
                                      where !r.RatingCategory.Name.StartsWith(ItemCategory) && r.RatingCategory.Custom == false &&
                                      r.RatingCategory.Name != "Egoless" && r.RatingCategory.Name != "Love" && (
                                (item.Operator == OperatorConditionEnum.Smaller && val >= item.Value))
                                      select 1).Any());
            }
            else if (item.Category.StartsWith("!"))
            {
                // All other energies smaller than...
                string ItemCategory = item.Category.Substring(1);
                Result = (v =>
                          !(from r in v.MediaRatings
                            let val = r.DbGetValue(r.Height, r.Depth, ratingRatio)
                                      where r.RatingCategory.Name != ItemCategory && (
                                (item.Operator == OperatorConditionEnum.Smaller && val >= item.Value))
                                      select 1).Any());
            }
            else if (item.Category.StartsWith("Intensity"))
            {
                // The average of the 5 highest values.
                Result = (v =>
                          (from t in v.MediaRatings
                           let val = (from r in v.MediaRatings
                                      let val = r.DbGetValue(r.Height, r.Depth, ratingRatio)
                                                orderby val descending
                                                select val).Take(5).Average()
                                     where context.CompareValues(val, item.Operator, item.Value)
                                     select 1).Any());
            }
            else if (item.Operator != OperatorConditionEnum.Smaller)
            {
                // Standard rating filters.
                Result = (v =>
                          (from t in
                           (from r in v.MediaRatings
                            where r.RatingCategory.Name.StartsWith(item.Category)
                            orderby r.DbGetValue(r.Height, r.Depth, ratingRatio) descending
                            select r).Take(1)
                           let val = t.DbGetValue(t.Height, t.Depth, ratingRatio)
                                     where context.CompareValues(val, item.Operator, item.Value)
                                     select 1).Any());
            }
            else
            {
                // Standard rating filter with < operator.
                Result = (v =>
                          (from t in
                           (from r in v.MediaRatings
                            where r.RatingCategory.Name.StartsWith(item.Category)
                            orderby r.DbGetValue(r.Height, r.Depth, ratingRatio) descending
                            select r).Take(1)
                           let val = t.DbGetValue(t.Height, t.Depth, ratingRatio)
                                     let val2 = t.DbGetValue(t.Height, t.Depth, 0) // '<' operator applies to both specified ratio and ratio 0.
                                                where val >= item.Value && val2 >= item.Value
                                                select 1).Any() == false);
            }

            // Apply 'or' filter.
            if (item.Or != null)
            {
                Result = Result.OrElse(GetFilterClause(Query, item.Or, ratingRatio, context));
            }

            return(Result);
        }
        /// <summary>
        /// Returns the Where clause for specified rating filter.
        /// </summary>
        /// <param name="Query">The video selection query to filter.</param>
        /// <param name="item">The rating filter to apply.</param>
        /// <param name="ratingRatio">The rating ratio.</param>
        /// <param name="context">The data context to the database.</param>
        /// <returns>The Where clause to apply to the query.</returns>
        public static Expression<Func<Media, bool>> GetFilterClause(IQueryable<Media> Query, SearchRatingSetting item, double ratingRatio, Entities context) {
            Expression<Func<Media, bool>> Result;
            if (item.Category == "Length")
                Result = (v => context.CompareValues(v.Length, item.Operator, item.Value * 60));
            else if (item.Category == "Height")
                Result = (v => context.CompareValues(v.Height, item.Operator, item.Value));
            else if (item.Category == "Preference")
                Result = (v => context.CompareValues(v.Preference, item.Operator, item.Value));
            else if (item.Category == "Highest")
                Result = (v => context.CompareValues(v.MediaRatings.Max(r => r.DbGetValue(r.Height, r.Depth, ratingRatio)), item.Operator, item.Value));
            else if (item.Category.StartsWith("!Physical") || item.Category.StartsWith("!Emotional") || item.Category.StartsWith("!Spiritual")) {
                // All other polarity energies smaller than...
                string ItemCategory = item.Category.Substring(1);
                Result = (v =>
                    !(from r in v.MediaRatings
                      let val = r.DbGetValue(r.Height, r.Depth, ratingRatio)
                      where !r.RatingCategory.Name.StartsWith(ItemCategory) && r.RatingCategory.Custom == false &&
                      r.RatingCategory.Name != "Egoless" && r.RatingCategory.Name != "Love" && (
                      (item.Operator == OperatorConditionEnum.Smaller && val >= item.Value))
                      select 1).Any());
            } else if (item.Category.StartsWith("!")) {
                // All other energies smaller than...
                string ItemCategory = item.Category.Substring(1);
                Result = (v =>
                    !(from r in v.MediaRatings
                      let val = r.DbGetValue(r.Height, r.Depth, ratingRatio)
                      where r.RatingCategory.Name != ItemCategory && (
                      (item.Operator == OperatorConditionEnum.Smaller && val >= item.Value))
                      select 1).Any());
            } else if (item.Category.StartsWith("Intensity"))
                // The average of the 5 highest values.
                Result = (v =>
                    (from t in v.MediaRatings
                     let val = (from r in v.MediaRatings
                                let val = r.DbGetValue(r.Height, r.Depth, ratingRatio)
                                orderby val descending
                                select val).Take(5).Average()
                     where context.CompareValues(val, item.Operator, item.Value)
                     select 1).Any());
            else if (item.Operator != OperatorConditionEnum.Smaller) {
                // Standard rating filters.
                Result = (v =>
                    (from t in
                         (from r in v.MediaRatings
                          where r.RatingCategory.Name.StartsWith(item.Category)
                          orderby r.DbGetValue(r.Height, r.Depth, ratingRatio) descending
                          select r).Take(1)
                     let val = t.DbGetValue(t.Height, t.Depth, ratingRatio)
                     where context.CompareValues(val, item.Operator, item.Value)
                     select 1).Any());
            } else {
                // Standard rating filter with < operator.
                Result = (v =>
                    (from t in
                         (from r in v.MediaRatings
                          where r.RatingCategory.Name.StartsWith(item.Category)
                          orderby r.DbGetValue(r.Height, r.Depth, ratingRatio) descending
                          select r).Take(1)
                     let val = t.DbGetValue(t.Height, t.Depth, ratingRatio)
                     let val2 = t.DbGetValue(t.Height, t.Depth, 0) // '<' operator applies to both specified ratio and ratio 0.
                     where val >= item.Value && val2 >= item.Value
                     select 1).Any() == false);
            }

            // Apply 'or' filter.
            if (item.Or != null)
                Result = Result.OrElse(GetFilterClause(Query, item.Or, ratingRatio, context));

            return Result;
        }
        private async void business_GetConditions(object sender, GetConditionsEventArgs e) {
            var Filters = e.Conditions.RatingFilters;
            Filters.Clear();
            switch (SessionCore.Instance.Business.PlayMode) {
                case PlayerMode.Normal:
                    double MaxCond = IntensitySlider.Value + e.QueuePos * GrowthSlider.Value;
                    // If decreasing heat, go down to Water from 1 above minimum
                    if (GrowthSlider.Value < 0 && MaxCond < IntensitySlider.Minimum + 1)
                        MaxCond = IntensitySlider.Minimum;
                    if (MaxCond > IntensitySlider.Maximum)
                        MaxCond = IntensitySlider.Maximum;
                    if (MaxCond > IntensitySlider.Minimum) {
                        // Exclude videos with Water >= 6
                        Filters.AddRange(FilterPresets.PresetWater(true));
                        // Exclude videos with Fire >= 8.5 && Intensity >= 9.5 unless we're at maximum heat.
                        if (MaxCond < IntensitySlider.Maximum)
                            Filters.AddRange(FilterPresets.PresetFire(true));

                        if (PolarityFocus.Text == "Intensity")
                            MaxCond -= 1;
                        // Min/Max Values.
                        SearchRatingSetting MinFilter = new SearchRatingSetting(PolarityFocus.Text, OperatorConditionEnum.GreaterOrEqual, Math.Round(MaxCond - ToleranceSlider.Value, 1));
                        SearchRatingSetting MaxFilter = new SearchRatingSetting(PolarityFocus.Text, OperatorConditionEnum.Smaller, Math.Round(MaxCond, 1));
                        Filters.Add(MinFilter);
                        Filters.Add(MaxFilter);
                        if (PolarityFocus.Text == "Intensity" && MaxCond == IntensitySlider.Maximum - 1)
                            MaxFilter.Value = IntensitySlider.Maximum;
                        if (e.IncreaseTolerance) {
                            MinFilter.Value -= .5f;
                            MaxFilter.Value += .5f;
                        }
                        if (PolarityFocus.Text == "Physical" || PolarityFocus.Text == "Emotional" || PolarityFocus.Text == "Spiritual") {
                            // Don't get videos that are more than .5 stronger on other values.
                            Filters.Add(new SearchRatingSetting("!" + PolarityFocus.Text, OperatorConditionEnum.Smaller, MaxFilter.Value + .5f));
                        } else if (PolarityFocus.Text == "Intensity") {
                            Filters.Add(new SearchRatingSetting("!Intensity", OperatorConditionEnum.Smaller, MaxFilter.Value + 2f));
                        }
                    } else { // Water
                        IntensitySlider.Value = IntensitySlider.Minimum;
                        await SessionCore.Instance.Business.SetWaterVideosAsync(true);
                    }
                    // Change condition display after "Fire" returns to normal.
                    DisplayConditionsText();
                    break;
                case PlayerMode.WarmPause:
                case PlayerMode.Fire:
                    Filters.AddRange(FilterPresets.PresetPause());
                    break;
                case PlayerMode.Water:
                    if (!e.IncreaseTolerance) {
                        Filters.Add(new SearchRatingSetting("Water", OperatorConditionEnum.GreaterOrEqual, 4f));
                    } else {
                        Filters.Add(new SearchRatingSetting("Intensity", OperatorConditionEnum.Smaller, 7f));
                        Filters.Add(new SearchRatingSetting("Party", OperatorConditionEnum.Smaller, 2f));
                        Filters.Add(new SearchRatingSetting("Vitality", OperatorConditionEnum.Smaller, 2f));
                        Filters.Add(new SearchRatingSetting("Fire", OperatorConditionEnum.Smaller, 2f));
                        Filters.Add(new SearchRatingSetting("!", OperatorConditionEnum.Smaller, 9f));
                    }
                    break;
                case PlayerMode.RequestCategory:
                    // Filters are already defined in Business.FilterSettings.
                    Filters.Add(new SearchRatingSetting());
                    break;
            }
        }