using System;
using System.Collections.Generic;
using System.Linq;
using CP.Cache;
using CP.Common;
using CP.Model;
namespace CP.Business
{
///
/// 海南4+1
///
public class Tchn41
{
///
/// 缓存
///
static WMCache cache = WMCache.GetCacheService();
#region 所有 海南4+1数据
///
/// 所有 海南4+1数据
///
///
public static List GetTchn41List()
{
string key = string.Format(CacheKeys.TCHN41_DATALIST);
List list = cache.GetObject>(key) as List;
if (list == null)
{
list = Tchn41Data.GetTchn41List();
cache.AddObject(key, list, (int)CacheTime.Data);
}
return list;
}
///
/// 数据筛选
///
/// 最近n条
/// 某年
/// 开始期
/// 结束期
/// 星期n(最近120期)
/// 单双期.1=单;2=双(最近120期)
///
public static List GetTchn41List(ref List list, int pagesize, int year, int sqi, int eqi, int week = 0, int ds = 0)
{
List rlist = new List();
if (list == null || list.Count == 0)
return rlist;
int size = list.Count;
if (pagesize > 0)
{
for (int i = (size - pagesize); i < size; i++)
{
rlist.Add(list[i]);
}
return rlist;
}
if (year > 0)
{
rlist.Clear();
for (int i = 0; i < size; i++)
{
if (TypeConverter.StrToInt(list[i].qi.ToString().Substring(0, 4), 0) == year)
rlist.Add(list[i]);
}
return rlist;
}
if (week > 0)
{
rlist.Clear();
List temp = new List();
for (int i = 0; i < size; i++)
{
if (list[i].week == week)
temp.Add(list[i]);
}
for (int i = (temp.Count - 120); i < temp.Count; i++)
{
rlist.Add(temp[i]);
}
return rlist;
}
if (ds > 0)
{
rlist.Clear();
List temp = new List();
for (int i = 0; i < size; i++)
{
if (ds == 1)
{
if (list[i].qi % 2 != 0)
temp.Add(list[i]);
}
else if (ds == 2)
{
if (list[i].qi % 2 == 0)
temp.Add(list[i]);
}
}
for (int i = (temp.Count - 120); i < temp.Count; i++)
{
rlist.Add(temp[i]);
}
return rlist;
}
if (sqi > 0 && eqi > 0)
{
rlist.Clear();
int srank = GetTchn41Info(ref list, sqi).rank;
int erank = GetTchn41Info(ref list, eqi).rank;
if (erank != 0 && srank != 0 && erank > srank)
{
for (int i = srank - 1; i < erank && i < size; i++)
{
rlist.Add(list[i]);
}
}
return rlist;
}
///无参数条件时,返回所有数据
if (pagesize == 0 && year == 0 && sqi == 0 && eqi == 0 && week == 0)
return list;
return rlist;
}
///
/// 根据当前出号和排名,查询出上一次出此号时的数据
/// 主要用在算遗漏时
///
/// 值
/// 当前排名
/// 类型 0=百位号;1=十位号;2=个位号;3=组选
///
public static Tchn41Info GetLastTchn41Info(ref List list, int val, int rank, int type)
{
Tchn41Info info = new Tchn41Info();
int size = list.Count;
///升序的情况
///未实现走势图倒序的情况..
for (int i = rank - 2; i >= 0; i--)
{
if (type == 0)
{
if (list[i].n1 == val)
{
info = list[i];
return info;
}
}
if (type == 1)
{
if (list[i].n2 == val)
{
info = list[i];
return info;
}
}
if (type == 2)
{
if (list[i].n3 == val)
{
info = list[i];
return info;
}
}
if (type == 4)
{
if (list[i].n4 == val)
{
info = list[i];
return info;
}
}
if (type == 5)
{
if (list[i].n5 == val)
{
info = list[i];
return info;
}
}
if (type == 6)
{
int n = new List { list[i].n1, list[i].n2, list[i].n3, list[i].n4, list[i].n5 }.Max();
if (n == val)
{
info = list[i];
return info;
}
}
if (type == 7)
{
int n = new List { list[i].n1, list[i].n2, list[i].n3, list[i].n4, list[i].n5 }.Min();
if (n == val)
{
info = list[i];
return info;
}
}
if (type == 3)
{
if (list[i].n1 == val || list[i].n2 == val || list[i].n3 == val)
{
info = list[i];
return info;
}
}
}
return info;
}
///
/// 根据期数获取期一期的数据...
///
///
///
public static Tchn41Info GetTchn41Info(ref List list, int qi)
{
Tchn41Info info = new Tchn41Info();
int size = list.Count;
for (int i = 0; i < size; i++)
{
if (list[i].qi == qi)
{
info = list[i];
break;
}
}
return info;
}
#endregion
///
/// 上一次海南41和值=val的数据
///
///
///
///
public static Tchn41Info GetLastHzTchn41Info(ref List list, int val, int rank)
{
Tchn41Info info = new Tchn41Info();
int size = list.Count;
for (int i = rank - 2; i >= 0; i--)
{
if (val < 12 && list[i].hz < 12)
{
info = list[i];
return info;
}
if (val > 33 && list[i].hz > 33)
{
info = list[i];
return info;
}
if (list[i].hz == val)
{
info = list[i];
return info;
}
}
return info;
}
///
/// 上一次和尾=val的数据
///
///
///
///
public static Tchn41Info GetLastHwTchn41Info(ref List list, int val, int rank)
{
Tchn41Info info = new Tchn41Info();
int size = list.Count;
for (int i = rank - 2; i >= 0; i--)
{
if (ZstUtils.GetHw(list[i].hz) == val)
{
info = list[i];
return info;
}
}
return info;
}
///
/// 根据当前排名,取出上一个排名,即上一期的数据.
///
///
///
public static Tchn41Info GetLastQiTchn41Info(ref List list, int rank)
{
Tchn41Info info = new Tchn41Info();
int size = list.Count;
for (int i = rank - 2; i >= 0; i--)
{
if (list[i].rank == rank - 1)
{
info = list[i];
return info;
}
}
return info;
}
///
/// 上一次和值奇偶
///
///
///
///
public static Tchn41Info GetLastHzJoTchn41Info(ref List list, int xt, int rank)
{
Tchn41Info info = new Tchn41Info();
int size = list.Count;
for (int i = rank - 2; i >= 0; i--)
{
if (xt == 0)
{
if (list[i].hz % 2 == 0)
{
info = list[i];
return info;
}
}
if (xt == 1)
{
if (list[i].hz % 2 != 0)
{
info = list[i];
return info;
}
}
}
return info;
}
///
/// 上一次和值大小
///
///
///
///
public static Tchn41Info GetLastHzDxTchn41Info(ref List list, int xt, int rank)
{
Tchn41Info info = new Tchn41Info();
int size = list.Count;
for (int i = rank - 2; i >= 0; i--)
{
if (xt == 0)
{
if (list[i].hz < 23)
{
info = list[i];
return info;
}
}
if (xt == 1)
{
if (list[i].hz > 22)
{
info = list[i];
return info;
}
}
}
return info;
}
///
/// 和值上次012情况
///
///
///
///
public static Tchn41Info GetLastHz012Tchn41Info(ref List list, int xt, int rank)
{
Tchn41Info info = new Tchn41Info();
int size = list.Count;
for (int i = rank - 2; i >= 0; i--)
{
if (xt == 0)
{
if (list[i].hz % 3 == 0)
{
info = list[i];
return info;
}
}
if (xt == 1)
{
if (list[i].hz % 3 == 1)
{
info = list[i];
return info;
}
}
if (xt == 2)
{
if (list[i].hz % 3 == 2)
{
info = list[i];
return info;
}
}
}
return info;
}
///
/// 上一次 hw奇偶
///
///
///
///
public static Tchn41Info GetLastHwJoTchn41Info(ref List list, int xt, int rank)
{
Tchn41Info info = new Tchn41Info();
int size = list.Count;
for (int i = rank - 2; i >= 0; i--)
{
if (xt == 0)
{
if (ZstUtils.GetHw(list[i].hz) % 2 == 0)
{
info = list[i];
return info;
}
}
if (xt == 1)
{
if (ZstUtils.GetHw(list[i].hz) % 2 != 0)
{
info = list[i];
return info;
}
}
}
return info;
}
///
/// 上一次hn4+1大小
///
///
///
///
public static Tchn41Info GetLastHwDxTchn41Info(ref List list, int xt, int rank)
{
Tchn41Info info = new Tchn41Info();
int size = list.Count;
for (int i = rank - 2; i >= 0; i--)
{
if (xt == 0)
{
if (ZstUtils.GetHw(list[i].hz) < 5)
{
info = list[i];
return info;
}
}
if (xt == 1)
{
if (ZstUtils.GetHw(list[i].hz) > 4)
{
info = list[i];
return info;
}
}
}
return info;
}
///
/// hn4+1 上次012
///
///
///
///
public static Tchn41Info GetLastHw012Tchn41Info(ref List list, int xt, int rank)
{
Tchn41Info info = new Tchn41Info();
int size = list.Count;
for (int i = rank - 2; i >= 0; i--)
{
if (xt == 0)
{
if (ZstUtils.GetHw(list[i].hz) == 0)
{
info = list[i];
return info;
}
}
if (xt == 1)
{
if (ZstUtils.GetHw(list[i].hz) == 1)
{
info = list[i];
return info;
}
}
if (xt == 2)
{
if (ZstUtils.GetHw(list[i].hz) == 2)
{
info = list[i];
return info;
}
}
}
return info;
}
}
}