private void GameSelectBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            timelineControl.Reset();

            if (e.AddedItems[0] is KeyValuePair <string, Game> pair)
            {
                logAllEvents = new List <ILogEvent>(pair.Value.AllEvents);

                playerFilters.Clear();

                GameLengthText.Text = "Game Length: " + (pair.Value.End - pair.Value.Start).ToString("c", CultureInfo.InvariantCulture);
                WinnerTeam.Text     = "Winner: " + pair.Value.WinnerTeam.ToString();

                MainWindow.MapBackground.Source = IconUtils.GetImageSource(pair.Value.Stage.ToString());

                var blueTeam   = new List <PvPPlayer>();
                var yellowTeam = new List <PvPPlayer>();

                var lastClassChangeTime = new Dictionary <PvPPlayer, DateTime>();

                foreach (var playerDictPair in LogParser.PlayerDict)
                {
                    playerDictPair.Value.SetPropertysAt(pair.Value.Start);

                    if (playerDictPair.Value.Team == Enums.TeamID.Blue)
                    {
                        blueTeam.Add(playerDictPair.Value);
                    }
                    else if (playerDictPair.Value.Team == Enums.TeamID.Yellow)
                    {
                        yellowTeam.Add(playerDictPair.Value);
                    }

                    lastClassChangeTime.Add(playerDictPair.Value, pair.Value.Start);

                    playerFilters.Add(playerDictPair.Value, false);
                }

                BlueTeam.ItemsSource   = blueTeam;
                YellowTeam.ItemsSource = yellowTeam;

                BluePoints.Text   = pair.Value.BluePoint + " points";
                YellowPoints.Text = pair.Value.YellowPoint + " points";

                var blueStat   = new List <PvPPlayerStat>();
                var yellowStat = new List <PvPPlayerStat>();

                var blueClassTime   = new Dictionary <string, TimeSpan>();
                var yellowClassTime = new Dictionary <string, TimeSpan>();

                foreach (var player in blueTeam)
                {
                    var stat = new PvPPlayerStat(player, pair.Value.Start, pair.Value.End);
                    blueStat.Add(stat);

                    foreach (var timePair in stat.ClassTime)
                    {
                        if (!blueClassTime.ContainsKey(timePair.Key))
                        {
                            blueClassTime.Add(timePair.Key, timePair.Value);
                        }
                        else
                        {
                            blueClassTime[timePair.Key] += timePair.Value;
                        }
                    }
                }

                foreach (var player in yellowTeam)
                {
                    var stat = new PvPPlayerStat(player, pair.Value.Start, pair.Value.End);
                    yellowStat.Add(stat);

                    foreach (var timePair in stat.ClassTime)
                    {
                        if (!yellowClassTime.ContainsKey(timePair.Key))
                        {
                            yellowClassTime.Add(timePair.Key, timePair.Value);
                        }
                        else
                        {
                            yellowClassTime[timePair.Key] += timePair.Value;
                        }
                    }
                }

                BlueTeamClass.ItemsSource   = blueClassTime.OrderByDescending(x => x.Value);
                YellowTeamClass.ItemsSource = yellowClassTime.OrderByDescending(x => x.Value);

                BlueTeamStat.ItemsSource   = blueStat;
                YellowTeamStat.ItemsSource = yellowStat;

                BlueTeamStat.UpdateLayout();
                YellowTeamStat.UpdateLayout();

                aggregateApply             = true;
                BlueTeamCheckAll.IsChecked = true;
                foreach (var item in BlueTeamStat.Items)
                {
                    if (BlueTeamStat.ItemContainerGenerator.ContainerFromItem(item) is ListBoxItem element)
                    {
                        FindVisualChild <CheckBox>(element).IsChecked = true;
                    }
                }

                YellowTeamCheckAll.IsChecked = true;
                foreach (var item in YellowTeamStat.Items)
                {
                    if (YellowTeamStat.ItemContainerGenerator.ContainerFromItem(item) is ListBoxItem element)
                    {
                        FindVisualChild <CheckBox>(element).IsChecked = true;
                    }
                }

                aggregateApply = false;
                ApplyFilters();
                SetEventsToTimeline();
            }
        }
