CzDataHelper.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. using Common;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Common
  9. {
  10. public static class CzDataHelper
  11. {
  12. #region 值的计算
  13. public static bool IsCf(string code)
  14. {
  15. var list = code.Split('+')[0].Split(',').ToList();
  16. if (list.GroupBy(i => i).Where(g => g.Count() > 1).Count() >= 1)
  17. return true;
  18. return false;
  19. }
  20. #region 和值相关
  21. /// <summary>
  22. /// 得到和值
  23. /// </summary>
  24. /// <param name="code"></param>
  25. /// <returns></returns>
  26. public static int GetHz(string code)
  27. {
  28. var list = code.Split('+')[0].Split(',').ToList();
  29. if (code.IsEmpty())
  30. return 0;
  31. return list.Sum(p => p.TryToInt32());
  32. }
  33. /// <summary>
  34. /// 得到和值的大小
  35. /// </summary>
  36. /// <param name="hz"></param>
  37. /// <returns></returns>
  38. public static string GetHzDxValue(int hz)
  39. {
  40. if (GetHzDx(hz) == 1)
  41. {
  42. return "大";
  43. }
  44. return "小";
  45. }
  46. #endregion
  47. /// <summary>
  48. /// 得到跨度
  49. /// </summary>
  50. /// <param name="code"></param>
  51. /// <returns></returns>
  52. public static int GetKd(string code)
  53. {
  54. var list = code.Split('+')[0].Split(',').ToList().OrderByDescending(p => p);
  55. if (code.IsEmpty())
  56. return 0;
  57. return list.FirstOrDefault().TryToInt32() - list.LastOrDefault().TryToInt32();
  58. }
  59. /// <summary>
  60. /// AC值计算
  61. /// </summary>
  62. /// <param name="kjh"></param>
  63. /// <returns></returns>
  64. public static int GetAc(string code)
  65. {
  66. var list = code.Split('+')[0].Split(',').ToList().OrderByDescending(p => p);
  67. List<string> result = GetCombination(list.ToArray(), 2);
  68. ArrayList acarray = new ArrayList();
  69. int tpac = 0;
  70. for (int i = 0; i < result.Count; i++)
  71. {
  72. string[] tp = result[i].Split(',');
  73. int tmp = Math.Abs(Convert.ToInt32(tp[0]) - Convert.ToInt32(tp[1]));
  74. if (!acarray.Contains(tmp))
  75. {
  76. tpac++;
  77. acarray.Add(tmp);
  78. }
  79. }
  80. return tpac - (list.Count() - 1);
  81. }
  82. /// <summary>
  83. /// 根据和值返回和尾
  84. /// </summary>
  85. /// <param name="hz"></param>
  86. /// <returns></returns>
  87. public static int GetHw(int hz)
  88. {
  89. return hz % 10;
  90. }
  91. /// <summary>
  92. /// 得到大小 和尾、跨度(值)
  93. /// </summary>
  94. /// <param name="hz"></param>
  95. /// <returns></returns>
  96. public static string GetDxValue(int value)
  97. {
  98. if (GetDx(value) == 1)
  99. {
  100. return "大";
  101. }
  102. return "小";
  103. }
  104. /// <summary>
  105. /// 得到单双(和值、合尾、跨度)
  106. /// </summary>
  107. /// <param name="hz"></param>
  108. /// <returns></returns>
  109. public static string GetDsValue(int value)
  110. {
  111. if (value % 2 != 0)
  112. {
  113. return "单";
  114. }
  115. return "双";
  116. }
  117. /// <summary>
  118. /// 得到形态 012路(和值、合尾、跨度)
  119. /// </summary>
  120. /// <param name="hz"></param>
  121. /// <returns></returns>
  122. public static string Get012Value(int value)
  123. {
  124. if (value % 3 == 0)
  125. {
  126. return "0";
  127. }
  128. else if (value % 3 == 1)
  129. {
  130. return "1";
  131. }
  132. return "2";
  133. }
  134. #region 形态
  135. /// <summary>
  136. /// 得到形态大小
  137. /// </summary>
  138. /// <param name="hz"></param>
  139. /// <returns></returns>
  140. public static string GetXtDxValue(string code)
  141. {
  142. var result = "";
  143. code.Split(',').ToList().ForEach(p =>
  144. {
  145. if (GetDx(int.Parse(p)) == 1)
  146. {
  147. result += "大";
  148. }
  149. else
  150. {
  151. result += "小";
  152. }
  153. });
  154. return result;
  155. }
  156. /// <summary>
  157. /// 得到形态 单双
  158. /// </summary>
  159. /// <param name="hz"></param>
  160. /// <returns></returns>
  161. public static string GetXtDsValue(string code)
  162. {
  163. var result = "";
  164. code.Split(',').ToList().ForEach(p =>
  165. {
  166. if (int.Parse(p) % 2 != 0)
  167. {
  168. result += "单";
  169. }
  170. else
  171. {
  172. result += "双";
  173. }
  174. });
  175. return result;
  176. }
  177. /// <summary>
  178. /// 得到形态 012路
  179. /// </summary>
  180. /// <param name="hz"></param>
  181. /// <returns></returns>
  182. public static string GetXt012Value(string code)
  183. {
  184. var result = "";
  185. code.Split(',').ToList().ForEach(p =>
  186. {
  187. if (int.Parse(p) % 3 == 0)
  188. {
  189. result += "0";
  190. }
  191. else if (int.Parse(p) % 3 == 1)
  192. {
  193. result += "1";
  194. }
  195. else
  196. {
  197. result += "2";
  198. }
  199. });
  200. return result;
  201. }
  202. #endregion
  203. /// <summary>
  204. /// 得到组选
  205. /// </summary>
  206. /// <param name="value"></param>
  207. /// <returns></returns>
  208. public static string GetZx(string value)
  209. {
  210. var list = value.Split(',').ToList();
  211. if (list.Count < 3)
  212. {
  213. list = new List<string>();
  214. foreach (var item in value)
  215. {
  216. list.Add(item.ToString());
  217. }
  218. }
  219. list = list.Where(p => !string.IsNullOrEmpty(p.Trim())).Select(p => p.Trim()).ToList();
  220. if (list.GroupBy(p => p).Count() == 1)
  221. {
  222. return "豹子";
  223. }
  224. else if (list.GroupBy(p => p).Count() == 2)
  225. {
  226. return "组三";
  227. }
  228. return "组六";
  229. }
  230. /// <summary>
  231. /// 奇偶比
  232. /// </summary>
  233. /// <param name="code"></param>
  234. /// <returns></returns>
  235. public static string GetJob(string code)
  236. {
  237. var list = code.Split('+')[0].Split(',').ToList();
  238. var j = 0;
  239. var o = 0;
  240. list.ForEach(p =>
  241. {
  242. if (int.Parse(p) % 2 == 0)
  243. {
  244. j++;
  245. }
  246. else
  247. o++;
  248. });
  249. return $"{j}:{o}";
  250. }
  251. /// <summary>
  252. /// 大小比
  253. /// </summary>
  254. /// <param name="code"></param>
  255. /// <param name="n">双色球33 大乐透35</param>
  256. /// <returns></returns>
  257. public static string GetDxb(string code, int n)
  258. {
  259. var z = n / 2;
  260. var d = 0;
  261. var x = 0;
  262. code.GetCode().ForEach(p =>
  263. {
  264. if (d >= z)
  265. d++;
  266. else
  267. x++;
  268. });
  269. return $"{d}:{x}";
  270. }
  271. #region 组合算法
  272. /// <summary>
  273. /// 组合算法
  274. /// </summary>
  275. /// <param name="data">组合源数据</param>
  276. /// <param name="count">所选组合个数</param>
  277. /// <returns></returns>
  278. public static List<string> GetCombination(string[] data, int count)
  279. {
  280. Dictionary<string, int> dic = new Dictionary<string, int>();
  281. List<string> output = new List<string>();
  282. for (int i = 0; i < data.Length; i++)
  283. {
  284. dic.Add(data[i], i);
  285. }
  286. SelectN(dic, data, count, 1, ref output);
  287. return output;
  288. }
  289. /// <summary>
  290. /// 字典组合算法
  291. /// </summary>
  292. /// <param name="dd"></param>
  293. /// <param name="data"></param>
  294. /// <param name="count"></param>
  295. /// <param name="times"></param>
  296. /// <param name="output"></param>
  297. public static void SelectN(Dictionary<string, int> dd, string[] data, int count, int times, ref List<string> output)
  298. {
  299. Dictionary<string, int> dic = new Dictionary<string, int>();
  300. foreach (KeyValuePair<string, int> kv in dd)
  301. {
  302. for (int i = kv.Value + 1; i < data.Length; i++)
  303. {
  304. if (times < count - 1)
  305. {
  306. dic.Add(kv.Key + "," + data[i], i);
  307. }
  308. else
  309. {
  310. output.Add(kv.Key + "," + data[i]);
  311. }
  312. }
  313. }
  314. times++;
  315. if (dic.Count > 0)
  316. {
  317. SelectN(dic, data, count, times, ref output);
  318. }
  319. }
  320. #endregion
  321. #endregion
  322. #region 是有计算
  323. #region 大小相关方法
  324. /// <summary>
  325. /// 3D/p3和值大小
  326. /// </summary>
  327. /// <param name="n"></param>
  328. /// <returns></returns>
  329. private static int GetHzDx(int n)
  330. {
  331. return GetDxBymiddle(n, 14);
  332. }
  333. /// <summary>
  334. /// 返回0~9大小的状态
  335. /// 0=小
  336. /// 1=大
  337. /// </summary>
  338. /// <param name="n"></param>
  339. /// <returns></returns>
  340. private static int GetDx(int n)
  341. {
  342. return GetDxBymiddle(n, 5);
  343. }
  344. /// <summary>
  345. /// 返回大小的状态,需要传中间值,小于中间值为小,大于等于中间值为大。
  346. /// </summary>
  347. /// <param name="n"></param>
  348. /// <param name="middle"></param>
  349. /// <returns></returns>
  350. private static int GetDxBymiddle(int n, int middle)
  351. {
  352. int r = 1;
  353. if (n < middle)
  354. r = 0;
  355. return r;
  356. }
  357. /// <summary>
  358. /// 大小比
  359. /// </summary>
  360. /// <param name="kjh">数据</param>
  361. /// <param name="middle">中间数</param>
  362. /// <returns></returns>
  363. private static string GetDxb(List<int> kjh, int middle)
  364. {
  365. int d = 0;
  366. int x = 0;
  367. for (int i = 0; i < kjh.Count; i++)
  368. {
  369. if (GetDxBymiddle(kjh[i], middle) == 1)
  370. d++;
  371. else
  372. x++;
  373. }
  374. return d.ToString() + ":" + x.ToString();
  375. }
  376. #endregion
  377. #endregion
  378. //#region 振幅
  379. ///// <summary>
  380. ///// 百十个分布
  381. ///// </summary>
  382. ///// <param name="jsList"></param>
  383. ///// <param name="dbList"></param>
  384. ///// <param name="max"></param>
  385. ///// <returns></returns>
  386. //public static Dictionary<int, List<ZsfbDTO>> Getgsbfb(List<ZsModel> jsList, List<ZsModel> dbList, int max)
  387. //{
  388. // var dict = new Dictionary<int, List<ZsfbDTO>>();
  389. // var fbbArray = new int[max];
  390. // foreach (var item in jsList)
  391. // {
  392. // var numberList = item.Number.Split('+')[0].Split(',').ToList();
  393. // var index = 0;
  394. // foreach (var n in numberList)
  395. // {
  396. // var zsfbList = new List<Zsfb>();
  397. // for (int i = 0; i < max; i++)
  398. // {
  399. // if (i == n.TryToInt32())
  400. // {
  401. // zsfbList.Add(
  402. // new Zsfb
  403. // {
  404. // IsZf = false,
  405. // Number = i,
  406. // JsNumber = i
  407. // });
  408. // }
  409. // else
  410. // {
  411. // var model = new Zsfb
  412. // {
  413. // IsZf = true,
  414. // Number = 0,
  415. // JsNumber = i
  416. // };
  417. // if (jsList.IndexOf(item) == 0)
  418. // {
  419. // model.Number = GetRank(dbList, i, item.Seq, numberList.IndexOf(n));
  420. // }
  421. // else
  422. // {
  423. // var prvModel = dict[index].LastOrDefault().Zsfb[i];
  424. // if (!prvModel.IsZf)
  425. // {
  426. // model.Number++;
  427. // }
  428. // else
  429. // {
  430. // model.Number = prvModel.Number + 1;
  431. // }
  432. // }
  433. // zsfbList.Add(model);
  434. // }
  435. // }
  436. // var zsfbModel = new ZsfbDTO { Qi = item.Qi, Zsfb = zsfbList };
  437. // if (dict.ContainsKey(index))
  438. // {
  439. // dict[index].Add(zsfbModel);
  440. // }
  441. // else
  442. // {
  443. // dict.Add(index, new List<ZsfbDTO> { zsfbModel });
  444. // }
  445. // index++;
  446. // }
  447. // }
  448. // return dict;
  449. //}
  450. ///// <summary>
  451. ///// 组选分布
  452. ///// </summary>
  453. ///// <param name="jsList"></param>
  454. ///// <param name="dbList"></param>
  455. ///// <param name="max"></param>
  456. ///// <returns></returns>
  457. //public static List<ZsfbDTO> GetZxfb(List<ZsModel> jsList, List<ZsModel> dbList, int max)
  458. //{
  459. // var list = new List<ZsfbDTO>();
  460. // var fbbArray = new int[max];
  461. // foreach (var item in jsList)
  462. // {
  463. // var zsfbList = new List<Zsfb>();
  464. // for (int i = 0; i < max; i++)
  465. // {
  466. // if (item.Number.Contains(i))
  467. // {
  468. // zsfbList.Add(new Zsfb
  469. // {
  470. // IsZf = false,
  471. // Number = i,
  472. // Zx = item.Number.Where(p => p == i).Count() > 1 ? ZxEnum.组三 : ZxEnum.组六,
  473. // JsNumber = i
  474. // });
  475. // }
  476. // else
  477. // {
  478. // var model = new Zsfb
  479. // {
  480. // IsZf = true,
  481. // Number = 0,
  482. // JsNumber = i
  483. // };
  484. // if (jsList.IndexOf(item) == 0)
  485. // {
  486. // model.Number = GetRank(dbList, i, item.Seq, 3);
  487. // }
  488. // else
  489. // {
  490. // var prvModel = list.LastOrDefault().Zsfb[i];
  491. // if (!prvModel.IsZf)
  492. // {
  493. // model.Number++;
  494. // }
  495. // else
  496. // {
  497. // model.Number = prvModel.Number + 1;
  498. // }
  499. // }
  500. // zsfbList.Add(model);
  501. // }
  502. // }
  503. // list.Add(new ZsfbDTO { Qi = item.Qi, Zsfb = zsfbList });
  504. // }
  505. // return list;
  506. //}
  507. /////// <summary>
  508. /////// 百十个分布
  509. /////// </summary>
  510. /////// <param name="jsList"></param>
  511. /////// <param name="dbList"></param>
  512. /////// <param name="max"></param>
  513. /////// <returns></returns>
  514. ////public static Dictionary<int, List<Zsfb>> Getgsbfb_Yl(List<ZsModel> jsList, List<ZsModel> dbList, int max)
  515. ////{
  516. //// var dict = new Dictionary<int, List<Zsfb>>();
  517. //// foreach (var item in jsList)
  518. //// {
  519. //// var numberList = item.Number.Split('+')[0].Split(',').ToList();
  520. //// var index = 0;
  521. //// foreach (var n in numberList)
  522. //// {
  523. //// var zsfbList = new List<Zsfb>();
  524. //// for (int i = 0; i < max; i++)
  525. //// {
  526. //// if (i == n.TryToInt32())
  527. //// {
  528. //// zsfbList.Add(
  529. //// new Zsfb
  530. //// {
  531. //// IsZf = false,
  532. //// Number = i,
  533. //// JsNumber = i
  534. //// });
  535. //// }
  536. //// else
  537. //// {
  538. //// var model = new Zsfb
  539. //// {
  540. //// IsZf = true,
  541. //// Number = 0,
  542. //// JsNumber = i
  543. //// };
  544. //// if (jsList.IndexOf(item) == 0)
  545. //// {
  546. //// model.Number = GetRank(dbList, i, item.Seq, numberList.IndexOf(n));
  547. //// }
  548. //// else
  549. //// {
  550. //// var list = dict[index];
  551. //// var prvModel = dict[index][list.Count-max];
  552. //// if (!prvModel.IsZf)
  553. //// {
  554. //// model.Number++;
  555. //// }
  556. //// else
  557. //// {
  558. //// model.Number = prvModel.Number + 1;
  559. //// }
  560. //// }
  561. //// zsfbList.Add(model);
  562. //// }
  563. //// }
  564. //// if (dict.ContainsKey(index))
  565. //// {
  566. //// dict[index]= dict[index].Concat((zsfbList)).ToList();
  567. //// }
  568. //// else
  569. //// {
  570. //// dict.Add(index, zsfbList);
  571. //// }
  572. //// index++;
  573. //// }
  574. //// }
  575. //// return dict;
  576. ////}
  577. ////public static List<Zsfb> GetZxfb_Yl(List<ZsModel> jsList, List<ZsModel> dbList, int max)
  578. ////{
  579. //// //var dict
  580. //// foreach (var item in jsList)
  581. //// {
  582. //// var numberList = item.Number.Split('+')[0].Split(',').GroupBy(p => p).Select(p => p.Key.TryToInt32()).ToList();
  583. //// for (int i = 0; i < max; i++)
  584. //// {
  585. //// if (numberList.Contains(i))
  586. //// {
  587. //// zsfbList.Add(new Zsfb
  588. //// {
  589. //// IsZf = false,
  590. //// Number = i,
  591. //// Zx = numberList.Where(p => p == i).Count() > 1 ? ZxEnum.组三 : ZxEnum.组六,
  592. //// JsNumber = i
  593. //// });
  594. //// }
  595. //// else
  596. //// {
  597. //// var model = new Zsfb
  598. //// {
  599. //// IsZf = true,
  600. //// Number = 0,
  601. //// JsNumber = i
  602. //// };
  603. //// if (jsList.IndexOf(item) == 0)
  604. //// {
  605. //// model.Number = GetRank(dbList, i, item.Seq, 3);
  606. //// }
  607. //// else
  608. //// {
  609. //// var prvModel = zsfbList[zsfbList.Count-max];
  610. //// if (!prvModel.IsZf)
  611. //// {
  612. //// model.Number++;
  613. //// }
  614. //// else
  615. //// {
  616. //// model.Number = prvModel.Number + 1;
  617. //// }
  618. //// }
  619. //// zsfbList.Add(model);
  620. //// }
  621. //// }
  622. //// }
  623. //// return zsfbList;
  624. ////}
  625. //public static int GetRank(List<ZsModel> dbList, int value, int rank, int type)
  626. //{
  627. // int size = dbList.Count;
  628. // var list = new List<int>();
  629. // for (int i = rank - 1; i > 0; i--)
  630. // {
  631. // var model = dbList.Where(p => p.Seq == i).FirstOrDefault();
  632. // if (model == null)
  633. // continue;
  634. // if (type == 0 || type == 1 || type == 2)
  635. // {
  636. // if (model.Number[type] == value)
  637. // return rank - model.Seq;
  638. // }
  639. // if (type == 3)
  640. // {
  641. // if (model.Number[0] == value || model.Number[1] == value || model.Number[2] == value)
  642. // {
  643. // return rank - model.Seq;
  644. // }
  645. // }
  646. // }
  647. // return 0;
  648. //}
  649. //#endregion
  650. }
  651. }