Exemplo n.º 1
0
        public EventAnalysis(FrcEvent frc) : this()
        {
            Event     = frc;
            EventName = frc.EventName;

            foreach (Team t in frc.AllTeams)
            {
                TeamAnalysis ta = new TeamAnalysis(Event, t);
                ta.CalculateSafe();
                TeamData.Add(ta);
            }

            foreach (Match m in frc.Matches)
            {
                MatchAnalysis ma = new MatchAnalysis(Event, m, TeamData);
                ma.CalculatePregame();
                MatchData.Add(ma);
            }
        }
		public EventAnalysis(FrcEvent frc) : this()
		{
			Event = frc;
			EventName = frc.EventName;

			foreach (Team t in frc.AllTeams)
			{
				TeamAnalysis ta = new TeamAnalysis(Event, t);
				ta.CalculateSafe();
				TeamData.Add(ta);
			}

			foreach (Match m in frc.Matches)
			{
				MatchAnalysis ma = new MatchAnalysis(Event, m, TeamData);
				ma.CalculatePregame();
				MatchData.Add(ma);
			}
		}
        /// <summary>
        /// Calculates all pregame analysis for the match
        /// </summary>
        public void CalculatePregame()
        {
            // Means of Winrates
            BlueWinRateMean = Match.BlueAlliance.ToList().ConvertAll <double>((t) =>
            {
                return(TeamAnalyses.Find((a) => a.Team == t).WinRate);
            }).Mean();

            RedWinRateMean = Match.RedAlliance.ToList().ConvertAll <double>((t) =>
            {
                return(TeamAnalyses.Find((a) => a.Team == t).WinRate);
            }).Mean();

            // Expected Winner and Advantage
            double rawAdv = BlueWinRateMean - RedWinRateMean;

            if (rawAdv == 0)
            {
                ExpectedWinner = AllianceColor.Indeterminate;
            }
            else
            {
                ExpectedWinner = (rawAdv > 0) ? AllianceColor.Blue : AllianceColor.Red;
            }
            Advantage = (rawAdv < 0) ? -rawAdv : rawAdv;

            // Expected Final Scores
            var blueAnalyses = from ta in TeamAnalyses
                               where Match.BlueAlliance.Contains(ta.Team)
                               select ta;

            BlueExpectedFinalScore = blueAnalyses.Sum((ta) => ta.FinalScore.Mean);

            BlueExpectedFinalScore = Match.BlueAlliance.ToList().ConvertAll <double>((t) =>
            {
                TeamAnalysis ta = TeamAnalyses.Find((a) => a.Team == t);
                ta.CalculateSafe();
                return(ta.FinalScore.Model.Mean);
            }).Sum();

            var redAnalyses = from ta in TeamAnalyses
                              where Match.RedAlliance.Contains(ta.Team)
                              select ta;

            RedExpectedFinalScore = redAnalyses.Sum((ta) => ta.FinalScore.Mean);

            RedExpectedFinalScore = Match.RedAlliance.ToList().ConvertAll <double>((t) =>
            {
                TeamAnalysis ta = TeamAnalyses.Find((a) => a.Team == t);
                ta.CalculateSafe();
                return(ta.FinalScore.Model.Mean);
            }).Sum();

            // Game Profile Value
            double meanWinRateAll = Match.RedAlliance.ToList().Concat(
                Match.BlueAlliance.ToList()).ToList().ConvertAll((t) =>
            {
                return(TeamAnalyses.Find((a) => a.Team == t).WinRate);
            }).Mean();
            double inverted = 1 - meanWinRateAll;

            GameProfileValue = 1 / inverted;
        }