Esempio n. 2
0
        private void TSVMenuItem_Click(object sender, RoutedEventArgs e)
        {
            var playerWins  = new Dictionary <string, int>();
            var playerLoses = new Dictionary <string, int>();

            if (!Directory.Exists("Output"))
            {
                Directory.CreateDirectory("Output");
            }

            if (games.Count == 0)
            {
                return;
            }

            var startDate = games.First(x => x.Key.StartsWith("#00", StringComparison.Ordinal)).Value.Start.ToString("T", CultureInfo.InvariantCulture).Replace(":", "-");

            foreach (var pair in games)
            {
                string gameLength = (pair.Value.End - pair.Value.Start).ToString("g", CultureInfo.InvariantCulture);
                string winner     = pair.Value.WinnerTeam.ToString();
                string loser      = pair.Value.WinnerTeam == Enums.TeamID.Blue ? Enums.TeamID.Yellow.ToString() : Enums.TeamID.Blue.ToString();

                string bluePoint   = pair.Value.BluePoint.ToString();
                string yellowPoint = pair.Value.YellowPoint.ToString();

                string stageName = pair.Value.Stage.ToString();

                var blueTeam   = new List <PvPPlayer>();
                var yellowTeam = new List <PvPPlayer>();

                var lastClassChangeTime = new Dictionary <PvPPlayer, DateTime>();

                foreach (var playerDictPair in LogParser.PlayerDict)
                {
                    playerDictPair.Value.SetPropertysAt(pair.Value.Start);

                    if (playerDictPair.Value.Team == Enums.TeamID.Blue)
                    {
                        blueTeam.Add(playerDictPair.Value);

                        if (pair.Value.WinnerTeam == Enums.TeamID.Blue)
                        {
                            if (playerWins.ContainsKey(playerDictPair.Key))
                            {
                                playerWins[playerDictPair.Key] += 1;
                            }
                            else
                            {
                                playerWins.Add(playerDictPair.Key, 1);
                            }
                        }
                        else
                        {
                            if (playerLoses.ContainsKey(playerDictPair.Key))
                            {
                                playerLoses[playerDictPair.Key] += 1;
                            }
                            else
                            {
                                playerLoses.Add(playerDictPair.Key, 1);
                            }
                        }
                    }
                    else if (playerDictPair.Value.Team == Enums.TeamID.Yellow)
                    {
                        yellowTeam.Add(playerDictPair.Value);

                        if (pair.Value.WinnerTeam == Enums.TeamID.Yellow)
                        {
                            if (playerWins.ContainsKey(playerDictPair.Key))
                            {
                                playerWins[playerDictPair.Key] += 1;
                            }
                            else
                            {
                                playerWins.Add(playerDictPair.Key, 1);
                            }
                        }
                        else
                        {
                            if (playerLoses.ContainsKey(playerDictPair.Key))
                            {
                                playerLoses[playerDictPair.Key] += 1;
                            }
                            else
                            {
                                playerLoses.Add(playerDictPair.Key, 1);
                            }
                        }
                    }

                    lastClassChangeTime.Add(playerDictPair.Value, pair.Value.Start);
                }

                var blueStat   = new List <PvPPlayerStat>();
                var yellowStat = new List <PvPPlayerStat>();

                var blueClassTime   = new Dictionary <string, TimeSpan>();
                var yellowClassTime = new Dictionary <string, TimeSpan>();

                var blueClassChangeTime   = new Dictionary <string, int>();
                var yellowClassChangeTime = new Dictionary <string, int>();

                foreach (var player in blueTeam)
                {
                    var stat = new PvPPlayerStat(player, pair.Value.Start, pair.Value.End);
                    blueStat.Add(stat);

                    foreach (var timePair in stat.ClassTime)
                    {
                        if (!blueClassTime.ContainsKey(timePair.Key))
                        {
                            blueClassTime.Add(timePair.Key, timePair.Value);
                            blueClassChangeTime.Add(timePair.Key, 1);
                        }
                        else
                        {
                            blueClassTime[timePair.Key]       += timePair.Value;
                            blueClassChangeTime[timePair.Key] += 1;
                        }
                    }
                }

                foreach (var player in yellowTeam)
                {
                    var stat = new PvPPlayerStat(player, pair.Value.Start, pair.Value.End);
                    yellowStat.Add(stat);

                    foreach (var timePair in stat.ClassTime)
                    {
                        if (!yellowClassTime.ContainsKey(timePair.Key))
                        {
                            yellowClassTime.Add(timePair.Key, timePair.Value);
                            yellowClassChangeTime.Add(timePair.Key, 1);
                        }
                        else
                        {
                            yellowClassTime[timePair.Key]       += timePair.Value;
                            yellowClassChangeTime[timePair.Key] += 1;
                        }
                    }
                }

                using (var sw = new StreamWriter(Path.Combine("Output", "stat_" + startDate + ".tsv"), true))
                {
                    sw.WriteLine(
                        string.Join(
                            "\t",
                            new object[]
                    {
                        stageName,
                        winner,
                        loser,
                        gameLength,
                        bluePoint,
                        yellowPoint,
                        GetClassStatString(blueClassTime, yellowClassTime, pair.Value.WinnerTeam == Enums.TeamID.Blue),
                    }));
                }
            }
        }