Exemple #1
0
        public void ResetDsTimeResult()
        {
            using (var scope = scopeFactory.CreateScope())
            {
                var context = scope.ServiceProvider.GetRequiredService <sc2dsstatsContext>();
                var replays = ReplayFilter.DefaultFilter(context);
                replays = replays.Where(x => x.Gametime >= new DateTime(2018, 1, 1));
                var results = replays
                              .Include(i => i.Dsplayers)
                              .Select(s => GetTimeResultValues(s)).ToList();

                // context.DsTimeResultValues.AddRange(results.SelectMany(s => s));


                var timeresults = context.DsTimeResults.ToList();
                timeresults.ForEach(f => { f.Count = 0; f.Wins = 0; f.MVP = 0; f.Duration = 0; f.Kills = 0; f.Army = 0; });
                context.SaveChanges();

                var participants = context.Participants.ToList();
                participants.ForEach(f => { f.Count = 0; f.Wins = 0; });
                context.SaveChanges();

                CollectTimeResults2(context, logger, results.SelectMany(s => s).ToList());
            }
        }
Exemple #2
0
        public static async Task <List <DsRankingResponse> > GetRanking(sc2dsstatsContext context)
        {
            var replays = ReplayFilter.DefaultFilter(context);

            replays = replays.Where(x => x.Gametime >= new DateTime(2018, 1, 1));
            var players = await GetDatasets(context);

            List <DsRankingResponse> rankings = new List <DsRankingResponse>();

            foreach (var ent in players)
            {
                var plReplays = from r in replays
                                from p in r.Dsplayers
                                where p.Name == ent.Key
                                select new RankingHelper()
                {
                    Id            = r.Id,
                    Gametime      = r.Gametime,
                    MVP           = r.Maxkillsum == p.Killsum,
                    WIN           = p.Win,
                    Commander     = ((DSData.Commander)p.Race).ToString(),
                    WithTeammates = r.Dsplayers.Where(x => x.Team == p.Team && x != p && x.isPlayer).Any()
                };
                var plData = await plReplays.AsSplitQuery().ToListAsync();

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

                int    maincount = 0;
                string main      = "";
                foreach (var cmdr in DSData.cmdrs)
                {
                    int c = plData.Where(x => x.Commander == cmdr).Count();
                    if (c > maincount)
                    {
                        maincount = c;
                        main      = cmdr;
                    }
                }

                rankings.Add(new DsRankingResponse()
                {
                    Playername    = !String.IsNullOrEmpty(ent.Value) ? ent.Value : ent.Key,
                    Games         = plData.Count,
                    Wins          = plData.Where(x => x.WIN).Count(),
                    MVPs          = plData.Where(x => x.MVP).Count(),
                    MainCommander = main,
                    GamesMain     = maincount,
                    Teamgames     = plData.Where(x => x.WithTeammates).Count()
                });
            }
            return(rankings);
        }
Exemple #3
0
        private static async Task <List <DbStatsResult> > GetData(DsRequest request, sc2dsstatsContext context)
        {
            var replays = ReplayFilter.DefaultFilter(context);

            var reps = request.Player switch
            {
                false => from r in replays
                from p in r.Dsplayers
                where r.Gametime >= request.StartTime && r.Gametime <= request.EndTime
                select new DbStatsResult()
                {
                    Id       = r.Id,
                    Win      = p.Win,
                    Race     = p.Race,
                    OppRace  = p.Opprace,
                    GameTime = r.Gametime
                },
                true => from r in replays
                from p in r.Dsplayers
                where r.Gametime >= request.StartTime && r.Gametime <= request.EndTime &&
                p.isPlayer
                select new DbStatsResult()
                {
                    Id       = r.Id,
                    Win      = p.Win,
                    Race     = p.Race,
                    OppRace  = p.Opprace,
                    GameTime = r.Gametime
                }
            };

            return(await reps.ToListAsync());

            //var dbresults = context.DbStatsResults
            // .AsNoTracking()
            // .Where(x =>
            //       x.GameTime >= request.StartTime
            //    && x.GameTime <= request.EndTime
            //);

            //if (request.Player)
            //{
            //    dbresults = dbresults.Where(x => x.Player == true);
            //}

            // return await dbresults.ToListAsync();
        }
