using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CB.Common;
using CB.Data;
using CB.Data.Frequency;
using CB.Entity;
using CB.Entity.Frequency;
using CB.Interface;
using CB.Interface.Infrastructure;
namespace CB.TrendChart.FrequencyTrendChart
{
///
/// 福彩3D走势图生成工具
///
public class KL12SiChuanTrend
{
#region
//public static int Cid = 5000;//Cid用于设置样式值
///
/// 预览走势图,默认显示近30期数据 (实时计算生成)
///
///
///
///
///
///
public static TrendChartData PreViewTrendChart(int chartId, TrendChartType chartType, LotterySearchField fields = null)
{
var list = KL12SiChuanService.GetTopListDesc(fields);
if (null == list || 0 >= list.Count)
return null;
list = list.ToList().OrderBy(info => info.Term).ToList();
//获取走势图项及配置数据
var trendChartItem = TrendChartItemService.ToListByChartId(chartId, chartType);
if (null == trendChartItem || 0 >= trendChartItem.Count)
return null;
int count = trendChartItem.Count;
IList> chartItem = new List>(count);
IList cssConfig = new List(count);
foreach (var item in trendChartItem)
{
//实例化项类型
chartItem.Add(TrendChartUtils.GetTrendChartInterface(item.ClassName));
//获取项CSS配置信息
cssConfig.Add(ChartCssConfigService.Get(item.FuntionType, item.ChartCssId));
}
//项初始化
for (int i = 0; i < count; i++)
{
trendChartItem[i].Cid = Cid;
chartItem[i].Init(cssConfig[i], trendChartItem[i]);
}
var sp = new StringBuilder(20000);
int record = list.Count;
int topSize = null == fields ? 30 : fields.TopSize;
if (30 > topSize)
topSize = 30;
var ResultEntity = new TrendChartData
{
LocalMiss = new string[count],
LastMiss = new string[count],
AllMaxMiss = new string[count],
AllAvgMiss = new string[count],
AllTimes = new string[count],
RecordCount = 0
};
for (int i = 0; i < record; i++)
{
for (int j = count - 1; j >= 0; j--)
{
if (ResultEntity.RecordCount == 0)
{
chartItem[j].MissDataInit(null, j);
}
else
{
chartItem[j].MissDataInit(ResultEntity, j);
}
chartItem[j].SetItemValue(list[i]);
ResultEntity.LocalMiss[j] = chartItem[j].GetMissData(MissDataType.LocalMiss);
ResultEntity.AllMaxMiss[j] = chartItem[j].GetMissData(MissDataType.AllMaxMiss);
ResultEntity.AllAvgMiss[j] = chartItem[j].GetMissData(MissDataType.AllAvgMiss);
ResultEntity.AllTimes[j] = chartItem[j].GetMissData(MissDataType.AllTimes);
ResultEntity.LastMiss[j] = chartItem[j].GetMissData(MissDataType.LastMiss);
}
ResultEntity.RecordCount++;
if (i >= record - topSize)
{
sp.Append("");
for (int j = 0; j < count; j++)
{
sp.Append(chartItem[j].GetFomartString("{1} | "));
}
sp.Append("
");
}
}
ResultEntity.HtmlData = sp.ToString();
return ResultEntity;
}
#endregion
public static int Cid = 59;//Cid用于设置样式值
///
/// 生成走势图,生成当前term数据及以后数据
/// by JNswins 2015-06-10
///
/// 走势图ID
/// 走势图类型
/// 需要生成走势图期数
/// 彩种开奖数据额外查询条件
///
public static Tuple CreateTrendChart(int chartId, TrendChartType chartType, long term, LotterySearchField fields = null)
{
//获取走势图项及配置数据
var trendChartItem = TrendChartItemService.ToListByChartId(chartId, chartType);
if (null == trendChartItem || 0 >= trendChartItem.Count)
return new Tuple(false, string.Format("未找到【ChartId={0}】走势图的项配置数据", chartId));
int count = trendChartItem.Count;
IList> chartItem = new List>(count);
IList cssConfig = new List(count);
foreach (var item in trendChartItem)
{
//实例化项类型
chartItem.Add(TrendChartUtils.GetTrendChartInterface(item.ClassName));
//获取项CSS配置信息
cssConfig.Add(ChartCssConfigService.Get(item.FuntionType, item.ChartCssId));
}
//各项初始化
for (int i = 0; i < count; i++)
{
trendChartItem[i].Cid = Cid;
chartItem[i].Init(cssConfig[i], trendChartItem[i]);
}
//大于等于term开奖数据
IList ListToEnd = KL12SiChuanService.GetListToEnd(term, fields);
if (null == ListToEnd || 0 >= ListToEnd.Count)
return new Tuple(false, "未找到有效开奖数据");
int j = 0;
TrendChartData entity = null;
var ResultEntity = new TrendChartData
{
ChartId = chartId,
Term = term,
ChartType = chartType,
LocalMiss = new string[count],
LastMiss = new string[count],
AllMaxMiss = new string[count],
AllAvgMiss = new string[count],
AllTimes = new string[count]
};
foreach (var currentData in ListToEnd)
{
//根据参数term期数获取近两期开奖信息TOP 2 [Term]<=term ORDER BY [Term] DESC
IList list = KL12SiChuanService.ToListForTrend(currentData.Term, fields);
KL12Info_SiChuan info = null;
info = list[0];
if (2 == list.Count)
{
//取当前期数的上一期的走势图信息及遗漏数据
entity = ResultEntity;
if (0 == j)
entity = SCKL12TrendChartDataService.GetTrendChartDataByTerm(chartId, chartType, list[1].Term);
}
bool yes = true;
var sp = new StringBuilder(20000);
sp.Append("");
for (int i = 0; i < count; i++)
{
//初始化遗漏数据(根据上期结果集计算_entity)
chartItem[i].MissDataInit(entity, i);
//计算项值及遗漏计算
yes = yes && chartItem[i].SetItemValue(info);
if (yes)
{
//结果集赋值
ResultEntity.LocalMiss[i] = chartItem[i].GetMissData(MissDataType.LocalMiss);
ResultEntity.LastMiss[i] = chartItem[i].GetMissData(MissDataType.LastMiss);
ResultEntity.AllMaxMiss[i] = chartItem[i].GetMissData(MissDataType.AllMaxMiss);
ResultEntity.AllAvgMiss[i] = chartItem[i].GetMissData(MissDataType.AllAvgMiss);
ResultEntity.AllTimes[i] = chartItem[i].GetMissData(MissDataType.AllTimes);
sp.Append(chartItem[i].GetFomartString("{1} | "));
}
}
sp.Append("
");
if (null != entity)
ResultEntity.RecordCount = entity.RecordCount + 1;
else
ResultEntity.RecordCount = 1;
ResultEntity.Term = currentData.Term;
ResultEntity.HtmlData = sp.ToString();
if (!yes)
{ return new Tuple(false, string.Format("无效开奖数据:数据生成截止期数为【term={0}】", ResultEntity.Term)); }
yes = yes && DatabaseProvider.GetDbProvider().Save(ResultEntity);
if (!yes)
{ return new Tuple(false, string.Format("数据保存出错:数据保存截止期数为【term={0}】", ResultEntity.Term)); }
j++;
}
return new Tuple(true, string.Format("正常生成完毕,截止期数为:Term={0}", ListToEnd[ListToEnd.Count - 1].Term));
}
}
}