public void get_hot_red_census(int start, int stop, BindingList <NumCensus> list) { int[] index = new int[36]; for (int i = 0; i < 36; i++) { index[i] = 0; } for (int i = index_begin; i <= index_end; i++) { LottoryItem item = (LottoryItem)ltData.ltSet[i]; for (int k = 0; k < 6; ++k) { index[item.red[k]]++; } } for (int i = 0; i < 36; i++) { if (index[i] > 0) { NumCensus census = new NumCensus(i, index[i]); list.Add(census); } } }
public static int string_to_item(string str, LottoryItem item) { long bit1 = 1; string[] strItem = str.Split(' '); if (strItem.Length > 7) { item.map = 0; item.id = int.Parse(strItem[0]); for (var i = 0; i < DEFINE.RED_ITEM_COUNT; i++) { item.red[i] = int.Parse(strItem[i + 1]); item.sum_all += item.red[i]; item.sum_red += item.red[i]; item.map |= bit1 << ((char)(item.red[i] - 1)); } item.blue = int.Parse(strItem[7]); item.sum_all += item.blue; item.init(); return(0); } MessageBox.Show("Wrong data"); return(-1); }
public int calc_ac() { long acmap = 0; long one = 1; int ac = 0; for (var i = 0; i < 5; i++) { for (var j = i + 1; j < 6; j++) { ac = Math.Abs((int)red[j] - (int)red[i]); acmap |= one << (ac - 1); } } this.ac = LottoryItem.bit_one_count(acmap) - 5; return(this.ac); }
public void refresh_dig_data() { if (runchart_is_drawing) { return; } runchart_is_drawing = true; string nameid = comb_name_select_r.EditValue.ToString(); //------------------------------------------- BindingList <NumCensus> list_census_1 = new BindingList <NumCensus>(); if (nameid == "热球") { get_hot_red_census(index_begin, index_end, list_census_1); } else { get_item_census(index_begin, index_end, LottoryItem.ItemCnId(comb_name_select_r.Text), list_census_1); } //平均值 float sum = 0; float count = 0; float aver = 0; foreach (NumCensus item in list_census_1) { count += item.COUNT; sum += item.NUM * item.COUNT; } aver = sum / count; label_average.Text = "平均值: " + aver.ToString("F2"); //---------------------------------------------- chart_dig_one.SeriesSerializable[0].DataSource = list_census_1; chart_dig_one.SeriesSerializable[0].Name = comb_name_select_r.Text; chart_dig_one.SeriesSerializable[0].ArgumentDataMember = "NUM"; chart_dig_one.SeriesSerializable[0].ValueDataMembers[0] = "COUNT"; runchart_is_drawing = false; }
public DistData(LottoryItem item) { id = item.id; miss = item.miss_row; num = string.Format("{0:00} {1:00} {2:00} {3:00} {4:00} {5:00} {6:00}" , item.red[0], item.red[1], item.red[2], item.red[3], item.red[4], item.red[5], item.blue); long Fix = 0x3F; for (int i = 0; i < 5; ++i) { long mapTmp = item.map & (Fix << (i * 6)); distr *= 10; distr += Combin.bit_count(mapTmp); } distr *= 10; distr += Combin.bit_count(item.map & 0x1C0000000); }
public int load_from_file(string history_file) { var sLine = string.Empty; var objReader = new StreamReader(history_file); while (sLine != null) { sLine = objReader.ReadLine(); if (sLine != null && !sLine.Equals(string.Empty)) { var item = new LottoryItem(); if (string_to_item(sLine, item) == 0) { ltSet.Add(item); } } } objReader.Close(); return(ltSet.Count); }
public void get_item_census(int start, int stop, int typeid, BindingList <NumCensus> list) { int[] index = new int[256]; for (int i = 0; i < 256; i++) { index[i] = 0; } for (int i = index_begin; i <= index_end; i++) { LottoryItem item = (LottoryItem)ltData.ltSet[i]; index[item.allNums[typeid]]++; } for (int i = 0; i < 256; i++) { if (index[i] > 0) { NumCensus census = new NumCensus(i, index[i]); list.Add(census); } } }
public void refresh_runchart_data() { if (runchart_is_drawing) { return; } runchart_is_drawing = true; string nameid = comb_name_select_r.EditValue.ToString(); if (nameid == "热球") { runchart_is_drawing = false; return; } //------------------------------------------- ArrayList list_data = ltData.ltSet.GetRange(index_begin, index_end - index_begin + 1); BindingList <LottoryItem> list_show = new BindingList <LottoryItem>(); foreach (LottoryItem item in list_data) { list_show.Add(item); } //---------------------------------------------- chart_line_one.DataSource = list_show; chart_line_one.SeriesSerializable[0].Name = comb_name_select_r.Text; chart_line_one.SeriesSerializable[0].ArgumentDataMember = "ID"; chart_line_one.SeriesSerializable[0].ValueDataMembers[0] = LottoryItem.names[LottoryItem.ItemCnId(comb_name_select_r.Text)]; runchart_is_drawing = false; }
public static void update_history(object ltd) { var ltData = (LtData)ltd; var url = DEFINE.WEB_DATA_URL + "/ssqhis/"; if (ltData.ltSet.Count == 0) { url += "2003001"; } else { var item = (LottoryItem)ltData.ltSet[ltData.ltSet.Count - 1]; url += (item.id + 1).ToString(); } url += "/2040001"; var strResult = string.Empty; int tryTimes = 3; RETRY: try { var request = (HttpWebRequest)WebRequest.Create(url); request.Timeout = 8000; request.Headers.Set("Pragma", "no-cache"); var response = (HttpWebResponse)request.GetResponse(); var streamReceive = response.GetResponseStream(); var encoding = Encoding.GetEncoding("GB2312"); var streamReader = new StreamReader(streamReceive, encoding); strResult = streamReader.ReadToEnd(); streamReader.Close(); } catch (System.Exception ex) { tryTimes--; if (tryTimes > 0) { goto RETRY; } MessageBox.Show("更新数据失败:" + ex.Message); return; } var items = strResult.Split('\n'); if (items.Length <= 0) { MessageBox.Show("服务器返回数据为空\n"); return; } if (items[0] != "SUCCESS") { MessageBox.Show("更新数据失败:\n" + items[0]); return; } var objWriter = new StreamWriter(DEFINE.HISTORY_FILE, true); for (var i = 1; i < items.Length; i++) { if (items[i] == string.Empty) { continue; } var item = new LottoryItem(); if (string_to_item(items[i], item) == 0) { ltData.ltSet.Add(item); items[i] += "\n"; objWriter.Write(items[i]); } } objWriter.Close(); if (items.Length > 2) { ltData.form.otherUpdateDatas(); } }
public static void get_new(object ltd) { LtData ltData = (LtData)ltd; int tryTimes = 3; int start = 2003001; int stop = 2020999; byte[] byteHead; byte[] byteData; if (ltData.ltSet.Count > 0) { start = ((LottoryItem)ltData.ltSet[ltData.ltSet.Count - 1]).id; start += 1; } RETRY: try { TcpClient tclient = new TcpClient(); tclient.Connect("42.121.193.75", 5000); NetworkStream stream = tclient.GetStream(); ReqHisData req = new ReqHisData(); req.head.key = 0; req.head.magic = IPAddress.HostToNetworkOrder((int)LtNet.LT_MAGIC); req.head.job = IPAddress.HostToNetworkOrder((int)JobId.JOB_HISTORY); req.head.len = IPAddress.HostToNetworkOrder(Marshal.SizeOf(req)); req.req.start = IPAddress.HostToNetworkOrder(start); req.req.stop = IPAddress.HostToNetworkOrder(stop); stream.Write(StructToBytes(req), 0, Marshal.SizeOf(req)); stream.Flush(); //读取头部 ResData res = new ResData(); int headSize = Marshal.SizeOf(res); byteHead = new byte[headSize]; int count = stream.Read(byteHead, 0, headSize); if (count < headSize) { stream.Close(); tclient.Close(); MessageBox.Show("更新数据失败:\n"); return; } res = (ResData)BytesToStruct(byteHead, res.GetType()); res.head.key = IPAddress.NetworkToHostOrder(res.head.key); res.head.magic = IPAddress.NetworkToHostOrder(res.head.magic); res.head.job = IPAddress.NetworkToHostOrder(res.head.job); res.head.len = IPAddress.NetworkToHostOrder(res.head.len); res.result = IPAddress.NetworkToHostOrder(res.result); if (res.head.magic != LtNet.LT_MAGIC || res.head.job != (int)JobId.JOB_HISTORY || res.head.len < headSize) { stream.Close(); tclient.Close(); MessageBox.Show("更新数据失败:错误的响应\n"); return; } if (res.result != 0) { stream.Close(); tclient.Close(); MessageBox.Show("更新数据失败:服务器错误\n"); return; } if (res.head.len == headSize) { stream.Close(); tclient.Close(); return; } int dataLen = res.head.len - headSize; byteData = new byte[dataLen]; int recvLen = 0; while (recvLen < dataLen) { int recvCount = stream.Read(byteData, recvLen, dataLen - recvLen); if (recvCount <= 0) { stream.Close(); tclient.Close(); MessageBox.Show("更新数据失败:\n"); return; } recvLen += recvCount; } } catch (System.Exception ex) { tryTimes--; if (tryTimes > 0) { goto RETRY; } //MessageBox.Show("更新数据失败:" + ex.Message); return; } StreamWriter objWriter = new StreamWriter(DEFINE.HISTORY_FILE, true); ASCIIEncoding encoding = new ASCIIEncoding(); string strLt = encoding.GetString(byteData); int itemAdd = 0; //objWriter.Write(strLt); string[] items = strLt.Split('\n'); for (int i = 0; i < items.Length; i++) { if (items[i].Length < 10) { continue; } LottoryItem item = new LottoryItem(); if (string_to_item(items[i], item) == 0) { ltData.ltSet.Add(item); //if (i < (items.Length - 1)) { items[i] += "\n"; } objWriter.Write(items[i]); itemAdd++; } } objWriter.Close(); if (itemAdd > 0) { Thread.Sleep(1000); ltData.form.otherUpdateDatas(); } }