コード例 #1
0
ファイル: dsunits.cs プロジェクト: Mnuzz/sc2dsstats
        public List <dsunits_grid> Sum(string interest, string vs, string gametime)
        {
            string sum = "";

            DSfilter        dsfil            = new DSfilter(MW);
            List <dsreplay> filtered_replays = new List <dsreplay>();

            filtered_replays = dsfil.Filter(MW.replays);

            List <dsreplay> replay_sorted = new List <dsreplay>();

            replay_sorted = filtered_replays.Where(x => x.RACES.Contains(interest)).OrderBy(o => o.GAMETIME).ToList();

            Dictionary <string, double> unit_sum = new Dictionary <string, double>();

            int mingametime = 0;

            if (gametime == "5min")
            {
                mingametime = MIN5;
            }
            if (gametime == "10min")
            {
                mingametime = MIN10;
            }
            if (gametime == "15min")
            {
                mingametime = MIN15;
            }

            int    i        = 0;
            int    wins     = 0;
            double duration = 0;

            foreach (dsreplay rep in replay_sorted)
            {
                if (mingametime > 0 && rep.DURATION < mingametime)
                {
                    continue;
                }

                //if (UNITLIST.ContainsKey(rep.REPLAY))
                //{
                foreach (dsplayer pl in rep.PLAYERS)
                {
                    if (pl.RACE == interest)
                    {
                        if ((MW.cb_player.IsChecked == true && MW.player_list.Contains(pl.NAME)) || MW.cb_player.IsChecked == false)
                        {
                            /**
                             * List<dsunits_player> pl_units = UNITLIST[rep.REPLAY].Where(x => int.Parse(x.PLAYERID) == pl.POS).ToList();
                             *  if (pl_units.Count > 0)
                             *  {
                             *      if (pl_units.ElementAt(0).UNITS.ContainsKey(gametime))
                             *      {
                             **/
                            if (pl.UNITS.ContainsKey(gametime))
                            {
                                //List<KeyValuePair<string, int>> units = pl_units.ElementAt(0).UNITS[gametime];
                                Dictionary <string, int> units = new Dictionary <string, int>(pl.UNITS[gametime]);
                                if (units.Count > 0)
                                {
                                    if (vs != null)
                                    {
                                        if (rep.GetOpp(pl.REALPOS).RACE != vs)
                                        {
                                            continue;
                                        }
                                    }
                                    i++;
                                    if (pl.TEAM == rep.WINNER)
                                    {
                                        wins++;
                                    }
                                    duration += rep.DURATION;
                                    foreach (KeyValuePair <string, int> unit in units)
                                    {
                                        if (unit_sum.ContainsKey(unit.Key))
                                        {
                                            unit_sum[unit.Key] += unit.Value;
                                        }
                                        else
                                        {
                                            unit_sum[unit.Key] = unit.Value;
                                        }
                                    }
                                }
                                //}
                            }
                        }
                    }
                }
                //}
            }

            double wr = 0;

            if (i > 0)
            {
                wr        = (double)wins * 100 / (double)i;
                wr        = Math.Round(wr, 2);
                duration /= i;
                duration /= 22.4;
                duration  = Math.Round(duration, 2);
            }
            TimeSpan t = TimeSpan.FromSeconds(duration);

            INFO = new List <dsunits_info>();
            WR   = wr;
            INFO.Add(new dsunits_info("winrate", wr.ToString()));
            GAMES = i;
            INFO.Add(new dsunits_info("games", i.ToString()));
            DURATION = t.Minutes + ":" + t.Seconds.ToString("D2") + " min";
            INFO.Add(new dsunits_info("duration", DURATION));
            GAMETIME = "startdate: " + MW.otf_startdate.SelectedDate.Value.ToString("yyyyMMdd") + "; enddate: " + MW.otf_enddate.SelectedDate.Value.ToString("yyyyMMdd");
            INFO.Add(new dsunits_info("gametime", GAMETIME));
            char average = '\u2300';

            sum = "cmdr: " + interest + "; gametime: " + gametime + "; games: " + i.ToString();
            if (vs != null)
            {
                sum += "; vs: " + vs;
            }
            sum += Environment.NewLine;
            sum += "startdate: " + MW.otf_startdate.SelectedDate.Value.ToString("yyyyMMdd") + "; enddate: " + MW.otf_enddate.SelectedDate.Value.ToString("yyyyMMdd") + Environment.NewLine;
            sum += "winrate: " + wr + "%; " + average.ToString() + " duration: " + t.Minutes + ":" + t.Seconds.ToString("D2") + " min" + Environment.NewLine;
            sum += "-----------------------------------------------------" + Environment.NewLine;
            MW.Dispatcher.Invoke(() =>
            {
                MW.tb_build.Text = sum;
            });
            var list = unit_sum.Keys.ToList();

            list.Sort();
            List <dsunits_grid> list_grid = new List <dsunits_grid>();

            foreach (string unit in list)
            {
                if (unit.StartsWith("Hybrid"))
                {
                    continue;
                }
                if (unit.StartsWith("MercCamp"))
                {
                    continue;
                }
                if (i > 0)
                {
                    double unit_count = 0;
                    unit_count = (double)unit_sum[unit] / (double)i;
                    unit_count = Math.Round(unit_count, 2);
                    if (MW.cb_build_sum.IsChecked == true)
                    {
                        unit_count = unit_sum[unit];
                    }
                    //sum += unit + " => " + unit_count.ToString() + Environment.NewLine;
                    dsunits_grid dsgrid = new dsunits_grid();
                    dsgrid.UNIT  = unit;
                    dsgrid.COUNT = unit_count;
                    list_grid.Add(dsgrid);
                }
            }
            MW.dg_build.ItemsSource = list_grid;
            MW.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.ApplicationIdle, new Action(ProcessRows_units));
            return(list_grid);
        }
