コード例 #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());
            }
        }
コード例 #2
0
        public static async Task GetInfo(sc2dsstatsContext context, string timespan)
        {
            DsRequest request = new DsRequest()
            {
                Filter = new DsFilter()
            };

            request.Filter.SetOff();
            request.SetTime(timespan);
            request.Filter.GameModes = new List <int>()
            {
                (int)Gamemode.Commanders, (int)Gamemode.CommandersHeroic
            };

            var replays = ReplayFilter.Filter(context, request);

            var leaver = from r in replays
                         group r by r.Maxleaver > 89 into g
                         select new
            {
                Leaver = g.Key,
                Count  = g.Count()
            };
            var lleaver = await leaver.ToListAsync();

            int count1 = lleaver[0].Count;
            int count2 = lleaver[1].Count;
        }
コード例 #3
0
ファイル: MvpService.cs プロジェクト: ipax77/sc2dsstats
        private static async Task <List <DbStatsResult> > GetMVPData(sc2dsstatsContext context, DsRequest request)
        {
            var replays = ReplayFilter.Filter(context, request);

            var results = from r in replays
                          from p in r.Dsplayers
                          select new DbStatsResult()
            {
                Id       = r.Id,
                Race     = p.Race,
                OppRace  = p.Opprace,
                Duration = r.Duration,
                Win      = p.Win,
                Player   = p.isPlayer,
                MVP      = p.Killsum == r.Maxkillsum
            };

            if (request.Interest != "ALL")
            {
                results = results.Where(x => x.Race == (byte)DSData.GetCommander(request.Interest));
            }

            if (request.Player)
            {
                results = results.Where(x => x.Player);
            }

            return(await results.ToListAsync());
        }
コード例 #4
0
        public static async Task <List <DbStatsResult> > GetTimelineData(TimelineRequest request, sc2dsstatsContext context)
        {
            var replays = ReplayFilter.Filter(context, request);

            var results = from r in replays
                          from p in r.Dsplayers
                          where p.Race == (byte)DSData.GetCommander(request.Interest)
                          select new DbStatsResult()
            {
                Id       = r.Id,
                Win      = p.Win,
                GameTime = r.Gametime,
                Player   = p.isPlayer,
                OppRace  = p.Opprace
            };

            if (request.Player)
            {
                results = results.Where(x => x.Player);
            }

            if (request.Versus != "ALL")
            {
                results = results.Where(x => x.OppRace == (byte)DSData.GetCommander(request.Versus));
            }

            return(await results.ToListAsync());
        }
コード例 #5
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);
        }
コード例 #6
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();
        }
コード例 #7
0
        public static void SetDefaultFilter(sc2dsstatsContext context)
        {
            var replays     = context.Dsreplays.OrderBy(o => o.Id);
            int step        = 1000;
            int i           = 0;
            var stepReplays = replays.Skip(i * step).Take(step).ToList();

            while (stepReplays.Any())
            {
                ReplayFilter.SetDefaultFilter(stepReplays);
                context.SaveChanges();
                i++;
                stepReplays = replays.Skip(i * step).Take(step).ToList();
                if (i % 100 == 0)
                {
                    Console.WriteLine(i);
                }
            }
        }
コード例 #8
0
        public async Task InsertReplays(List <Dsreplay> dsreplays, string id, EventWaitHandle ewh = null)
        {
            if (!String.IsNullOrEmpty(id))
            {
                dsreplays.ForEach(f => f.Id = 0);
                dsreplays.SelectMany(s => s.Middles).ToList().ForEach(f => f.Id   = 0);
                dsreplays.SelectMany(s => s.Dsplayers).ToList().ForEach(f => f.Id = 0);
                dsreplays.SelectMany(s => s.Dsplayers).SelectMany(s => s.Breakpoints).ToList().ForEach(f => f.Id = 0);
                dsreplays.SelectMany(s => s.Dsplayers).SelectMany(s => s.Breakpoints).SelectMany(s => s.Dsunits).ToList().ForEach(f => f.Id = 0);
                dsreplays.SelectMany(s => s.Dsplayers).Where(x => x.Name == "player").ToList().ForEach(f => { f.Name = id; f.isPlayer = true; });
            }
            ReplayFilter.SetDefaultFilter(dsreplays);

            foreach (var rep in dsreplays)
            {
                Replays.Add(rep);
            }

            await InsertJob(ewh);
        }
コード例 #9
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);
        }
コード例 #10
0
ファイル: DurationService.cs プロジェクト: ipax77/sc2dsstats
        public static async Task <TimelineResponse> GetDuration(sc2dsstatsContext context, DsRequest request)
        {
            var replays = ReplayFilter.Filter(context, request);

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

            var results = request.Player switch
            {
                true => from r in replays
                from p in r.Dsplayers
                where p.Race == (byte)DSData.GetCommander(request.Interest) && p.isPlayer
                select new
                {
                    r.Id,
                    r.Duration,
                    p.Win
                },
                false => from r in replays
                from p in r.Dsplayers
                where p.Race == (byte)DSData.GetCommander(request.Interest)
                select new
                {
                    r.Id,
                    r.Duration,
                    p.Win
                }
            };
            var lresults = await results.ToListAsync();

            TimelineResponse response = new TimelineResponse()
            {
                Interest    = request.Interest,
                Count       = lresults.Select(s => s.Id).Distinct().Count(),
                AvgDuration = (int)(lresults.Sum(s => s.Duration) / lresults.Count),
                Items       = new List <DsResponseItem>()
            };

            if (lresults.Any())
            {
                for (int i = 0; i < DSData.durations.Length; i++)
                {
                    int startd = 0;
                    if (i > 0)
                    {
                        Match m = d_rx.Match(DSData.durations[i]);
                        if (m.Success)
                        {
                            startd = int.Parse(m.Value);
                        }
                    }
                    int endd = startd + 3;
                    if (i == 0)
                    {
                        endd = 8;
                    }
                    if (i == DSData.durations.Length - 1)
                    {
                        endd = 200;
                    }
                    var ilresults = lresults.Where(x => x.Duration > startd * 60 && x.Duration < endd * 60).ToList();


                    response.Items.Add(new DsResponseItem()
                    {
                        Label = $"{DSData.durations[i]} min ({ilresults.Count})",
                        Count = ilresults.Count,
                        Wins  = ilresults.Where(x => x.Win == true).Count()
                    });
                }
            }
            var sma = new SimpleMovingAverage(4);

            response.SmaData = new List <double>();
            response.SmaData = TimelineService.GetNiceLineData(response.Items.Select(s => s.Count == 0 ? 0 : ((double)s.Wins * 100.0 / (double)s.Count)), 4);

            return(response);
        }
    }
コード例 #11
0
ファイル: PlayerService.cs プロジェクト: ipax77/sc2dsstats
        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")}");
                }
            }
        }