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()); }
public static DsResponse GetMvp(DsRequest request, List <CmdrStats> cmdrstats) { var stats = GetTimeStats(request, cmdrstats); if (request.Interest != "ALL") { stats = stats.Where(x => x.RACE == (byte)DSData.GetCommander(request.Interest)).ToList(); } List <DsResponseItem> items = request.Interest == "ALL" ? stats.GroupBy(g => g.RACE).Select(s => new DsResponseItem { Label = ((Commander)s.Key).ToString(), Count = s.Sum(c => c.count), Wins = s.Sum(c => c.mvp), }).ToList() : stats.GroupBy(g => g.OPPRACE).Select(s => new DsResponseItem { Label = ((Commander)s.Key).ToString(), Count = s.Sum(c => c.count), Wins = s.Sum(c => c.mvp), }).ToList(); int tcount = items.Sum(s => s.Count); return(new DsResponse() { Interest = request.Interest, Count = request.Player ? tcount : tcount / 6, AvgDuration = tcount == 0 ? 0 : (int)(stats.Sum(s => s.duration) / tcount), Items = items }); }
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()); }
public Dsreplay(DsReplayDto dto) { Dsplayers = dto.DSPlayer.Select(s => new Dsplayer() { Breakpoints = s.Breakpoints.Select(b => new Breakpoint() { Breakpoint1 = b.Breakpoint, Gas = b.Gas, Income = b.Income, Army = b.Army, Kills = b.Kills, Upgrades = b.Upgrades, Tier = b.Tier, Mid = b.Mid, DsUnitsString = b.dsUnitsString, DbUnitsString = b.dbUnitsString, DbUpgradesString = b.dbUpgradesString }).ToList(), Pos = (byte)s.POS, Realpos = (byte)s.REALPOS, Name = s.NAME, Race = (byte)DSData.GetCommander(s.RACE), Opprace = (byte)DSData.GetCommander(s.OPPRACE), Win = s.WIN, Team = (byte)s.TEAM, Killsum = s.KILLSUM, Income = s.INCOME, Pduration = s.PDURATION, Army = s.ARMY, Gas = (byte)s.GAS, isPlayer = s.isPlayer }).ToList(); Middles = dto.Middle.Select(m => new Middle() { Gameloop = m.Gameloop, Team = (byte)m.Team }).ToList(); Replay = dto.REPLAY; Gametime = dto.GAMETIME; Winner = (sbyte)dto.WINNER; Duration = dto.DURATION; Minkillsum = dto.MINKILLSUM; Maxkillsum = dto.MAXKILLSUM; Minarmy = dto.MINARMY; Minincome = dto.MININCOME; Maxleaver = dto.MAXLEAVER; Playercount = (byte)dto.PLAYERCOUNT; Reported = (byte)dto.REPORTED; Isbrawl = dto.ISBRAWL; Gamemode = (byte)DSData.GetGameMode(dto.GAMEMODE); Version = dto.VERSION; Hash = dto.HASH; Replaypath = dto.REPLAYPATH; Objective = dto.OBJECTIVE; Upload = dto.Upload; Bunker = dto.Bunker; Cannon = dto.Cannon; Mid1 = dto.Mid1; Mid2 = dto.Mid2; }
private static IQueryable <Dsreplay> GetCountReplays(sc2dsstatsContext context, DsRequest request) { var replays = context.Dsreplays.Where(x => x.Gametime > request.StartTime); if (request.Filter == null) { replays = replays.Where(x => new List <int>() { (int)Gamemode.Commanders, (int)Gamemode.CommandersHeroic }.Contains(x.Gamemode)); } else if (request.Filter.GameModes.Any()) { replays = replays.Where(x => request.Filter.GameModes.Contains(x.Gamemode)); } if (request.EndTime != DateTime.Today) { replays = replays.Where(x => x.Gametime <= request.EndTime); } if (!String.IsNullOrEmpty(request.Interest) && !request.Interest.Equals("ALL")) { replays = replays.Include(i => i.Dsplayers); if (request.Player) { replays = from r in replays from p in r.Dsplayers where p.isPlayer && p.Race == (byte)DSData.GetCommander(request.Interest) select r; } else { replays = from r in replays from p in r.Dsplayers where p.Race == (byte)DSData.GetCommander(request.Interest) select r; } replays = replays.Distinct(); } if (request.Filter != null && request.Filter.Players.Any()) { replays = from r in replays from p in r.Dsplayers where request.Filter.Players.Contains(p.Name) select r; if (request.Filter.Players.Count > 0) { return(replays.Distinct()); } } return(replays); }
public static async Task <DsResponse> GetSynergy(sc2dsstatsContext context, DsRequest request) { var replays = ReplayFilter.Filter(context, request); var synergy = request.Player ? from r in replays from p in r.Dsplayers from t in r.Dsplayers where p.isPlayer && p.Race == (byte)DSData.GetCommander(request.Interest) && t.Team == p.Team && t.Id != p.Id group new { r, p } by t.Race into g select new DsResponseItem() { Label = ((DSData.Commander)g.Key).ToString(), Count = g.Count(), Wins = g.Count(c => c.p.Win), } : from r in replays from p in r.Dsplayers from t in r.Dsplayers where p.Race == (byte)DSData.GetCommander(request.Interest) && t.Team == p.Team && t.Id != p.Id group new { r, p } by t.Race into g select new DsResponseItem() { Label = ((DSData.Commander)g.Key).ToString(), Count = g.Count(), Wins = g.Count(c => c.p.Win), }; var items = await synergy.ToListAsync(); items = items.Where(x => DSData.cmdrs.Contains(x.Label)).OrderBy(o => o.Label).ToList(); return(new DsResponse() { Interest = request.Interest, Count = items.Sum(s => s.Count), Items = items }); }
public static IQueryable <BuildHelper> GetBuildResultQuery(IQueryable <Dsreplay> replays, DsBuildRequest request, List <string> playernames) { return((String.IsNullOrEmpty(request.Versus), !playernames.Any()) switch { (true, true) => from r in replays from p in r.Dsplayers where p.Race == (byte)DSData.GetCommander(request.Interest) from b in p.Breakpoints select new BuildHelper() { Id = r.Id, Hash = r.Hash, Gametime = r.Gametime, UnitString = b.DsUnitsString, Win = p.Win, UpgradeSpending = b.Upgrades, GasCount = b.Gas, Breakpoint = b.Breakpoint1, Duration = r.Duration }, (true, false) => from r in replays from p in r.Dsplayers where p.Race == (byte)DSData.GetCommander(request.Interest) && playernames.Contains(p.Name) from b in p.Breakpoints select new BuildHelper() { Id = r.Id, Hash = r.Hash, Gametime = r.Gametime, UnitString = b.DsUnitsString, Win = p.Win, UpgradeSpending = b.Upgrades, GasCount = b.Gas, Breakpoint = b.Breakpoint1, Duration = r.Duration }, (false, true) => from r in replays from p in r.Dsplayers where p.Race == (byte)DSData.GetCommander(request.Interest) && p.Opprace == (byte)DSData.GetCommander(request.Versus) from b in p.Breakpoints select new BuildHelper() { Id = r.Id, Hash = r.Hash, Gametime = r.Gametime, UnitString = b.DsUnitsString, Win = p.Win, UpgradeSpending = b.Upgrades, GasCount = b.Gas, Breakpoint = b.Breakpoint1, Duration = r.Duration }, (false, false) => from r in replays from p in r.Dsplayers where p.Race == (byte)DSData.GetCommander(request.Interest) && p.Opprace == (byte)DSData.GetCommander(request.Versus) && playernames.Contains(p.Name) from b in p.Breakpoints select new BuildHelper() { Id = r.Id, Hash = r.Hash, Gametime = r.Gametime, UnitString = b.DsUnitsString, Win = p.Win, UpgradeSpending = b.Upgrades, GasCount = b.Gas, Breakpoint = b.Breakpoint1, Duration = r.Duration }, });
public static TimelineResponse GetTimeline(TimelineRequest request, List <CmdrStats> cmdrstats) { if (request.Step < 3) { request.Step = 3; } if (request.smaK < 3) { request.smaK = 3; } var stats = GetTimeStats(request, cmdrstats); int tcount = stats.Sum(s => s.count); TimelineResponse response = new TimelineResponse() { Interest = request.Interest, Count = request.Player ? tcount : tcount / 6, Versus = request.Versus, AvgDuration = tcount == 0 ? 0 : (int)(stats.Sum(s => s.duration) / tcount), Items = new List <DsResponseItem>() }; DateTime requestTime = request.StartTime; while (requestTime < request.EndTime) { var timeResults = stats.Where(f => f.year == requestTime.Year && f.month == requestTime.Month && f.RACE == (byte)DSData.GetCommander(request.Interest)); if (!timeResults.Any()) { response.Items.Add(new TimelineResponseItem() { Label = $"{requestTime.ToString("yyyy-MM")} (0)", Count = 0, Wins = 0 }); } else { int ccount = timeResults.Sum(s => s.count); response.Items.Add(new TimelineResponseItem() { Label = $"{requestTime.ToString("yyyy-MM")} ({ccount})", Count = ccount, Wins = timeResults.Sum(s => s.wins) }); } requestTime = requestTime.AddMonths(1); } if (response.Items.Any() && response.Items.Last().Count < 10) { response.Items.RemoveAt(response.Items.Count - 1); } var sma = new SimpleMovingAverage(request.smaK); response.SmaData = new List <double>(); response.SmaData = GetNiceLineData(response.Items.Select(s => s.Count == 0 ? 0 : ((double)s.Wins * 100.0 / (double)s.Count)), request.smaK); return(response); }
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 = lresults.Count == 0 ? 0 : (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); } }
public static async Task <DsResponse> GetStandardTeamWinrate(DsRequest request, sc2dsstatsContext context) { var replays = context.Dsreplays .Include(i => i.Dsplayers) .AsNoTracking() .Where(x => x.Gamemode == (byte)DSData.Gamemode.Standard && x.Gametime > request.StartTime && x.Duration > 300 && x.Maxleaver < 90 && x.Playercount == 6 ); if (request.EndTime != DateTime.Today) { replays = replays.Where(x => x.Gametime < request.EndTime); } byte[] races = null; if (!String.IsNullOrEmpty(request.Interest) && request.Interest != "ALL") { string[] iSplit = Regex.Split(request.Interest, @"(?<!^)(?=[A-Z])"); if (iSplit.Length == 3) { races = iSplit.Select(s => (byte)DSData.GetCommander(s)).ToArray(); } } List <DsResponseItem> teamResponses = new List <DsResponseItem>(); for (int p1 = 1; p1 < 4; p1++) { for (int p2 = 1; p2 < 4; p2++) { for (int p3 = 1; p3 < 4; p3++) { var team1Replays = races == null? replays.Where(x => (x.Dsplayers.Where(s => s.Realpos == 1 && s.Race == p1).Any() && x.Dsplayers.Where(s => s.Realpos == 2 && s.Race == p2).Any() && x.Dsplayers.Where(s => s.Realpos == 3 && s.Race == p3).Any()) ) : replays.Where(x => (x.Dsplayers.Where(s => s.Realpos == 1 && s.Race == p1).Any() && x.Dsplayers.Where(s => s.Realpos == 2 && s.Race == p2).Any() && x.Dsplayers.Where(s => s.Realpos == 3 && s.Race == p3).Any()) && (x.Dsplayers.Where(s => s.Realpos == 4 && s.Race == races[0]).Any() && x.Dsplayers.Where(s => s.Realpos == 5 && s.Race == races[1]).Any() && x.Dsplayers.Where(s => s.Realpos == 6 && s.Race == races[2]).Any()) ); var team2Replays = races == null? replays.Where(x => (x.Dsplayers.Where(s => s.Realpos == 4 && s.Race == p1).Any() && x.Dsplayers.Where(s => s.Realpos == 5 && s.Race == p2).Any() && x.Dsplayers.Where(s => s.Realpos == 6 && s.Race == p3).Any()) ) : replays.Where(x => (x.Dsplayers.Where(s => s.Realpos == 4 && s.Race == p1).Any() && x.Dsplayers.Where(s => s.Realpos == 5 && s.Race == p2).Any() && x.Dsplayers.Where(s => s.Realpos == 6 && s.Race == p3).Any()) && (x.Dsplayers.Where(s => s.Realpos == 1 && s.Race == races[0]).Any() && x.Dsplayers.Where(s => s.Realpos == 2 && s.Race == races[1]).Any() && x.Dsplayers.Where(s => s.Realpos == 3 && s.Race == races[2]).Any()) ); var team1Results = from r in team1Replays group r by r.Winner into g select new { Winner = g.Key, Count = g.Count(), duration = g.Sum(s => s.Duration), }; var team2Results = from r in team2Replays group r by r.Winner into g select new { Winner = g.Key, Count = g.Select(s => s.Id).Distinct().Count(), duration = g.Sum(s => s.Duration), }; var t1 = await team1Results.AsNoTracking().ToListAsync(); var t2 = await team2Results.AsNoTracking().ToListAsync(); int count = t1.Sum(s => s.Count) + t2.Sum(s => s.Count); if (count > 0) { teamResponses.Add(new DsResponseItem() { Label = ((DSData.Commander)p1).ToString() + ((DSData.Commander)p2).ToString() + ((DSData.Commander)p3).ToString(), Count = count, Wins = t1.Where(x => x.Winner == 0).Sum(s => s.Count) + t2.Where(x => x.Winner == 1).Sum(s => s.Count), duration = t1.Sum(s => s.duration) + t2.Sum(s => s.duration), Replays = count, }); } } } } int tcount = teamResponses.Sum(s => s.Count); return(new DsResponse() { Interest = request.Interest, Count = tcount, AvgDuration = tcount == 0 ? 0 : (int)(teamResponses.Sum(s => s.duration) / tcount), Items = teamResponses }); }
public static async Task <DsResponse> GetStandardWinrate(DsRequest request, sc2dsstatsContext context) { var replays = context.Dsreplays.Where(x => x.Gamemode == (byte)DSData.Gamemode.Standard && x.Gametime > request.StartTime ).AsNoTracking(); if (request.EndTime < DateTime.Today) { replays = replays.Where(x => x.Gametime < request.EndTime); } var responses = (request.Player, request.Interest == "ALL") switch { (false, true) => from r in replays from p in r.Dsplayers group new { r, p } by new { race = p.Race } into g select new DsResponseItem() { Label = ((DSData.Commander)g.Key.race).ToString(), Count = g.Count(), Wins = g.Count(c => c.p.Win), duration = g.Sum(s => s.r.Duration), Replays = g.Select(s => s.r.Id).Distinct().Count() }, (false, false) => from r in replays from p in r.Dsplayers where p.Race == (byte)DSData.GetCommander(request.Interest) group new { r, p } by new { race = p.Opprace } into g select new DsResponseItem() { Label = ((DSData.Commander)g.Key.race).ToString(), Count = g.Count(), Wins = g.Count(c => c.p.Win), duration = g.Sum(s => s.r.Duration), Replays = g.Select(s => s.r.Id).Distinct().Count() }, (true, true) => from r in replays from p in r.Dsplayers where p.isPlayer group new { r, p } by new { race = p.Race } into g select new DsResponseItem() { Label = ((DSData.Commander)g.Key.race).ToString(), Count = g.Count(), Wins = g.Count(c => c.p.Win), duration = g.Sum(s => s.r.Duration), Replays = g.Select(s => s.r.Id).Distinct().Count() }, (true, false) => from r in replays from p in r.Dsplayers where p.isPlayer && p.Race == (byte)DSData.GetCommander(request.Interest) group new { r, p } by new { race = p.Opprace } into g select new DsResponseItem() { Label = ((DSData.Commander)g.Key.race).ToString(), Count = g.Count(), Wins = g.Count(c => c.p.Win), duration = g.Sum(s => s.r.Duration), Replays = g.Select(s => s.r.Id).Distinct().Count() } }; var items = await responses.ToListAsync(); items = items.Where(x => DSData.cmdrs.Contains(x.Label)).ToList(); int tcount = items.Sum(s => s.Count); return(new DsResponse() { Interest = request.Interest, Count = tcount / 6, AvgDuration = tcount == 0 ? 0 : (int)(items.Sum(s => s.duration) / tcount), Items = items }); }
public static async Task <DsResponse> GetCustomMvp(DsRequest request, sc2dsstatsContext context) { var replays = ReplayFilter.Filter(context, request); var responses = (request.Player, request.Interest == "ALL") switch { (false, true) => from r in replays from p in r.Dsplayers group new { r, p } by new { race = p.Race } into g select new DsResponseItem() { Label = ((Commander)g.Key.race).ToString(), Count = g.Count(), Wins = g.Count(c => c.p.Killsum == c.r.Maxkillsum), duration = g.Sum(s => s.r.Duration) }, (false, false) => from r in replays from p in r.Dsplayers where p.Race == (byte)DSData.GetCommander(request.Interest) group new { r, p } by new { race = p.Opprace } into g select new DsResponseItem() { Label = ((Commander)g.Key.race).ToString(), Count = g.Count(), Wins = g.Count(c => c.p.Killsum == c.r.Maxkillsum), duration = g.Sum(s => s.r.Duration) }, (true, true) => from r in replays from p in r.Dsplayers where p.isPlayer group new { r, p } by new { race = p.Race } into g select new DsResponseItem() { Label = ((Commander)g.Key.race).ToString(), Count = g.Count(), Wins = g.Count(c => c.p.Killsum == c.r.Maxkillsum), duration = g.Sum(s => s.r.Duration) }, (true, false) => from r in replays from p in r.Dsplayers where p.isPlayer && p.Race == (byte)DSData.GetCommander(request.Interest) group new { r, p } by new { race = p.Opprace } into g select new DsResponseItem() { Label = ((Commander)g.Key.race).ToString(), Count = g.Count(), Wins = g.Count(c => c.p.Killsum == c.r.Maxkillsum), duration = g.Sum(s => s.r.Duration) } }; var items = await responses.ToListAsync(); items = items.Where(x => DSData.cmdrs.Contains(x.Label)).ToList(); int tcount = items.Sum(s => s.Count); return(new DsResponse() { Interest = request.Interest, Count = tcount / 6, AvgDuration = tcount == 0 ? 0 : (int)(items.Sum(s => s.duration) / tcount), Items = items }); }