/// <summary> /// Initialize team values for the first time /// </summary> /// <param name="demo"></param> /// <param name="team"></param> private static void InitTeam(Demo demo, Team team) { team.RoundCount = demo.Rounds.Count(); UpdateWinner(demo, team); UpdateRoundsStats(demo, team); UpdateBombStats(demo, team); }
/// <summary> /// Update team's stats /// </summary> /// <param name="demo"></param> /// <param name="team"></param> private static void UpdateTeamStats(Demo demo, Team team) { team.MatchCount++; team.RoundCount += demo.Rounds.Count(); team.Players = demo.TeamCT.Equals(team) ? new ObservableCollection <Player>(demo.TeamCT.Players.Concat(team.Players).ToList()) : new ObservableCollection <Player>(demo.TeamT.Players.Concat(team.Players).ToList()); UpdateWinner(demo, team); UpdateRoundsStats(demo, team); UpdateBombStats(demo, team); }
private static void UpdateRoundsStats(Demo demo, Team team) { foreach (Round round in demo.Rounds) { if (round.WinnerName == team.Name) { team.WinRoundCount++; if (round.WinnerSide == Side.CounterTerrorist) { team.WinRoundCtCount++; } else { team.WinRoundTCount++; } if (round.SideTrouble != Side.None) { switch (round.Type) { case RoundType.PISTOL_ROUND: team.WinPistolRoundCount++; break; case RoundType.ECO: team.WinEcoRoundCount++; break; case RoundType.SEMI_ECO: team.WinSemiEcoRoundCount++; break; case RoundType.FORCE_BUY: team.WinForceBuyRoundCount++; break; } } } else { team.LostRoundCount++; if (round.WinnerSide == Side.CounterTerrorist) { team.LostRoundTCount++; } else { team.LostRoundCtCount++; } } } }
/// <summary> /// Update teams data /// </summary> private void UpdateTeams() { Team teamCt = GetTeamBySide(Side.CounterTerrorist); Team teamT = GetTeamBySide(Side.Terrorist); if (!string.IsNullOrEmpty(Parser.TClanName) && !string.IsNullOrEmpty(Parser.TClanName) && teamCt.Name == Parser.TClanName && teamT.Name == Parser.CTClanName) { SwapTeams(); } UpdatePlayers(); }
private static void UpdateWinner(Demo demo, Team team) { if (demo.Winner == null) { return; } if (demo.Winner.Equals(team)) { team.WinCount++; } else { team.LostCount++; } }
private static void UpdateBombStats(Demo demo, Team team) { foreach (BombPlantedEvent plantedEvent in demo.BombPlanted) { if (team.Players.FirstOrDefault(p => p.SteamId == plantedEvent.PlanterSteamId) != null) { if (plantedEvent.Site == "A") { team.BombPlantedOnACount++; } else { team.BombPlantedOnBCount++; } } } }
public Task <Demo> AnalyzeDemo(Demo demo, CancellationToken token, Action <string, float> progressCallback = null) { Random random = new Random(); ObservableCollection <Player> players = new ObservableCollection <Player>(); for (int i = 0; i < 10; i++) { Player player = new Player { Name = "player" + (i + 1), HeadshotCount = random.Next(14), OneKillCount = random.Next(10, 30), TwoKillCount = random.Next(10, 20), ThreeKillCount = random.Next(0, 10), FourKillCount = random.Next(0, 5), FiveKillCount = random.Next(0, 2), BombDefusedCount = random.Next(0, 2), BombPlantedCount = random.Next(0, 2), DeathCount = random.Next(0, 32), KillCount = random.Next(30), AssistCount = random.Next(15), Score = random.Next(10, 80), RoundMvpCount = random.Next(6), RankNumberNew = 5, RankNumberOld = 4, RatingHltv = (float)random.NextDouble(), SteamId = random.Next(1000, 800000), IsOverwatchBanned = random.Next(100) < 40, IsVacBanned = random.Next(100) < 40, TeamKillCount = random.Next(0, 1), WinCount = random.Next(10, 687), MolotovThrownCount = random.Next(0, 10), DecoyThrownCount = random.Next(0, 10), IncendiaryThrownCount = random.Next(20), SmokeThrownCount = random.Next(20), FlashbangThrownCount = random.Next(20), HeGrenadeThrownCount = random.Next(20), BombExplodedCount = random.Next(5), AvatarUrl = string.Empty, KillDeathRatio = (decimal)random.NextDouble(), MatchCount = random.Next(100), RoundPlayedCount = random.Next(100) }; players.Add(player); } Team teamCt = new Team { Name = "Team 1", Players = new ObservableCollection <Player>(players.Take(5)), Score = 6, ScoreFirstHalf = 6, ScoreSecondHalf = 1, }; Team teamT = new Team { Name = "Team 2", Players = new ObservableCollection <Player>(players.Skip(5).Take(5)), Score = 16, ScoreFirstHalf = 10, ScoreSecondHalf = 5, }; ObservableCollection <Round> rounds = new ObservableCollection <Round>(); for (int i = 0; i < 32; i++) { ObservableCollection <KillEvent> kills = new ObservableCollection <KillEvent>(); for (int j = 0; j < random.Next(1, 9); j++) { Player killer = players.ElementAt(random.Next(9)); Player killed = players.ElementAt(random.Next(9)); kills.Add(new KillEvent(random.Next(1, 10000), random.Next(1, 100)) { KillerName = killer.Name, KillerSteamId = killer.SteamId, KillerSide = killer.Side, KilledName = killed.Name, KilledSteamId = killed.SteamId, KilledSide = killed.Side, RoundNumber = i, Weapon = Weapon.WeaponList.ElementAt(random.Next(44)) }); } // generate open / entry kills for this round Round round = new Round { Number = i + 1, OneKillCount = random.Next(5), TwoKillCount = random.Next(2), ThreeKillCount = random.Next(1), FourKillCount = random.Next(1), FiveKillCount = random.Next(1), EquipementValueTeamCt = random.Next(4200, 30000), EquipementValueTeamT = random.Next(4200, 30000), StartMoneyTeamCt = random.Next(4200, 50000), StartMoneyTeamT = random.Next(4200, 50000), Tick = random.Next(7000, 100000), EndTick = random.Next(7000, 100000), FreezetimeEndTick = random.Next(7000, 100000), WinnerName = teamCt.Name, WinnerSide = Side.CounterTerrorist, BombDefused = null, BombPlanted = null, BombExploded = null, Type = RoundType.NORMAL, EndReason = RoundEndReason.CTWin, EntryKillEvent = new EntryKillEvent(random.Next(1, 10000), random.Next(1, 100)) { HasWon = random.Next(100) < 50, KillerSteamId = players.ElementAt(random.Next(9)).SteamId, KillerName = players.ElementAt(random.Next(9)).Name, KilledSteamId = players.ElementAt(random.Next(9)).SteamId, KilledName = players.ElementAt(random.Next(9)).Name, Weapon = Weapon.WeaponList.ElementAt(random.Next(44)), KilledSide = Side.CounterTerrorist, KillerSide = Side.Terrorist }, SideTrouble = Side.None, Kills = kills }; rounds.Add(round); } demo.Id = "de_dust25445648778447878"; demo.Source = new Valve(); demo.Name = "esea_nip_vs_titan.dem"; demo.Tickrate = 15; demo.ServerTickrate = 128; demo.MapName = "de_dust2"; demo.ClientName = "localhost"; demo.Hostname = "local"; demo.OneKillCount = 90; demo.TwoKillCount = 30; demo.ThreeKillCount = 25; demo.FourKillCount = 3; demo.FiveKillCount = 1; demo.Path = "C:\\mydemo.dem"; demo.Type = "GOTV"; demo.Comment = "comment"; demo.TeamCT = teamCt; demo.TeamT = teamT; demo.Players = players; demo.Rounds = rounds; demo.MostKillingWeapon = Weapon.WeaponList[random.Next(44)]; foreach (KillEvent e in rounds.SelectMany(round => round.Kills)) { demo.Kills.Add(e); } return(Task.FromResult(demo)); }
private static Demo GenerateDemo() { int currentTick = 1; ObservableCollection <Player> players = new ObservableCollection <Player>(); Random random = new Random(); ObservableCollection <EntryKillEvent> entryKills = new ObservableCollection <EntryKillEvent>(); for (int indexEntryKill = 0; indexEntryKill < random.Next(5); indexEntryKill++) { currentTick *= indexEntryKill; Player killer = players.ElementAt(random.Next(0, 9)); Player killed = players.ElementAt(random.Next(0, 9)); EntryKillEvent entryKill = new EntryKillEvent(currentTick, random.Next(1, 50000)) { KilledSteamId = killed.SteamId, KilledName = killed.Name, KilledSide = killed.Side, KillerSteamId = killer.SteamId, KillerName = killer.Name, KillerSide = killer.Side }; entryKills.Add(entryKill); } for (int j = 0; j < 10; j++) { Player player = new Player { Name = "player" + (j + 1), HeadshotCount = random.Next(14), OneKillCount = random.Next(10, 30), TwoKillCount = random.Next(10, 20), ThreeKillCount = random.Next(0, 10), FourKillCount = random.Next(0, 5), FiveKillCount = random.Next(0, 2), BombDefusedCount = random.Next(0, 2), BombPlantedCount = random.Next(0, 2), EntryKills = entryKills, DeathCount = random.Next(0, 32), KillCount = random.Next(30), AssistCount = random.Next(15), Score = random.Next(10, 80), RoundMvpCount = random.Next(6) }; players.Add(player); } currentTick = 1; ObservableCollection <Round> rounds = new ObservableCollection <Round>(); for (int k = 0; k < 32; k++) { Round round = new Round { Number = k + 1, OneKillCount = random.Next(5), TwoKillCount = random.Next(2), ThreeKillCount = random.Next(1), FourKillCount = random.Next(1), FiveKillCount = random.Next(1), EquipementValueTeamCt = random.Next(4200, 30000), EquipementValueTeamT = random.Next(4200, 30000), StartMoneyTeamCt = random.Next(4200, 50000), StartMoneyTeamT = random.Next(4200, 50000), Tick = currentTick * k, EndTick = currentTick + 5000, }; currentTick += 5000; rounds.Add(round); } Demo demo = new Demo { Id = "de_dust25445648778447878", Name = "mydemo.dem", Tickrate = 32, ServerTickrate = 64, MapName = "de_dust2", ClientName = "localhost", Hostname = "local", OneKillCount = random.Next(50, 90), TwoKillCount = random.Next(20, 50), ThreeKillCount = random.Next(10), FourKillCount = random.Next(3), FiveKillCount = random.Next(1), Path = "C:\\mydemo.dem", Type = "GOTV", Comment = "comment", Players = players, MostBombPlantedPlayer = players.ElementAt(random.Next(10)), MostHeadshotPlayer = players.ElementAt(random.Next(10)), Rounds = rounds, Duration = 2651.65625f, }; Team teamCt = new Team { Name = "Team 1", Players = new ObservableCollection <Player>(players.Take(5)), Score = 6, ScoreFirstHalf = 6, ScoreSecondHalf = 1, }; Team teamT = new Team { Name = "Team 2", Players = new ObservableCollection <Player>(players.Skip(5).Take(5)), Score = 16, ScoreFirstHalf = 10, ScoreSecondHalf = 5, }; demo.TeamT = teamT; demo.TeamCT = teamCt; return(demo); }
/// <summary> /// Update players and their team relation /// </summary> protected void UpdatePlayers() { Team teamCt = GetTeamBySide(Side.CounterTerrorist); Team teamT = GetTeamBySide(Side.Terrorist); foreach (DemoInfo.Player player in Parser.PlayingParticipants) { if (player.SteamID != 0) { Player pl = Demo.Players.FirstOrDefault(p => p.SteamId == player.SteamID); if (pl != null) { pl.Side = player.Team.ToSide(); if (player.Team == DemoInfo.Team.CounterTerrorist) { if (teamT.Players.Contains(pl)) { Application.Current.Dispatcher.Invoke(() => teamT.Players.Remove(pl)); } if (!teamCt.Players.Contains(pl)) { Application.Current.Dispatcher.Invoke(() => teamCt.Players.Add(pl)); } } else if (player.Team == DemoInfo.Team.Terrorist) { if (teamCt.Players.Contains(pl)) { Application.Current.Dispatcher.Invoke(() => teamCt.Players.Remove(pl)); } if (!teamT.Players.Contains(pl)) { Application.Current.Dispatcher.Invoke(() => teamT.Players.Add(pl)); } } } else { // new player pl = new Player { SteamId = player.SteamID, Name = player.Name, Side = player.Team.ToSide() }; Application.Current.Dispatcher.Invoke(() => Demo.Players.Add(pl)); if (player.Team == DemoInfo.Team.CounterTerrorist) { pl.TeamName = Demo.TeamCT.Name; // Check swap if (Demo.TeamT.Players.Contains(pl)) { Application.Current.Dispatcher.Invoke(delegate { Demo.TeamCT.Players.Add(Demo.TeamT.Players.First(p => p.Equals(pl))); Demo.TeamT.Players.Remove(pl); }); } else { if (!Demo.TeamCT.Players.Contains(pl)) { Application.Current.Dispatcher.Invoke(() => Demo.TeamCT.Players.Add(pl)); } } } else if (player.Team == DemoInfo.Team.Terrorist) { pl.TeamName = Demo.TeamT.Name; // Check swap if (Demo.TeamCT.Players.Contains(pl)) { Application.Current.Dispatcher.Invoke(delegate { Demo.TeamT.Players.Add(Demo.TeamCT.Players.First(p => p.Equals(pl))); Demo.TeamCT.Players.Remove(pl); }); } else { if (!Demo.TeamT.Players.Contains(pl)) { Application.Current.Dispatcher.Invoke(() => Demo.TeamT.Players.Add(pl)); } } } } } } }
public Task <List <Demo> > GetDemosHeader(List <string> folders, List <Demo> currentDemos = null, int size = 0) { List <Demo> demos = new List <Demo>(); for (int i = 0; i < 20; i++) { ObservableCollection <Player> players = new ObservableCollection <Player>(); Random random = new Random(); ObservableCollection <EntryKillEvent> entryKills = new ObservableCollection <EntryKillEvent>(); for (int indexEntryKill = 0; indexEntryKill < random.Next(5); indexEntryKill++) { Player killer = players.ElementAt(random.Next(0, 9)); Player killed = players.ElementAt(random.Next(0, 9)); EntryKillEvent entryKill = new EntryKillEvent(random.Next(7000, 100000), random.Next(1, 50000)) { KilledSteamId = killed.SteamId, KilledName = killed.Name, KilledSide = killed.Side, KillerSteamId = killer.SteamId, KillerName = killer.Name, KillerSide = killer.Side }; entryKills.Add(entryKill); } for (int j = 0; j < 10; j++) { Player player = new Player { Name = "player" + (j + 1), HeadshotCount = random.Next(14), OneKillCount = random.Next(10, 30), TwoKillCount = random.Next(10, 20), ThreeKillCount = random.Next(0, 10), FourKillCount = random.Next(0, 5), FiveKillCount = random.Next(0, 2), BombDefusedCount = random.Next(0, 2), BombPlantedCount = random.Next(0, 2), EntryKills = entryKills, DeathCount = random.Next(0, 32), KillCount = random.Next(30), AssistCount = random.Next(15), Score = random.Next(10, 80), RoundMvpCount = random.Next(6) }; players.Add(player); } ObservableCollection <Round> rounds = new ObservableCollection <Round>(); for (int k = 0; k < 32; k++) { Round round = new Round { Number = k + 1, OneKillCount = random.Next(5), TwoKillCount = random.Next(2), ThreeKillCount = random.Next(1), FourKillCount = random.Next(1), FiveKillCount = random.Next(1), EquipementValueTeamCt = random.Next(4200, 30000), EquipementValueTeamT = random.Next(4200, 30000), StartMoneyTeamCt = random.Next(4200, 50000), StartMoneyTeamT = random.Next(4200, 50000), Tick = random.Next(7000, 100000) }; rounds.Add(round); } Demo demo = new Demo { Id = "de_dust25445648778447878", Name = "mydemo" + (i + 1) + ".dem", Tickrate = 128, MapName = "de_dust2", ClientName = "localhost", Hostname = "local", OneKillCount = random.Next(50, 90), TwoKillCount = random.Next(20, 50), ThreeKillCount = random.Next(10), FourKillCount = random.Next(3), FiveKillCount = random.Next(1), Path = "C:\\mydemo.dem", Type = "GOTV", Comment = "comment", Players = players, MostBombPlantedPlayer = players.ElementAt(random.Next(10)), MostHeadshotPlayer = players.ElementAt(random.Next(10)), Rounds = rounds }; Team teamCt = new Team { Name = "Team 1", Players = new ObservableCollection <Player>(players.Take(5)), Score = 6, ScoreFirstHalf = 6, ScoreSecondHalf = 1, }; Team teamT = new Team { Name = "Team 2", Players = new ObservableCollection <Player>(players.Skip(5).Take(5)), Score = 16, ScoreFirstHalf = 10, ScoreSecondHalf = 5, }; demo.TeamT = teamT; demo.TeamCT = teamCt; demos.Add(demo); } return(Task.FromResult(demos)); }
private void AddTeams() { // Detect possible swap by teams name, work for some demos if (Parser.TClanName == Demo.TeamCT.Name || Parser.CTClanName == Demo.TeamT.Name) { Team tmp = Demo.TeamT; Demo.TeamT = Demo.TeamCT; Demo.TeamCT = tmp.Clone(); } // Add all players to our ObservableCollection of PlayerExtended foreach (DemoInfo.Player player in Parser.PlayingParticipants) { if (player.SteamID != 0) { Player pl = new Player { SteamId = player.SteamID, Name = player.Name, Side = player.Team.ToSide() }; Application.Current.Dispatcher.Invoke(delegate { if (!Demo.Players.Contains(pl)) { Demo.Players.Add(pl); } if (pl.Side == Side.CounterTerrorist) { pl.TeamName = Demo.TeamCT.Name; // Check swap if (Demo.TeamT.Players.Contains(pl)) { Demo.TeamCT.Players.Add(Demo.TeamT.Players.First(p => p.Equals(pl))); Demo.TeamT.Players.Remove(pl); } else { if (!Demo.TeamCT.Players.Contains(pl)) { Demo.TeamCT.Players.Add(pl); } } } if (pl.Side == Side.Terrorist) { pl.TeamName = Demo.TeamT.Name; // Check swap if (Demo.TeamCT.Players.Contains(pl)) { Demo.TeamT.Players.Add(Demo.TeamCT.Players.First(p => p.Equals(pl))); Demo.TeamCT.Players.Remove(pl); } else { if (!Demo.TeamT.Players.Contains(pl)) { Demo.TeamT.Players.Add(pl); } } } }); } } }
public override async Task GenerateContent() { await Task.Factory.StartNew(() => { List <Team> teams = new List <Team>(); foreach (Demo demo in Demos) { if (teams.Contains(demo.TeamCT)) { Team team = teams.First(t => t.Equals(demo.TeamCT)); UpdateTeamStats(demo, team); } else { Team team = demo.TeamCT.Clone(); InitTeam(demo, team); teams.Add(team); } if (teams.Contains(demo.TeamT)) { Team team = teams.First(t => t.Equals(demo.TeamT)); UpdateTeamStats(demo, team); } else { Team team = demo.TeamT.Clone(); InitTeam(demo, team); teams.Add(team); } } int rowCount = 1; foreach (Team team in teams) { IRow row = Sheet.CreateRow(rowCount++); int columnNumber = 0; SetCellValue(row, columnNumber++, CellType.String, team.Name); SetCellValue(row, columnNumber++, CellType.Numeric, team.MatchCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.WinCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.LostCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.KillCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.DeathCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.AssistCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.RoundCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.WinRoundCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.LostRoundCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.WinRoundCtCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.LostRoundCtCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.WinRoundTCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.LostRoundTCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.WinPistolRoundCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.WinEcoRoundCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.WinSemiEcoRoundCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.WinForceBuyRoundCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.BombPlantedCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.BombDefusedCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.BombExplodedCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.BombPlantedOnACount); SetCellValue(row, columnNumber++, CellType.Numeric, team.BombPlantedOnBCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.FiveKillCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.FourKillCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.ThreeKillCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.TwoKillCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.OneKillCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.TradeKillCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.TradeDeathCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.JumpKillCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.CrouchKillCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.FlashbangThrownCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.HeGrenadeThrownCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.SmokeThrownCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.MolotovThrownCount); SetCellValue(row, columnNumber++, CellType.Numeric, team.IncendiaryThrownCount); SetCellValue(row, columnNumber, CellType.Numeric, team.DecoyThrownCount); } }); }
protected new void HandleRoundOfficiallyEnd(object sender, RoundOfficiallyEndedEventArgs e) { if (!IsMatchStarted || IsFreezetime) { return; } CurrentRound.EndTickOfficially = Parser.IngameTick; CurrentRound.Duration = (float)Math.Round((CurrentRound.EndTickOfficially - CurrentRound.Tick) / Demo.ServerTickrate, 2); // sometimes round_end isn't triggered, I update scores here if (!IsRoundEndOccured) { Core.Models.Team teamCt = GetTeamBySide(Side.CounterTerrorist); if (teamCt.Score < Parser.CTScore) { UpdateTeamScore(new RoundEndedEventArgs { Winner = DemoInfo.Team.CounterTerrorist }); } else { UpdateTeamScore(new RoundEndedEventArgs { Winner = DemoInfo.Team.Terrorist }); } } CheckForSpecialClutchEnd(); UpdateKillsCount(); UpdatePlayerScore(); if (!IsLastRoundHalf || !IsRoundEndOccured) { Application.Current.Dispatcher.Invoke(() => { CurrentRound.Number = Demo.Rounds.Count + 1; Demo.Rounds.Add(CurrentRound); }); } if (!IsOvertime && IsLastRoundHalf) { IsLastRoundHalf = false; IsHalfMatch = true; } if (IsSwapTeamRequired) { SwapTeams(); IsSwapTeamRequired = false; if (IsOvertime) { IsHalfMatch = !IsHalfMatch; } } Demo.RaiseScoresChanged(); if (!IsMatchStarted || IsFreezetime) { return; } if (_isRoundFinal) { _isRoundFinal = false; if (IsOvertime) { Application.Current.Dispatcher.Invoke(() => Demo.Overtimes.Add(CurrentOvertime)); IsHalfMatch = !IsHalfMatch; } else { IsOvertime = true; } CreateNewOvertime(); } }