コード例 #2
0
ファイル: dsunits.cs プロジェクト: Mnuzz/sc2dsstats
        public void ProcessRows_units()
        {
            int itct = MW.dg_build.Items.Count;

            double max1 = 0;
            double max2 = 0;
            double max3 = 0;

            List <double> list = new List <double>();

            for (int i = 0; i < itct; i++)
            {
                ///var row = dg_player.ItemContainerGenerator.ContainerFromItem(pl) as DataGridRow;

                dsunits_grid unit = MW.dg_build.Items[i] as dsunits_grid;
                list.Add(unit.COUNT);
            }

            list.Sort(delegate(double x, double y)
            {
                if (x == 0 && y == 0)
                {
                    return(0);
                }
                else if (x == 0)
                {
                    return(-1);
                }
                else if (y == 0)
                {
                    return(1);
                }
                else
                {
                    return(x.CompareTo(y));
                }
            });

            if (list.Count >= 3)
            {
                max1 = list.ElementAt(list.Count - 1);
                max2 = list.ElementAt(list.Count - 2);
                max3 = list.ElementAt(list.Count - 3);
            }

            for (int i = 0; i < itct; i++)
            {
                ///var row = dg_player.ItemContainerGenerator.ContainerFromItem(pl) as DataGridRow;

                dsunits_grid unit = MW.dg_build.Items[i] as dsunits_grid;

                var row = MW.dg_build.ItemContainerGenerator.ContainerFromIndex(i) as DataGridRow;
                if (row != null)
                {
                    if (unit.COUNT >= max1)
                    {
                        row.Background = Brushes.GreenYellow;
                    }
                    else if (unit.COUNT >= max2)
                    {
                        row.Background = Brushes.YellowGreen;
                    }
                    else if (unit.COUNT >= max3)
                    {
                        row.Background = Brushes.Yellow;
                    }
                    else
                    {
                        //row.Background = Brushes.DarkSlateGray;
                    }
                }
            }
        }