Beispiel #1
0
        public static DataResult GetDurations(DSoptions _options, DSReplayContext _context, IJSRuntime _jsRuntime, object lockobject)
        {
            if (String.IsNullOrEmpty(_options.Interest))
            {
                return(new DataResult());
            }

            var replays = DBReplayFilter.Filter(_options, _context, false);

            var result = (_options.Player, _options.Dataset.Any()) switch
            {
                (true, false) => from r in replays
                from p in r.DSPlayer
                where p.RACE == _options.Interest && p.NAME.Length == 64
                select new
                {
                    r.ID,
                    r.DURATION,
                    p.WIN
                },
                (true, true) => from r in replays
                from p in r.DSPlayer
                where p.RACE == _options.Interest && _options.Dataset.Contains(p.NAME)
                select new
                {
                    r.ID,
                    r.DURATION,
                    p.WIN
                },
                _ => from r in replays
                from p in r.DSPlayer
                where p.RACE == _options.Interest
                select new
                {
                    r.ID,
                    r.DURATION,
                    p.WIN
                }
            };
            var lresult = result.ToList();

            if (!lresult.Any())
            {
                return(new DataResult());
            }

            CultureInfo           provider = CultureInfo.InvariantCulture;
            DataResult            dresult  = new DataResult();
            List <double>         data     = new List <double>();
            List <double>         xdata    = new List <double>();
            List <double>         ydata    = new List <double>();
            List <string>         labels   = new List <string>();
            Func <double, double> f        = null;

            int count = lresult.Count;

            dresult.CmdrInfo.Wins      = lresult.Where(x => x.WIN == true).Count();
            dresult.CmdrInfo.Games     = count;
            dresult.CmdrInfo.AWinrate  = Math.Round((double)dresult.CmdrInfo.Wins * 100 / dresult.CmdrInfo.Games, 2);
            dresult.CmdrInfo.ADuration = TimeSpan.FromDays(3);
            dresult.CmdrInfo.GameIDs   = lresult.Select(s => s.ID).ToHashSet();


            for (int i = 0; i < DSdata.s_durations.Length; i++)
            {
                double games  = 1;
                double wins   = 0;
                int    startd = 0;

                if (i > 0)
                {
                    Match m = d_rx.Match(DSdata.s_durations[i]);
                    if (m.Success)
                    {
                        startd = int.Parse(m.Value);
                    }
                }

                int endd = startd + 3;
                if (i == 0)
                {
                    endd = 8;
                }
                if (i == DSdata.s_durations.Length - 1)
                {
                    endd = 200;
                }

                var ilresult = lresult.Where(x => x.DURATION > startd * 60 && x.DURATION < endd * 60);
                games = ilresult.Count();
                wins  = ilresult.Where(x => x.WIN == true).Count();

                data.Add(Math.Round(wins * 100 / games, 2));
                labels.Add(DSdata.s_durations[i] + " min (" + games + ")");
                xdata.Add(i);
                ydata.Add(data.Last());
            }

            if (xdata.Any() && xdata.Count > 1)
            {
                int order = 3;
                if (xdata.Count <= 3)
                {
                    if (xdata.Count < 3)
                    {
                        order = 1;
                    }
                    else
                    {
                        order = xdata.Count - 2;
                    }
                }
                f = Fit.PolynomialFunc(xdata.ToArray(), ydata.ToArray(), order);
            }

            dresult.Labels       = labels;
            dresult.Dataset.data = data;
            dresult.fTimeline    = f;
            dresult.fStartTime   = DateTime.MinValue;

            ChartService.SetColor(dresult.Dataset, _options.Chart.type, _options.Interest);
            dresult.Dataset.fill             = false;
            dresult.Dataset.pointRadius      = 2;
            dresult.Dataset.pointHoverRadius = 10;
            dresult.Dataset.showLine         = false;
            for (int i = 0; i < dresult.Labels.Count; i++)
            {
                ChartJSInterop.AddData(_jsRuntime,
                                       dresult.Labels[i],
                                       dresult.Dataset.data[i],
                                       dresult.Dataset.backgroundColor.Last(),
                                       null,
                                       lockobject
                                       ).GetAwaiter();
            }
            if (dresult.fTimeline != null)
            {
                ChartJSdataset dataset = new ChartJSdataset();
                dataset.label       = _options.Interest + "_line";
                dataset.borderWidth = 3;
                dataset.pointRadius = 1;
                ChartService.SetColor(dataset, _options.Chart.type, _options.Interest);
                dataset.backgroundColor.Clear();
                _options.Chart.data.datasets.Add(dataset);
                ChartJSInterop.AddDataset(_jsRuntime, JsonConvert.SerializeObject(dataset, Formatting.Indented), lockobject).GetAwaiter();

                for (int i = 0; i < dresult.Labels.Count; i++)
                {
                    double fdata = dresult.fTimeline(i);

                    ChartJSInterop.AddData(_jsRuntime,
                                           dresult.Labels[i],
                                           fdata,
                                           dresult.Dataset.backgroundColor.Last(),
                                           null,
                                           lockobject
                                           ).GetAwaiter();
                }
            }
            return(dresult);
        }
