public override ExpectList <T> ReadHistory <T>(string begt, string endt) { DateTime dt = DateTime.Parse(begt); MongoDataDictionary <ExchangeMongoData> res = GetAllCodeDateSerialDataList <ExchangeMongoData>(begt, endt, true); Dictionary <string, MongoReturnDataList <ExchangeMongoData> > data = res; ExpectList <ExchangeMongoData> ret = new ExpectList <ExchangeMongoData>(data, true); ExpectList <T> retlist = new ExpectList <T>(); ret.DataList.ForEach(a => { ExpectData <T> ed = new ExpectData <T>(); ed.CurrTime = null; ed.Key = "Security"; foreach (string code in a.Keys) { if (ed.CurrTime == null) { ed.CurrTime = a[code].date; } ed.Expect = MongoDateTime.StampToDate(a[code].date_stamp).Ticks.ToString(); ed.Add(code, a[code] as T); } retlist.Add(ed); }); return(retlist); }
public override ExpectList <T> getJsonData <T>(string strXml) { Web52CP_KL12_DataClass dc = new Web52CP_KL12_DataClass(); dc = dc.FromJson(strXml); ExpectList <T> ret = new ExpectList <T>(); if (dc.result != null) { for (int i = dc.result.Count - 1; i >= 0; i--) { ExpectData <T> data = new ExpectData <T>(); Web52CP_Lotty_KL12_DataClass obj = dc.result[i]; data.Expect = obj.expect; data.OpenCode = obj.num; if (string.IsNullOrEmpty(obj.num)) { if (string.IsNullOrEmpty(obj.num10)) { data.OpenCode = string.Format("{0},{1},{2},{3},{4}", obj.num1, obj.num2, obj.num3, obj.num4, obj.num5); } else { data.OpenCode = string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", obj.num1, obj.num2, obj.num3, obj.num4, obj.num5, obj.num6, obj.num7, obj.num8, obj.num9, obj.num10); } } data.OpenTime = new DateTime(1970, 1, 1).ToLocalTime().AddSeconds(obj.opentime); data.ExpectSerialByType = 2; data.ExpectSerialLong = 3; ret.Add(data); } } return(ret); }
/// <summary> /// 计算峰值 /// </summary> /// <param name="N">回览次数</param> /// <param name="K">成功次数</param> /// <param name="p">正常概率</param> public override List <ChanceClass> getChances(BaseCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); MLDataFactory pkdls = new MLDataFactory();// this.LastUseData()); //Dictionary<int, Dictionary<int, int>> res = pkdls.getAllShiftAndColMaxProbList(this.ReviewExpectCnt- this.InputMinTimes-1, this.InputMinTimes,true); List <MLFeature <int> > features = pkdls.getAllSpecRowRoundFeatures(this.LastUseData().Count - 1, this.InputMinTimes, 0); Dictionary <string, int> AllCodes = new Dictionary <string, int>(); for (int i = 0; i < features.Count; i++) { MLFeature <int> feature = features[i]; MaxEnt me = new MaxEnt(); if (MaxEnt.FeatureSummary == null) { me.OnLoadLocalFile = LoadLocalTrainData; me.LoadSummary(); } me.FillStructBySummary(i); MLInstance <int, int> instance = new MLInstance <int, int>(feature); int label = me.Classify(instance); if (label < 0) { continue; } string strAllCode = string.Format("{0}/{1}", (i + 1) % 10, label); AllCodes.Add(strAllCode, 1); } ////foreach (int key in res.Keys) //// AllCodes.Add(string.Format("{0}/{1}",key,string.Join("",res[key].Keys.ToArray())),1); if (true) { ChanceClass cc = new ChanceClass(); cc.SignExpectNo = ed.Expect; cc.ChanceType = 2; cc.InputTimes = 1; cc.strInputTimes = string.Join("_", new string[2] { "1", "1" }); //cc.AllowMaxHoldTimeCnt = this.AllowMaxHoldTimeCnt; cc.InputExpect = ed; cc.StragId = this.GUID; //cc.MinWinRate = this.CommSetting.GetGlobalSetting().DefaultHoldAmtSerials.MaxRates[cc.ChipCount - 1]; cc.IsTracer = 0; cc.HoldTimeCnt = 1; cc.Odds = this.CommSetting.GetGlobalSetting().Odds; cc.ExpectCode = ed.Expect; cc.ChanceCode = string.Join("+", AllCodes.Keys.ToArray()); cc.ChipCount = ChanceClass.getChipsByCode(cc.ChanceCode); cc.CreateTime = DateTime.Now; cc.UpdateTime = DateTime.Now; cc.AllowMaxHoldTimeCnt = 1; cc.Closed = false; ret.Add(cc); } return(ret); }
public override ExpectList <T> getXmlData <T>(string strXml) { ExpectList <T> ret = new ExpectList <T>(); XmlDocument doc = new XmlDocument(); try { doc.LoadXml(strXml); XmlNodeList rows = doc.SelectNodes("/xml/row"); if (rows.Count == 0) { return(ret); } for (int i = rows.Count - 1; i >= 0; i--) { ExpectData <T> ed = new ExpectData <T>(); ed.Expect = rows[i].Attributes["expect"].Value; ed.OpenCode = rows[i].Attributes["opencode"].Value; ed.OpenTime = DateTime.Parse(rows[i].Attributes["opentime"].Value); if (!ed.IsValidData()) { continue; } ret.Add(ed as ExpectData <T>); } } catch (Exception e) { LogLib.LogableClass.ToLog(string.Format("非正常的xml数据,[{0}]:[{1}]", e.Message, e.StackTrace), strXml); } return(ret); }
object getGridAfterMouseUp <T1>(DataGridView dg, MouseEventArgs e) { if (dg.SelectedRows.Count <= 0) { return(default(T)); } if (dg.SelectedRows[0].Index < 0) { return(default(T)); } int index = dg.SelectedRows[0].Index; DataTable dt = dg.Tag as DataTable; if (dt == null) { MessageBox.Show("附加表为空!"); return(default(T)); } if (dt.Rows.Count < index + 1) { MessageBox.Show("表长度不足!"); return(default(T)); } DataRow dr = dt.Rows[index]; ////if (dr["GUID"] == null) ////{ //// MessageBox.Show("GUID未找到!"); //// return default(T); ////} string pguid = ""; if (dt.Columns.Contains("GUID")) //支持所有guid { dr["GUID"].ToString(); } if (typeof(T1) == typeof(BaseStragClass <T>)) { return(getServiceStrag(pguid)); } else if (typeof(T1) == typeof(StragRunPlanClass <T>)) { return(getServicePlan(pguid)); } else if (typeof(T1) == typeof(ExpectData)) { List <ExpectData> list = new ExpectData().FillByTable <ExpectData>(dt); return(list[index]); } else if (typeof(T1) == typeof(ChanceClass)) { List <ChanceClass> list = new ChanceClass().FillByTable <ChanceClass>(dt); return(list[index]); } else { return(default(T1)); } //return plan; }
public override List <ChanceClass <T> > getChances(BaseCollection <T> sc, ExpectData <T> ed) { List <ChanceClass <T> > ret = new List <ChanceClass <T> >(); FirstPointFilter_Logic_Strategy fpf = new FirstPointFilter_Logic_Strategy(new CommDataIntface()); fpf.InParam = new CommStrategyInClass(); return(ret); }
public override ExpectList <T> getHisData <T>(string strHtml) { return(getData <T>(strHtml)); ExpectList <T> ret = new ExpectList <T>(); string strBeg = "<table cellspacing=\"0\" cellpadding=\"0\" class=\"dt caipiao mbm\""; string strEnd = "</table>"; int ibeg = strHtml.IndexOf(strBeg); strHtml = strHtml.Substring(ibeg); int iend = strHtml.IndexOf(strEnd) + strEnd.Length; if (ibeg == 0) { return(ret); } if (iend <= 0) { return(ret); } string txtTable = strHtml.Substring(0, iend); XmlDocument doc = new XmlDocument(); try { doc.LoadXml(txtTable); XmlNodeList nodelist = doc.SelectNodes("table/tr"); for (int i = 0; i < nodelist.Count; i++) { if (i == 0) { continue; } XmlNodeList tdlist = nodelist[i].SelectNodes("td"); if (tdlist.Count == 0) { continue; } ExpectData <T> ed = new ExpectData <T>(); string strExpect = tdlist[0].InnerText; string strIndex = tdlist[1].InnerText; string strOpenCodes = string.Join(",", tdlist[2].InnerText.Substring(0, 5).ToCharArray()); string[] strTimes = strExpect.Split(' '); DateTime dt = DateTime.ParseExact(strExpect, "yyyyMMdd HH:mm", CultureInfo.InvariantCulture); DateTime bdt = DateTime.Parse(dt.ToShortDateString()); string strRindex = "0000" + dt.Subtract(bdt).TotalMinutes.ToString(); ed.Expect = string.Format("{0}{1}", strTimes[0], strRindex.Substring(strRindex.Length - 4)); ed.OpenCode = strOpenCodes; ed.OpenTime = dt; ret.Add(ed); } } catch (Exception ce) { } return(ret); }
public List <ChanceClass <T> > ExecExchange(ExpectData <T> data) { List <ChanceClass <T> > ret = new List <ChanceClass <T> >(); //////////ExchanceClass ec = new ExchanceClass(); //////////for (int i = 0; i < gobj.CurrStags.Count; i++) //////////{ //////////} return(ret); }
public override List <ChanceClass> getChances(BaseCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); ExpectList el = sc.orgData; List <ChanceClass> scs = new List <ChanceClass>(); strag_CommOldClass coc = new strag_CommOldClass(); coc.CommSetting = this.CommSetting; coc.ChipCount = this.ChipCount; coc.FixChipCnt = true; //coc.AllowMaxHoldTimeCnt = this.AllowMaxHoldTimeCnt; coc.BySer = this.BySer; //coc.ReviewExpectCnt = ; coc.InputMinTimes = this.InputMinTimes; coc.StagSetting = new StagConfigSetting(); if (!this.IsTracing)//未持仓时才计算过往概率 { double sucrate = double.NaN; if (this.CommSetting.UseLocalWaveData)//如果使用本地数据,获取该期本地数据 { sucrate = this.LocalWaveData[el.LastData.Expect]; } if (double.IsNaN(sucrate)) //如果数据异常,继续去寻找 { sucrate = getSucRate(el, coc, true); //该类策略全部是一次性机会,可反复下注 } if (this.RateDic == null) { this.RateDic = new Dictionary <string, double>(); } if (!this.RateDic.ContainsKey(this.LastUseData().LastData.Expect))//加入胜率队列 { RateDic.Add(this.LastUseData().LastData.Expect, sucrate); } if (!this.CheckEnableIn()) { return(ret); } this.IsTracing = true;//满足条件,开始持仓 //this.debug_maxRate = 0; } BaseCollection scc = new ExpectListProcess(el).getSerialData(InputMinTimes, BySer) as BaseCollection; ret = coc.getChances(scc, el.LastData); for (int i = 0; i < ret.Count; i++) { ret[i].NeedConditionEnd = true; ret[i].OnCheckTheChance += CheckNeedEndTheChance; } return(ret); }
/// <summary> /// 计算峰值 /// </summary> /// <param name="N">回览次数</param> /// <param name="K">成功次数</param> /// <param name="p">正常概率</param> public override List <ChanceClass> getChances(BaseCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); PKDataListSetFactory pkdls = new PKDataListSetFactory(this.LastUseData()); Dictionary <int, Dictionary <int, int> > res = pkdls.OccurrSpecLengthShiftProbList(this.ReviewExpectCnt, 1, 0, 10); Dictionary <string, int> AllCodes = new Dictionary <string, int>(); foreach (int key in res.Keys) { Dictionary <int, int> sres = res[key].Where(p => p.Value > this.InputMinTimes).ToDictionary(p => p.Key, p => p.Value); if (sres.Count == 0) { continue; } AllCodes.Add(string.Format("{0}/{1}", key, string.Join("", sres.Keys.ToArray())), 1); } string strAllCode = string.Join("+", AllCodes.Keys.ToArray()); if (ChanceClass.getChipsByCode(strAllCode) < this.ChipCount) { return(ret); } if (true) { ChanceClass cc = new ChanceClass(); cc.SignExpectNo = ed.Expect; cc.ChanceType = 2; cc.InputTimes = 1; cc.strInputTimes = string.Join("_", new string[2] { "1", "1" }); //cc.AllowMaxHoldTimeCnt = this.AllowMaxHoldTimeCnt; cc.InputExpect = ed; cc.StragId = this.GUID; //cc.MinWinRate = this.CommSetting.GetGlobalSetting().DefaultHoldAmtSerials.MaxRates[cc.ChipCount - 1]; cc.IsTracer = 0; cc.HoldTimeCnt = 1; cc.Odds = this.CommSetting.GetGlobalSetting().Odds; cc.ExpectCode = ed.Expect; cc.ChanceCode = string.Join("+", AllCodes.Keys.ToArray()); cc.ChipCount = ChanceClass.getChipsByCode(cc.ChanceCode); cc.CreateTime = DateTime.Now; cc.UpdateTime = DateTime.Now; cc.AllowMaxHoldTimeCnt = 1; cc.Closed = false; ret.Add(cc); } return(ret); }
private void dg_baseData_MouseUp(object sender, MouseEventArgs e) { DisableAllMenus(); ExpectData ed = getGridAfterMouseUp <ExpectData>(this.dg_baseData, e) as ExpectData; if (e.Button == System.Windows.Forms.MouseButtons.Right) { if (ed == null) { this.tmi_Delete.Visible = true; this.tmi_Delete.Enabled = true; this.tmi_Delete.Tag = ed; } this.tmi_refreshPlans.Visible = true; this.tmi_refreshPlans.Enabled = true; this.tmi_refreshPlans.Tag = ed; } dg_baseData.ContextMenuStrip = this.contextMenuStrip_OperatePlan; }
public override ExpectList <T> getData <T>(string strHtml) { ExpectList <T> ret = new ExpectList <T>(); string strBeg = "<table"; string strEnd = "</table>"; int ibeg = strHtml.IndexOf(strBeg); int iend = strHtml.IndexOf(strEnd) + strEnd.Length; if (ibeg == 0) { return(ret); } if (iend <= ibeg) { return(ret); } string txtTable = strHtml.Substring(ibeg, iend - ibeg); XmlDocument doc = new XmlDocument(); try { doc.LoadXml(txtTable); XmlNodeList nodelist = doc.SelectNodes("table/tr"); for (int i = 0; i < nodelist.Count; i++) { XmlNodeList tdlist = nodelist[i].SelectNodes("td"); if (tdlist.Count == 0) { continue; } ExpectData <T> ed = new ExpectData <T>(); ed.Expect = tdlist[1].InnerText.Replace("-", ""); ed.OpenCode = tdlist[4].InnerText; ed.OpenTime = DateTime.Parse(tdlist[2].InnerText); ret.Add(ed); } } catch (Exception ce) { } return(ret); }
public override ExpectList <T> getData <T>(string strHtml) { ExpectList <T> ret = new ExpectList <T>(); string startStr = "lg-history-table\">"; string endStr = "</table>"; string strXml = strHtml.Substring(strHtml.IndexOf(startStr) + startStr.Length); int endPos = strXml.IndexOf(endStr) + endStr.Length; strXml = strXml.Substring(0, endPos); XmlDocument doc = new XmlDocument(); try { doc.LoadXml(strXml); XmlNodeList rows = doc.SelectNodes("/table/tbody/tr"); if (rows.Count == 0) { return(ret); } for (int i = rows.Count - 1; i >= 0; i--) { XmlNodeList tdNodes = rows[i].SelectNodes("td"); XmlNodeList td2Nodes = tdNodes[2].SelectNodes("div"); ExpectData <T> ed = new ExpectData <T>(); ed.Expect = tdNodes[0].InnerText; string strCode = string.Join(",", td2Nodes[0].InnerText.Replace("10", "0").ToCharArray()); ed.OpenCode = ChanceCodes(strCode); ed.OpenTime = DateTime.Now.Date.Add(DateTime.Parse(tdNodes[1].InnerText).TimeOfDay); if (!ed.IsValidData()) { continue; } ret.Add(ed); } } catch { } return(ret); }
public override List <ChanceClass <TimeSerialData> > getChances(BaseCollection <TimeSerialData> sc, ExpectData <TimeSerialData> ed) { //return null;// BaseCollection inBc = sc as BaseCollection; ExpectData inData = ed.CopyTo <ExpectData>(); try { List <ChanceClass> ret = getChances(inBc, inData); List <ChanceClass <TimeSerialData> > retval = new List <ChanceClass <TimeSerialData> >(); ret.ForEach(a => { ChanceClass <TimeSerialData> cc = a; retval.Add(cc); }); return(retval); } catch (Exception ce) { Log(string.Format("策略{0}错误", this.StragClassName), string.Format("{0}:{1}", ce.Message, ce.StackTrace)); } return(new List <ChanceClass <TimeSerialData> >()); }
public override List <ChanceClass> getChances(BaseCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); if (sc == null || sc.Table == null || sc.Table.Rows.Count < this.ReviewExpectCnt) { return(ret); } DataTableEx dt = sc.CarTable; if (dt == null) { throw new Exception("无法获得概率分布表!"); } //Log("最后一期数据", string.Join(",", dt.Rows[0].ItemArray)); //Log("最后二期数据", string.Join(",", dt.Rows[1].ItemArray)); string val = dt.Rows[dt.Rows.Count - 1][string.Format("{0}", InputMinTimes)].ToString(); OnceChance cc = new OnceChance(); cc.SignExpectNo = ed.Expect; cc.ChanceType = 1; string code_model = "{0}/{1}"; HoldCnt++; cc.ChanceCode = BySer ? string.Format(code_model, InputMaxTimes, val) : string.Format(code_model, val, InputMaxTimes); cc.ChipCount = 1;//码数必须是实际码数,使用的金额队列必须是1码的队列 cc.InputTimes = HoldCnt; cc.strInputTimes = string.Format("{0}", cc.InputTimes); cc.AllowMaxHoldTimeCnt = 1; cc.InputExpect = ed; cc.StragId = this.GUID; cc.NeedConditionEnd = true;//这是必须的,才能在整体回测中触发CheckNeedEndTheChance //cc.MinWinRate = this.CommSetting.GetGlobalSetting().DefaultHoldAmtSerials.MaxRates[cc.ChipCount - 1]; cc.IsTracer = 0; cc.Odds = this.CommSetting.GetGlobalSetting().Odds; //cc.UnitCost = this.getChipAmount(0,cc,); ret.Add(cc); return(ret); }
public abstract List <ChanceClass> getChances(CommCollection sc, ExpectData ed);
public override List <ChanceClass> getChances(BaseCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); //ExpectListProcess elp = new ExpectListProcess(Data); //CommCollection sc = elp.getSerialData(ReviewExpectCnt,BySer); for (int i = 0; i < 10; i++) { Dictionary <int, string> SerStrs = sc.Data[i]; int ishift = sc.Data[0].Count - 1; while (ishift >= this.InputMinTimes) { if (SerStrs.ContainsKey(ishift)) { if (SerStrs[ishift].Trim().Length == (10 - this.ChipCount)) { if (this.ExcludeBS && ChanceClass.isBS(SerStrs[ishift].Trim())) { break; } if (this.ExcludeSD && ChanceClass.isSD(SerStrs[ishift].Trim())) { break; } if (this.OnlyBS && !ChanceClass.isBS(SerStrs[ishift].Trim())) { break; } if (this.OnlySD && !ChanceClass.isSD(SerStrs[ishift].Trim())) { break; } ChanceClass cc = new ChanceClass(); cc.SignExpectNo = ed.Expect; cc.ChanceType = 2; cc.InputTimes = ishift; cc.InputExpect = ed; string strCode = ""; if (BySer) { strCode = string.Format("{0}/{1}", (i + 1) % 10, SerStrs[ishift].Trim()); } else { strCode = string.Format("{0}/{1}", SerStrs[ishift].Trim(), i); } cc.ChanceCode = ChanceClass.getRevChance(strCode); cc.CreateTime = ed.OpenTime; cc.Closed = false; ret.Add(cc); break; } else { ishift--; } } } } return(ret); }
public override List <ChanceClass> getChances(BaseCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); CurrChancesCnt = 0;//置零,防止后面留存 ExpectList LastDataList = this.LastUseData(); if (LastDataList == null) { Log(this.StragClassName, "数据为空!"); return(ret); } if (LastDataList.Count < ReviewExpectCnt) { Log("基础数据数量不足", string.Format("小于回览期数:{0}", ReviewExpectCnt)); return(ret); } //ExpectList LastDataList = datas; ExpectData PreData = LastDataList[LastDataList.Count - 2]; //Log(string.Format("前期{0}:{1}", PreData.Expect, PreData.OpenCode), string.Format("当期{0}:{1}", LastDataList.LastData.Expect, LastDataList.LastData.OpenCode)); //Log(string.Format("el数据长度:{0},First:{1};Last{2}", LastDataList.Count,LastDataList.FirstData.Expect,LastDataList.LastData.Expect), string.Format("原始数据长度:{0};First:{1};Last:{2}", sc.orgData.Count,sc.orgData.FirstData.Expect,sc.orgData.LastData.Expect)); DataTableEx dt = sc.getSubTable(sc.orgData.Count - this.ReviewExpectCnt, this.ReviewExpectCnt); List <string> strCodes = new List <string>(); for (int i = 0; i < 10; i++)//遍历每个车号/名次 { List <int> coldata = null; string strCol = string.Format("{0}", (i + 1) % 10); dt.getColumnData(strCol, ref coldata); //Log(string.Format("车/次:{0}",strCol), string.Format("取得的数据:{0}",string.Join(",",coldata))); int RepeatCnt = 0; for (int j = 1; j < ReviewExpectCnt; j++) { if (coldata[j] == coldata[j - 1]) { RepeatCnt++; } } if (RepeatCnt < this.ReviewExpectCnt - 1)//如果重复次数小于回顾次数减一,表示重复次数不够,跳过 { continue; } string strCode = "";//其实无需比较,对单个车/名次来说,矩阵都一样,策略只需建立一个即可 strCode = string.Format("{0}/{1}", strCol, coldata[0]); //Log(string.Format("车/次:{0}", strCol), strCode); strCodes.Add(strCode); if (HoldCnt >= 0) //当持有次数超过指定次数后,不再增加 { HoldCnt++; //持有次数加1 } //Log("获得机会处理", string.Format("当前持有次数:{0}", HoldCnt)); RealCnt++; } if (strCodes.Count == 0)//机会数为0 { return(ret); } if (!GetRev) { OnceChance cc = new OnceChance(); cc.SignExpectNo = ed.Expect; cc.ChanceType = 1; cc.ChanceCode = string.Join("+", strCodes); cc.ChipCount = strCodes.Count;//码数必须是实际码数,使用的金额队列必须是1码的队列 cc.InputTimes = RealCnt; cc.strInputTimes = string.Format("{0}", cc.InputTimes); cc.AllowMaxHoldTimeCnt = 1; cc.InputExpect = ed; cc.NeedConditionEnd = true; cc.StragId = this.GUID; //cc.MinWinRate = this.CommSetting.GetGlobalSetting().DefaultHoldAmtSerials.MaxRates[cc.ChipCount - 1]; cc.IsTracer = 0; cc.Odds = this.CommSetting.GetGlobalSetting().Odds; CurrChancesCnt = strCodes.Count; //cc.UnitCost = this.getChipAmount(0,cc,); ret.Add(cc); //获得所有机会后,统一为本次机会分配资金 return(ret); } else { for (int i = 0; i < strCodes.Count; i++) { NolimitTraceChance cc = new NolimitTraceChance(); cc.SignExpectNo = ed.Expect; cc.ChanceType = 1; cc.ChanceCode = ChanceClass.getRevChance(strCodes[i]); cc.ChipCount = 9;//码数必须是实际码数,使用的金额队列必须是1码的队列 cc.InputTimes = RealCnt; cc.strInputTimes = string.Format("{0}", cc.InputTimes); cc.AllowMaxHoldTimeCnt = 1; cc.InputExpect = ed; cc.StragId = this.GUID; //cc.MinWinRate = this.CommSetting.GetGlobalSetting().DefaultHoldAmtSerials.MaxRates[cc.ChipCount - 1]; cc.IsTracer = 1; cc.Odds = this.CommSetting.GetGlobalSetting().Odds; CurrChancesCnt = strCodes.Count; //cc.UnitCost = this.getChipAmount(0,cc,); ret.Add(cc); } return(ret); } }
public override ExpectList <T> getData <T>(string strHtml) { DateTime Now = DateTime.Now; ExpectList <T> ret = new ExpectList <T>(); string classTable = @"class=""list"""; string regtxt = @"<table class=""list"">.*(<tr>.*?</tr>)</tbody></table>"; Regex regTr = new Regex(@"(?is)(?<=<table[^>]*?" + classTable + "[^>]*?>(?:(?!</?table).)*)(?is)<tr[^>]*?>(?:\\s*<td[^>]*>(.*?)</td>)*\\s*</tr>"); //MatchCollection mc = Regex.Matches(strHtml, regtxt); MatchCollection mc = regTr.Matches(strHtml); HashSet <string> AllEds = new HashSet <string>(); for (int ci = mc.Count - 1; ci >= 0; ci--) { Match m = mc[ci]; Regex regTd = new Regex(@"(?is)(?<=<td(\s+align=[^>]+)?>).*?(?=\s*</td)"); MatchCollection mtd = regTd.Matches(m.Value); ExpectData <T> ed = new ExpectData <T>(); ed.Expect = mtd[0].Value; string[] strs = mtd[2].Value.Split('=')[0].Replace(" ", "").Split('+'); for (int i = 0; i < strs.Length; i++) { strs[i] = ((strs[i] == "0")?"1":"0") + strs[i]; } ed.OpenCode = string.Join(",", strs); DateTime currVal = DateTime.Parse(string.Format("{0}-{1}", Now.Year, mtd[1].Value)); if (currVal > Now) //如果匹配出的时间大于当前时间 { currVal = DateTime.Parse(string.Format("{0}-{1}", Now.Year - 1, mtd[1].Value)); } ed.OpenTime = currVal; if (AllEds.Contains(ed.Expect)) { continue; } AllEds.Add(ed.Expect); ret.Add(ed); } return(ret); string strBeg = "<table"; string strEnd = "</table>"; int ibeg = strHtml.IndexOf(strBeg); int iend = strHtml.IndexOf(strEnd) + strEnd.Length; if (ibeg == 0) { return(ret); } if (iend <= ibeg) { return(ret); } string txtTable = strHtml.Substring(ibeg, iend - ibeg); XmlDocument doc = new XmlDocument(); try { doc.LoadXml(txtTable); XmlNodeList nodelist = doc.SelectNodes("table/tr"); for (int i = 0; i < nodelist.Count; i++) { XmlNodeList tdlist = nodelist[i].SelectNodes("td"); if (tdlist.Count == 0) { continue; } ExpectData <T> ed = new ExpectData <T>(); ed.Expect = tdlist[1].InnerText.Replace("-", ""); ed.OpenCode = tdlist[4].InnerText; ed.OpenTime = DateTime.Parse(tdlist[2].InnerText); ret.Add(ed); } } catch (Exception ce) { } return(ret); }
public ExpectList <T> getFileData <T>(string filename) where T : TimeSerialData { ExpectList <T> ret = new ExpectList <T>(); FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read); StreamReader str = new StreamReader(file, Encoding.Default); try { //用以接受FileStream对象中的数据,第2个参数是字节数组中开始写入数据的位置,它通常是0, //表示从数组的开端文件中向数组写数据,最后一个参数规定从文件读多少字符. Decoder d = Encoding.Default.GetDecoder(); int lcnt = 0; string txtline; while ((txtline = str.ReadLine()) != null) { lcnt++; if (lcnt <= 1) { continue;//标题跳过 } if (txtline.Trim().Length == 0) { continue; } txtline = txtline.Replace(" ", ","); string[] items = txtline.Split(','); if (items.Length != 2) { throw new Exception(string.Format("{0}第{1}行数据异常!", filename, lcnt)); } ExpectData <T> ed = new ExpectData <T>(); ed.OpenCode = string.Join(",", items[1].ToCharArray()); string strOrg = items[0]; string[] strOrgs = strOrg.Split('-'); if (strOrgs.Length > 1) { string strDate = strOrgs[0]; string strId = strOrgs[1]; string DstrDate = string.Format("{0}-{1}-{2}", strDate.Substring(0, 4), strDate.Substring(4, 2), strDate.Substring(6)); DateTime etime = DateTime.Parse(DstrDate); ed.OpenTime = etime.AddMinutes(int.Parse(strId)).AddSeconds(6); ed.Expect = ed.OpenTime.ToString("yyyy-MM-dd HH-mm-SS").Replace("-", "").Replace("/", "").Replace(":", "").Replace(" ", "").Substring(0, 12); } else { ed.Expect = strOrg; string strDate = strOrg.Substring(0, 8); string strId = ed.Expect.Substring(8); string DstrDate = string.Format("{0}-{1}-{2} {3}:{4}:{5}", strDate.Substring(0, 4), strDate.Substring(4, 2), strDate.Substring(6), strId.Substring(0, 2), strId.Substring(2), "06"); DateTime etime = DateTime.Parse(DstrDate); ed.OpenTime = etime; } //ed.Expect = items[0].Replace("-", ""); //if (ed.OpenCode == "0,0,0,0,0") ret.Add(ed); } str.Close(); //file.Close(); } catch (IOException e) { str.Close(); //file.Close(); throw e; } return(ret); }
public override List <ChanceClass> getChances(BaseCollection sc, ExpectData ed) { throw new NotImplementedException(); }
public override List <ChanceClass> getChances(BaseCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); DataTableEx dt = null; if (this.BySer) { dt = sc.SerialDistributionTable; } else { dt = sc.CarDistributionTable; } if (dt == null) { throw new Exception("无法获得概率分布表!"); } int MatchCnt = 0; string strAllCodes = ""; double MinSucRate = 0; if (this.FixChipCnt) { MinSucRate = this.CommSetting.Odds / this.ChipCount; //指定注数需要的最小胜率 } for (int i = 0; i < 10; i++) { //获得各项的最小的 List <double> coldata = null; string strCol = string.Format("{0}", (i + 1) % 10); string strVal = ed.ValueList[i]; int ExistCnt = sc.FindLastDataExistCount(this.InputMinTimes, strCol, strVal); if (ExistCnt > 1)//前n次不是最后一次才出现 { continue; } dt.getColumnData(strCol, ref coldata); double avgval = coldata.Average(); double stdval = ProbMath.CalculateStdDev(coldata); string strSql = string.Format("[{0}]={1}", "Id", strVal); string strSort = string.Format("[{0}] asc", "Id"); DataRow[] drs = dt.Select(strSql, ""); if (drs.Length != 1) { throw new Exception("概率数据表错乱!"); } int InAllViewExistCnt = int.Parse(drs[0][strCol].ToString()); //前100(指定的viewcnt)期出现的次数 if (InAllViewExistCnt > avgval - stdval * this.StdvCnt) //如果前100期内出现的概率大于指定的标准差数,跳过 { continue; } if (InAllViewExistCnt > this.ReviewExpectCnt * (1 - MinSucRate))//如果成功数小于对应注数的失败数 { continue; } string strCode = string.Format("{0}/{1}", BySer ? strCol : strVal, BySer ? strVal : strCol); MatchCnt++; strAllCodes = string.Format("{0}{1}{2}", strAllCodes, MatchCnt > 1 ? "+" : "", strCode); } if (MatchCnt < this.ChipCount) { return(ret); } ChanceClass cc = new ChanceClass(); cc.SignExpectNo = ed.Expect; cc.ChanceType = 3; cc.InputTimes = 1; cc.strInputTimes = "1"; cc.AllowMaxHoldTimeCnt = 1; cc.InputExpect = ed; cc.ChipCount = MatchCnt; cc.ChanceCode = strAllCodes; cc.CreateTime = ed.OpenTime; cc.NeedConditionEnd = true; cc.OnCheckTheChance += CheckNeedEndTheChance; cc.Closed = false; ret.Add(cc); return(ret); }
public override List <ChanceClass> getChances(BaseCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); //ExpectListProcess elp = new ExpectListProcess(Data); //CommCollection sc = elp.getSerialData(ReviewExpectCnt,BySer); Dictionary <string, int> MatchTimes = new Dictionary <string, int>(); Dictionary <string, string> MatchChances = new Dictionary <string, string>(); Dictionary <string, string> CombDic = new Dictionary <string, string>(); Dictionary <int, int> MaxCnts = new Dictionary <int, int>(); Dictionary <int, int> NoCnts = new Dictionary <int, int>(); int MinLimit = this.CommSetting.minColTimes[this.ChipCount + 3 - 1]; #region 获取所有满足基本条件的组合 for (int i = 0; i < 10; i++) { Dictionary <int, string> SerStrs = sc.Data[i]; int ishift = MinLimit - 1; //多三级 if (SerStrs[ishift].Length < this.ChipCount) //不满足基本条件 { continue; } MaxCnts.Add(i, this.ReviewExpectCnt);//默认长度都是reviewcnt,如果大于指定长度的机会持续次数大于review,所有子机会都会加一 NoCnts.Add(i, SerStrs[ishift].Length); string strColKeymModel = "{0}_{1}"; while (ishift < this.ReviewExpectCnt)//从前三级开始爬 { ishift++; if (SerStrs.ContainsKey(ishift) && SerStrs.ContainsKey(ishift - 1)) { string strCode = ""; int INo = -1; if (BySer) { INo = (i) % 10; strCode = SerStrs[ishift - 1].Trim();//1,2,3,4,5,6,7,8,9,0 } else { INo = i; strCode = SerStrs[ishift - 1].Trim(); //0,1,2,3,4,5,6,7,8,9 } if (SerStrs[ishift].Trim().Length >= this.ChipCount) //往上看 { bool Matched = false; if (SerStrs[ishift].Trim().Length < SerStrs[ishift - 1].Trim().Length)//收缩,当前行小于上一行 { Matched = true; } else { if (ishift >= this.ReviewExpectCnt - 1)//结束了还未收缩,则加入 { Matched = true; } } if (Matched) { List <string> AllStrCode = new List <string>(); if (strCode.Trim().Length == this.ChipCount) { AllStrCode.Add(strCode); } else { AllStrCode = ChanceClass.getAllSubCode(strCode, this.ChipCount); } for (int j = 0; j < AllStrCode.Count; j++) { string strColKey = string.Format(strColKeymModel, INo, AllStrCode[j]); if (!MatchChances.ContainsKey(strColKey)) { MatchChances.Add(strColKey, AllStrCode[j]); MatchTimes.Add(strColKey, ishift + 1 - 1); } else { MatchTimes[strColKey] = ishift + 1 - 1; } } } } else//爬到看到的数量小于长度时,很可能会匹配不到,因为到最后一条数据显示长度仍然大于等于长度,所以,review需要足够长,最好大于高一码的最大长度 { string strColKey = string.Format(strColKeymModel, INo, strCode); if (!MatchChances.ContainsKey(strColKey)) { MatchChances.Add(strColKey, strCode); MatchTimes.Add(strColKey, ishift + 1 - 1); } else { MatchTimes[strColKey] = ishift + 1 - 1; } MaxCnts[i] = ishift; //每列符合条件的最大值,作为判断是否是本车/本排名的最大列用 break; // } } } } #endregion string ComKeyModel = "{0}+{1}";//小大排列 if (MatchChances.Count <= 1) { return(ret); //只有一个组合 } foreach (string _key in MatchChances.Keys) { string[] keyArr = _key.Split('_'); int key = int.Parse(keyArr[0]); //int cnt = int.Parse(keyArr[1]); foreach (string _key1 in MatchChances.Keys) { string[] keyArr1 = _key1.Split('_'); int key1 = int.Parse(keyArr1[0]); //int cnt1 = int.Parse(keyArr1[1]); if (key == key1) { continue; } string sKey, bKey; if (key < key1) { sKey = _key; bKey = _key1; } else { sKey = _key1; bKey = _key; } string CombKey = string.Format(ComKeyModel, sKey, bKey); if (CombDic.ContainsKey(CombKey)) { continue;//防止实质相同但是顺序相反组合重复进入 } int Time1, Time2, SameNoCnt; Time1 = MatchTimes[_key]; Time2 = MatchTimes[_key1]; if (!BySer)//如果是按车视图 { Time1 -= 2; Time2 -= 2; } SameNoCnt = ChanceClass.getSameNoCnt(MatchChances[_key], MatchChances[_key1]); //获得相同号码的数量 //判断两个是不是本车/本排名中最大长度的机会 int AddSameNocnt = -2; //只有两个都是最长才不减,否则每个减1 if (MaxCnts[key] > Time1) { Time1 -= 2; } if (MaxCnts[key1] > Time2) { Time2 -= 2; } if (MaxCnts[key] < this.CommSetting.minColTimes[this.ChipCount]) { Time1 -= 2; } if (MaxCnts[key1] < this.CommSetting.minColTimes[this.ChipCount]) { Time2 -= 2; } //SameNoCnt += AddSameNocnt; bool Matched = false; //Level1 int LevelU2 = this.CommSetting.minColTimes[this.ChipCount + 2 - 1]; //上两级 int LevelU1 = this.CommSetting.minColTimes[this.ChipCount + 1 - 1]; //上一级 int LevelU0 = this.CommSetting.minColTimes[this.ChipCount - 1]; //本级 List <string> strCodes = getAllCodes(MatchChances[_key], MatchChances[_key1], this.BySer); //////if (BySer) ////// strCode = string.Format("{0}/{1}", (i + 1) % 10, SerStrs[ishift].Trim()); //////else ////// strCode = string.Format("{0}/{1}", SerStrs[ishift].Trim(), i); string strCode = this.BySer ? string.Format("{0}/{1}+{2}/{3}", (key + 1) % 10, MatchChances[_key], (key1 + 1) % 10, MatchChances[_key1]) : string.Format("{0}/{1}+{2}/{3}", MatchChances[_key], key, MatchChances[_key1], key1); if (SameNoCnt >= 3)//所有相同个数等于 { if (Time1 >= MinLimit && Time2 >= MinLimit && this.ChipCount == SameNoCnt) { Matched = true; } //////else //////{ if ((Time1 + Time2) >= (LevelU1 + LevelU2) && Time1 >= LevelU2 && Time2 > LevelU2) { Matched = true; } //////} } if (SameNoCnt >= 2) { if (Time1 * 2 >= (LevelU2 + LevelU1) && Time2 * 2 >= (LevelU2 + LevelU1) && (Time1 + Time2) >= 2 * LevelU1) { Matched = true; } } if (SameNoCnt >= 1) { if (Time1 >= LevelU1 && Time2 >= LevelU1 && (Time1 + Time2) >= (LevelU1 + LevelU0)) { Matched = true; } } if (SameNoCnt >= -2) { if (Time1 * 2 >= (LevelU0 + LevelU1) && Time2 * 2 >= (LevelU1 + LevelU0)) { Matched = true; } } if (!Matched) { continue; } CombDic.Add(CombKey, strCode); NolimitTraceChance cc = new NolimitTraceChance(); cc.ChipCount = this.ChipCount * 2; //cc.AllowMaxHoldTimeCnt = this.AllowMaxHoldTimeCnt; cc.SignExpectNo = ed.Expect; cc.ChanceType = 0; cc.InputTimes = Math.Min(Time1, Time2); cc.strInputTimes = string.Format("{0}_{1}", Time1, Time2); cc.InputExpect = ed; cc.ChanceCode = strCode; cc.IsTracer = 1; cc.CreateTime = ed.OpenTime; cc.Closed = false; ret.Add(cc); } } return(ret); }
public override List <ChanceClass> getChances(BaseCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); Dictionary <string, string> MatchCols = new Dictionary <string, string>(); Dictionary <string, int> MatchCnt = new Dictionary <string, int>(); int MutliMinCnt = this.CommSetting.GetGlobalSetting().SingleColMinTimes; int TwoMinCnt = (this.CommSetting.GetGlobalSetting().MinTimeForChance(1) + this.CommSetting.GetGlobalSetting().MinTimeForChance(2)) / 2; string colmodel = "{0}_{1}";//列_长度 for (int i = 0; i < 10; i++) { int ishift = MutliMinCnt; if (!sc.Data[i].ContainsKey(ishift) || sc.Data[i][ishift].Trim().Length == 0) //不及最小值,跳过 { continue; } string strCol = string.Format(colmodel, i, sc.Data[i][ishift].Length); if (!MatchCols.ContainsKey(strCol)) { MatchCols.Add(strCol, sc.Data[i][ishift]); MatchCnt.Add(strCol, ishift + 1);//实际数量 } ishift++; while (sc.Data[i].ContainsKey(ishift) && sc.Data[i][ishift].Trim().Length > 0) //一直往上找 { string lastVal = sc.Data[i][ishift]; //可能不止一个数字 strCol = string.Format(colmodel, i, lastVal.Length); if (!MatchCols.ContainsKey(strCol)) { MatchCols.Add(strCol, lastVal); MatchCnt.Add(strCol, ishift + 1);//实际数量 } else { MatchCnt[strCol] = MatchCnt[strCol] + 1; } ishift++; } //ishift--; } //替换列中数据长度大于1的数据,只留最短的 for (int i = 0; i < 10; i++) { string keymodel = "{0}_{1}"; string key = string.Format(keymodel, i, 1); if (!MatchCols.ContainsKey(key))//如果1个都不存在,跳过 { continue; } string strVal = MatchCols[key]; int k = 2; key = string.Format(keymodel, i, k); while (MatchCols.ContainsKey(key))//逐级替换 { string tmp = MatchCols[key]; MatchCols[key] = MatchCols[key].Replace(strVal, ""); strVal = tmp; k++; key = string.Format(keymodel, i, k); } } if (MatchCols.Count > 1) { Log("50以上的组合", string.Join("+", MatchCols.Select(p => string.Format("{0}/{1}:{2}", p.Key, p.Value, MatchCnt[p.Key])).ToArray())); } if (MatchCols.Count < 2) { return(ret); } List <string> strCodes = new List <string>(); List <string> strCodes2 = new List <string>(); List <int> intCnt2 = new List <int>(); foreach (string key in MatchCnt.Keys) { string[] keys = key.Split('_'); string strCode = string.Format("{0}/{1}", (int.Parse(keys[0]) + 1) % 10, MatchCols[key]); if (MatchCnt[key] > TwoMinCnt)//如果2个数小于58 { strCodes2.Add(strCode); intCnt2.Add(MatchCnt[key]); } strCodes.Add(strCode); } if (strCodes.Count == 2) { if (strCodes2.Count < 2) { return(ret); } } List <string> strCommCodes = new List <string>(); List <string> strCommCnts = new List <string>(); if (strCodes2.Count >= 2) //合成2个的组合 { Log("50以上机会:", string.Join("+", strCodes2.ToArray())); for (int i = 0; i < strCodes2.Count; i++) { for (int j = i + 1; j < strCodes2.Count; j++) { strCommCodes.Add(string.Format("{0}+{1}", strCodes2[i], strCodes2[j])); strCommCnts.Add(string.Format("{0}_{1}", intCnt2[i], intCnt2[j])); } } } for (int i = 0; i < strCommCodes.Count; i++) { NolimitTraceChance cc = new NolimitTraceChance(); cc.SignExpectNo = ed.Expect; cc.ChanceType = 0; cc.ChipCount = 2; cc.InputTimes = MatchCnt.Values.Min <int>(); cc.strInputTimes = strCommCnts[i]; //cc.AllowMaxHoldTimeCnt = this.AllowMaxHoldTimeCnt; cc.InputExpect = ed; cc.StragId = this.GUID; cc.MinWinRate = this.CommSetting.GetGlobalSetting().DefaultHoldAmtSerials.MaxRates[cc.ChipCount - 1]; cc.IsTracer = 1; cc.HoldTimeCnt = 1; cc.Odds = this.CommSetting.GetGlobalSetting().Odds; cc.ExpectCode = ed.Expect; cc.ChanceCode = strCommCodes[i]; cc.CreateTime = DateTime.Now; cc.UpdateTime = DateTime.Now; cc.Closed = false; ret.Add(cc); } if (strCodes.Count > 2) { string strAllCodes = string.Join("+", strCodes.ToArray()); NolimitTraceChance cc = new NolimitTraceChance(); cc.SignExpectNo = ed.Expect; cc.ChanceType = 0; cc.ChipCount = strCodes.Count; cc.InputTimes = MatchCnt.Values.Min <int>(); cc.strInputTimes = string.Join("_", MatchCnt.Values.ToArray <int>()); //cc.AllowMaxHoldTimeCnt = this.AllowMaxHoldTimeCnt; cc.InputExpect = ed; cc.StragId = this.GUID; cc.MinWinRate = this.CommSetting.GetGlobalSetting().DefaultHoldAmtSerials.MaxRates[cc.ChipCount - 1]; cc.IsTracer = 1; cc.HoldTimeCnt = 1; cc.Odds = this.CommSetting.GetGlobalSetting().Odds; cc.ExpectCode = ed.Expect; cc.ChanceCode = strAllCodes; cc.CreateTime = DateTime.Now; cc.UpdateTime = DateTime.Now; cc.Closed = false; ret.Add(cc); } return(ret); }
public override List <ChanceClass> getChances(BaseCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); //ExpectListProcess elp = new ExpectListProcess(Data); //CommCollection sc = elp.getSerialData(ReviewExpectCnt,BySer); // Log("策略关键参数",string.Format("name:{4};ViewCnt:{0};MinInput:{1};DataCnt:{2};Chipcnt:{3}",this.ReviewExpectCnt,this.InputMinTimes,sc.Data[0].Count,this.ChipCount,this.StragScript)); for (int i = 0; i < 10; i++) { Dictionary <int, string> SerStrs = sc.Data[i]; if (!SerStrs.ContainsKey(this.InputMinTimes - 1)) { continue; } if (SerStrs[this.InputMinTimes - 1].Length < this.ChipCount) { continue; } int ishift = this.InputMinTimes - 1; //Log("起始位置", ishift.ToString()); List <string> strCcs = ChanceClass.getAllSubCode(SerStrs[ishift].Trim(), this.ChipCount); for (int j = 0; j < strCcs.Count; j++) { string strCars = strCcs[j]; if (this.ExcludeBS && ChanceClass.isBS(strCars)) { continue; } if (this.ExcludeSD && ChanceClass.isSD(strCars)) { continue; } if (this.OnlyBS && !ChanceClass.isBS(strCars)) { continue; } if (this.OnlySD && !ChanceClass.isSD(strCars)) { continue; } NolimitTraceChance cc = new NolimitTraceChance(); cc.SignExpectNo = ed.Expect; cc.ChanceType = 0; cc.ChipCount = strCars.Length; cc.InputTimes = ishift + 1; cc.strInputTimes = cc.InputTimes.ToString(); //cc.AllowMaxHoldTimeCnt = this.AllowMaxHoldTimeCnt; cc.InputExpect = ed; cc.StragId = this.GUID; cc.MinWinRate = this.CommSetting.GetGlobalSetting().DefaultHoldAmtSerials.MaxRates[cc.ChipCount - 1]; cc.IsTracer = 1; cc.HoldTimeCnt = 1; cc.Odds = this.CommSetting.GetGlobalSetting().Odds; cc.ExpectCode = ed.Expect; string strCode = ""; if (BySer) { strCode = string.Format("{0}/{1}", (i + 1) % 10, strCcs[j].Trim()); } else { strCode = string.Format("{0}/{1}", strCcs[j].Trim(), i); } cc.ChanceCode = strCode; cc.CreateTime = DateTime.Now; cc.UpdateTime = DateTime.Now; cc.Closed = false; ret.Add(cc); } //} //} } return(ret); }
public override List <ChanceClass> getChances(CommCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); DataTableEx dt = null; if (this.BySer) { dt = sc.SerialDistributionTable; } else { dt = sc.CarDistributionTable; } if (dt == null) { throw new Exception("无法获得概率分布表!"); } string strCodes = ""; int AllChipCnt = 0; for (int i = 0; i < 10; i++) { //获得各项的最小的 List <double> coldata = null; string strCol = string.Format("{0}", (i + 1) % 10); dt.getColumnData(strCol, ref coldata); double avgval = coldata.Average(); double stdval = ProbMath.CalculateStdDev(coldata); string strSql = string.Format("[{0}]<{1}", strCol, avgval - this.StdvCnt * stdval); string strSort = string.Format("[{0}] asc", "Id"); DataRow[] drs = dt.Select(strSql, strSort); if (drs.Length < this.ChipCount) { continue; } string strCode = ""; StringBuilder sb = new StringBuilder(); bool Matched = false; for (int j = 0; j < drs.Length; j++) { string strId = drs[j]["Id"].ToString(); int RowCnt = sc.FindLastDataExistCount(this.InputMinTimes, strCol, strId); if (RowCnt > 0)//任何一个不匹配最近5期内出现,不满足条件 { Matched = false; break; } sb.Append(drs[j]["Id"].ToString()); Matched = true; } if (!Matched) { continue; } AllChipCnt += drs.Length; if (BySer) { strCode = string.Format("{0}/{1}", strCol, sb.ToString()); } else { strCode = string.Format("{0}/{1}", sb.ToString(), strCol); } if (strCode.Length > 0) { strCodes = string.Format("{0}{1}{2}", strCodes, strCodes.Length > 0?"+":"", strCode); } } if (strCodes.Length < 2 * (this.ChipCount + 2)) { return(ret); } ChanceClass cc = new ChanceClass(); cc.SignExpectNo = ed.Expect; cc.ChanceType = 3; cc.InputTimes = 1; cc.strInputTimes = "1"; cc.AllowMaxHoldTimeCnt = 1; cc.InputExpect = ed; cc.ChipCount = AllChipCnt; cc.ChanceCode = strCodes; cc.CreateTime = ed.OpenTime; cc.Closed = false; ret.Add(cc); return(ret); }
public override List <ChanceClass> getChances(BaseCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); return(ret); }
public override List <ChanceClass> getChances(CommCollection sc, ExpectData ed) { List <ChanceClass> ret = new List <ChanceClass>(); if (sc == null || sc.Table == null || sc.Table.Rows.Count < this.ReviewExpectCnt) { return(ret); } if (this.getAllStdDev() == null) { this.setAllStdDev(new Dictionary <string, List <double> >()); } double stdval = 0; List <double> list = sc.getAllDistrStdDev(this.ReviewExpectCnt, this.InputMaxTimes); if (!this.getAllStdDev().ContainsKey(ed.Expect)) { stdval = list[10];//最后一位 this.getAllStdDev().Add(ed.Expect, list); } if (getAllStdDev().Count < 20) { return(ret); } MA ma20 = new MA(getAllStdDev().Values.Select(p => p[10]).ToArray(), 20); MA ma5 = new MA(getAllStdDev().Values.Select(p => p[10]).ToArray(), 5); if (!IsTracing) { //if (stdval > 0.2) return ret; if (ma20.IsDownCross())//下穿均线,开始跟踪 { IsTracing = true; } else { return(ret); } } else { ////if (stdval > 0.2) ////{ //// IsTracing = false; //// return ret; ////} if (ma5.IsUpCross())//上穿均线,停止跟踪 { IsTracing = false; return(ret); } } strag_CommOldClass strag = new strag_CommOldClass(); strag.BySer = this.BySer; strag.ChipCount = this.ChipCount; strag.InputMinTimes = this.InputMinTimes; List <ChanceClass> tmp = strag.getChances(sc, ed); Dictionary <string, double> dic = new Dictionary <string, double>(); for (int i = 0; i < 10; i++) { if (list[i] < stdval)//小于整体的才有效 { string strcol = string.Format("{0}", (i + 1) % 10); dic.Add(strcol, list[i]); } } for (int i = 0; i < tmp.Count; i++) { if (dic.ContainsKey(tmp[i].GetCodeKey(this.BySer))) { ret.Add(tmp[i]); } } return(ret); }
double getSucRate(ExpectList el, strag_CommOldClass coc, bool OnlyOnceChance) { Dictionary <string, ChanceClass> NoEndChances = new Dictionary <string, ChanceClass>(); Dictionary <string, ChanceClass> TmpChances = new Dictionary <string, ChanceClass>(); int MatchTimes = 0; int AllTimes = 0; for (int i = this.InputMaxTimes; i < el.Count; i++)//因为最后一次数据如果下注就不知道结果,所以最后一次排除下注,只做验证上次结果用 { ExpectList useList = el.getSubArray(i - this.InputMinTimes, this.InputMinTimes); ExpectData CurrData = useList.LastData; TmpChances = new Dictionary <string, ChanceClass>(); foreach (string key in NoEndChances.Keys) { ChanceClass cc = NoEndChances[key]; int MatchCnt = 0; bool Matched = cc.Matched(CurrData, out MatchCnt, false); if (Matched) { if (OnlyOnceChance)//如果是一次性机会 { if (cc.HoldTimeCnt == 1) { MatchTimes++; continue; } } else { MatchTimes++; } } else { if (!TmpChances.ContainsKey(key)) { cc.HoldTimeCnt++; cc.Closed = false; TmpChances.Add(key, cc); if (!OnlyOnceChance)//如果不是一次性机会,每次机会都加1 { AllTimes++; } } } } if (i == el.Count - 1) { break;//最后一期不找机会 } NoEndChances = new Dictionary <string, ChanceClass>(); foreach (string key in TmpChances.Keys)//遗留机会 { NoEndChances.Add(key, TmpChances[key]); } CommCollection scc = new ExpectListProcess(useList).getSerialData(InputMinTimes, BySer); List <ChanceClass> ccs = coc.getChances(scc, CurrData); for (int j = 0; j < ccs.Count; j++)//新增机会 { if (!NoEndChances.ContainsKey(ccs[j].ChanceCode)) { NoEndChances.Add(ccs[j].ChanceCode, ccs[j]); AllTimes++; } } } return((double)100 * MatchTimes / AllTimes); }
public override List <ChanceClass> getChances(CommCollection sc, ExpectData ed) { InitAllPeaks();//初始化峰值列表 List <ChanceClass> ret = new List <ChanceClass>(); if (sc == null || sc.Table == null || sc.Table.Rows.Count < this.ReviewExpectCnt) { return(ret); } int AllItemCnt = AllBinomPeaks.Count; Dictionary <string, Dictionary <int, int> > AllList = new Dictionary <string, Dictionary <int, int> >(); for (int i = 0; i < 10; i++)//遍历各车/各名次 { string strCol = string.Format("{0}", (i + 1) % 10); //string strVal = ed.ValueList[i]; Dictionary <int, int> ValCntItems = new Dictionary <int, int>(); for (int val = 0; val < 10; val++)//对每个数字出现的次数检查 { ValCntItems.Add(val, 0); string strVal = string.Format("{0}", val); foreach (string key in AllBinomPeaks.Keys) //遍历所有峰值清单 { int ViewCnt = int.Parse(key.Split('_')[0]); //获得峰值清单对应的实验次数 int ExistCnt = sc.FindLastDataExistCount(ViewCnt, strCol, strVal); //获得前N-1次该车次出现的次数 if (AllBinomPeaks[key].Contains(ExistCnt + 1)) //如果该二项分布检查的峰值是7,8,9,值出现的次数是6,7,8,匹配,+1 { ValCntItems[val] = ValCntItems[val] + 1; } } } //满足所有二项分布的才入选 Dictionary <int, int> ValidItems = ValCntItems.Where(c => c.Value == AllItemCnt).ToDictionary(a => a.Key, b => b.Value); Dictionary <int, int> MatchPoisonItems = new Dictionary <int, int>(); foreach (int key in ValidItems.Keys) { int ViewCnt = MinFilterCnt - 1; //找出所有值在前100次里出现的次数 int ExistCnt = sc.FindLastDataExistCount(ViewCnt, strCol, key.ToString()); //满足最泊松分布最顶峰 if (ExistCnt == ViewCnt / 10 - 1) { MatchPoisonItems.Add(key, ValidItems[key]); } } AllList.Add(strCol, MatchPoisonItems); } //检查所有满足条件的清单 Dictionary <string, int> AllCodes = new Dictionary <string, int>(); List <string> strCnts = new List <string>(); bool RetMutliChances = this.FixChipCnt; foreach (string strcol in AllList.Keys) { if (AllList[strcol].Count == 0) { continue; } int MaxCnt = AllList[strcol].Values.Max();//选最优 //Dictionary<int,int> strCodeList = AllList[strcol].Where(a => a.Value == MaxCnt).ToDictionary(a => a.Key, b => b.Value); Dictionary <int, int> strCodeList = AllList[strcol]; string StrCode = ""; string StrVal = string.Join("", strCodeList.Keys.ToArray()); string strCnt = string.Join("_", strCodeList.Values.ToArray()); strCnts.Add(strCnt); if (BySer) { StrCode = string.Format("{0}/{1}", strcol, StrVal); } else { StrCode = string.Format("{0}/{1}", StrVal, strcol); } AllCodes.Add(StrCode, strCodeList.Count); } Log("所有选出来的记录", string.Join("+", AllCodes.Keys.ToArray())); if (AllCodes.Count == 0) { return(ret); } if (RetMutliChances) { foreach (string key in AllCodes.Keys) { int Chips = AllCodes[key]; if (Chips == 1) { continue; } if (Chips < this.ChipCount) { continue; } ChanceClass cc = new ChanceClass(); cc.ChanceCode = key; cc.SignExpectNo = ed.Expect; cc.ChanceType = 2; cc.ChipCount = AllCodes[key]; cc.InputTimes = 1; cc.strInputTimes = "";// string.Join("_", strCnts.ToArray()); //cc.AllowMaxHoldTimeCnt = this.AllowMaxHoldTimeCnt; cc.InputExpect = ed; cc.StragId = this.GUID; //cc.MinWinRate = this.CommSetting.GetGlobalSetting().DefaultHoldAmtSerials.MaxRates[cc.ChipCount - 1]; cc.IsTracer = 0; cc.HoldTimeCnt = 1; cc.Odds = this.CommSetting.GetGlobalSetting().Odds; cc.ExpectCode = ed.Expect; cc.CreateTime = DateTime.Now; cc.UpdateTime = DateTime.Now; cc.MaxHoldTimeCnt = 1; cc.Closed = false; ret.Add(cc); } return(ret); } ////if (AllCodes.Count == 1 && AllCodes.First().Value == 1)//独此一份 //// return ret; string strAllCode = string.Join("+", AllCodes.Keys.ToArray()); if (ChanceClass.getChipsByCode(strAllCode) < this.ChipCount) { return(ret); } if (!RetMutliChances) { ChanceClass cc = new ChanceClass(); cc.SignExpectNo = ed.Expect; cc.ChanceType = 2; cc.ChipCount = AllCodes.Sum(p => p.Value); cc.InputTimes = 1; cc.strInputTimes = string.Join("_", strCnts.ToArray()); //cc.AllowMaxHoldTimeCnt = this.AllowMaxHoldTimeCnt; cc.InputExpect = ed; cc.StragId = this.GUID; //cc.MinWinRate = this.CommSetting.GetGlobalSetting().DefaultHoldAmtSerials.MaxRates[cc.ChipCount - 1]; cc.IsTracer = 0; cc.HoldTimeCnt = 1; cc.Odds = this.CommSetting.GetGlobalSetting().Odds; cc.ExpectCode = ed.Expect; cc.ChanceCode = string.Join("+", AllCodes.Keys.ToArray()); cc.CreateTime = DateTime.Now; cc.UpdateTime = DateTime.Now; cc.MaxHoldTimeCnt = 1; cc.Closed = false; ret.Add(cc); } return(ret); }