关于PCRArenaCardRecorder&Analyzer的概率分析相关逻辑代码
嘛,这次为了把分析器写好写对,真的是吃了不少苦头,都怪我一开始数据库设计弱耦合(×)无关联(√)角色与图片的关系,现在好了,数据库设计简单了,代码就复杂了……
以下是frmAnalyzer的部分逻辑代码:
public void GetTheTopTeam()
{
using (var playerData = new PlayerDbContext())
{
var GenreId = playerData.Genres.SingleOrDefault(x => x.Name == GenreN);
var Player = playerData.PlayerDatas.SingleOrDefault(x => x.PId == Pid);
var line = playerData.Lineups;
//筛选出该玩家的所有记录
var singlePlayer = line.Where(x => x.PlayerId == Player.Id);
//筛选出进攻还是防守
int RecordCount = singlePlayer.Count(x => x.GenreId == GenreId.Id);
if (RecordCount > 0)
{
//获得要查询的队伍集合
var Teams = singlePlayer.Where(x => x.GenreId == GenreId.Id);
//获得用户特定位置的集合
var Team1 = Teams.Where(x => x.PositionId == 1);
var Team2 = Teams.Where(x => x.PositionId == 2);
var Team3 = Teams.Where(x => x.PositionId == 3);
//group根据T1~T5分组,查出来的值还是T1~T5,并且还是按照数量进行倒序排名的
var q1 = Team1.ToList().GroupBy(x => x.T1 + x.T2 + x.T3 + x.T4 + x.T5, x => x.T1 +","+ x.T2 +","+ x.T3 +","+ x.T4 +","+ x.T5).OrderByDescending(x=>x.Count());
var q2 = Team2.ToList().GroupBy(x => x.T1 + x.T2 + x.T3 + x.T4 + x.T5, x => x.T1 +","+ x.T2 +","+ x.T3 +","+ x.T4 +","+ x.T5).OrderByDescending(x => x.Count());
var q3 = Team3.ToList().GroupBy(x => x.T1 + x.T2 + x.T3 + x.T4 + x.T5, x => x.T1 +","+ x.T2 +","+ x.T3 +","+ x.T4 +","+ x.T5).OrderByDescending(x => x.Count());
//第一个就是重复次数最多的
var maxTeam1 = q1.FirstOrDefault();
var maxTeam2 = q2.FirstOrDefault();
var maxTeam3 = q3.FirstOrDefault();
string[] teamPath1=null;
string[] teamPath2=null;
string[] teamPath3=null;
foreach (var name in maxTeam1)
{
teamPath1 = name.Split(',');
}
foreach (var name in maxTeam2)
{
teamPath2 = name.Split(',');
}
foreach (var name in maxTeam3)
{
teamPath3 = name.Split(',');
}
//teamPath1
pictureBox1.ImageLocation = teamPath1[0];
pictureBox2.ImageLocation = teamPath1[1];
pictureBox3.ImageLocation = teamPath1[2];
pictureBox4.ImageLocation = teamPath1[3];
pictureBox5.ImageLocation = teamPath1[4];
//teamPath2
pictureBox6.ImageLocation = teamPath2[0];
pictureBox7.ImageLocation = teamPath2[1];
pictureBox8.ImageLocation = teamPath2[2];
pictureBox9.ImageLocation = teamPath2[3];
pictureBox10.ImageLocation = teamPath2[4];
//teamPath3
pictureBox11.ImageLocation = teamPath3[0];
pictureBox12.ImageLocation = teamPath3[1];
pictureBox13.ImageLocation = teamPath3[2];
pictureBox14.ImageLocation = teamPath3[3];
pictureBox15.ImageLocation = teamPath3[4];
//再算一下概率
//q本身只是以编队类型进行了分组,q的数量不能代表max的数量,q的数量只能代表有几种类型
//当你确定了最大类型时,以最大类型为标准,在特定位置的Team里面进行筛选
int first=0;
foreach(var item in Team1)
{
if(item.T1+item.T2+item.T3+item.T4+item.T5== maxTeam1.Key)
{
first++;
}
}
int second = 0;
foreach(var item in Team2)
{
if(item.T1 + item.T2 + item.T3 + item.T4 + item.T5 == maxTeam2.Key)
{
second++;
}
}
int third = 0;
foreach(var item in Team3)
{
if (item.T1 + item.T2 + item.T3 + item.T4 + item.T5 == maxTeam3.Key)
{
third++;
}
}
double per1 = Convert.ToDouble(first) /Team1.Count();
lblFirstPer.Text = per1.ToString("P");
double per2 = Convert.ToDouble(second) / Team2.Count();
lblSecondPer.Text = per2.ToString("P");
double per3 = Convert.ToDouble(third) / Team3.Count();
lblThirdPer.Text = per3.ToString("P");
}
else
{
MessageBox.Show("该玩家没有" + GenreN + "记录!");
}
}
}
讲真,当出现
System.InvalidOperationException:“Client side GroupBy is not supported.”
的那一刻,我都打算阉割了这个Analyzer功能,干脆直接叫Recorder算了。
但是后来解决了问题之后,发现之前的概率分析是有问题的。
可能是当时写代码的时候,脑子不太清醒吧。代码一复杂,再加上人不在状态,越来越容易犯错。
现在回过味儿来了。
改,都可以改!总算是改完了。
今天就先记一下这个代码。
Today's comments have reached the limit. If you want to comment, please wait until tomorrow (UTC-Time).
There is 18h54m58s left until you can comment.