/// <summary>
 /// Initialize team values for the first time
 /// </summary>
 /// <param name="demo"></param>
 /// <param name="team"></param>
 private static void InitTeam(Demo demo, TeamExtended team)
 {
     team.RoundCount = demo.Rounds.Count();
     UpdateWinner(demo, team);
     UpdateRoundsStats(demo, team);
     UpdateBombStats(demo, team);
 }
 private static void UpdateWinner(Demo demo, TeamExtended team)
 {
     if (demo.Winner.Equals(team))
     {
         team.WinCount++;
     }
     else
     {
         team.LostCount++;
     }
 }
 /// <summary>
 /// Update team's stats
 /// </summary>
 /// <param name="demo"></param>
 /// <param name="team"></param>
 private static void UpdateTeamStats(Demo demo, TeamExtended team)
 {
     team.MatchCount++;
     team.RoundCount += demo.Rounds.Count();
     team.Players     = demo.TeamCT.Equals(team)
                         ? new ObservableCollection <PlayerExtended>(demo.TeamCT.Players.Concat(team.Players).ToList())
                         : new ObservableCollection <PlayerExtended>(demo.TeamT.Players.Concat(team.Players).ToList());
     UpdateWinner(demo, team);
     UpdateRoundsStats(demo, team);
     UpdateBombStats(demo, team);
 }
Beispiel #4
0
        public T1 GetView(ApplicationDbContext db)
        {
            int?id = Parameters as int?;

            if (id == null)
            {
                return(null);
            }
            Team team = db.T_Teams.Find(id);

            if (team == null)
            {
                return(null);
            }

            Employee manager     = null;
            string   managerName = "";

            manager = db.T_Employees.Find(team.ManagerId);
            if (manager != null)
            {
                managerName = manager.FirstName + " " + manager.LastName;
            }


            TeamStructure teamStructure = new TeamStructure();
            TeamExtended  teamExtended  = new TeamExtended()
            {
                ManagerName = managerName,
                Name        = team.Name
            };

            List <EmployeeExtended> TeamMembers = new List <EmployeeExtended>();

            teamStructure.TeamMembers =
                (from e in db.T_Employees
                 join p in db.T_Positions on e.PositionId equals p.Id
                 into Joinp
                 from jp in Joinp.DefaultIfEmpty()
                 where e.TeamId == id
                 orderby e.FirstName + e.LastName
                 select new EmployeeExtended
            {
                FirstName = e.FirstName,
                LastName = e.LastName,
                PositionName = jp.Name
            }).ToList();

            teamStructure.TeamExtended = teamExtended;

            return(teamStructure as T1);
        }
        private static void UpdateRoundsStats(Demo demo, TeamExtended team)
        {
            foreach (Round round in demo.Rounds)
            {
                if (round.WinnerName == team.Name)
                {
                    team.WinRoundCount++;
                    if (round.WinnerSide == Team.CounterTerrorist)
                    {
                        team.WinRoundCtCount++;
                    }
                    else
                    {
                        team.WinRoundTCount++;
                    }
                    if (round.SideTrouble != Team.Spectate)
                    {
                        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 == Team.CounterTerrorist)
                    {
                        team.LostRoundTCount++;
                    }
                    else
                    {
                        team.LostRoundCtCount++;
                    }
                }
            }
        }
 private static void UpdateBombStats(Demo demo, TeamExtended 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++;
             }
         }
     }
 }
