private void BestGameSort_Changed(object sender, EventArgs e) { if (BestGameComboBox.Text == "wins.") { if (BestGameDict.Count() != 0) { BestGame.ItemsSource = BestGameDict; } else { BestGame.ItemsSource = null; } if (WorstGameDict.Count() != 0) { WorstGame.ItemsSource = WorstGameDict; } else { WorstGame.ItemsSource = null; } } else if (BestGameComboBox.Text == "win percentage.") { Dictionary <string, string> WinDict = new Dictionary <string, string>(); Dictionary <string, string> LossDict = new Dictionary <string, string>(); foreach (KeyValuePair <string, double> entry in WinPercentageDict) { string key = entry.Key; string value = entry.Value.ToString("P"); WinDict.Add(key, value); } foreach (KeyValuePair <string, double> entry in LossPercentageDict) { string key = entry.Key; double valueNum = entry.Value; valueNum = 1 - valueNum; string value = valueNum.ToString("P"); LossDict.Add(key, value); } BestGame.ItemsSource = WinDict; WorstGame.ItemsSource = LossDict; } RefreshView(); }
private void CalculateGames(Dictionary <string, int> winDictionary, Dictionary <string, int> lossDictionary) { int max = 0; BestGameDict = new Dictionary <string, int>(); WorstGameDict = new Dictionary <string, int>(); if (winDictionary.Count != 0) { max = winDictionary.Values.Max(); BestGameDict = winDictionary; foreach (KeyValuePair <string, int> entry in winDictionary.Where(pair => (pair.Value < max)).ToList()) { BestGameDict.Remove(entry.Key); } } if (lossDictionary.Count != 0) { max = lossDictionary.Values.Max(); WorstGameDict = lossDictionary; foreach (KeyValuePair <string, int> entry in lossDictionary.Where(pair => (pair.Value < max)).ToList()) { WorstGameDict.Remove(entry.Key); } } double maxPercentage = 0.0; maxPercentage = WinPercentageDict.Values.Max(); foreach (KeyValuePair <string, double> entry in WinPercentageDict.Where(pair => (pair.Value < maxPercentage)).ToList()) { WinPercentageDict.Remove(entry.Key); } maxPercentage = LossPercentageDict.Values.Max(); foreach (KeyValuePair <string, double> entry in LossPercentageDict.Where(pair => (pair.Value < maxPercentage)).ToList()) { LossPercentageDict.Remove(entry.Key); } if (BestGameDict.Count() != 0) { BestGame.ItemsSource = BestGameDict; } else { BestGame.ItemsSource = new List <string> { "-" }; } if (WorstGameDict.Count() != 0) { WorstGame.ItemsSource = WorstGameDict; } else { WorstGame.ItemsSource = new List <string> { "-" }; } }