Beispiel #2
0
        public static async Task GetBuild(DSoptions _options, DSReplayContext _context, object dblock, ILogger _logger)
        {
            if (_options.Vs == "ALL")
            {
                _options.Vs = String.Empty;
            }
            string Hash = _options.GenHash();

            if (!_options.Decoding && BuildCache.ContainsKey(Hash))
            {
                _options.buildResult = BuildCache[Hash];
                return;
            }

            bool doWait = false;

            lock (Computing)
            {
                if (!Computing.Contains(Hash))
                {
                    Computing.Add(Hash);
                }
                else
                {
                    doWait = true;
                }
            }

            if (doWait)
            {
                while (Computing.Contains(Hash))
                {
                    await Task.Delay(500);
                }
                if (BuildCache.ContainsKey(Hash))
                {
                    _options.buildResult = BuildCache[Hash];
                }
                return;
            }

            BuildResult bresult = new BuildResult();

            foreach (var ent in _options.Gamemodes.Keys.ToArray())
            {
                _options.Gamemodes[ent] = false;
            }

            if (_options.Interest == "Terran" || _options.Interest == "Zerg" || _options.Interest == "Protoss")
            {
                _options.Gamemodes["GameModeStandard"] = true;
            }
            else
            {
                _options.Gamemodes["GameModeCommanders"]       = true;
                _options.Gamemodes["GameModeCommandersHeroic"] = true;
            }

            lock (dblock)
            {
                bool mengskfilter = _options.MengskPreviewFilter;
                _options.MengskPreviewFilter = false;
                var replays = DBReplayFilter.Filter(_options, _context);
                _options.MengskPreviewFilter = mengskfilter;

                bresult.TotalGames = replays.Count();

                var presult = (String.IsNullOrEmpty(_options.Vs) switch
                {
                    true => from r in replays
                    from t1 in r.DSPlayer
                    where t1.RACE == _options.Interest
                    where _options.Dataset.Contains(t1.NAME)
                    from u1 in t1.Breakpoints
                    where u1.Breakpoint == _options.Breakpoint
                    select new
                    {
                        r.ID,
                        r.DURATION,
                        r.GAMETIME,
                        t1.WIN,
                        u1.dsUnitsString,
                        u1.Upgrades,
                        u1.Gas
                    },
                    false => from r in replays
                    from t1 in r.DSPlayer
                    where t1.RACE == _options.Interest && t1.OPPRACE == _options.Vs
                    where _options.Dataset.Contains(t1.NAME)
                    from u1 in t1.Breakpoints
                    where u1.Breakpoint == _options.Breakpoint
                    select new
                    {
                        r.ID,
                        r.DURATION,
                        r.GAMETIME,
                        t1.WIN,
                        u1.dsUnitsString,
                        u1.Upgrades,
                        u1.Gas
                    }
                });
Beispiel #3
0
        async Task GetDatasetInfo()
        {
            DateTime t = DateTime.UtcNow;

            using (var scope = scopeFactory.CreateScope())
            {
                var context = scope.ServiceProvider.GetRequiredService <DSReplayContext>();
                DSdata.Datasets = new List <DatasetInfo>();
                var names = context.DSPlayers.Select(s => s.NAME).Distinct().ToArray();

                DSoptions _options = new DSoptions();
                _options.Startdate = new DateTime(2018, 1, 1);
                var replays = DBReplayFilter.Filter(_options, context, false);

                var ireps = from r in replays
                            from p in r.DSPlayer
                            where p.NAME.Length == 64
                            from p2 in r.DSPlayer
                            where p2 != p && p2.TEAM == p.TEAM
                            select new
                {
                    r.ID,
                    r.GAMETIME,
                    p.WIN,
                    p.NAME,
                    p.RACE,
                    TEAM = p2.NAME.Length == 64,
                    MVP  = r.MAXKILLSUM == p.KILLSUM
                };
                var lireps = ireps.ToList();

                foreach (var hash in names.Where(x => x.Length == 64))
                {
                    /*
                     * var qreps = from r in replays
                     *         from p in r.DSPlayer
                     *         where p.NAME == hash
                     *         from p2 in r.DSPlayer
                     *         where p2 != p && p2.TEAM == p.TEAM
                     *         select new
                     *         {
                     *             r.ID,
                     *             p.WIN,
                     *             TEAM = p2.NAME.Length == 64,
                     *             MVP = r.MAXKILLSUM == p.KILLSUM
                     *         };
                     */
                    // var reps = qreps.ToList();
                    var reps = lireps.Where(x => x.NAME == hash);

                    if (reps.Count() < 20)
                    {
                        continue;
                    }

                    if (reps.OrderByDescending(o => o.GAMETIME).First().GAMETIME.AddMonths(3) < DateTime.UtcNow)
                    {
                        continue;
                    }

                    DatasetInfo setinfo = new DatasetInfo();
                    setinfo.Dataset = hash;

                    setinfo.Count = reps.Count();

                    //var teams = reps.Where(x => x.DSPlayer.Where(y => y.NAME.Length == 64 && y.TEAM == x.TEAM).Count() > 1);
                    //int teamgames = teams.Count();
                    setinfo.Teamgames = MathF.Round((float)reps.Where(x => x.TEAM == true).Count() * 100 / (float)setinfo.Count, 2);


                    int wins = reps.Where(x => x.WIN == true).Count();
                    setinfo.Winrate = MathF.Round((float)wins * 100 / (float)setinfo.Count, 2);
                    setinfo.MVP     = MathF.Round((float)reps.Where(x => x.MVP == true).Count() * 100 / (float)setinfo.Count, 2);

                    int    maincount = 0;
                    string maincmdr  = "";
                    foreach (string cmdr in DSdata.s_races_cmdr)
                    {
                        int c = reps.Where(x => x.RACE == cmdr).Count();
                        if (c > maincount)
                        {
                            maincount = c;
                            maincmdr  = cmdr;
                        }
                    }
                    float mainper = MathF.Round((float)maincount * 100 / (float)setinfo.Count, 2);
                    //if (mainper < 100 / DSdata.s_races_cmdr.Count() + 5)
                    //    maincmdr = "Random";
                    setinfo.Main = new KeyValuePair <string, float>(maincmdr, mainper);

                    setinfo.Count = reps.Select(s => s.ID).Distinct().Count();
                    DSdata.Datasets.Add(setinfo);
                }
            }
            Console.WriteLine($"Dataset info created in {(DateTime.UtcNow - t).TotalSeconds}");
        }
        public static DataResult GetTimeLine(DSoptions _options, DSReplayContext _context, IJSRuntime _jsRuntime, object lockobject)
        {
            if (String.IsNullOrEmpty(_options.Interest))
            {
                return(new DataResult());
            }

            var replays = DBReplayFilter.Filter(_options, _context, false);

            var result = (_options.Player, _options.Dataset.Any()) switch
            {
                (true, false) => from r in replays
                from p in r.DSPlayer
                where p.RACE == _options.Interest && p.NAME.Length == 64
                select new
                {
                    r.ID,
                    r.GAMETIME,
                    p.WIN
                },
                (true, true) => from r in replays
                from p in r.DSPlayer
                where p.RACE == _options.Interest && _options.Dataset.Contains(p.NAME)
                select new
                {
                    r.ID,
                    r.GAMETIME,
                    p.WIN
                },
                _ => from r in replays
                from p in r.DSPlayer
                where p.RACE == _options.Interest
                select new
                {
                    r.ID,
                    r.GAMETIME,
                    p.WIN
                }
            };
            var lresult = result.OrderBy(o => o.GAMETIME).ToList();

            if (!lresult.Any())
            {
                return(new DataResult());
            }

            CultureInfo           provider = CultureInfo.InvariantCulture;
            DataResult            dresult  = new DataResult();
            List <double>         data     = new List <double>();
            List <double>         xdata    = new List <double>();
            List <double>         ydata    = new List <double>();
            List <string>         labels   = new List <string>();
            Func <double, double> f        = null;

            int count = lresult.Count;
            int step  = 50;
            int cstep = count / step;

            while (cstep < 10)
            {
                step -= 1;
                cstep = count / step;
                if (step <= 1)
                {
                    break;
                }
            }
            dresult.CmdrInfo.Wins      = lresult.Where(x => x.WIN == true).Count();
            dresult.CmdrInfo.Games     = count;
            dresult.CmdrInfo.AWinrate  = Math.Round((double)dresult.CmdrInfo.Wins * 100 / dresult.CmdrInfo.Games, 2);
            dresult.CmdrInfo.ADuration = TimeSpan.FromDays(cstep);
            dresult.CmdrInfo.GameIDs   = lresult.Select(s => s.ID).ToHashSet();


            for (int i = 0; i < step; i++)
            {
                var sreps = lresult.Skip(i * cstep).Take(cstep);
                if (!sreps.Any())
                {
                    continue;
                }
                data.Add(Math.Round((double)sreps.Where(x => x.WIN == true).Count() * 100 / (double)sreps.Count(), 2));
                labels.Add(sreps.Last().GAMETIME.ToString("yyyy-MM-dd"));
                xdata.Add(i);
                ydata.Add(data.Last());
            }

            if (xdata.Any() && xdata.Count > 1)
            {
                int order = 6;
                if (xdata.Count <= 6)
                {
                    if (xdata.Count < 3)
                    {
                        order = 1;
                    }
                    else
                    {
                        order = xdata.Count - 2;
                    }
                }
                f = Fit.PolynomialFunc(xdata.ToArray(), ydata.ToArray(), order);
            }

            dresult.Labels       = labels;
            dresult.Dataset.data = data;
            dresult.fTimeline    = f;
            dresult.fStartTime   = lresult.First().GAMETIME;

            ChartService.SetColor(dresult.Dataset, _options.Chart.type, _options.Interest);
            dresult.Dataset.fill             = false;
            dresult.Dataset.pointRadius      = 2;
            dresult.Dataset.pointHoverRadius = 10;
            dresult.Dataset.showLine         = false;
            for (int i = 0; i < dresult.Labels.Count; i++)
            {
                ChartJSInterop.AddData(_jsRuntime,
                                       dresult.Labels[i],
                                       dresult.Dataset.data[i],
                                       dresult.Dataset.backgroundColor.Last(),
                                       null,
                                       lockobject
                                       ).GetAwaiter();
            }
            if (dresult.fTimeline != null)
            {
                string   fstart  = dresult.Labels.First().Substring(0, 10);
                DateTime ffstart = DateTime.ParseExact(fstart, "yyyy-MM-dd", provider);

                ChartJSdataset dataset = new ChartJSdataset();
                dataset.label       = _options.Interest + "_line";
                dataset.borderWidth = 3;
                dataset.pointRadius = 1;
                ChartService.SetColor(dataset, _options.Chart.type, _options.Interest);
                dataset.backgroundColor.Clear();
                _options.Chart.data.datasets.Add(dataset);
                ChartJSInterop.AddDataset(_jsRuntime, JsonConvert.SerializeObject(dataset, Formatting.Indented), lockobject).GetAwaiter();

                for (int i = 0; i < dresult.Labels.Count; i++)
                {
                    double fdata = dresult.fTimeline(i);

                    ChartJSInterop.AddData(_jsRuntime,
                                           dresult.Labels[i],
                                           fdata,
                                           dresult.Dataset.backgroundColor.Last(),
                                           null,
                                           lockobject
                                           ).GetAwaiter();
                }
            }
            return(dresult);
        }