/// <summary> /// 获取号码下一个可能出现的周期 /// </summary> /// <param name="CaiData">配置数据</param> /// <returns>周期数据列表</returns> public List<NumSpanData> GetNextPeriod(CaiConfigData CaiData,List<NumSpanData> spans) { //需要重新计算以下值 //next 并且按照next进行排序 //计算第二天出现的情况进行参照 DwSpanDAO da = new DwSpanDAO(ConfigHelper.GetDwSpanTableName(CaiData.NumType), ConfigHelper.GetConnString(CaiData.CaiType)); foreach (NumSpanData span in spans) { int spanAvg = span.SpanAvg;//平均值 string num = span.num; string pBegin = BizBase.getPByDate(CaiData.NowCaculate, CaiData);//开始计算的时间 DataSet ds = da.SelectTopNSpan(num, 1008, pBegin); List<int> dtos = new List<int>(); foreach (DataRow dr in ds.Tables[0].Rows) { dtos.Add(Convert.ToInt32(dr["P2Spans"].ToString())); } int count = 97; List<int> cycles = new List<int>(); int cycleAvg = 0; for (int i = 0; i < count; i++) { int cycle = 0; for (int j = i + 1; j < count; j++) { int spanJust = dtos[j]; cycle += spanJust; if (Math.Abs((cycle / (j - i)) - spanAvg) <= spanAvg*0.2) { if (j - i < CaiData.PeriodPerDay) { cycles.Add(j - i); break; } } } } //var gps = cycles.GroupBy(x =>x).ToDictionary(x=>x.Key,y=>y.Count()).OrderByDescending(x=>x.Value).ToDictionary(x=>x,y=>y); cycleAvg = Convert.ToInt32(cycles.Average()); int cycleLast = Convert.ToInt32(dtos.GetRange(0, cycleAvg - 1).Average()); //span.NextAbility = (2 * spanAvg - cycleLast).ToString(); int ability = (2 * spanAvg - cycleLast)-span.SpanTillNow; if (ability > 0 && ability < CaiData.PeriodPerDay) { span.NextAbility = ability.ToString(); } CaiData.StatusLabel = span.num+" NextPeriod Geted!"; } return spans; }
/// <summary> /// 获取号码下一个可能出现的周期 /// </summary> /// <param name="CaiData">配置数据</param> /// <returns>周期数据列表</returns> public List <NumSpanData> GetNextPeriod(CaiConfigData CaiData, List <NumSpanData> spans) { //需要重新计算以下值 //next 并且按照next进行排序 //计算第二天出现的情况进行参照 DwSpanDAO da = new DwSpanDAO(ConfigHelper.GetDwSpanTableName(CaiData.NumType), ConfigHelper.GetConnString(CaiData.CaiType)); foreach (NumSpanData span in spans) { int spanAvg = span.SpanAvg; //平均值 string num = span.num; string pBegin = BizBase.getPByDate(CaiData.NowCaculate, CaiData); //开始计算的时间 DataSet ds = da.SelectTopNSpan(num, 1008, pBegin); List <int> dtos = new List <int>(); foreach (DataRow dr in ds.Tables[0].Rows) { dtos.Add(Convert.ToInt32(dr["P2Spans"].ToString())); } int count = 97; List <int> cycles = new List <int>(); int cycleAvg = 0; for (int i = 0; i < count; i++) { int cycle = 0; for (int j = i + 1; j < count; j++) { int spanJust = dtos[j]; cycle += spanJust; if (Math.Abs((cycle / (j - i)) - spanAvg) <= spanAvg * 0.2) { if (j - i < CaiData.PeriodPerDay) { cycles.Add(j - i); break; } } } } //var gps = cycles.GroupBy(x =>x).ToDictionary(x=>x.Key,y=>y.Count()).OrderByDescending(x=>x.Value).ToDictionary(x=>x,y=>y); cycleAvg = Convert.ToInt32(cycles.Average()); int cycleLast = Convert.ToInt32(dtos.GetRange(0, cycleAvg - 1).Average()); //span.NextAbility = (2 * spanAvg - cycleLast).ToString(); int ability = (2 * spanAvg - cycleLast) - span.SpanTillNow; if (ability > 0 && ability < CaiData.PeriodPerDay) { span.NextAbility = ability.ToString(); } CaiData.StatusLabel = span.num + " NextPeriod Geted!"; } return(spans); }
/// <summary> /// 获取周期统计 /// </summary> /// <param name="CaiData">配置数据对象</param> /// <returns>周期对象列表</returns> public List<NumSpanData> GetSpanCount(CaiConfigData CaiData) { if(CaiData.IsLoadFromCache){ //从缓存中获取 List<NumSpanData> re = BizBase.XMLDeserialize(CaiData); if (re != null) { //计算一下next period re = GetNextPeriod(CaiData, re); return re; } } List<NumSpanData> spans = new List<NumSpanData>(); DwSpanDAO da = new DwSpanDAO("DwPeroidSpan", ConfigHelper.GetConnString(CaiData.CaiType)); //全部数字组合 string[] numList = Data.Biz.D11X5.NumberCache.Instance.GetNumbers(CaiData.NumType).ToArray<string>(); //获取今天出的全部号码 DwNumberDAO nda = new DwNumberDAO(ConfigHelper.GetConnString(CaiData.CaiType)); DateTime dt = CaiData.NowCaculate.AddDays(1); string NumCondition = "where date = "+dt.ToString("yyyyMMdd"); List<DwNumber> TodayDtos = nda.SelectWithCondition(NumCondition,new string[]{"P","D1","N","P2","Date"}); foreach (string num in numList) { NumSpanData span = new NumSpanData(); span.num = num; string pBegin = BizBase.getPByDate(CaiData.NowCaculate, CaiData);//开始计算的时间 DataSet dtos = da.SelectTopNSpan(num,1008,pBegin); List<int> spanList = new List<int>(); int i = 0; foreach (DataRow dto in dtos.Tables[0].Rows) { if (i == 0) { span.p = dto["P"].ToString(); span.SpanLast = Convert.ToInt32(dto["P2Spans"].ToString()); span.SpanTillNow = BizBase.getSpanTillNow(span.p, CaiData); } //span.SpanRec += dto["P2Span"].ToString() + ","; i++; spanList.Add(Convert.ToInt32(dto["P2Spans"].ToString())); } span.SpanMax = da.SelectMaxSpan(span.num); span.SpanAvg = da.SelectAvgSpan(span.num); span.NextAll = getNextCyclesByNum(span, spanList, CaiData); //pBegin后的第二天出现的期数 span.Next = this.GETNFromDate(span.num,CaiData,TodayDtos); //最小误差 span = this.GetNextTest(span); //最近出现的总次数及每日次数 string numsql = " where p < "+pBegin+" order by p desc"; List<DwNumber> numdtos = nda.SelectTopN((1008+(10*CaiData.PeriodPerDay)),numsql,new string[]{"P","D1","N","P2","Date"}); span = this.getTimesByNum(span,CaiData,numdtos); span.TimesDay1 = span.Next.Split(',').Length-1; //最近周期 span = this.getHotTrends(span,CaiData,numdtos); //周期热度 if(span.Times<5) span.HotType = -1; else if(span.Times>=12) span.HotType = 1; else span.HotType = 0; CaiData.StatusLabel = span.num+" Caculated!"; spans.Add(span); } //计算一下next period spans = GetNextPeriod(CaiData,spans); //序列化保存至缓存 BizBase.XMLSerialize(spans,CaiData); return spans; }
/// <summary> /// 获取周期统计 /// </summary> /// <param name="CaiData">配置数据对象</param> /// <returns>周期对象列表</returns> public List <NumSpanData> GetSpanCount(CaiConfigData CaiData) { if (CaiData.IsLoadFromCache) { //从缓存中获取 List <NumSpanData> re = BizBase.XMLDeserialize(CaiData); if (re != null) { //计算一下next period re = GetNextPeriod(CaiData, re); return(re); } } List <NumSpanData> spans = new List <NumSpanData>(); DwSpanDAO da = new DwSpanDAO("DwPeroidSpan", ConfigHelper.GetConnString(CaiData.CaiType)); //全部数字组合 string[] numList = Data.Biz.D11X5.NumberCache.Instance.GetNumbers(CaiData.NumType).ToArray <string>(); //获取今天出的全部号码 DwNumberDAO nda = new DwNumberDAO(ConfigHelper.GetConnString(CaiData.CaiType)); DateTime dt = CaiData.NowCaculate.AddDays(1); string NumCondition = "where date = " + dt.ToString("yyyyMMdd"); List <DwNumber> TodayDtos = nda.SelectWithCondition(NumCondition, new string[] { "P", "D1", "N", "P2", "Date" }); foreach (string num in numList) { NumSpanData span = new NumSpanData(); span.num = num; string pBegin = BizBase.getPByDate(CaiData.NowCaculate, CaiData);//开始计算的时间 DataSet dtos = da.SelectTopNSpan(num, 1008, pBegin); List <int> spanList = new List <int>(); int i = 0; foreach (DataRow dto in dtos.Tables[0].Rows) { if (i == 0) { span.p = dto["P"].ToString(); span.SpanLast = Convert.ToInt32(dto["P2Spans"].ToString()); span.SpanTillNow = BizBase.getSpanTillNow(span.p, CaiData); } //span.SpanRec += dto["P2Span"].ToString() + ","; i++; spanList.Add(Convert.ToInt32(dto["P2Spans"].ToString())); } span.SpanMax = da.SelectMaxSpan(span.num); span.SpanAvg = da.SelectAvgSpan(span.num); span.NextAll = getNextCyclesByNum(span, spanList, CaiData); //pBegin后的第二天出现的期数 span.Next = this.GETNFromDate(span.num, CaiData, TodayDtos); //最小误差 span = this.GetNextTest(span); //最近出现的总次数及每日次数 string numsql = " where p < " + pBegin + " order by p desc"; List <DwNumber> numdtos = nda.SelectTopN((1008 + (10 * CaiData.PeriodPerDay)), numsql, new string[] { "P", "D1", "N", "P2", "Date" }); span = this.getTimesByNum(span, CaiData, numdtos); span.TimesDay1 = span.Next.Split(',').Length - 1; //最近周期 span = this.getHotTrends(span, CaiData, numdtos); //周期热度 if (span.Times < 5) { span.HotType = -1; } else if (span.Times >= 12) { span.HotType = 1; } else { span.HotType = 0; } CaiData.StatusLabel = span.num + " Caculated!"; spans.Add(span); } //计算一下next period spans = GetNextPeriod(CaiData, spans); //序列化保存至缓存 BizBase.XMLSerialize(spans, CaiData); return(spans); }