Esempio n. 1
0
        /// <summary>
        /// 前二预测
        /// 历史数据加一 有一位重合 则为匹配成功
        ///
        /// </summary>
        /// <param name="db"></param>
        /// <param name="openNumber"></param>
        /// <returns></returns>
        private string ForecastC(OlaEntities db, LotteryOpenHistory lottery)
        {
            var olds = db.LotteryOpenHistories
                       .Where(w => w.Used != true && w.LotteryId == this.lottery.LotteryId)
                       .OrderByDescending(w => w.QiHao)
                       .Take(50).ToList();
            var currentOpenNumbers = SplitOpenNumber2IntList(lottery.OpenNumber.Substring(0, 5));

            foreach (var item in olds)
            {
                var openNumbers             = SplitOpenNumber2IntList(item.OpenNumber.Substring(0, 5));
                var currentOpenNumbers_plus = new List <int>();
                foreach (var n in openNumbers)
                {
                    currentOpenNumbers_plus.Add(n + 1 == 12 ? 1 : n + 1);
                }
                var intersect = currentOpenNumbers.Intersect(currentOpenNumbers_plus);

                if (intersect.Count() == 1)
                {
                    lottery.ForecastFrom += item.QiHao;
                    //log.Info(item.QiHao + " 预测C:" + JsonConvert.SerializeObject(item));
                    var except = new List <int>();
                    except.AddRange(currentOpenNumbers_plus.Except(currentOpenNumbers));
                    item.Used   = true;
                    item.UsedBy = lottery.QiHao;
                    db.SaveChanges();
                    return(Except2String(except));
                }
            }
            return(null);
        }
