/// <summary> /// 返回一个本控件的窗体 /// </summary> public static FormModel CreateForm(RuleInfo[] rules) { DataFilter dm = new DataFilter(); dm.AllRules = rules; dm.Dock = DockStyle.Fill; FormModel tf = new FormModel(); tf.Size = new Size(dm.Width + 17, dm.Size.Height + 40); tf.Controls.Add(dm);//将控件添加到窗体中 tf.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; return tf; }
/// <param name="ruleList">规则列表</param> public override bool[][] ValidateRuleList(RuleInfo[] ruleList) { bool[][] res = new bool[ruleList.Length][]; for (int i = 0; i < ruleList.Length; i++) { //首先获取计算的数据,直接从data中获取 ruleList[i].IndexSelector.RuleInfoParams = ruleList[i]; res[i] = ruleList[i].IndexSelector.GetValidateResult (GetNeedDataByCache(ruleList[i].CalcuteRows + ruleList[i].NeedRows));//已经考虑多期指标 } return res; }
private static LotTickData[] FilterData(RuleInfo[] rules) { Dictionary<int, string> dic; LotTickData[] result = TwoColorBall.FilteByRuleList(rules, out dic); //过滤结果写入数据库,并刷新 foreach (var item in dic) { tb_Rules temp = tb_Rules.FindById(item.Key); temp.FilterInfo = item.Value; temp.Update(); } return result; }
/// <summary> /// 需要自定义的长度L /// </summary> public Index_红求余覆盖数(RuleInfo ruleInfo, bool isDeleteMode = false) { this.RuleInfoParams = ruleInfo; IsDeleteNumberMode = isDeleteMode; if (ruleInfo.CondtionParams.ParamsValue != null) { L = Convert.ToInt32(ruleInfo.CondtionParams.ParamsValue); } else { L = 17; } }
/// <summary> /// 初始化,传入参数对象 /// TODO:传入一个实际的彩票类型对象(包括了需要计算的数据和参数),指标根据参数计算得到需要计算的数据 /// </summary> public LotIndex(RuleInfo ruleInfo,bool isDeleteMode = false) { this.RuleInfoParams = ruleInfo; IsDeleteNumberMode = isDeleteMode; }
public Index_Base杀号(RuleInfo ruleInfo) { this.RuleInfoParams = ruleInfo; this.IsDeleteNumberMode = true;//默认为杀号模式 }
/// <summary> /// 根据过滤规则数据,对数据进行过滤:这是不使用提前方案 /// 直接对所有数据过滤,速度较慢 /// </summary> /// <param name="ruleList">规则列表</param> /// <param name="filterInfos">过滤信息</param> /// <returns>过滤后的数据集合</returns> /// <param name="fileName">需要加载的初始数据文件名称</param> public static LotTickData[] FilteByRuleList(RuleInfo[] ruleList, out Dictionary<int, string> filterInfos,string fileName = null ) { if (fileName == null) return FilterByNotUsePrepareData(ruleList, out filterInfos);//不使用预处理数据 else return FilterByUsePrepareData(ruleList,out filterInfos,fileName );//使用初始数据 }
//保存方案数据 public static void SaveData(RuleInfo[] ruleList, string fileName) { List<int> RedBall = new List<int>(33); for (int i = 0; i <33 ; i++) RedBall.Add (i +1); int[][] Red = new Combination(RedBall.Count , 6).Rows.Select (n => Combination.Permute(n, RedBall ).ToArray()).ToArray(); LotTickData[] res = Red.Select (n=>new LotTickData (n )).ToArray (); Dictionary<int, string> filterInfos = new Dictionary<int,string> (); LotTickData[] data = FilterByRules(res ,ruleList , out filterInfos); //方案保存不涉及最高优先级的杀号,因此可以直接进行过滤操作 if (!File.Exists(fileName)) throw new Exception("文件不存在"); NewLife.Serialization.BinaryWriterX binX = new NewLife.Serialization.BinaryWriterX(); FileStream fs = new FileStream(fileName, FileMode.Create); binX.Writer = new BinaryWriter(fs); binX.WriteObject (ruleList,typeof (LotTickData[]),null ); }
/// <summary> /// 保存方案和数据 /// </summary> /// <param name="ruleList">规则列表</param> /// <param name="fileName">保存的文件名称</param> /// <param name="isSaveData">是否保存数据,false则只保存规则</param> public static void SaveProjectData(RuleInfo[] ruleList,string fileName ,bool isSaveData = false ) { SaveRules(ruleList, fileName);//先保存规则信息 if (isSaveData) SaveData(ruleList, fileName); //保存数据 }
public static void SaveRules(RuleInfo[] ruleList, string fileName) { //保存规则 if (File.Exists(fileName)) File.Delete(fileName); NewLife.Xml.XmlWriterX xml = new NewLife.Xml.XmlWriterX(); //写入格式控制 XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.OmitXmlDeclaration = true; settings.NewLineOnAttributes = true; using (XmlWriter writer = XmlWriter.Create(fileName,settings )) { xml.Writer = writer; xml.WriteObject(ruleList, typeof(RuleInfo[]), null); } }
/// <summary> /// 获取杀号类型规则后形成的列表:适用于不是用预处理直接获取数据的情况 /// </summary> /// <param name="ruleList">杀号规则列表</param> public static LotTickData[] GetInitiaDataByNotUserPrepareData(RuleInfo[] ruleList) { List<int> RedBall = new List<int>(33); List<int> BlueBall = new List<int>(16); //初始化 for (int i = 0; i <33 ; i++) RedBall.Add (i +1); for (int i = 0; i <16 ; i++) BlueBall.Add (i +1); for (int i = 0; i < ruleList.Length ; i++) { LotTickData[] curData = new LotTickData[ruleList[i].CalcuteRows + ruleList[i].NeedRows]; if (ruleList[i].IndexSelector.ToString().Contains("红")) //杀红 RedBall =RedBall.Except(ruleList[i].IndexSelector.DeleteNumbers(curData)).ToList (); else //杀篮 BlueBall =BlueBall.Except(ruleList[i].IndexSelector.DeleteNumbers(curData)).ToList (); } //对红和蓝进行组合、迭代获取所有组合序列,并对每个序列进行判断 int[][] Red = new Combination(RedBall.Count , 6).Rows.Select (n => Combination.Permute(n, RedBall ).ToArray()).ToArray(); LotTickData[] res = new LotTickData[Red.GetLength(0) * BlueBall.Count];//总数 int count = 0; for (int i = 0; i < Red.GetLength(0); i++) { for (int j = 0; j < BlueBall.Count ; j++) { res[count] = new LotTickData();//红蓝组合 res[count].NormalData = Red[i]; res[count++].SpecialData = BlueBall[j]; } } return res ; }
public static LotTickData[] DeleteNoProcess(LotTickData[] preData, RuleInfo[] ruleList) { for (int i = 0; i < ruleList.Length; i++) { preData = ruleList[i].IndexSelector.GetFilterResult(preData); } return preData; }
public static LotTickData[] FilterByUsePrepareData(RuleInfo[] ruleList, out Dictionary<int, string> filterInfos, string fileName ) { //先加载初始数据,初始数据只有红球,然后对最高优先级进行处理,然后合并,再进行其他处理 LotTickData[] firData = ReadData(fileName); //TODO:最高优先级处理,并杀号,再组合,并进行其他过滤 RuleInfo[] First = ruleList.Where(n => tb_IndexInfo.Find(tb_IndexInfo._.IndexName, n.IndexSelector.ToString().Replace("LotTick.Index_", "")).PriorLevel == 6).ToArray(); LotTickData[] secData = FilterByRules(firData, First, out filterInfos);//过滤 //排序,按照优先级大小进行 RuleInfo[] LastOrder = ruleList.OrderByDescending(n=>tb_IndexInfo.Find(tb_IndexInfo._.IndexName, n.IndexSelector.ToString().Replace("LotTick.Index_", "")).PriorLevel).ToArray(); return FilterByRules(firData, LastOrder, out filterInfos); }
public static LotTickData[] FilterByRules(LotTickData[] InitData,RuleInfo[] rules, out Dictionary<int, string> filterInfos) { filterInfos = new Dictionary<int, string>(); for (int i = 0; i < rules.Length; i++) { //首先获取计算的数据,直接从data中获取 rules[i].IndexSelector.RuleInfoParams = rules[i]; int firCount = InitData.Length; InitData = rules[i].IndexSelector.GetFilterResult(InitData, GetNeedDataByCache(rules[i].NeedRows)); int lastCount = InitData.Length; //如何返回过滤信息?用字典,加一个规则编号和结果信息 filterInfos.Add(rules[i].RuleID, (firCount - lastCount).ToString()); } return InitData; }
public static LotTickData[] FilterByNotUsePrepareData(RuleInfo[] ruleList, out Dictionary<int, string> filterInfos) { //先获取优先级列表,从指标数据表中获取 RuleInfo[] First = ruleList.Where(n => tb_IndexInfo.Find(tb_IndexInfo._.IndexName, n.IndexSelector.ToString().Replace("LotTick.Index_", "")).PriorLevel == 6).ToArray(); RuleInfo[] Last = ruleList.Where(n => tb_IndexInfo.Find(tb_IndexInfo._.IndexName, n.IndexSelector.ToString().Replace("LotTick.Index_", "")).PriorLevel < 6).ToArray(); //先按照优先级进行划分,对最高级进行处理后,分为杀红号和杀蓝号 LotTickData[] InitData = GetInitiaDataByNotUserPrepareData(First); //组合为LotTickData[],再进行其他的过滤,并输出过滤信息,过滤前后的数目 return FilterByRules(InitData, Last, out filterInfos); }