Ejemplo n.º 1
0
        private void UpdateMetrics(int gameIdentID)
        {
            using (DataAccess.CSSStatsDataContext statsDB = new Allegiance.CommunitySecuritySystem.DataAccess.CSSStatsDataContext())
            {
                var game = statsDB.Games.FirstOrDefault(p => p.GameIdentID == gameIdentID);

                if (game == null)
                {
                    throw new Exception("Couldn't get game for ID: " + gameIdentID);
                }

                if (IsGameEligibleForLogging(game) == false)
                {
                    return;
                }

                DataAccess.StatsMetric statsMetric = statsDB.StatsMetrics.FirstOrDefault();

                var averages = statsDB.StatsLeaderboards
                               .Where(p => p.DateModified > DateTime.Now.AddDays(-1 * Common.Constants.Leaderboard.MaxLastActiveDays))
                               .GroupBy(p => p)
                               .Select(p => new
                {
                    CommandRank = p.Average(x => x.CommandRank),
                    Rank        = p.Average(x => x.Rank)
                })
                               .FirstOrDefault();

                double averageCommandRank = 0;
                double averageRank        = 0;

                if (averages != null)
                {
                    averageCommandRank = averages.CommandRank;
                    averageRank        = averages.Rank;
                }

                if (statsMetric == null)
                {
                    statsMetric = new Allegiance.CommunitySecuritySystem.DataAccess.StatsMetric()
                    {
                        AverageCommandRank = averageCommandRank,
                        AveragePlayerRank  = averageRank,
                        DateModified       = DateTime.Now,
                        LastGameProcessed  = gameIdentID,
                        TotalGamesLogged   = 1
                    };

                    statsDB.StatsMetrics.InsertOnSubmit(statsMetric);
                }
                else
                {
                    statsMetric.AverageCommandRank = averageCommandRank;
                    statsMetric.AveragePlayerRank  = averageRank;
                    statsMetric.DateModified       = DateTime.Now;
                    statsMetric.LastGameProcessed  = gameIdentID;
                    statsMetric.TotalGamesLogged++;
                }

                statsDB.SubmitChanges();
            }
        }
Ejemplo n.º 2
0
        private void UpdateFactionStats(int gameIdentID)
        {
            using (DataAccess.CSSStatsDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSStatsDataContext())
            {
                var game = db.Games.FirstOrDefault(p => p.GameIdentID == gameIdentID);

                if (game == null)
                {
                    throw new Exception("Couldn't get game for ID: " + gameIdentID);
                }

                if (IsGameEligibleForLogging(game) == false)
                {
                    return;
                }

                if (IsDrawGame(game) == true)
                {
                    return;
                }

                if (game.GameTeams.Count != 2)
                {
                    return;
                }

                DataAccess.GameTeam winningTeam;
                DataAccess.GameTeam losingTeam;

                if (game.GameTeams[0].GameTeamWinner == true)
                {
                    winningTeam = game.GameTeams[0];
                    losingTeam  = game.GameTeams[1];
                }
                else
                {
                    winningTeam = game.GameTeams[1];
                    losingTeam  = game.GameTeams[0];
                }

                DataAccess.StatsFaction statsFaction = db.StatsFactions.FirstOrDefault(p =>
                                                                                       p.WinFactionName == winningTeam.GameTeamFaction &&
                                                                                       p.WinExpansion == winningTeam.GameTeamExpansion &&
                                                                                       p.WinShipyard == winningTeam.GameTeamShipyard &&
                                                                                       p.WinStarbase == winningTeam.GameTeamStarbase &&
                                                                                       p.WinSupremacy == winningTeam.GameTeamSupremacy &&
                                                                                       p.WinTactical == winningTeam.GameTeamTactical &&
                                                                                       p.LossFactionName == losingTeam.GameTeamFaction &&
                                                                                       p.LossExpansion == losingTeam.GameTeamExpansion &&
                                                                                       p.LossShipyard == losingTeam.GameTeamShipyard &&
                                                                                       p.LossStarbase == losingTeam.GameTeamStarbase &&
                                                                                       p.LossSupremacy == losingTeam.GameTeamSupremacy &&
                                                                                       p.LossTactical == losingTeam.GameTeamTactical
                                                                                       );

                if (statsFaction == null)
                {
                    statsFaction = new Allegiance.CommunitySecuritySystem.DataAccess.StatsFaction()
                    {
                        GamesPlayed     = 1,
                        HoursPlayed     = game.GameEndTime.Subtract(game.GameStartTime).TotalMinutes / 60,
                        LossExpansion   = losingTeam.GameTeamExpansion,
                        LossFactionName = losingTeam.GameTeamFaction,
                        LossShipyard    = losingTeam.GameTeamShipyard,
                        LossStarbase    = losingTeam.GameTeamStarbase,
                        LossSupremacy   = losingTeam.GameTeamSupremacy,
                        LossTactical    = losingTeam.GameTeamTactical,
                        WinExpansion    = winningTeam.GameTeamExpansion,
                        WinFactionName  = winningTeam.GameTeamFaction,
                        WinShipyard     = winningTeam.GameTeamShipyard,
                        WinStarbase     = winningTeam.GameTeamStarbase,
                        WinSupremacy    = winningTeam.GameTeamSupremacy,
                        WinTactical     = winningTeam.GameTeamTactical,
                        DateModified    = DateTime.Now
                    };

                    db.StatsFactions.InsertOnSubmit(statsFaction);
                }
                else
                {
                    statsFaction.GamesPlayed++;
                    statsFaction.HoursPlayed += game.GameEndTime.Subtract(game.GameStartTime).TotalMinutes / 60;
                    statsFaction.DateModified = DateTime.Now;
                }

                db.SubmitChanges();
            }
        }
