用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 else
25 {
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());//紅1
17 dr["R" + item.R2] = "R" + GetStr(item.R2.ToString());//紅2
18 dr["R" + item.R3] = "R" + GetStr(item.R3.ToString());//紅3
19 dr["R" + item.R4] = "R" + GetStr(item.R4.ToString());//紅4
20 dr["R" + item.R5] = "R" + GetStr(item.R5.ToString());//紅5
21 dr["R" + item.R6] = "R" + GetStr(item.R6.ToString());//紅6
22 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());//紅1
28 cleandr["R" + item.R2] = GetStr(item.R2.ToString());//紅2
29 cleandr["R" + item.R3] = GetStr(item.R3.ToString());//紅3
30 cleandr["R" + item.R4] = GetStr(item.R4.ToString());//紅4
31 cleandr["R" + item.R5] = GetStr(item.R5.ToString());//紅5
32 cleandr["R" + item.R6] = GetStr(item.R6.ToString());//紅6
33 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 else
48 {
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 else
65 {
66 xint = 0;
67 }
68 }
69 }
70
71 if (this.IsHandleCreated)
72 {
73 this.Invoke((MethodInvoker)delegate
74 {
75 if (flag)
76 {
77 cleantable.DefaultView.Sort = "QiHao DESC";
78 this.gridControl1.DataSource = cleantable.DefaultView.ToTable();
79 }
80 else
81 {
82 table.DefaultView.Sort = "QiHao DESC";
83 this.gridControl1.DataSource = table.DefaultView.ToTable();
84 }
85 });
86 }
87 }
88 }
89 #endregion
實現紅球三分區走勢圖關鍵代碼:
復制代碼
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 else
131 {
132 xint1++;//奇數
133 }
134 }
135 return xint1.ToString() + ":" + xint2.ToString();
136 }
137 #endregion