首页 > 代码库 > 用C#开发的双色球走势图(原创)值得园友拥有
用C#开发的双色球走势图(原创)值得园友拥有
首先声明,个人纯粹无聊之作,不作商业用途。
我相信每个人都拥有一个梦想那就是有朝一日能中500W,这个也一直是我的梦想,并默默每一期双色球或多或少要贡献自己一点点力量,本人并不属于那种铁杆的彩票迷,每次都是纯粹娱乐而已,因为深知这个中奖的概率太低了,每一次买也是随机而已,运气好的话还能中个五块钱,运气不好的话随机买五注,甚至一个号码也中不到,每次去购买双色球都会看到走势图,所以个人最近就花了一点时间在这个上面,进行了一番研究,现将研究成果写出来,供园友一起探讨,愿各位早日中500W。
双色球开奖数据个人也是从某网站抓取的,不保存到数据库,根据这些原始数据去分析双色球的走势,如有基本走势图、红球三分区走势图、红球四分区走势图、红球七分区走势图、红球连号走势图、和值走势图、篮球综合走势图和历史同期等等组成。
首先介绍双色球原始数据是如何获取的?这个对于各位来说都比较简单,就是获取HTML源码,根据HTML去提取相关信息。
获取网页上数据后,再提取HTML相关信息,提取代码如下:
1 /// <summary> 2 /// 循环解析Tr 3 /// </summary> 4 /// <param name="wnRepo"></param> 5 /// <param name="content"><tbody></tbody>之间的内容</param> 6 private void ResolveTr(string content) 7 { 8 listWinNo.Clear(); 9 //--10 string trContent = string.Empty;11 WinNo wn = null;12 Regex regex = new Regex("<tr>");13 //在<tbody></tbody>之间的内容搜索所有匹配<tr>的项14 MatchCollection matches = regex.Matches(content);15 foreach (Match item in matches)16 {17 wn = new WinNo();18 //如果当前匹配项的下一个匹配项的值不为空19 if (!string.IsNullOrEmpty(item.NextMatch().Value))20 {21 trContent = content.Substring(item.Index, item.NextMatch().Index - item.Index);22 }23 //最后一个<tr>的匹配项24 else25 {26 trContent = content.Substring(item.Index, content.Length - item.Index);27 }28 ResolveTd(ref wn, trContent);29 //wnRepo.Insert(wn);30 listWinNo.Add(wn);31 }32 }
存放双色球红球和篮球的实体类:
1 #region * 实体类 2 public class WinNo 3 { 4 /// <summary> 5 /// 期号 6 /// </summary> 7 public string QiHao { get; set; } 8 9 /// <summary>10 /// 第一个红球号码11 /// </summary>12 public int R1 { get; set; }13 /// <summary>14 /// 第二个红球号码15 /// </summary>16 public int R2 { get; set; }17 /// <summary>18 /// 第三个红球号码19 /// </summary>20 public int R3 { get; set; }21 /// <summary>22 /// 第四个红球号码23 /// </summary>24 public int R4 { get; set; }25 /// <summary>26 /// 第五个红球号码27 /// </summary>28 public int R5 { get; set; }29 /// <summary>30 /// 第六个红球号码31 /// </summary>32 public int R6 { get; set; }33 /// <summary>34 /// 篮球号码35 /// </summary>36 public int B { get; set; }37 38 /// <summary>39 /// 用于存放历史数据40 /// </summary>41 public List<string> Data { get; set; }42 }43 #endregion
获取每一期的号码,并返回一个实体:
1 /// <summary> 2 /// 在一个TR中,解析TD,获取一期的号码 3 /// </summary> 4 /// <param name="wn"></param> 5 /// <param name="trContent"></param> 6 private void ResolveTd(ref WinNo wn, string trContent) 7 { 8 List<int> redBoxList = null; 9 //匹配期号的表达式10 string patternQiHao = "<td align=\"center\" title=\"开奖日期";11 Regex regex = new Regex(patternQiHao);12 Match qhMatch = regex.Match(trContent);13 wn.QiHao = trContent.Substring(qhMatch.Index + 17 + patternQiHao.Length, 7);14 //匹配蓝球的表达式15 string patternChartBall02 = "<td class=\"chartBall02\">";16 regex = new Regex(patternChartBall02);17 Match bMatch = regex.Match(trContent);18 wn.B = Convert.ToInt32(trContent.Substring(bMatch.Index + patternChartBall02.Length, 2));19 //存放匹配出来的红球号码20 redBoxList = new List<int>();21 //匹配红球的表达式22 string patternChartBall01 = "<td class=\"chartBall01\">";23 regex = new Regex(patternChartBall01);24 MatchCollection rMatches = regex.Matches(trContent);25 foreach (Match r in rMatches)26 {27 redBoxList.Add(Convert.ToInt32(trContent.Substring(r.Index + patternChartBall01.Length, 2)));28 }29 //匹配红球的表达式30 string patternChartBall07 = "<td class=\"chartBall07\">";31 regex = new Regex(patternChartBall07);32 rMatches = regex.Matches(trContent);33 foreach (Match r in rMatches)34 {35 redBoxList.Add(Convert.ToInt32(trContent.Substring(r.Index + patternChartBall07.Length, 2)));36 }37 //排序红球号码38 redBoxList.Sort();39 //第一个红球号码40 wn.R1 = redBoxList[0];41 //第二个红球号码42 wn.R2 = redBoxList[1];43 wn.R3 = redBoxList[2];44 wn.R4 = redBoxList[3];45 wn.R5 = redBoxList[4];46 wn.R6 = redBoxList[5];47 }
通过以上几个步骤就拿到网站关于双色球红球和篮球的原始数据,下面就根据这些原始数据进行分析。
通过线程池同时去分析双色球的这些数据,节省显示数据的时间,让用户体验更好,这个每个人应该都会。
1.基本走势图
基本走势图包括红球和篮球的走势情况,包括可以显示和不显示遗漏数据的走势图,效果图分别如下:
不带遗漏数据的走势图:
显示双色球基本走势图关键代码如下:
1 #region * 基本走势图 2 /// <summary> 3 /// 基本走势图 4 /// </summary> 5 /// <param name="obj"></param> 6 private void GetData1(object obj) 7 { 8 table.Clear(); 9 cleantable.Clear();10 if (listWinNo != null && listWinNo.Count > 0)11 {12 foreach (WinNo item in listWinNo)13 {14 DataRow dr = table.NewRow();15 dr["QiHao"] = item.QiHao;16 dr["R" + item.R1] = "R" + GetStr(item.R1.ToString());//红117 dr["R" + item.R2] = "R" + GetStr(item.R2.ToString());//红218 dr["R" + item.R3] = "R" + GetStr(item.R3.ToString());//红319 dr["R" + item.R4] = "R" + GetStr(item.R4.ToString());//红420 dr["R" + item.R5] = "R" + GetStr(item.R5.ToString());//红521 dr["R" + item.R6] = "R" + GetStr(item.R6.ToString());//红622 dr["B" + item.B] = "B" + GetStr(item.B.ToString());//篮球23 table.Rows.Add(dr);24 25 DataRow cleandr = cleantable.NewRow();26 cleandr["QiHao"] = item.QiHao;27 cleandr["R" + item.R1] = GetStr(item.R1.ToString());//红128 cleandr["R" + item.R2] = GetStr(item.R2.ToString());//红229 cleandr["R" + item.R3] = GetStr(item.R3.ToString());//红330 cleandr["R" + item.R4] = GetStr(item.R4.ToString());//红431 cleandr["R" + item.R5] = GetStr(item.R5.ToString());//红532 cleandr["R" + item.R6] = GetStr(item.R6.ToString());//红633 cleandr["B" + item.B] = GetStr(item.B.ToString());//篮球34 cleantable.Rows.Add(cleandr);35 }36 37 for (int j = 1; j < 34; j++)38 {39 int xint = 0;40 for (int i = 0; i < table.Rows.Count; i++)41 {42 if (string.IsNullOrEmpty(table.Rows[i]["R" + j].ToString()))43 {44 xint++;45 table.Rows[i]["R" + j] = xint;46 }47 else48 {49 xint = 0;50 }51 }52 }53 54 for (int j = 1; j < 17; j++)55 {56 int xint = 0;57 for (int i = 0; i < table.Rows.Count; i++)58 {59 if (string.IsNullOrEmpty(table.Rows[i]["B" + j].ToString()))60 {61 xint++;62 table.Rows[i]["B" + j] = xint;63 }64 else65 {66 xint = 0;67 }68 }69 }70 71 if (this.IsHandleCreated)72 {73 this.Invoke((MethodInvoker)delegate74 {75 if (flag)76 {77 cleantable.DefaultView.Sort = "QiHao DESC";78 this.gridControl1.DataSource = cleantable.DefaultView.ToTable();79 }80 else81 {82 table.DefaultView.Sort = "QiHao DESC";83 this.gridControl1.DataSource = table.DefaultView.ToTable();84 }85 });86 }87 }88 }89 #endregion
2.红球三分区走势图
红球三分区走势图显示效果如下:(同时也包括带遗漏数据和不带遗漏数据的效果)
不带遗漏数据的红球三分区走势图效果:
实现红球三分区走势图关键代码:
1 #region * 红球三分区走势图 2 /// <summary> 3 /// 红球三分区走势图 4 /// </summary> 5 /// <param name="obj"></param> 6 private void GetData2(object obj) 7 { 8 sedredtable.Clear(); 9 sedcleanredtable.Clear(); 10 if (listWinNo != null && listWinNo.Count > 0) 11 { 12 foreach (WinNo item in listWinNo) 13 { 14 List<int> redList = new List<int>(); 15 redList.Add(item.R1); 16 redList.Add(item.R2); 17 redList.Add(item.R3); 18 redList.Add(item.R4); 19 redList.Add(item.R5); 20 redList.Add(item.R6); 21 //-- 22 DataRow reddr = sedredtable.NewRow(); 23 reddr["QiHao"] = item.QiHao; 24 reddr["R" + item.R1] = "R" + GetStr(item.R1.ToString());//红1 25 reddr["R" + item.R2] = "R" + GetStr(item.R2.ToString());//红2 26 reddr["R" + item.R3] = "R" + GetStr(item.R3.ToString());//红3 27 reddr["R" + item.R4] = "R" + GetStr(item.R4.ToString());//红4 28 reddr["R" + item.R5] = "R" + GetStr(item.R5.ToString());//红5 29 reddr["R" + item.R6] = "R" + GetStr(item.R6.ToString());//红6 30 reddr["A1"] = item.R1 + item.R2 + item.R3 + item.R4 + item.R5 + item.R6;//和值 31 reddr["A2"] = item.R6 - item.R1;//跨度 32 reddr["A3"] = GetQujian(redList);//区间比 33 reddr["A4"] = GetJio(redList);//奇偶比 34 sedredtable.Rows.Add(reddr); 35 36 DataRow cleanreddr = sedcleanredtable.NewRow(); 37 cleanreddr["QiHao"] = item.QiHao; 38 cleanreddr["R" + item.R1] = GetStr(item.R1.ToString());//红1 39 cleanreddr["R" + item.R2] = GetStr(item.R2.ToString());//红2 40 cleanreddr["R" + item.R3] = GetStr(item.R3.ToString());//红3 41 cleanreddr["R" + item.R4] = GetStr(item.R4.ToString());//红4 42 cleanreddr["R" + item.R5] = GetStr(item.R5.ToString());//红5 43 cleanreddr["R" + item.R6] = GetStr(item.R6.ToString());//红6 44 cleanreddr["A1"] = item.R1 + item.R2 + item.R3 + item.R4 + item.R5 + item.R6;//和值 45 cleanreddr["A2"] = item.R6 - item.R1;//跨度 46 cleanreddr["A3"] = GetQujian(redList);//区间比 47 cleanreddr["A4"] = GetJio(redList);//奇偶比 48 sedcleanredtable.Rows.Add(cleanreddr); 49 } 50 51 for (int j = 1; j < 34; j++) 52 { 53 int xint = 0; 54 for (int i = 0; i < sedredtable.Rows.Count; i++) 55 { 56 if (string.IsNullOrEmpty(sedredtable.Rows[i]["R" + j].ToString())) 57 { 58 xint++; 59 sedredtable.Rows[i]["R" + j] = xint; 60 } 61 else 62 { 63 xint = 0; 64 } 65 } 66 } 67 68 if (this.IsHandleCreated) 69 { 70 this.Invoke((MethodInvoker)delegate 71 { 72 if (flag) 73 { 74 sedcleanredtable.DefaultView.Sort = "QiHao DESC"; 75 this.gridControl2.DataSource = sedcleanredtable.DefaultView.ToTable(); 76 } 77 else 78 { 79 sedredtable.DefaultView.Sort = "QiHao DESC"; 80 this.gridControl2.DataSource = sedredtable.DefaultView.ToTable(); 81 } 82 }); 83 } 84 } 85 } 86 87 /// <summary> 88 /// 区间比 89 /// </summary> 90 /// <param name="redList"></param> 91 /// <returns></returns> 92 private string GetQujian(List<int> redList) 93 { 94 int xint1 = 0; 95 int xint2 = 0; 96 int xint3 = 0; 97 foreach (int item in redList) 98 { 99 if (item < 12)100 {101 xint1++;102 }103 else if (item > 11 && item < 23)104 {105 xint2++;106 }107 else if (item > 22)108 {109 xint3++;110 }111 }112 return xint1.ToString() + ":" + xint2.ToString() + ":" + xint3.ToString();113 }114 115 /// <summary>116 /// 奇偶比117 /// </summary>118 /// <param name="redList"></param>119 /// <returns></returns>120 private string GetJio(List<int> redList)121 {122 int xint1 = 0;//奇数123 int xint2 = 0;//偶数124 foreach (int item in redList)125 {126 if (item % 2 == 0)127 {128 xint2++;//偶数129 }130 else131 {132 xint1++;//奇数133 }134 }135 return xint1.ToString() + ":" + xint2.ToString();136 }137 #endregion
预知下文如何,请听下回分解!望各位园友拍砖灌水,让博主有动力继续下面...
3.红球四分区走势图
4.红球七分区走势图
5.红球连号走势图
6.和值走势图
7.篮球综合走势图
8.历史同期
敬请期待下文的补充...
用C#开发的双色球走势图(原创)值得园友拥有