Exemple #4
0
        public static async Task <DsBuildResponse> GetBuild(sc2dsstatsContext context, DsBuildRequest request)
        {
            var replays = ReplayFilter.DefaultFilter(context);

            replays = replays.Where(x => x.Gametime >= request.StartTime);
            if (request.EndTime != DateTime.Today)
            {
                replays = replays.Where(x => x.Gametime <= request.EndTime);
            }

            IQueryable <BuildHelper> buildResults;

            if (request.Playernames == null || !request.Playernames.Any())
            {
                string Playername = request.Playername;
                if (!String.IsNullOrEmpty(Playername))
                {
                    var player = await context.DsPlayerNames.FirstOrDefaultAsync(f => f.Name == request.Playername);

                    if (player != null)
                    {
                        Playername = player.DbId.ToString();
                    }
                    //Playername = request.Playername switch
                    //{
                    //    "PAX" => await context.DsPlayerNames.FirstOrDefaultAsync(f => f.Name ==),
                    //    "Feralan" => "e2dfd75fcad1c454cfb2526fae4f3feb5e901039f7d366f69094c0d16a12e338",
                    //    "Panzerfaust" => "bd78339bb80c299a6c82812d9d4547d09cf15b0e8bb99b38090dc3bc4a5af8b5",
                    //    _ => "b33aef3fcc740b0d67eda3faa12c0f94cef5213fe70921d72fc2bfa8125a5889"
                    //};
                }

                buildResults = GetBuildResultQuery(replays, request, new List <string>()
                {
                    Playername
                });
            }
            else
            {
                buildResults = GetBuildResultQuery(replays, request, request.Playernames);
            }

            var builds = await buildResults.AsSplitQuery().ToListAsync();

            var uniqueBuilds = builds.GroupBy(g => g.Id).Select(s => s.First()).ToList();


            var response = new DsBuildResponse()
            {
                Interest = request.Interest,
                Versus   = request.Versus,
                Count    = uniqueBuilds.Count,
                Wins     = uniqueBuilds.Where(s => s.Win).Count(),
                Duration = uniqueBuilds.Sum(s => s.Duration),
                Gas      = uniqueBuilds.Sum(s => s.GasCount),
                Upgrades = uniqueBuilds.Sum(s => s.UpgradeSpending),
                Replays  = uniqueBuilds.Select(t => new DsBuildResponseReplay()
                {
                    Hash     = t.Hash,
                    Gametime = t.Gametime
                }).ToList(),
                Breakpoints = new List <DsBuildResponseBreakpoint>()
            };

            var breakpoints = buildResults.Select(s => s.Breakpoint).Distinct();

            foreach (var bp in breakpoints)
            {
                var bpReplays = builds.Where(x => x.Breakpoint == bp).ToList();

                response.Breakpoints.Add(new DsBuildResponseBreakpoint()
                {
                    Breakpoint = bp,
                    Count      = bpReplays.Count,
                    Wins       = bpReplays.Where(x => x.Win).Count(),
                    Duration   = bpReplays.Sum(s => s.Duration),
                    Gas        = bpReplays.Sum(s => s.GasCount),
                    Upgrades   = bpReplays.Sum(s => s.UpgradeSpending),
                    Units      = GetUnits(bpReplays.Select(s => s.UnitString).ToList())
                });
            }
            return(response);
        }
Exemple #5
0
        public static async Task GetPlayerStats(sc2dsstatsContext context, List <string> playerNames)
        {
            var replays = ReplayFilter.DefaultFilter(context);
            var cmdrs   = from r in replays
                          from p in r.Dsplayers
                          where playerNames.Contains(p.Name)
                          group p by p.Race into g
                          select new
            {
                cmdr  = g.Key,
                count = g.Count()
            };
            var lcmdrs = await cmdrs.ToListAsync();

            if (lcmdrs.Any())
            {
                var count       = lcmdrs.Sum(s => s.count);
                var mostplayed  = lcmdrs.OrderByDescending(o => o.count).First();
                var leastplayed = lcmdrs.OrderByDescending(o => o.count).Last();
                Console.WriteLine($"Most played Commander is {mostplayed.cmdr} ({(mostplayed.count * 100 / (double)count).ToString("N2")})");
                Console.WriteLine($"Least played Commander is {leastplayed.cmdr} ({(leastplayed.count * 100 / (double)count).ToString("N2")})");
            }

            var wrs = from r in replays
                      from p in r.Dsplayers
                      where playerNames.Contains(p.Name)
                      group p by p.Race into g
                      select new
            {
                cmdr  = g.Key,
                count = g.Count(),
                wins  = g.Count(s => s.Win)
            };
            var lwrs = await wrs.ToListAsync();

            if (lwrs.Any())
            {
                var bestcmdr  = lwrs.OrderByDescending(o => o.wins * 100 / (double)o.count).First();
                var worstcmdr = lwrs.OrderByDescending(o => o.wins * 100 / (double)o.count).Last();
                Console.WriteLine($"Best cmdr is {bestcmdr.cmdr} ({(bestcmdr.wins * 100 / (double)bestcmdr.count).ToString("N2")})");
                Console.WriteLine($"Worst cmdr is {worstcmdr.cmdr} ({(worstcmdr.wins * 100 / (double)worstcmdr.count).ToString("N2")})");
            }

            var matchups = from r in replays
                           from p in r.Dsplayers
                           where playerNames.Contains(p.Name)
                           group p by new { cmdr = p.Race, opp = p.Opprace } into g
                select new
            {
                matchup = g.Key,
                count   = g.Count(),
                wins    = g.Count(s => s.Win)
            };
            var lmatchups = await matchups.ToListAsync();

            if (lmatchups.Any())
            {
                var bestmatchup  = lmatchups.OrderByDescending(o => o.wins * 100 / (double)o.count).First();
                var worstmatchup = lmatchups.OrderByDescending(o => o.wins * 100 / (double)o.count).Last();
                Console.WriteLine($"Best matchup is {bestmatchup.matchup.cmdr} vs {bestmatchup.matchup.opp} ({(bestmatchup.wins * 100 / (double)bestmatchup.count).ToString("N2")})");
                Console.WriteLine($"Worst matchup is {worstmatchup.matchup.cmdr} vs {worstmatchup.matchup.opp} ({(worstmatchup.wins * 100 / (double)worstmatchup.count).ToString("N2")})");
            }

            var poss = from r in replays
                       from p in r.Dsplayers
                       where playerNames.Contains(p.Name)
                       group p by p.Pos into g
                       select new
            {
                pos   = g.Key,
                count = g.Count(),
                wins  = g.Count(s => s.Win)
            };
            var lposs = await poss.ToListAsync();

            if (lposs.Any())
            {
                foreach (var pos in lposs.OrderBy(o => o.pos))
                {
                    Console.WriteLine($"Pos: {pos.pos} => {(pos.wins * 100 / (double)pos.count).ToString("N2")}");
                }
            }
        }