123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717 |
- using Common;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Common
- {
- public static class CzDataHelper
- {
- #region 值的计算
- public static bool IsCf(string code)
- {
- var list = code.Split('+')[0].Split(',').ToList();
- if (list.GroupBy(i => i).Where(g => g.Count() > 1).Count() >= 1)
- return true;
- return false;
- }
- #region 和值相关
- /// <summary>
- /// 得到和值
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- public static int GetHz(string code)
- {
- var list = code.Split('+')[0].Split(',').ToList();
- if (code.IsEmpty())
- return 0;
- return list.Sum(p => p.TryToInt32());
- }
- /// <summary>
- /// 得到和值的大小
- /// </summary>
- /// <param name="hz"></param>
- /// <returns></returns>
- public static string GetHzDxValue(int hz)
- {
- if (GetHzDx(hz) == 1)
- {
- return "大";
- }
- return "小";
- }
- #endregion
- /// <summary>
- /// 得到跨度
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- public static int GetKd(string code)
- {
- var list = code.Split('+')[0].Split(',').ToList().OrderByDescending(p => p);
- if (code.IsEmpty())
- return 0;
- return list.FirstOrDefault().TryToInt32() - list.LastOrDefault().TryToInt32();
- }
- /// <summary>
- /// AC值计算
- /// </summary>
- /// <param name="kjh"></param>
- /// <returns></returns>
- public static int GetAc(string code)
- {
- var list = code.Split('+')[0].Split(',').ToList().OrderByDescending(p => p);
- List<string> result = GetCombination(list.ToArray(), 2);
- ArrayList acarray = new ArrayList();
- int tpac = 0;
- for (int i = 0; i < result.Count; i++)
- {
- string[] tp = result[i].Split(',');
- int tmp = Math.Abs(Convert.ToInt32(tp[0]) - Convert.ToInt32(tp[1]));
- if (!acarray.Contains(tmp))
- {
- tpac++;
- acarray.Add(tmp);
- }
- }
- return tpac - (list.Count() - 1);
- }
- /// <summary>
- /// 根据和值返回和尾
- /// </summary>
- /// <param name="hz"></param>
- /// <returns></returns>
- public static int GetHw(int hz)
- {
- return hz % 10;
- }
- /// <summary>
- /// 得到大小 和尾、跨度(值)
- /// </summary>
- /// <param name="hz"></param>
- /// <returns></returns>
- public static string GetDxValue(int value)
- {
- if (GetDx(value) == 1)
- {
- return "大";
- }
- return "小";
- }
- /// <summary>
- /// 得到单双(和值、合尾、跨度)
- /// </summary>
- /// <param name="hz"></param>
- /// <returns></returns>
- public static string GetDsValue(int value)
- {
- if (value % 2 != 0)
- {
- return "单";
- }
- return "双";
- }
- /// <summary>
- /// 得到形态 012路(和值、合尾、跨度)
- /// </summary>
- /// <param name="hz"></param>
- /// <returns></returns>
- public static string Get012Value(int value)
- {
- if (value % 3 == 0)
- {
- return "0";
- }
- else if (value % 3 == 1)
- {
- return "1";
- }
- return "2";
- }
- #region 形态
- /// <summary>
- /// 得到形态大小
- /// </summary>
- /// <param name="hz"></param>
- /// <returns></returns>
- public static string GetXtDxValue(string code)
- {
- var result = "";
- code.Split(',').ToList().ForEach(p =>
- {
- if (GetDx(int.Parse(p)) == 1)
- {
- result += "大";
- }
- else
- {
- result += "小";
- }
- });
- return result;
- }
- /// <summary>
- /// 得到形态 单双
- /// </summary>
- /// <param name="hz"></param>
- /// <returns></returns>
- public static string GetXtDsValue(string code)
- {
- var result = "";
- code.Split(',').ToList().ForEach(p =>
- {
- if (int.Parse(p) % 2 != 0)
- {
- result += "单";
- }
- else
- {
- result += "双";
- }
- });
- return result;
- }
- /// <summary>
- /// 得到形态 012路
- /// </summary>
- /// <param name="hz"></param>
- /// <returns></returns>
- public static string GetXt012Value(string code)
- {
- var result = "";
- code.Split(',').ToList().ForEach(p =>
- {
- if (int.Parse(p) % 3 == 0)
- {
- result += "0";
- }
- else if (int.Parse(p) % 3 == 1)
- {
- result += "1";
- }
- else
- {
- result += "2";
- }
- });
- return result;
- }
- #endregion
- /// <summary>
- /// 得到组选
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static string GetZx(string value)
- {
- var list = value.Split(',').ToList();
- if (list.Count < 3)
- {
- list = new List<string>();
- foreach (var item in value)
- {
- list.Add(item.ToString());
- }
- }
- list = list.Where(p => !string.IsNullOrEmpty(p.Trim())).Select(p => p.Trim()).ToList();
- if (list.GroupBy(p => p).Count() == 1)
- {
- return "豹子";
- }
- else if (list.GroupBy(p => p).Count() == 2)
- {
- return "组三";
- }
- return "组六";
- }
- /// <summary>
- /// 奇偶比
- /// </summary>
- /// <param name="code"></param>
- /// <returns></returns>
- public static string GetJob(string code)
- {
- var list = code.Split('+')[0].Split(',').ToList();
- var j = 0;
- var o = 0;
- list.ForEach(p =>
- {
- if (int.Parse(p) % 2 == 0)
- {
- j++;
- }
- else
- o++;
- });
- return $"{j}:{o}";
- }
- /// <summary>
- /// 大小比
- /// </summary>
- /// <param name="code"></param>
- /// <param name="n">双色球33 大乐透35</param>
- /// <returns></returns>
- public static string GetDxb(string code, int n)
- {
- var z = n / 2;
- var d = 0;
- var x = 0;
- code.GetCode().ForEach(p =>
- {
- if (d >= z)
- d++;
- else
- x++;
- });
- return $"{d}:{x}";
- }
-
- #region 组合算法
- /// <summary>
- /// 组合算法
- /// </summary>
- /// <param name="data">组合源数据</param>
- /// <param name="count">所选组合个数</param>
- /// <returns></returns>
- public static List<string> GetCombination(string[] data, int count)
- {
- Dictionary<string, int> dic = new Dictionary<string, int>();
- List<string> output = new List<string>();
- for (int i = 0; i < data.Length; i++)
- {
- dic.Add(data[i], i);
- }
- SelectN(dic, data, count, 1, ref output);
- return output;
- }
- /// <summary>
- /// 字典组合算法
- /// </summary>
- /// <param name="dd"></param>
- /// <param name="data"></param>
- /// <param name="count"></param>
- /// <param name="times"></param>
- /// <param name="output"></param>
- public static void SelectN(Dictionary<string, int> dd, string[] data, int count, int times, ref List<string> output)
- {
- Dictionary<string, int> dic = new Dictionary<string, int>();
- foreach (KeyValuePair<string, int> kv in dd)
- {
- for (int i = kv.Value + 1; i < data.Length; i++)
- {
- if (times < count - 1)
- {
- dic.Add(kv.Key + "," + data[i], i);
- }
- else
- {
- output.Add(kv.Key + "," + data[i]);
- }
- }
- }
- times++;
- if (dic.Count > 0)
- {
- SelectN(dic, data, count, times, ref output);
- }
- }
- #endregion
- #endregion
- #region 是有计算
- #region 大小相关方法
- /// <summary>
- /// 3D/p3和值大小
- /// </summary>
- /// <param name="n"></param>
- /// <returns></returns>
- private static int GetHzDx(int n)
- {
- return GetDxBymiddle(n, 14);
- }
- /// <summary>
- /// 返回0~9大小的状态
- /// 0=小
- /// 1=大
- /// </summary>
- /// <param name="n"></param>
- /// <returns></returns>
- private static int GetDx(int n)
- {
- return GetDxBymiddle(n, 5);
- }
- /// <summary>
- /// 返回大小的状态,需要传中间值,小于中间值为小,大于等于中间值为大。
- /// </summary>
- /// <param name="n"></param>
- /// <param name="middle"></param>
- /// <returns></returns>
- private static int GetDxBymiddle(int n, int middle)
- {
- int r = 1;
- if (n < middle)
- r = 0;
- return r;
- }
- /// <summary>
- /// 大小比
- /// </summary>
- /// <param name="kjh">数据</param>
- /// <param name="middle">中间数</param>
- /// <returns></returns>
- private static string GetDxb(List<int> kjh, int middle)
- {
- int d = 0;
- int x = 0;
- for (int i = 0; i < kjh.Count; i++)
- {
- if (GetDxBymiddle(kjh[i], middle) == 1)
- d++;
- else
- x++;
- }
- return d.ToString() + ":" + x.ToString();
- }
- #endregion
- #endregion
- //#region 振幅
- ///// <summary>
- ///// 百十个分布
- ///// </summary>
- ///// <param name="jsList"></param>
- ///// <param name="dbList"></param>
- ///// <param name="max"></param>
- ///// <returns></returns>
- //public static Dictionary<int, List<ZsfbDTO>> Getgsbfb(List<ZsModel> jsList, List<ZsModel> dbList, int max)
- //{
- // var dict = new Dictionary<int, List<ZsfbDTO>>();
- // var fbbArray = new int[max];
- // foreach (var item in jsList)
- // {
- // var numberList = item.Number.Split('+')[0].Split(',').ToList();
- // var index = 0;
- // foreach (var n in numberList)
- // {
- // var zsfbList = new List<Zsfb>();
- // for (int i = 0; i < max; i++)
- // {
- // if (i == n.TryToInt32())
- // {
- // zsfbList.Add(
- // new Zsfb
- // {
- // IsZf = false,
- // Number = i,
- // JsNumber = i
- // });
- // }
- // else
- // {
- // var model = new Zsfb
- // {
- // IsZf = true,
- // Number = 0,
- // JsNumber = i
- // };
- // if (jsList.IndexOf(item) == 0)
- // {
- // model.Number = GetRank(dbList, i, item.Seq, numberList.IndexOf(n));
- // }
- // else
- // {
- // var prvModel = dict[index].LastOrDefault().Zsfb[i];
- // if (!prvModel.IsZf)
- // {
- // model.Number++;
- // }
- // else
- // {
- // model.Number = prvModel.Number + 1;
- // }
- // }
- // zsfbList.Add(model);
- // }
- // }
- // var zsfbModel = new ZsfbDTO { Qi = item.Qi, Zsfb = zsfbList };
- // if (dict.ContainsKey(index))
- // {
- // dict[index].Add(zsfbModel);
- // }
- // else
- // {
- // dict.Add(index, new List<ZsfbDTO> { zsfbModel });
- // }
- // index++;
- // }
- // }
- // return dict;
- //}
- ///// <summary>
- ///// 组选分布
- ///// </summary>
- ///// <param name="jsList"></param>
- ///// <param name="dbList"></param>
- ///// <param name="max"></param>
- ///// <returns></returns>
- //public static List<ZsfbDTO> GetZxfb(List<ZsModel> jsList, List<ZsModel> dbList, int max)
- //{
- // var list = new List<ZsfbDTO>();
- // var fbbArray = new int[max];
- // foreach (var item in jsList)
- // {
- // var zsfbList = new List<Zsfb>();
- // for (int i = 0; i < max; i++)
- // {
- // if (item.Number.Contains(i))
- // {
- // zsfbList.Add(new Zsfb
- // {
- // IsZf = false,
- // Number = i,
- // Zx = item.Number.Where(p => p == i).Count() > 1 ? ZxEnum.组三 : ZxEnum.组六,
- // JsNumber = i
- // });
- // }
- // else
- // {
- // var model = new Zsfb
- // {
- // IsZf = true,
- // Number = 0,
- // JsNumber = i
- // };
- // if (jsList.IndexOf(item) == 0)
- // {
- // model.Number = GetRank(dbList, i, item.Seq, 3);
- // }
- // else
- // {
- // var prvModel = list.LastOrDefault().Zsfb[i];
- // if (!prvModel.IsZf)
- // {
- // model.Number++;
- // }
- // else
- // {
- // model.Number = prvModel.Number + 1;
- // }
- // }
- // zsfbList.Add(model);
- // }
- // }
- // list.Add(new ZsfbDTO { Qi = item.Qi, Zsfb = zsfbList });
- // }
- // return list;
- //}
- /////// <summary>
- /////// 百十个分布
- /////// </summary>
- /////// <param name="jsList"></param>
- /////// <param name="dbList"></param>
- /////// <param name="max"></param>
- /////// <returns></returns>
- ////public static Dictionary<int, List<Zsfb>> Getgsbfb_Yl(List<ZsModel> jsList, List<ZsModel> dbList, int max)
- ////{
- //// var dict = new Dictionary<int, List<Zsfb>>();
- //// foreach (var item in jsList)
- //// {
- //// var numberList = item.Number.Split('+')[0].Split(',').ToList();
- //// var index = 0;
- //// foreach (var n in numberList)
- //// {
- //// var zsfbList = new List<Zsfb>();
- //// for (int i = 0; i < max; i++)
- //// {
- //// if (i == n.TryToInt32())
- //// {
- //// zsfbList.Add(
- //// new Zsfb
- //// {
- //// IsZf = false,
- //// Number = i,
- //// JsNumber = i
- //// });
- //// }
- //// else
- //// {
- //// var model = new Zsfb
- //// {
- //// IsZf = true,
- //// Number = 0,
- //// JsNumber = i
- //// };
- //// if (jsList.IndexOf(item) == 0)
- //// {
- //// model.Number = GetRank(dbList, i, item.Seq, numberList.IndexOf(n));
- //// }
- //// else
- //// {
- //// var list = dict[index];
- //// var prvModel = dict[index][list.Count-max];
- //// if (!prvModel.IsZf)
- //// {
- //// model.Number++;
- //// }
- //// else
- //// {
- //// model.Number = prvModel.Number + 1;
- //// }
- //// }
- //// zsfbList.Add(model);
- //// }
- //// }
-
- //// if (dict.ContainsKey(index))
- //// {
- //// dict[index]= dict[index].Concat((zsfbList)).ToList();
- //// }
- //// else
- //// {
- //// dict.Add(index, zsfbList);
- //// }
- //// index++;
- //// }
- //// }
- //// return dict;
- ////}
- ////public static List<Zsfb> GetZxfb_Yl(List<ZsModel> jsList, List<ZsModel> dbList, int max)
- ////{
- //// //var dict
- //// foreach (var item in jsList)
- //// {
- //// var numberList = item.Number.Split('+')[0].Split(',').GroupBy(p => p).Select(p => p.Key.TryToInt32()).ToList();
-
- //// for (int i = 0; i < max; i++)
- //// {
- //// if (numberList.Contains(i))
- //// {
- //// zsfbList.Add(new Zsfb
- //// {
- //// IsZf = false,
- //// Number = i,
- //// Zx = numberList.Where(p => p == i).Count() > 1 ? ZxEnum.组三 : ZxEnum.组六,
- //// JsNumber = i
- //// });
- //// }
- //// else
- //// {
- //// var model = new Zsfb
- //// {
- //// IsZf = true,
- //// Number = 0,
- //// JsNumber = i
- //// };
- //// if (jsList.IndexOf(item) == 0)
- //// {
- //// model.Number = GetRank(dbList, i, item.Seq, 3);
- //// }
- //// else
- //// {
- //// var prvModel = zsfbList[zsfbList.Count-max];
- //// if (!prvModel.IsZf)
- //// {
- //// model.Number++;
- //// }
- //// else
- //// {
- //// model.Number = prvModel.Number + 1;
- //// }
- //// }
- //// zsfbList.Add(model);
- //// }
- //// }
- //// }
- //// return zsfbList;
- ////}
- //public static int GetRank(List<ZsModel> dbList, int value, int rank, int type)
- //{
- // int size = dbList.Count;
- // var list = new List<int>();
- // for (int i = rank - 1; i > 0; i--)
- // {
- // var model = dbList.Where(p => p.Seq == i).FirstOrDefault();
- // if (model == null)
- // continue;
- // if (type == 0 || type == 1 || type == 2)
- // {
- // if (model.Number[type] == value)
- // return rank - model.Seq;
- // }
- // if (type == 3)
- // {
- // if (model.Number[0] == value || model.Number[1] == value || model.Number[2] == value)
- // {
- // return rank - model.Seq;
- // }
- // }
- // }
- // return 0;
- //}
- //#endregion
- }
- }
|