Ejemplo n.º 3
0
        private void UpdateLeaderboard(int gameIdentID)
        {
            using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext())
            {
                using (DataAccess.CSSStatsDataContext statsDB = new Allegiance.CommunitySecuritySystem.DataAccess.CSSStatsDataContext())
                {
                    var game = statsDB.Games.FirstOrDefault(p => p.GameIdentID == gameIdentID);

                    if (game == null)
                    {
                        throw new Exception("Couldn't get game for ID: " + gameIdentID);
                    }

                    if (IsGameEligibleForLogging(game) == false)
                    {
                        return;
                    }

                    bool isDrawGame = IsDrawGame(game);

                    foreach (DataAccess.GameTeam team in game.GameTeams)
                    {
                        var commanderAlias = DataAccess.Alias.GetAliasByCallsign(db, team.GameTeamCommander);

                        foreach (DataAccess.GameTeamMember teamMember in team.GameTeamMembers)
                        {
                            int shipKills       = 0;
                            int stationKills    = 0;
                            int stationCaptures = 0;
                            int droneKills      = 0;
                            int ejects          = 0;
                            int defection       = 0;
                            int score           = 0;

                            var alias = DataAccess.Alias.GetAliasByCallsign(db, teamMember.GameTeamMemberCallsign);

                            if (alias == null)
                            {
                                continue;
                            }

                            // Check current team member for defections.
                            foreach (DataAccess.GameTeam otherTeam in game.GameTeams)
                            {
                                if (otherTeam.GameTeamID == team.GameTeamID)
                                {
                                    continue;
                                }

                                foreach (DataAccess.GameTeamMember otherTeamMember in otherTeam.GameTeamMembers)
                                {
                                    var otherLogin = DataAccess.Alias.GetAliasByCallsign(db, otherTeamMember.GameTeamMemberCallsign);

                                    if (otherLogin != null && otherLogin.LoginId == alias.LoginId)
                                    {
                                        defection = 1;
                                        break;
                                    }
                                }

                                if (defection != 0)
                                {
                                    break;
                                }
                            }

                            var primaryMemberEvents = game.GameEvents.Where
                                                      (
                                p => p.GameEventPerformerID != 1
                                &&
                                (
                                    p.GameEventPerformerLoginID == alias.Login.Id &&
                                    (
                                        p.EventID == (int)AllegianceEventIDs.StationDestroyed ||
                                        p.EventID == (int)AllegianceEventIDs.StationCaptured ||
                                        p.EventID == (int)AllegianceEventIDs.ShipKilled
                                    )
                                )
                                ||
                                (
                                    p.GameEventTargetLoginID == alias.Login.Id &&
                                    p.EventID == (int)AllegianceEventIDs.ShipKilled
                                )
                                                      );

                            foreach (var primaryMemberEvent in primaryMemberEvents)
                            {
                                switch (primaryMemberEvent.EventID)
                                {
                                case (int)Common.Enumerations.AllegianceEventIDs.ShipKilled:
                                    if (primaryMemberEvent.GameEventPerformerName.StartsWith(".") == true)
                                    {
                                        droneKills++;
                                        score += DroneKillPoints;
                                    }
                                    else
                                    {
                                        if (primaryMemberEvent.GameEventPerformerLoginID == teamMember.GameTeamMemberLoginID)
                                        {
                                            ejects++;
                                        }
                                        else
                                        {
                                            shipKills++;
                                            score += ShipKillPoints;
                                        }
                                    }
                                    break;

                                case (int)Common.Enumerations.AllegianceEventIDs.StationCaptured:
                                {
                                    stationCaptures++;
                                    score += StationCapturePoints;
                                }
                                break;

                                case (int)Common.Enumerations.AllegianceEventIDs.StationDestroyed:
                                {
                                    stationKills++;
                                    score += StationKillPoints;
                                }
                                break;
                                }
                            }

                            if (alias != null)
                            {
                                var leaderboard = statsDB.StatsLeaderboards.FirstOrDefault(p => p.LoginID == alias.Login.Id);

                                if (leaderboard == null)
                                {
                                    leaderboard = new Allegiance.CommunitySecuritySystem.DataAccess.StatsLeaderboard()
                                    {
                                        CommandDraws    = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        CommandLosses   = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        CommandMu       = 25D,
                                        CommandRank     = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        CommandSigma    = 25D / 3D,
                                        CommandWins     = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Defects         = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Draws           = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        DroneKills      = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Ejects          = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        HoursPlayed     = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Kills           = 0,                               // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        LoginUsername   = alias.Login.Username,
                                        LoginID         = alias.Login.Id,
                                        Losses          = 0,                              // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Mu              = 25D,
                                        Rank            = 0,                              // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Sigma           = 25D / 3D,
                                        StackRating     = 0,                              // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        StationCaptures = 0,                              // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        StationKills    = 0,                              // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Wins            = 0,                              // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        DateModified    = DateTime.Now



                                                          //CommandDraws = commanderAlias.LoginId == alias.LoginId && isDrawGame == true && defection == 0 ? 1 : 0,
                                                          //CommandLosses = commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0,
                                                          //CommandMu = 25D,
                                                          //CommandRank = 0,
                                                          //CommandSigma = 25D / 3D,
                                                          //CommandWins = commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == true && defection == 0 ? 1 : 0,
                                                          //Defects = defection,
                                                          //Draws = isDrawGame == true && defection == 0 ? 1 : 0,
                                                          //DroneKills = droneKills,
                                                          //Ejects = ejects,
                                                          //HoursPlayed = teamMember.GameTeamMemberDuration / 60.0 / 60.0,
                                                          //Kills = shipKills,
                                                          //LoginUsername = alias.Login.Username,
                                                          //LoginID = alias.Login.Id,
                                                          //Losses = team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0,
                                                          //Mu = 25D,
                                                          //Rank = 0,
                                                          //Sigma = 25D / 3D,
                                                          //StackRating = 0,
                                                          //StationCaptures = stationCaptures,
                                                          //StationKills = stationKills,
                                                          //Wins = team.GameTeamWinner == true && defection == 0 ? 1 : 0,
                                                          //DateModified = DateTime.Now
                                    };

                                    statsDB.StatsLeaderboards.InsertOnSubmit(leaderboard);
                                }
                                else
                                {
                                    // These values are all set by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.

                                    //leaderboard.CommandDraws += commanderAlias.LoginId == alias.LoginId && isDrawGame == true && defection == 0 ? 1 : 0;
                                    //leaderboard.CommandLosses += commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0;
                                    //leaderboard.CommandWins += commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == true && defection == 0 ? 1 : 0;
                                    //leaderboard.Defects += defection;
                                    //leaderboard.Draws += isDrawGame == true && defection == 0 ? 1 : 0;
                                    //leaderboard.DroneKills += droneKills;
                                    //leaderboard.Ejects += ejects;
                                    //leaderboard.HoursPlayed += teamMember.GameTeamMemberDuration / 60.0 / 60.0;
                                    //leaderboard.Kills += shipKills;
                                    //leaderboard.Losses += team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0;
                                    //leaderboard.StationCaptures += stationCaptures;
                                    //leaderboard.StationKills += stationKills;
                                    //leaderboard.Wins += team.GameTeamWinner == true && defection == 0 ? 1 : 0;
                                    //leaderboard.DateModified = DateTime.Now;
                                }

                                teamMember.Score = score;

                                statsDB.SubmitChanges();
                                db.SubmitChanges();
                            }
                        }
                    }
                }
            }
        }
        private void UpdateMetrics(int gameIdentID)
        {
            using (DataAccess.CSSStatsDataContext statsDB = new Allegiance.CommunitySecuritySystem.DataAccess.CSSStatsDataContext())
            {
                var game = statsDB.Games.FirstOrDefault(p => p.GameIdentID == gameIdentID);

                if (game == null)
                    throw new Exception("Couldn't get game for ID: " + gameIdentID);

                if (IsGameEligibleForLogging(game) == false)
                    return;

                DataAccess.StatsMetric statsMetric = statsDB.StatsMetrics.FirstOrDefault();

                var averages = statsDB.StatsLeaderboards
                    .Where(p => p.DateModified > DateTime.Now.AddDays(-1 * Common.Constants.Leaderboard.MaxLastActiveDays))
                    .GroupBy(p => p)
                    .Select(p => new
                    {
                        CommandRank = p.Average(x => x.CommandRank),
                        Rank = p.Average(x => x.Rank)
                    })
                    .FirstOrDefault();

                double averageCommandRank = 0;
                double averageRank = 0;

                if (averages != null)
                {
                    averageCommandRank = averages.CommandRank;
                    averageRank = averages.Rank;
                }

                if (statsMetric == null)
                {
                    statsMetric = new Allegiance.CommunitySecuritySystem.DataAccess.StatsMetric()
                    {
                        AverageCommandRank = averageCommandRank,
                        AveragePlayerRank = averageRank,
                        DateModified = DateTime.Now,
                        LastGameProcessed = gameIdentID,
                        TotalGamesLogged = 1
                    };

                    statsDB.StatsMetrics.InsertOnSubmit(statsMetric);
                }
                else
                {
                    statsMetric.AverageCommandRank = averageCommandRank;
                    statsMetric.AveragePlayerRank = averageRank;
                    statsMetric.DateModified = DateTime.Now;
                    statsMetric.LastGameProcessed = gameIdentID;
                    statsMetric.TotalGamesLogged++;
                }

                statsDB.SubmitChanges();

            }
        }
        private void UpdateLeaderboard(int gameIdentID)
        {
            using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext())
            {
                using (DataAccess.CSSStatsDataContext statsDB = new Allegiance.CommunitySecuritySystem.DataAccess.CSSStatsDataContext())
                {
                    var game = statsDB.Games.FirstOrDefault(p => p.GameIdentID == gameIdentID);

                    if (game == null)
                        throw new Exception("Couldn't get game for ID: " + gameIdentID);

                    if (IsGameEligibleForLogging(game) == false)
                        return;

                    bool isDrawGame = IsDrawGame(game);

                    foreach (DataAccess.GameTeam team in game.GameTeams)
                    {
                        var commanderAlias = DataAccess.Alias.GetAliasByCallsign(db, team.GameTeamCommander);

                        foreach (DataAccess.GameTeamMember teamMember in team.GameTeamMembers)
                        {
                            int shipKills = 0;
                            int stationKills = 0;
                            int stationCaptures = 0;
                            int droneKills = 0;
                            int ejects = 0;
                            int defection = 0;
                            int score = 0;

                            var alias = DataAccess.Alias.GetAliasByCallsign(db, teamMember.GameTeamMemberCallsign);

                            if (alias == null)
                                continue;

                            // Check current team member for defections.
                            foreach (DataAccess.GameTeam otherTeam in game.GameTeams)
                            {
                                if (otherTeam.GameTeamID == team.GameTeamID)
                                    continue;

                                foreach (DataAccess.GameTeamMember otherTeamMember in otherTeam.GameTeamMembers)
                                {
                                    var otherLogin = DataAccess.Alias.GetAliasByCallsign(db, otherTeamMember.GameTeamMemberCallsign);

                                    if (otherLogin != null && otherLogin.LoginId == alias.LoginId)
                                    {
                                        defection = 1;
                                        break;
                                    }
                                }

                                if (defection != 0)
                                    break;
                            }

                            var primaryMemberEvents = game.GameEvents.Where
                            (
                                p => p.GameEventPerformerID != 1
                                &&
                                (
                                    p.GameEventPerformerLoginID == alias.Login.Id
                                    && (
                                            p.EventID == (int)AllegianceEventIDs.StationDestroyed
                                            || p.EventID == (int)AllegianceEventIDs.StationCaptured
                                            || p.EventID == (int)AllegianceEventIDs.ShipKilled
                                        )
                                )
                                ||
                                (
                                    p.GameEventTargetLoginID == alias.Login.Id
                                    && p.EventID == (int)AllegianceEventIDs.ShipKilled
                                )
                            );

                            foreach (var primaryMemberEvent in primaryMemberEvents)
                            {
                                switch (primaryMemberEvent.EventID)
                                {
                                    case (int)Common.Enumerations.AllegianceEventIDs.ShipKilled:
                                        if (primaryMemberEvent.GameEventPerformerName.StartsWith(".") == true)
                                        {
                                            droneKills++;
                                            score += DroneKillPoints;
                                        }
                                        else
                                        {
                                            if (primaryMemberEvent.GameEventPerformerLoginID == teamMember.GameTeamMemberLoginID)
                                            {
                                                ejects++;
                                            }
                                            else
                                            {
                                                shipKills++;
                                                score += ShipKillPoints;
                                            }
                                        }
                                        break;

                                    case (int)Common.Enumerations.AllegianceEventIDs.StationCaptured:
                                        {
                                            stationCaptures++;
                                            score += StationCapturePoints;
                                        }
                                        break;

                                    case (int)Common.Enumerations.AllegianceEventIDs.StationDestroyed:
                                        {
                                            stationKills++;
                                            score += StationKillPoints;
                                        }
                                        break;
                                }
                            }

                            if (alias != null)
                            {
                                var leaderboard = statsDB.StatsLeaderboards.FirstOrDefault(p => p.LoginID == alias.Login.Id);

                                if (leaderboard == null)
                                {
                                    leaderboard = new Allegiance.CommunitySecuritySystem.DataAccess.StatsLeaderboard()
                                    {
                                        CommandDraws = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        CommandLosses = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        CommandMu = 25D,
                                        CommandRank = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        CommandSigma = 25D / 3D,
                                        CommandWins = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Defects = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Draws = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        DroneKills = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Ejects = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        HoursPlayed = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Kills = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        LoginUsername = alias.Login.Username,
                                        LoginID = alias.Login.Id,
                                        Losses = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Mu = 25D,
                                        Rank = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Sigma = 25D / 3D,
                                        StackRating = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        StationCaptures = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        StationKills = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        Wins = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.
                                        DateModified = DateTime.Now

                                        //CommandDraws = commanderAlias.LoginId == alias.LoginId && isDrawGame == true && defection == 0 ? 1 : 0,
                                        //CommandLosses = commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0,
                                        //CommandMu = 25D,
                                        //CommandRank = 0,
                                        //CommandSigma = 25D / 3D,
                                        //CommandWins = commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == true && defection == 0 ? 1 : 0,
                                        //Defects = defection,
                                        //Draws = isDrawGame == true && defection == 0 ? 1 : 0,
                                        //DroneKills = droneKills,
                                        //Ejects = ejects,
                                        //HoursPlayed = teamMember.GameTeamMemberDuration / 60.0 / 60.0,
                                        //Kills = shipKills,
                                        //LoginUsername = alias.Login.Username,
                                        //LoginID = alias.Login.Id,
                                        //Losses = team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0,
                                        //Mu = 25D,
                                        //Rank = 0,
                                        //Sigma = 25D / 3D,
                                        //StackRating = 0,
                                        //StationCaptures = stationCaptures,
                                        //StationKills = stationKills,
                                        //Wins = team.GameTeamWinner == true && defection == 0 ? 1 : 0,
                                        //DateModified = DateTime.Now
                                    };

                                    statsDB.StatsLeaderboards.InsertOnSubmit(leaderboard);
                                }
                                else
                                {
                                    // These values are all set by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation.

                                    //leaderboard.CommandDraws += commanderAlias.LoginId == alias.LoginId && isDrawGame == true && defection == 0 ? 1 : 0;
                                    //leaderboard.CommandLosses += commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0;
                                    //leaderboard.CommandWins += commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == true && defection == 0 ? 1 : 0;
                                    //leaderboard.Defects += defection;
                                    //leaderboard.Draws += isDrawGame == true && defection == 0 ? 1 : 0;
                                    //leaderboard.DroneKills += droneKills;
                                    //leaderboard.Ejects += ejects;
                                    //leaderboard.HoursPlayed += teamMember.GameTeamMemberDuration / 60.0 / 60.0;
                                    //leaderboard.Kills += shipKills;
                                    //leaderboard.Losses += team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0;
                                    //leaderboard.StationCaptures += stationCaptures;
                                    //leaderboard.StationKills += stationKills;
                                    //leaderboard.Wins += team.GameTeamWinner == true && defection == 0 ? 1 : 0;
                                    //leaderboard.DateModified = DateTime.Now;
                                }

                                teamMember.Score = score;

                                statsDB.SubmitChanges();
                                db.SubmitChanges();
                            }
                        }
                    }

                }
            }
        }
        private void UpdateFactionStats(int gameIdentID)
        {
            using (DataAccess.CSSStatsDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSStatsDataContext())
            {
                var game = db.Games.FirstOrDefault(p => p.GameIdentID == gameIdentID);

                if (game == null)
                    throw new Exception("Couldn't get game for ID: " + gameIdentID);

                if (IsGameEligibleForLogging(game) == false)
                    return;

                if (IsDrawGame(game) == true)
                    return;

                if(game.GameTeams.Count != 2)
                    return;

                DataAccess.GameTeam winningTeam;
                DataAccess.GameTeam losingTeam;

                if(game.GameTeams[0].GameTeamWinner == true)
                {
                    winningTeam = game.GameTeams[0];
                    losingTeam = game.GameTeams[1];
                }
                else
                {
                    winningTeam = game.GameTeams[1];
                    losingTeam = game.GameTeams[0];
                }

                DataAccess.StatsFaction statsFaction = db.StatsFactions.FirstOrDefault(p =>
                        p.WinFactionName == winningTeam.GameTeamFaction
                    &&	p.WinExpansion == winningTeam.GameTeamExpansion
                    &&	p.WinShipyard == winningTeam.GameTeamShipyard
                    &&	p.WinStarbase == winningTeam.GameTeamStarbase
                    &&	p.WinSupremacy == winningTeam.GameTeamSupremacy
                    &&	p.WinTactical == winningTeam.GameTeamTactical
                    &&	p.LossFactionName == losingTeam.GameTeamFaction
                    &&	p.LossExpansion == losingTeam.GameTeamExpansion
                    &&	p.LossShipyard == losingTeam.GameTeamShipyard
                    &&	p.LossStarbase == losingTeam.GameTeamStarbase
                    &&	p.LossSupremacy == losingTeam.GameTeamSupremacy
                    &&	p.LossTactical == losingTeam.GameTeamTactical
                    );

                if(statsFaction == null)
                {
                    statsFaction = new Allegiance.CommunitySecuritySystem.DataAccess.StatsFaction()
                    {
                        GamesPlayed = 1,
                        HoursPlayed = game.GameEndTime.Subtract(game.GameStartTime).TotalMinutes / 60,
                        LossExpansion = losingTeam.GameTeamExpansion,
                        LossFactionName = losingTeam.GameTeamFaction,
                        LossShipyard = losingTeam.GameTeamShipyard,
                        LossStarbase = losingTeam.GameTeamStarbase,
                        LossSupremacy = losingTeam.GameTeamSupremacy,
                        LossTactical = losingTeam.GameTeamTactical,
                        WinExpansion = winningTeam.GameTeamExpansion,
                        WinFactionName = winningTeam.GameTeamFaction,
                        WinShipyard = winningTeam.GameTeamShipyard,
                        WinStarbase = winningTeam.GameTeamStarbase,
                        WinSupremacy = winningTeam.GameTeamSupremacy,
                        WinTactical = winningTeam.GameTeamTactical,
                        DateModified = DateTime.Now
                    };

                    db.StatsFactions.InsertOnSubmit(statsFaction);
                }
                else
                {
                    statsFaction.GamesPlayed++;
                    statsFaction.HoursPlayed += game.GameEndTime.Subtract(game.GameStartTime).TotalMinutes / 60;
                    statsFaction.DateModified = DateTime.Now;
                }

                db.SubmitChanges();
            }
        }