Beispiel #7
0
        private void InitPlayers()
        {
            // We must set team1 as CT and team2 as T
            TeamExtended team1 = new TeamExtended()
            {
                Name = !string.IsNullOrWhiteSpace(Parser.CTClanName) ? Parser.CTClanName : TEAM1_NAME
            };

            TeamExtended team2 = new TeamExtended()
            {
                Name = !string.IsNullOrWhiteSpace(Parser.TClanName) ? Parser.TClanName : TEAM2_NAME
            };

            Demo.ClanTagNameTeam1 = team1.Name;
            Demo.ClanTagNameTeam2 = team2.Name;

            // Add all players to our ObservableCollection of PlayerExtended and teams
            foreach (Player player in Parser.PlayingParticipants)
            {
                PlayerExtended pl = new PlayerExtended
                {
                    SteamId = player.SteamID,
                    Name    = player.Name,
                    Team    = player.Team
                };

                Application.Current.Dispatcher.Invoke(delegate
                {
                    if (!Demo.Players.Contains(pl))
                    {
                        Demo.Players.Add(pl);
                    }

                    if (pl.Team == Team.CounterTerrorist)
                    {
                        if (!Demo.PlayersTeam1.Contains(pl))
                        {
                            Demo.PlayersTeam1.Add(pl);
                        }
                        if (!team1.Players.Contains(pl))
                        {
                            team1.Players.Add(pl);
                        }
                    }

                    if (pl.Team == Team.Terrorist)
                    {
                        if (!Demo.PlayersTeam2.Contains(pl))
                        {
                            Demo.PlayersTeam2.Add(pl);
                        }
                        if (!team2.Players.Contains(pl))
                        {
                            team2.Players.Add(pl);
                        }
                    }
                });
            }

            // Add teams
            Application.Current.Dispatcher.Invoke(delegate
            {
                Demo.Teams.Clear();
                Demo.Teams.Add(team1);
                Demo.Teams.Add(team2);
            });
        }
        private void AddTeams()
        {
            // Detect possible swap by teams name, work for some demos
            if (Parser.TClanName == Demo.TeamCT.Name || Parser.CTClanName == Demo.TeamT.Name)
            {
                TeamExtended tmp = Demo.TeamT;
                Demo.TeamT  = Demo.TeamCT;
                Demo.TeamCT = tmp.Clone();
            }

            // Add all players to our ObservableCollection of PlayerExtended
            foreach (Player player in Parser.PlayingParticipants)
            {
                if (player.SteamID != 0)
                {
                    PlayerExtended pl = new PlayerExtended
                    {
                        SteamId = player.SteamID,
                        Name    = player.Name,
                        Side    = player.Team
                    };

                    Application.Current.Dispatcher.Invoke(delegate
                    {
                        if (!Demo.Players.Contains(pl))
                        {
                            Demo.Players.Add(pl);
                        }

                        if (pl.Side == Team.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 == Team.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 <TeamExtended> teams = new List <TeamExtended>();
                foreach (Demo demo in Demos)
                {
                    if (teams.Contains(demo.TeamCT))
                    {
                        TeamExtended team = teams.First(t => t.Equals(demo.TeamCT));
                        UpdateTeamStats(demo, team);
                    }
                    else
                    {
                        TeamExtended team = demo.TeamCT.Clone();
                        InitTeam(demo, team);
                        teams.Add(team);
                    }

                    if (teams.Contains(demo.TeamT))
                    {
                        TeamExtended team = teams.First(t => t.Equals(demo.TeamT));
                        UpdateTeamStats(demo, team);
                    }
                    else
                    {
                        TeamExtended team = demo.TeamT.Clone();
                        InitTeam(demo, team);
                        teams.Add(team);
                    }
                }

                int rowCount = 1;
                foreach (TeamExtended 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);
                }
            });
        }
Beispiel #10
0
        public Task <Demo> AnalyzeDemo(Demo demo, CancellationToken token)
        {
            Random random = new Random();

            ObservableCollection <PlayerExtended> players = new ObservableCollection <PlayerExtended>();

            for (int i = 0; i < 10; i++)
            {
                PlayerExtended player = new PlayerExtended
                {
                    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),
                    Clutch1V1Count        = random.Next(1),
                    Clutch1V2Count        = random.Next(1),
                    Clutch1V3Count        = random.Next(1),
                    Clutch1V4Count        = random.Next(1),
                    Clutch1V5Count        = random.Next(1),
                    BombDefusedCount      = random.Next(0, 2),
                    BombPlantedCount      = random.Next(0, 2),
                    DeathCount            = random.Next(0, 32),
                    KillsCount            = 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,
                    ClutchCount           = random.Next(5),
                    ClutchLostCount       = random.Next(5),
                    KillDeathRatio        = (decimal)random.NextDouble(),
                    MatchCount            = random.Next(100),
                    OpponentClutchCount   = random.Next(5),
                    RoundPlayedCount      = random.Next(100)
                };

                players.Add(player);
            }
            TeamExtended teamT = new TeamExtended
            {
                Name    = "Team 1",
                Players = new ObservableCollection <PlayerExtended>(players.Take(5))
            };
            TeamExtended teamCt = new TeamExtended
            {
                Name    = "Team 2",
                Players = new ObservableCollection <PlayerExtended>(players.Skip(5).Take(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++)
                {
                    PlayerExtended killer = players.ElementAt(random.Next(9));
                    PlayerExtended 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),
                    EquipementValueTeam1 = random.Next(4200, 30000),
                    EquipementValueTeam2 = random.Next(4200, 30000),
                    StartMoneyTeam1      = random.Next(4200, 50000),
                    StartMoneyTeam2      = random.Next(4200, 50000),
                    Tick             = random.Next(7000, 100000),
                    WinnerName       = teamCt.Name,
                    WinnerSide       = Team.CounterTerrorist,
                    StartTimeSeconds = random.Next(1),
                    BombDefused      = null,
                    EndTimeSeconds   = random.Next(100),
                    BombPlanted      = null,
                    BombExploded     = null,
                    Type             = RoundType.NORMAL,
                    EndReason        = RoundEndReason.CTWin,
                    EntryKillEvent   = new EntryKillEvent(random.Next(1, 10000), random.Next(1, 100))
                    {
                        HasWin        = 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    = Team.CounterTerrorist,
                        KillerSide    = Team.Terrorist
                    },
                    OpenKillEvent = new OpenKillEvent(random.Next(1, 10000), random.Next(1, 100))
                    {
                        HasWin        = 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    = Team.CounterTerrorist,
                        KillerSide    = Team.Terrorist
                    },
                    SideTrouble = Team.Spectate,
                    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.ScoreTeam1           = 16;
            demo.ScoreTeam2           = 6;
            demo.Type                 = "GOTV";
            demo.Comment              = "comment";
            demo.ScoreFirstHalfTeam1  = 10;
            demo.ScoreFirstHalfTeam2  = 5;
            demo.ScoreSecondHalfTeam1 = 6;
            demo.ScoreSecondHalfTeam2 = 1;
            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));
        }
Beispiel #11
0
        private void AddTeams()
        {
            // We must set team1 as CT and team2 as T
            TeamExtended team1 = new TeamExtended()
            {
                Name = Parser.CTClanName
            };

            TeamExtended team2 = new TeamExtended()
            {
                Name = Parser.TClanName
            };

            Demo.ClanTagNameTeam1 = team1.Name;
            Demo.ClanTagNameTeam2 = team2.Name;

            // Add all players to our ObservableCollection of PlayerExtended and teams
            foreach (Player player in Parser.PlayingParticipants)
            {
                if (player.SteamID != 0)
                {
                    PlayerExtended pl = new PlayerExtended
                    {
                        SteamId = player.SteamID,
                        Name    = player.Name,
                        Team    = player.Team
                    };

                    Application.Current.Dispatcher.Invoke(delegate
                    {
                        if (!Demo.Players.Contains(pl))
                        {
                            Demo.Players.Add(pl);
                        }

                        if (pl.Team == Team.CounterTerrorist)
                        {
                            // Check swap
                            if (Demo.PlayersTeam2.Contains(pl))
                            {
                                Demo.PlayersTeam1.Add(Demo.PlayersTeam2.First(p => p.Equals(pl)));
                                Demo.PlayersTeam2.Remove(pl);
                            }
                            else
                            {
                                if (!Demo.PlayersTeam1.Contains(pl))
                                {
                                    Demo.PlayersTeam1.Add(pl);
                                }
                            }
                            team1.Players.Add(Demo.Players.First(p => p.Equals(pl)));
                        }

                        if (pl.Team == Team.Terrorist)
                        {
                            // Check swap
                            if (Demo.PlayersTeam1.Contains(pl))
                            {
                                Demo.PlayersTeam2.Add(Demo.PlayersTeam1.First(p => p.Equals(pl)));
                                Demo.PlayersTeam1.Remove(pl);
                            }
                            else
                            {
                                if (!Demo.PlayersTeam2.Contains(pl))
                                {
                                    Demo.PlayersTeam2.Add(pl);
                                }
                            }
                            team2.Players.Add(Demo.Players.First(p => p.Equals(pl)));
                        }
                    });
                }
            }

            // Add teams
            Application.Current.Dispatcher.Invoke(delegate
            {
                Demo.Teams.Clear();
                Demo.Teams.Add(team1);
                Demo.Teams.Add(team2);
            });
        }
        protected override void HandleMatchStarted(object sender, MatchStartedEventArgs e)
        {
            if (IsMatchStarted)
            {
                Demo.ResetStats(false);
            }
            RoundCount     = 0;
            IsMatchStarted = true;

            TeamExtended team1 = new TeamExtended()
            {
                Name = !string.IsNullOrWhiteSpace(Parser.CTClanName) ? Parser.CTClanName : TEAM1_NAME
            };
            TeamExtended team2 = new TeamExtended()
            {
                Name = !string.IsNullOrWhiteSpace(Parser.TClanName) ? Parser.TClanName : TEAM2_NAME
            };

            Demo.ClanTagNameTeam1 = team1.Name;
            Demo.ClanTagNameTeam2 = team2.Name;

            // Add all players to our ObservableCollection of PlayerExtended
            foreach (Player player in Parser.PlayingParticipants)
            {
                // don't add bot
                if (player.SteamID != 0)
                {
                    PlayerExtended pl = new PlayerExtended
                    {
                        SteamId = player.SteamID,
                        Name    = player.Name,
                        Team    = player.Team
                    };
                    if (!Demo.Players.Contains(pl))
                    {
                        Application.Current.Dispatcher.Invoke(delegate
                        {
                            Demo.Players.Add(pl);
                            if (pl.Team == Team.CounterTerrorist && !Demo.PlayersTeam1.Contains(pl))
                            {
                                Demo.PlayersTeam1.Add(pl);
                                if (!team1.Players.Contains(pl))
                                {
                                    team1.Players.Add(pl);
                                }
                            }

                            if (pl.Team == Team.Terrorist && !Demo.PlayersTeam2.Contains(pl))
                            {
                                Demo.PlayersTeam2.Add(pl);
                                if (!team2.Players.Contains(pl))
                                {
                                    team2.Players.Add(pl);
                                }
                            }
                        });
                    }
                }
            }

            Application.Current.Dispatcher.Invoke(delegate
            {
                if (!Demo.Teams.Contains(team1))
                {
                    Demo.Teams.Add(team1);
                }
                if (!Demo.Teams.Contains(team2))
                {
                    Demo.Teams.Add(team2);
                }
            });

            // First round handled here because round_start is raised before begin_new_match
            CreateNewRound();
        }