/// <summary>
        ///     分析一段日期的历史趋势,(通过号码集合分析历史趋势)
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public List <FactorTrendCorrectRate> AnalyseHistoricalTrend(PermutationFactorHistoricalTrendAnalyseDto <byte> dto)
        {
            var trends = new List <FactorTrendCorrectRate>();

            if (dto.Numbers.Count < dto.AnalyseNumberCount)
            {
                throw new Exception("分析历史趋势时,分析记录数量不能大于记录数量!");
            }

            var analyseNumbers   = dto.Numbers.OrderByDescending(n => n.TimesValue).Skip(0).Take(dto.AnalyseNumberCount).ToList();
            var factorResultDict = new Dictionary <int, List <PermutationFactorTrendConsecutiveDetails <byte> > >();

            //先记录分析结果
            for (int i = 0, maxCount = analyseNumbers.Count; i < maxCount; i++)
            {
                var timesValue = analyseNumbers[i].TimesValue;
                var numbers    = dto.Numbers.Where(n => n.TimesValue < timesValue).Select(n => n.Number).ToList();

                var factorResults = Analyse(new PermutationFactorTrendAnalyseDto <byte>
                {
                    Numbers             = numbers,
                    PermutationFactors  = dto.PermutationFactors,
                    AllowMinTimes       = dto.AllowMinTimes,
                    NumbersTailCutCount = dto.NumbersTailCutCount,
                    AllowMinFactorCurrentConsecutiveTimes = dto.StartAllowMinFactorCurrentConsecutiveTimes,
                    AllowMaxInterval = dto.StartAllowMaxInterval
                });
                factorResultDict.Add(i, factorResults);
            }


            //允许的连续次数,由小到大
            for (var consecutiveTimes = dto.StartAllowMinFactorCurrentConsecutiveTimes; consecutiveTimes <= dto.EndAllowMinFactorCurrentConsecutiveTimes; consecutiveTimes++)
            {
                //允许的间隔数,由大到小
                for (var interval = dto.StartAllowMaxInterval; interval >= dto.EndAllowMaxInterval; interval--)
                {
                    var resultCount  = 0;
                    var successCount = 0;

                    var trend = new FactorTrendCorrectRate
                    {
                        //HistoricalTrendType = dto.HistoricalTrendType,
                        StartTimes = analyseNumbers[0].TimesValue,
                        //Items = new List<HistoricalTrendItem>(),
                        Location = dto.Location,
                        AllowConsecutiveTimes = consecutiveTimes,
                        AllowInterval         = interval,
                        AnalyseNumberCount    = dto.AnalyseNumberCount,
                        TypeDescription       = dto.TypeDescription
                    };
                    trends.Add(trend);
                    for (int i = 0, maxCount = analyseNumbers.Count; i < maxCount; i++)
                    {
                        var number = analyseNumbers[i].Number;
                        var times  = analyseNumbers[i].Times;

                        var factorResults = factorResultDict[i];

                        //结果是否正确
                        var success = false;

                        //对结果再分析
                        //1、按允许的最小因子当前连续次数和允许的最大间隔次数筛选
                        //2、先按最大连续次数然后按最小间隔次数排序
                        factorResults = factorResults
                                        .Where(m => m.FactorCurrentConsecutiveTimes >= consecutiveTimes && m.Interval <= interval)
                                        .OrderByDescending(t => t.FactorCurrentConsecutiveTimes)
                                        .ThenBy(t => t.Interval).ToList();

                        var factorResult = factorResults.OrderByDescending(t => t.FactorCurrentConsecutiveTimes).FirstOrDefault();
                        if (factorResult == null)
                        {
                            continue;
                        }
                        var resultConsecutiveTimes = factorResult.FactorCurrentConsecutiveTimes;
                        var resultInterval         = factorResult.Interval;
                        if (factorResult.PredictiveFactor != null && factorResult.PredictiveFactor.Count > 0)
                        {
                            resultCount++;

                            if (factorResult.PredictiveFactor.Contains(number))
                            {
                                successCount++;
                                success = true;
                            }
                        }
                        var trendItem = new HistoricalTrendItem
                        {
                            Times   = times,
                            Number  = number,
                            Success = success,
                            ResultConsecutiveTimes = resultConsecutiveTimes,
                            ResultInterval         = resultInterval,
                            PredictiveFactor       = factorResult.PredictiveFactor
                        };

                        //trend.Items.Add(trendItem);


                        /*  分析结果为也作记录
                         * var factorResult = factorResults.OrderByDescending(t => t.MaxConsecutiveTimes).FirstOrDefault();
                         * var factors = new List<byte>();
                         * var resultConsecutiveTimes = 0;
                         * var resultInterval = 0;
                         * if (factorResult != null)
                         * {
                         *  factors = factorResult.PredictiveFactor;
                         *  resultConsecutiveTimes = factorResult.MaxConsecutiveTimes;
                         *  resultInterval = factorResult.MaxInterval;
                         *  if (factorResult.PredictiveFactor != null && factorResult.PredictiveFactor.Count > 0)
                         *  {
                         *      resultCount++;
                         *
                         *      if (factors.Contains(number))
                         *      {
                         *          successCount++;
                         *          success = true;
                         *      }
                         *  }
                         * }
                         *
                         * var trendItem = new HistoricalTrendItem
                         * {
                         *  Times = times,
                         *  Number = number,
                         *  Success = success,
                         *  ResultConsecutiveTimes = resultConsecutiveTimes,
                         *  ResultInterval = resultInterval,
                         *  PredictiveFactor = factors
                         * };
                         *
                         * trend.Items.Add(trendItem);
                         */
                    }
                    trend.AnalyticalCount = resultCount;
                    trend.CorrectCount    = successCount;
                    trend.CorrectRate     = trend.AnalyticalCount == 0 ? 0 : (double)trend.CorrectCount / trend.AnalyticalCount;
                }
            }
            return(trends);
        }
        public List <FactorTrendCorrectRate> AnalyseHistoricalTrend_Old(PermutationFactorHistoricalTrendAnalyseDto <byte> dto)
        {
            var trends = new List <FactorTrendCorrectRate>();

            if (dto.Numbers.Count < dto.AnalyseNumberCount)
            {
                throw new Exception("分析历史趋势时,分析记录数量不能大于记录数量!");
            }

            var analyseNumbers = dto.Numbers.OrderByDescending(n => n.TimesValue).Skip(0).Take(dto.AnalyseNumberCount).ToList();



            //允许的连续次数,由小到大
            for (var consecutiveTimes = dto.StartAllowMinFactorCurrentConsecutiveTimes; consecutiveTimes <= dto.EndAllowMinFactorCurrentConsecutiveTimes; consecutiveTimes++)
            {
                //允许的间隔数,由大到小
                for (var interval = dto.StartAllowMaxInterval; interval >= dto.EndAllowMaxInterval; interval--)
                {
                    var resultCount  = 0;
                    var successCount = 0;

                    var trend = new FactorTrendCorrectRate
                    {
                        //HistoricalTrendType = dto.HistoricalTrendType,
                        StartTimes = analyseNumbers[0].TimesValue,
                        //Items = new List<HistoricalTrendItem>(),
                        Location = dto.Location,
                        AllowConsecutiveTimes = consecutiveTimes,
                        AllowInterval         = interval,
                        AnalyseNumberCount    = dto.AnalyseNumberCount,
                        TypeDescription       = dto.TypeDescription
                    };
                    trends.Add(trend);
                    for (int i = 0, maxCount = analyseNumbers.Count; i < maxCount; i++)
                    {
                        var number     = analyseNumbers[i].Number;
                        var times      = analyseNumbers[i].Times;
                        var timesValue = analyseNumbers[i].TimesValue;
                        var numbers    = dto.Numbers.Where(n => n.TimesValue < timesValue).Select(n => n.Number).ToList();

                        var factorResults = Analyse(new PermutationFactorTrendAnalyseDto <byte>
                        {
                            Numbers             = numbers,
                            AllowMinTimes       = dto.AllowMinTimes,
                            NumbersTailCutCount = dto.NumbersTailCutCount,
                            AllowMinFactorCurrentConsecutiveTimes = consecutiveTimes,
                            AllowMaxInterval   = interval,
                            PermutationFactors = dto.PermutationFactors
                        });

                        //结果是否正确
                        var success = false;

                        //对结果再分析
                        var factorResult           = factorResults.OrderByDescending(t => t.FactorCurrentConsecutiveTimes).FirstOrDefault();
                        var factors                = new List <byte>();
                        var resultConsecutiveTimes = 0;
                        var resultInterval         = 0;
                        if (factorResult != null)
                        {
                            factors = factorResult.PredictiveFactor;
                            resultConsecutiveTimes = factorResult.FactorCurrentConsecutiveTimes;
                            resultInterval         = factorResult.Interval;
                            if (factorResult.PredictiveFactor != null && factorResult.PredictiveFactor.Count > 0)
                            {
                                resultCount++;

                                if (factors.Contains(number))
                                {
                                    successCount++;
                                    success = true;
                                }
                            }
                        }

                        var trendItem = new HistoricalTrendItem
                        {
                            Times   = times,
                            Number  = number,
                            Success = success,
                            ResultConsecutiveTimes = resultConsecutiveTimes,
                            ResultInterval         = resultInterval,
                            PredictiveFactor       = factors
                        };

                        trend.AnalyticalCount = resultCount;
                        trend.CorrectCount    = successCount;
                        trend.CorrectRate     = trend.AnalyticalCount == 0 ? 0 : (double)trend.CorrectCount / trend.AnalyticalCount;
                        //trend.Items.Add(trendItem);
                    }
                }
            }
            return(trends);
        }