Esempio n. 2
0
        private void Generate(DateTime startTime, DateTime endTime, int step, int startQiHao)
        {
            using (var db = new OlaEntities())
            {
                while (startTime <= endTime)
                {
                    string qihao  = startTime.ToString("yyyyMMdd") + startQiHao.ToString(this.QiHaoFormat);
                    var    exists = db.LotteryOpenTimes.Any(w => w.LotteryId == this.LotteryId && w.QiHao == qihao);
                    if (exists)
                    {
                        startQiHao++;
                        startTime = startTime.AddMinutes(step);
                        continue;
                    }

                    string next_qihao = startTime.ToString("yyyyMMdd") + (startQiHao + 1).ToString(this.QiHaoFormat);
                    if (startQiHao + 1 > this.MaxQiHao)
                    {
                        next_qihao = startTime.AddDays(1).ToString("yyyyMMdd") + this.MinQiHao.ToString(this.QiHaoFormat);
                    }

                    string pre_qihao = startTime.ToString("yyyyMMdd") + (startQiHao - 1).ToString(this.QiHaoFormat);
                    if (startQiHao - 1 == 0)
                    {
                        pre_qihao = startTime.AddDays(-1).ToString("yyyyMMdd") + this.MaxQiHao.ToString(this.QiHaoFormat);
                    }

                    db.LotteryOpenTimes.Add(new LotteryOpenTime
                    {
                        CreateTime = DateTime.Now,
                        Id         = Guid.NewGuid(),
                        LotteryId  = this.LotteryId,
                        NextQiHao  = next_qihao,
                        PreQiHao   = pre_qihao,
                        OpenTime   = startTime,
                        QiHao      = qihao,
                        StartTime  = startTime.AddMinutes(-step).AddSeconds(-30),
                        EndTime    = startTime.AddSeconds(-30),
                    });

                    startQiHao++;
                    startTime = startTime.AddMinutes(step);
                }
                db.SaveChanges();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 生成一天的开奖时间
        /// </summary>
        /// <param name="date"></param>
        private void GenerateOneDay(DateTime date)
        {
            // 00:05 -- 02:00
            var startTime = new DateTime(date.Year, date.Month, date.Day, 0, 5, 0);
            var endTime   = new DateTime(date.Year, date.Month, date.Day, 2, 0, 0);

            Generate(startTime, endTime, 5, this.MinQiHao);
            // 10:00 -- 22:00
            startTime = new DateTime(date.Year, date.Month, date.Day, 10, 0, 0);
            endTime   = new DateTime(date.Year, date.Month, date.Day, 22, 10, 0);
            Generate(startTime, endTime, 10, 24);

            // 22:05 -- 00:00
            startTime = new DateTime(date.Year, date.Month, date.Day, 22, 5, 0);
            var nextDay = date.AddDays(1);

            endTime = new DateTime(nextDay.Year, nextDay.Month, nextDay.Day, 0, 0, 0);
            Generate(startTime, endTime, 5, 97);
            // 第 120 期
            using (var db = new OlaEntities())
            {
                db.LotteryOpenTimes.Add(new LotteryOpenTime
                {
                    CreateTime = DateTime.Now,
                    Id         = Guid.NewGuid(),
                    LotteryId  = this.LotteryId,
                    NextQiHao  = date.ToString("yyyyMMdd") + this.MinQiHao.ToString(this.QiHaoFormat),
                    PreQiHao   = date.AddDays(-1).ToString("yyyyMMdd") + (this.MaxQiHao - 1).ToString(this.QiHaoFormat),
                    OpenTime   = date,
                    QiHao      = date.AddDays(-1).ToString("yyyyMMdd") + this.MaxQiHao.ToString(this.QiHaoFormat),
                    StartTime  = date.AddMinutes(-5).AddSeconds(-30),
                    EndTime    = date.AddSeconds(-30),
                });
                db.SaveChanges();
            }
        }
Esempio n. 4
0
        public void GetLotteryOpenNumberFromkm28()
        {
            if (DateTime.Now <= this.NextRequestDT ||
                string.IsNullOrEmpty(this.lottery.urlkm28))
            {
                return;
            }
            try
            {
                HtmlWeb htmlWeb = new HtmlWeb();
                HtmlWeb.PreRequestHandler handler = delegate(HttpWebRequest request)
                {
                    request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
                    request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
                    request.CookieContainer        = new CookieContainer();
                    return(true);
                };
                htmlWeb.PreRequest += handler;
                var url = this.lottery.urlkm28.Replace("{date}", DateTime.Now.ToString("yyyy-MM-dd"));
                var doc = htmlWeb.Load(url);
                var trs = doc.DocumentNode.SelectNodes("//table[@class='tac fl']/tr");

                var lotteries = new List <LotteryOpenHistory>();
                foreach (var tr in trs)
                {
                    try
                    {
                        var tds = tr.SelectNodes("./td");
                        if (tds == null || tds.Count != 3)
                        {
                            continue;
                        }

                        var period = tds[0].InnerText;
                        if (string.IsNullOrEmpty(period))
                        {
                            continue;
                        }
                        var win_number = tds[2].InnerText;
                        if (string.IsNullOrEmpty(win_number))
                        {
                            continue;
                        }
                        win_number = win_number.Replace(" ", ",");
                        period     = DateTime.Now.ToString("yyyyMMdd") + period;
                        // 过滤掉已经添加的期号
                        var qihao = Convert.ToInt32(period);
                        if (qihao < this.NextQiHao)
                        {
                            continue;
                        }
                        lotteries.Add(new LotteryOpenHistory
                        {
                            OpenNumber = win_number,
                            QiHao      = period,
                        });
                    }
                    catch (Exception ex)
                    {
                        log.Error(this.lottery.Name + " GetLotteryOpenNumberFromkm28 解析数据失败", ex);
                    }
                }

                lotteries = lotteries.OrderBy(w => w.QiHao).ToList();
                //log.Info("下一期期号:" + this.NextQiHao + this.lottery.Name + ":" + lotteries.Count + " " + JsonConvert.SerializeObject(lotteries));
                using (var db = new OlaEntities())
                {
                    foreach (var lotteryOpen in lotteries)
                    {
                        try
                        {
                            var lotteryOpenTimes = db.LotteryOpenTimes
                                                   .FirstOrDefault(w => w.LotteryId == this.lottery.LotteryId && w.QiHao == lotteryOpen.QiHao);
                            if (lotteryOpenTimes != null)
                            {
                                lotteryOpen.OpenTime = lotteryOpenTimes.OpenTime.ToString("yyyy-MM-dd HH:mm:ss");
                                var history = db.LotteryOpenHistories
                                              .Any(w => w.LotteryId == this.lottery.LotteryId && w.QiHao == lotteryOpen.QiHao);
                                if (!history)
                                {
                                    // 预测
                                    GetForecast(db, lotteryOpen);

                                    lotteryOpen.Id         = Guid.NewGuid();
                                    lotteryOpen.LotteryId  = this.lottery.LotteryId;
                                    lotteryOpen.CreateTime = DateTime.Now;
                                    lotteryOpen.Source     = (int)LotteryOpenNumberSourceEnum.开门彩;
                                    // 获取前三期的预测号码
                                    GetPreForecast(db, lotteryOpen);
                                    db.LotteryOpenHistories.Add(lotteryOpen);
                                    db.SaveChanges();
                                    UpdateWebClientLotteryOpenInfo(lotteryOpen.LotteryId);
                                    var nextInfo = db.LotteryOpenTimes.FirstOrDefault(w => w.LotteryId == lotteryOpen.LotteryId && w.QiHao == lotteryOpenTimes.NextQiHao);
                                    if (nextInfo != null)
                                    {
                                        this.NextQiHao     = Convert.ToInt32(nextInfo.QiHao);
                                        this.NextRequestDT = nextInfo.OpenTime;
                                        log.Info("添加:" + this.lottery.Name + " 期号:" + lotteryOpen.QiHao + " 开奖号码:" + lotteryOpen.OpenNumber + " 获取时间: " + DateTime.Now + ":下次获取时间 " + this.NextRequestDT);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error(this.lottery.Name + " GetLotteryOpenNumberFromgdlottery 解析数据失败", ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(this.lottery.Name + " GetLotteryOpenNumberFromgdlottery 获取数据失败", ex);
            }
        }
Esempio n. 5
0
        public void GetLotteryOpenNumberFrom163()
        {
            if (DateTime.Now <= this.NextRequestDT ||
                string.IsNullOrEmpty(this.lottery.url163))
            {
                return;
            }
            try
            {
                HtmlWeb htmlWeb = new HtmlWeb();
                HtmlWeb.PreRequestHandler handler = delegate(HttpWebRequest request)
                {
                    request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
                    request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
                    request.CookieContainer        = new CookieContainer();
                    return(true);
                };
                htmlWeb.PreRequest += handler;
                var doc = htmlWeb.Load(this.lottery.url163);

                var tds = doc.DocumentNode.SelectNodes("//td");
                if (tds == null)
                {
                    return;
                }
                var lotteries = new List <LotteryOpenHistory>();
                foreach (var td in tds)
                {
                    try
                    {
                        HtmlAttribute attr_data_win_number = td.Attributes["data-award"];
                        HtmlAttribute attr_data_period     = td.Attributes["data-period"];
                        if (attr_data_win_number != null && attr_data_period != null)
                        {
                            var win_number = attr_data_win_number.Value;
                            var period     = attr_data_period.Value;
                            if (string.IsNullOrEmpty(win_number) || string.IsNullOrEmpty(period))
                            {
                                continue;
                            }
                            period = this.lottery.Prefix + period;
                            // 过滤掉已经添加的期号
                            var qihao = Convert.ToInt32(period);
                            if (qihao < this.NextQiHao)
                            {
                                continue;
                            }
                            lotteries.Add(new LotteryOpenHistory
                            {
                                OpenNumber = win_number.Replace(" ", ","),
                                QiHao      = period,
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error(this.lottery.Name + " GetLotteryOpenNumberFrom163 解析数据失败", ex);
                    }
                }
                lotteries = lotteries.OrderBy(w => w.QiHao).ToList();
                //log.Info("下一期期号:" + this.NextQiHao + this.lottery.Name + ":" + lotteries.Count + " " + JsonConvert.SerializeObject(lotteries));
                using (var db = new OlaEntities())
                {
                    foreach (var lotteryOpen in lotteries)
                    {
                        try
                        {
                            var lotteryOpenTimes = db.LotteryOpenTimes
                                                   .FirstOrDefault(w => w.LotteryId == this.lottery.LotteryId && w.QiHao == lotteryOpen.QiHao);
                            if (lotteryOpenTimes != null)
                            {
                                lotteryOpen.OpenTime = lotteryOpenTimes.OpenTime.ToString("yyyy-MM-dd HH:mm:ss");
                                var history = db.LotteryOpenHistories
                                              .Any(w => w.LotteryId == this.lottery.LotteryId && w.QiHao == lotteryOpen.QiHao);
                                if (!history)
                                {
                                    // 预测
                                    GetForecast(db, lotteryOpen);

                                    lotteryOpen.Id         = Guid.NewGuid();
                                    lotteryOpen.LotteryId  = this.lottery.LotteryId;
                                    lotteryOpen.CreateTime = DateTime.Now;
                                    lotteryOpen.Source     = (int)LotteryOpenNumberSourceEnum.网易彩票;

                                    // 获取前三期的预测号码
                                    GetPreForecast(db, lotteryOpen);
                                    db.LotteryOpenHistories.Add(lotteryOpen);
                                    db.SaveChanges();
                                    UpdateWebClientLotteryOpenInfo(lotteryOpen.LotteryId);
                                    var nextInfo = db.LotteryOpenTimes.FirstOrDefault(w => w.LotteryId == lotteryOpen.LotteryId && w.QiHao == lotteryOpenTimes.NextQiHao);
                                    if (nextInfo != null)
                                    {
                                        this.NextQiHao     = Convert.ToInt32(nextInfo.QiHao);
                                        this.NextRequestDT = nextInfo.OpenTime;
                                        log.Info("添加:" + this.lottery.Name + " 期号:" + lotteryOpen.QiHao + " 开奖号码:" + lotteryOpen.OpenNumber + " 获取时间: " + DateTime.Now + " 下次获取时间: " + this.NextRequestDT);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error(this.lottery.Name + " GetLotteryOpenNumberFrom163 解析数据失败", ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(this.lottery.Name + " GetLotteryOpenNumberFrom163 获取数据失败", ex);
            }
        }
Esempio n. 6
0
        public void GetLotteryOpenNumberFromgdlottery()
        {
            if (DateTime.Now <= this.NextRequestDT ||
                string.IsNullOrEmpty(this.lottery.urlgdlottery))
            {
                return;
            }
            try
            {
                HtmlWeb htmlWeb = new HtmlWeb();
                HtmlWeb.PreRequestHandler handler = delegate(HttpWebRequest request)
                {
                    request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
                    request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
                    request.CookieContainer        = new CookieContainer();
                    return(true);
                };
                htmlWeb.PreRequest += handler;
                var doc = htmlWeb.Load(this.lottery.urlgdlottery);
                var trs = doc.DocumentNode.SelectNodes("//table[@bordercolorlight='#008000']/tr");
                if (trs == null)
                {
                    return;
                }
                trs.RemoveAt(0);
                trs.RemoveAt(0);

                var lotteries = new List <LotteryOpenHistory>();
                foreach (var tr in trs)
                {
                    try
                    {
                        var tds = tr.ChildNodes;
                        if (tds.Count < 4)
                        {
                            continue;
                        }
                        var period = tds[1].InnerHtml.Trim('\r');
                        var td     = tds[3];
                        var spans  = td.ChildNodes;
                        if (spans.Count < 2)
                        {
                            continue;
                        }
                        var strongs = spans[1].ChildNodes;
                        if (strongs.Count < 2)
                        {
                            continue;
                        }
                        var win_number = strongs[1].InnerHtml.Replace("\r\n\t", "");
                        win_number = win_number.Replace("\r\n\t", "");
                        win_number = win_number.Replace("   \t", "");
                        win_number = win_number.Trim(' ');
                        win_number = win_number.Replace(',', ',');
                        if (string.IsNullOrEmpty(win_number) || string.IsNullOrEmpty(period))
                        {
                            continue;
                        }
                        period = this.lottery.Prefix + period;
                        // 过滤掉已经添加的期号
                        var qihao = Convert.ToInt32(period);
                        if (qihao < this.NextQiHao)
                        {
                            continue;
                        }
                        lotteries.Add(new LotteryOpenHistory
                        {
                            OpenNumber = win_number,
                            QiHao      = period,
                        });
                    }
                    catch (Exception ex)
                    {
                        log.Error(this.lottery.Name + " GetLotteryOpenNumberFromgdlottery 解析数据失败", ex);
                    }
                }
                lotteries = lotteries.OrderBy(w => w.QiHao).ToList();
                //log.Info("下一期期号:" + this.NextQiHao + this.lottery.Name + ":" + lotteries.Count + " " + JsonConvert.SerializeObject(lotteries));
                using (var db = new OlaEntities())
                {
                    foreach (var lotteryOpen in lotteries)
                    {
                        try
                        {
                            var lotteryOpenTimes = db.LotteryOpenTimes
                                                   .FirstOrDefault(w => w.LotteryId == this.lottery.LotteryId && w.QiHao == lotteryOpen.QiHao);
                            if (lotteryOpenTimes != null)
                            {
                                lotteryOpen.OpenTime = lotteryOpenTimes.OpenTime.ToString("yyyy-MM-dd HH:mm:ss");
                                var history = db.LotteryOpenHistories
                                              .Any(w => w.LotteryId == this.lottery.LotteryId && w.QiHao == lotteryOpen.QiHao);
                                if (!history)
                                {
                                    // 预测
                                    GetForecast(db, lotteryOpen);

                                    lotteryOpen.Id         = Guid.NewGuid();
                                    lotteryOpen.LotteryId  = this.lottery.LotteryId;
                                    lotteryOpen.CreateTime = DateTime.Now;
                                    lotteryOpen.Source     = (int)LotteryOpenNumberSourceEnum.广东体彩网;

                                    // 获取前三期的预测号码
                                    GetPreForecast(db, lotteryOpen);
                                    db.LotteryOpenHistories.Add(lotteryOpen);
                                    db.SaveChanges();
                                    UpdateWebClientLotteryOpenInfo(lotteryOpen.LotteryId);
                                    var nextInfo = db.LotteryOpenTimes.FirstOrDefault(w => w.LotteryId == lotteryOpen.LotteryId && w.QiHao == lotteryOpenTimes.NextQiHao);
                                    if (nextInfo != null)
                                    {
                                        this.NextQiHao     = Convert.ToInt32(nextInfo.QiHao);
                                        this.NextRequestDT = nextInfo.OpenTime;
                                        log.Info("添加:" + this.lottery.Name + " 期号:" + lotteryOpen.QiHao + " 开奖号码:" + lotteryOpen.OpenNumber + " 获取时间: " + DateTime.Now + ":下次获取时间 " + this.NextRequestDT);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error(this.lottery.Name + " GetLotteryOpenNumberFromgdlottery 解析数据失败", ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(this.lottery.Name + " GetLotteryOpenNumberFromgdlottery 获取数据失败", ex);
            }
        }
Esempio n. 7
0
        public void GetLotteryOpenNumberFrom500()
        {
            if (DateTime.Now <= this.NextRequestDT ||
                string.IsNullOrEmpty(this.lottery.url500))
            {
                return;
            }
            try
            {
                var url  = this.lottery.url500.Replace("{date}", DateTime.Now.ToString("yyyyMMdd"));
                var xDoc = XDocument.Load(url);

                var result = from x in xDoc.Descendants("row")
                             select new LotteryOpenHistory
                {
                    OpenNumber = x.Attribute("opencode").Value,
                    QiHao      = this.lottery.Prefix + x.Attribute("expect").Value.Replace("-", ""),
                };
                result = result.OrderBy(w => w.QiHao);
                using (var db = new OlaEntities())
                {
                    foreach (var lotteryOpen in result)
                    {
                        try
                        {
                            var qihao = Convert.ToInt32(lotteryOpen.QiHao);
                            if (qihao < this.NextQiHao)
                            {
                                continue;
                            }
                            var lotteryOpenTimes = db.LotteryOpenTimes
                                                   .FirstOrDefault(w => w.LotteryId == this.lottery.LotteryId && w.QiHao == lotteryOpen.QiHao);
                            if (lotteryOpenTimes != null)
                            {
                                lotteryOpen.OpenTime = lotteryOpenTimes.OpenTime.ToString("yyyy-MM-dd HH:mm:ss");
                                var history = db.LotteryOpenHistories
                                              .Any(w => w.LotteryId == this.lottery.LotteryId && w.QiHao == lotteryOpen.QiHao);
                                if (!history)
                                {
                                    // 预测
                                    GetForecast(db, lotteryOpen);

                                    lotteryOpen.CreateTime = DateTime.Now;
                                    lotteryOpen.Id         = Guid.NewGuid();
                                    lotteryOpen.LotteryId  = this.lottery.LotteryId;
                                    lotteryOpen.Source     = (int)LotteryOpenNumberSourceEnum.五百彩票;
                                    // 获取前三期的预测号码
                                    GetPreForecast(db, lotteryOpen);
                                    db.LotteryOpenHistories.Add(lotteryOpen);
                                    db.SaveChanges();
                                    UpdateWebClientLotteryOpenInfo(lotteryOpen.LotteryId);
                                    var nextInfo = db.LotteryOpenTimes.FirstOrDefault(w => w.LotteryId == lotteryOpen.LotteryId && w.QiHao == lotteryOpenTimes.NextQiHao);
                                    if (nextInfo != null)
                                    {
                                        this.NextQiHao     = Convert.ToInt32(nextInfo.QiHao);
                                        this.NextRequestDT = nextInfo.OpenTime;
                                        log.Info("添加:" + this.lottery.Name + " 期号:" + lotteryOpen.QiHao + " 开奖号码:" + lotteryOpen.OpenNumber + " 获取时间: " + DateTime.Now + " 下次获取时间: " + this.NextRequestDT);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error(this.lottery.Name + " GetLotteryOpenNumberFrom500 解析数据失败", ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(this.lottery.Name + " GetLotteryOpenNumberFrom500 爬取数据失败", ex);
            }
        }