Exemple #1
0
        /// <summary>
        /// Go to home page; also updates news read dates
        /// </summary>
        public ActionResult Index()
        {
            // TODO: make two separate pages -- one for logged in users, one for not-logged in users
            // logged in users see their user profile
            // non-logged in users see promotional page

            var db = new ZkDataContext();

            if (!Global.IsAccountAuthorized)
            {
                return(View("Splash"));
            }

            // TODO: randomized backgrounds move here
            var result = new IndexResult
            {
                Spotlight         = SpotlightHandler.GetRandom(),
                Top10Players      = RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetTopPlayers(10),
                WikiRecentChanges = MediaWikiRecentChanges.LoadRecentChanges(),
                LobbyStats        = MemCache.GetCached("lobby_stats", GetCurrentLobbyStats, 60 * 2),
                News       = db.News.Where(x => x.Created < DateTime.UtcNow).OrderByDescending(x => x.Created),
                Headlines  = GetHeadlines(db),
                NewThreads = GetNewForumThreads(db)
            };

            return(View("HomeIndex", result));
        }
Exemple #2
0
 public List <float> GetAllyteamWinChances()
 {
     if (!IsRatedMatch())
     {
         return(new List <float>());
     }
     return(RatingSystems.GetRatingSystem(GetRatingCategory()).PredictOutcome(SpringBattlePlayers.Where(x => !x.IsSpectator).OrderBy(x => x.AllyNumber).GroupBy(x => x.AllyNumber).Select(x => x.Select(y => y.Account).ToList()).ToList(), StartTime));
 }
Exemple #3
0
        public IList <GraphPoint> GetDailyValues(DateTime fromTime, DateTime toTime)
        {
            Dictionary <DateTime, float> ratings = RatingSystems.GetRatingSystem(Category).GetPlayerRatingHistory(AccountID);

            return(ratings.Where(x => x.Key >= fromTime && x.Key <= toTime).Select(x => new GraphPoint()
            {
                Day = x.Key, Value = x.Value,
            }).ToList());
        }
Exemple #4
0
            public PlayerEntry(User user, List <MatchMakerSetup.Queue> queueTypes, PartyManager.Party party)
            {
                Party      = party;
                QueueTypes = queueTypes;
                LobbyUser  = user;
                float  recentWinChance = RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetAverageRecentWinChance(user.AccountID);
                double bonusElo        = -400 * Math.Log(1 / recentWinChance - 1) / Math.Log(10);

                bonusElo         = Math.Min(300, Math.Max(-300, bonusElo));
                MinConsideredElo = (int)Math.Round(LobbyUser.EffectiveMmElo + DynamicConfig.Instance.MmEloBonusMultiplier * bonusElo);
                //Trace.TraceInformation($"Player {user.AccountID} with recent win chance {recentWinChance} receives {DynamicConfig.Instance.MmEloBonusMultiplier} * {bonusElo} bonusElo => {MinConsideredElo} Effective Elo");
            }
            public BattleModel(SpringBattle bat)
            {
                WholeHistoryRating whr = RatingSystems.GetRatingSystem(bat.GetRatingCategory()) as WholeHistoryRating;

                players = bat.SpringBattlePlayers.Where(x => !x.IsSpectator).Select(player => new PlayerModel()
                {
                    rating    = whr.GetInternalRating(player.AccountID, bat.StartTime)?.GetElo() + WholeHistoryRating.RatingOffset,
                    stdev     = whr.GetInternalRating(player.AccountID, bat.StartTime)?.GetEloStdev(),
                    accountId = player.AccountID,
                }).ToList();
                id = bat.SpringBattleID;
            }
 public List <float> GetAllyteamWinChances()
 {
     try
     {
         if (IsRatedMatch())
         {
             return(RatingSystems.GetRatingSystem(GetRatingCategory()).PredictOutcome(SpringBattlePlayers.Where(x => !x.IsSpectator).OrderBy(x => x.AllyNumber).GroupBy(x => x.AllyNumber).Select(x => x.Select(y => y.Account).ToList()).ToList(), StartTime));
         }
     }
     catch (Exception ex)
     {
         Trace.TraceWarning("Invalid rating settings for B" + SpringBattleID + ", unable to calculate win chances. \n" + ex);
     }
     return(new List <float>(new float[GetAllyteamIds().Count]));
 }
Exemple #7
0
 public bool IsTop20(int lobbyID)
 {
     if (topPlayersExceptions.Contains(lobbyID))
     {
         return(true);
     }
     if (RatingSystems.GetRatingSystem(RatingCategory.Casual).GetPlayerRating(lobbyID).Rank <= 20)
     {
         return(true);
     }
     if (RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetPlayerRating(lobbyID).Rank <= 20)
     {
         return(true);
     }
     return(false);
 }
Exemple #8
0
        public void CalculateAllElo(bool noElo = false)
        {
            if (IsEloProcessed)
            {
                return;
            }

            if (!noElo)
            {
                ResetApplicableRatings();
            }

            if (IsRatedMatch())
            {
                Rank = SpringBattlePlayers.Select(x => x.Account.Rank).Max();
            }

            if (Duration > GlobalConst.MinDurationForXP)
            {
                if (!IsRatedMatch())
                {
                    WinnerTeamXpChange = GlobalConst.XpForMissionOrBotsVictory;
                    LoserTeamXpChange  = GlobalConst.XpForMissionOrBots;
                }
                else
                {
                    var losers  = SpringBattlePlayers.Where(x => !x.IsSpectator && !x.IsInVictoryTeam).Select(x => x.Account).ToList();
                    var winners = SpringBattlePlayers.Where(x => !x.IsSpectator && x.IsInVictoryTeam).Select(x => x.Account).ToList();
                    if ((losers.Count > 0) && (winners.Count > 0))
                    {
                        List <float> probabilities = RatingSystems.GetRatingSystem(GetRatingCategory()).PredictOutcome(new List <ICollection <Account> > {
                            winners, losers
                        }, StartTime);
                        var eWin  = probabilities[0];
                        var eLose = probabilities[1];

                        WinnerTeamXpChange = (int)(20 + (300 + 600 * (1 - eWin)) / (3.0 + winners.Count)); // a bit ugly this sets to battle directly
                        LoserTeamXpChange  = (int)(20 + (200 + 400 * (1 - eLose)) / (2.0 + losers.Count));
                    }
                }

                ApplyXpChanges();
            }

            IsEloProcessed = true;
        }
Exemple #9
0
        // GET: Charts/Ratings
        public ActionResult Ratings(ChartsModel model)
        {
            model = model ?? new ChartsModel();

            var to   = model.To.Date;
            var from = model.From.Date;

            var providers = new List <IGraphDataProvider>();

            if (model.UserId != null)
            {
                providers.AddRange(model.UserId.Select(x => (IGraphDataProvider) new RatingHistory(x, model.RatingCategory)).ToList());
                //providers.AddRange(model.UserId.Select(x => (IGraphDataProvider)new LadderRatingHistory(x, model.RatingCategory)).ToList()); //75% confidence
            }

            var series = new List <GraphSeries>();

            foreach (var prov in providers)
            {
                series.Add(new GraphSeries()
                {
                    Title = prov.Title, Data = prov.GetDailyValues(from, to)
                });
            }

            model.GraphingData = series;

            if (model.UserId != null)
            {
                using (var db = new ZkDataContext())
                {
                    model.UserStats = model.UserId.Select(id => new UserStats()
                    {
                        Account   = db.Accounts.Where(x => x.AccountID == id).Include(x => x.Faction).Include(x => x.Clan).FirstOrDefault(),
                        RankStats = RatingSystems.ratingCategories.Select(s => new RankStats()
                        {
                            System        = s.ToString(),
                            CurrentRating = RatingSystems.GetRatingSystem(s).GetPlayerRating(id),
                            Bracket       = RatingSystems.GetRatingSystem(s).GetPercentileBracket(db.Accounts.FirstOrDefault(a => a.AccountID == id).Rank),
                        }).ToList(),
                    }).ToList();
                }
            }
            return(View("ChartsRatings", model));
        }
Exemple #10
0
        public Dictionary <int, float> GetAllyteamWinChances()
        {
            var allyteams = SpringBattlePlayers.Where(x => !x.IsSpectator).OrderBy(x => x.AllyNumber).Select(x => x.AllyNumber).Distinct().ToList();

            try
            {
                if (IsRatedMatch())
                {
                    var chances = RatingSystems.GetRatingSystem(GetRatingCategory()).PredictOutcome(SpringBattlePlayers.Where(x => !x.IsSpectator).OrderBy(x => x.AllyNumber).GroupBy(x => x.AllyNumber).Select(x => x.Select(y => y.Account).ToList()).ToList(), StartTime);
                    return(allyteams.Zip(chances, (k, v) => new { k, v }).ToDictionary(x => x.k, x => x.v));
                }
            }
            catch (Exception ex)
            {
                Trace.TraceWarning("Invalid rating settings for B" + SpringBattleID + ", unable to calculate win chances. \n" + ex);
            }
            return(allyteams.ToDictionary(x => x, x => 1f / allyteams.Count));
        }
        public PlayerRating GetBestRating()
        {
            var casual = RatingSystems.GetRatingSystem(RatingCategory.Casual).GetPlayerRating(AccountID);
            var mm     = RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetPlayerRating(AccountID);
            var pw     = RatingSystems.GetRatingSystem(RatingCategory.Planetwars).GetPlayerRating(AccountID);

            if ((casual.Elo >= mm.Elo || mm.Rank == int.MaxValue) && casual.Rank < int.MaxValue)
            {
                return(casual);
            }
            if ((mm.Elo >= casual.Elo || casual.Rank == int.MaxValue) && mm.Rank < int.MaxValue)
            {
                return(mm);
            }
            //ignore pw

            return(WholeHistoryRating.DefaultRating);
        }
Exemple #12
0
        public PlayerRating GetBestRating()
        {
            var casual = RatingSystems.GetRatingSystem(RatingCategory.Casual).GetPlayerRating(this);
            var mm     = RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetPlayerRating(this);
            var pw     = RatingSystems.GetRatingSystem(RatingCategory.Planetwars).GetPlayerRating(this);

            if ((casual.Elo >= mm.Elo || mm.Uncertainty > GlobalConst.MaxLadderUncertainty) && casual.Uncertainty < GlobalConst.MaxLadderUncertainty)
            {
                return(casual);
            }
            if ((mm.Elo >= casual.Elo || casual.Uncertainty > GlobalConst.MaxLadderUncertainty) && mm.Uncertainty < GlobalConst.MaxLadderUncertainty)
            {
                return(mm);
            }
            //ignore pw

            return(new PlayerRating(int.MaxValue, 1, 0, float.PositiveInfinity));
        }
Exemple #13
0
        public ActionResult ResetRatings()
        {
            using (var db = new ZkDataContext())
            {
                db.SpringBattles.Where(x => x.ApplicableRatings == RatingCategoryFlags.Planetwars || x.ApplicableRatings == (RatingCategoryFlags.Planetwars | RatingCategoryFlags.Casual)).Update(x => new SpringBattle()
                {
                    ApplicableRatings = RatingCategoryFlags.Casual
                });
                db.AccountRatings.Where(x => x.RatingCategory == RatingCategory.Planetwars).Update(x => new AccountRating()
                {
                    Percentile  = WholeHistoryRating.DefaultRating.Percentile,
                    Rank        = WholeHistoryRating.DefaultRating.Rank,
                    RealElo     = WholeHistoryRating.DefaultRating.RealElo,
                    Uncertainty = 1000,
                    Elo         = WholeHistoryRating.DefaultRating.Elo,
                });
            }
            (RatingSystems.GetRatingSystem(RatingCategory.Planetwars) as WholeHistoryRating).ResetAll();

            return(RedirectToAction("Index"));
        }
Exemple #14
0
 public PlayerRating GetRating(RatingCategory category)
 {
     return(RatingSystems.GetRatingSystem(category).GetPlayerRating(this));
 }
        public override async Task ExecuteArmed(ServerBattle battle, Say e)
        {
            var b = battle;
            List <IEnumerable <Account> > teams;

            RatingCategory cat = RatingCategory.Casual;

            if (b.IsMatchMakerBattle)
            {
                cat = RatingCategory.MatchMaking;
            }
            if (b.Mode == PlasmaShared.AutohostMode.Planetwars)
            {
                cat = RatingCategory.Planetwars;
            }

            using (var db = new ZkDataContext())
            {
                if (battle.IsInGame)
                {
                    teams = b.spring.LobbyStartContext?.Players.Where(u => !u.IsSpectator)
                            .GroupBy(u => u.AllyID)
                            .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList();
                }
                else
                {
                    switch (battle.Mode)
                    {
                    case PlasmaShared.AutohostMode.Game1v1:
                        teams = b.Users.Values.Where(u => !u.IsSpectator)
                                .GroupBy(u => u.Name)
                                .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList();
                        break;

                    case PlasmaShared.AutohostMode.Teams:
                        teams = PartitionBalance.Balance(battle.IsCbalEnabled ? Balancer.BalanceMode.ClanWise : Balancer.BalanceMode.Normal, b.Users.Values.Where(u => !u.IsSpectator).Select(x => x.LobbyUser).Select(x => new PartitionBalance.PlayerItem(x.AccountID, x.EffectiveElo, x.Clan, x.PartyID)).ToList())
                                .Players
                                .GroupBy(u => u.AllyID)
                                .Select(x => x.Select(p => db.Accounts.Where(a => a.AccountID == p.LobbyID).FirstOrDefault())).ToList();
                        break;

                    default:
                        teams = b.Users.Values.Where(u => !u.IsSpectator)
                                .GroupBy(u => u.AllyNumber)
                                .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList();
                        break;
                    }
                }

                if (teams.Count < 2)
                {
                    await battle.SayBattle($"!predict needs at least two human teams to work");

                    return;
                }

                var chances = RatingSystems.GetRatingSystem(cat).PredictOutcome(teams, DateTime.UtcNow);
                for (int i = 0; i < teams.Count; i++)
                {
                    await battle.SayBattle($"Team {teams[i].OrderByDescending(x => x.GetRating(cat).Elo).Select(x => x.Name).Aggregate((a, y) => a + ", " + y)} has a {Math.Round(1000 * chances[i]) / 10}% chance to win");
                }
            }
        }
 public PlayerRating GetRating(RatingCategory category)
 {
     return(RatingSystems.GetRatingSystem(category).GetPlayerRating(AccountID));
 }
Exemple #17
0
        public override async Task ExecuteArmed(ServerBattle battle, Say e)
        {
            var b = battle;
            List <IEnumerable <Account> > teams;

            RatingCategory cat = RatingCategory.Casual;

            if (b.IsMatchMakerBattle)
            {
                cat = RatingCategory.MatchMaking;
            }
            if (b.Mode == PlasmaShared.AutohostMode.Planetwars)
            {
                cat = RatingCategory.Planetwars;
            }

            using (var db = new ZkDataContext())
            {
                if (battle.IsInGame)
                {
                    teams = b.spring.LobbyStartContext?.Players.Where(u => !u.IsSpectator)
                            .GroupBy(u => u.AllyID)
                            .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList();
                }
                else
                {
                    switch (battle.Mode)
                    {
                    case PlasmaShared.AutohostMode.Game1v1:
                        teams = b.Users.Values.Where(u => !u.IsSpectator)
                                .GroupBy(u => u.Name)
                                .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList();
                        break;

                    case PlasmaShared.AutohostMode.Teams:
                        await battle.SayBattle($"The battle will be balanced when it starts");

                        return;

                    default:
                        teams = b.Users.Values.Where(u => !u.IsSpectator)
                                .GroupBy(u => u.AllyNumber)
                                .Select(x => x.Select(p => Account.AccountByName(db, p.Name))).ToList();
                        break;
                    }
                }

                if (teams.Count < 2)
                {
                    await battle.SayBattle($"!predict needs at least two human teams to work");

                    return;
                }

                var chances = RatingSystems.GetRatingSystem(cat).PredictOutcome(teams, DateTime.UtcNow);
                for (int i = 0; i < teams.Count; i++)
                {
                    await battle.SayBattle($"Team {teams[i].OrderByDescending(x => x.GetRating(cat).Elo).First().Name} has a {Math.Round(1000 * chances[i]) / 10}% chance to win");
                }
            }
        }
        /// <summary>
        /// Go to home page; also updates news read dates
        /// </summary>
        public ActionResult Index()
        {
            var db = new ZkDataContext();


            var result = new IndexResult()
            {
                Spotlight         = SpotlightHandler.GetRandom(),
                Top10Players      = RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetTopPlayers(10),
                WikiRecentChanges = MediaWikiRecentChanges.LoadRecentChanges()
            };

            result.LobbyStats = MemCache.GetCached("lobby_stats", GetCurrentLobbyStats, 60 * 2);

            result.News = db.News.Where(x => x.Created < DateTime.UtcNow).OrderByDescending(x => x.Created);
            if (Global.Account != null)
            {
                result.Headlines =
                    db.News.Where(
                        x => x.Created <DateTime.UtcNow && x.HeadlineUntil != null && x.HeadlineUntil> DateTime.UtcNow && !x.ForumThread.ForumThreadLastReads.Any(y => y.AccountID == Global.AccountID && y.LastRead != null)).
                    OrderByDescending(x => x.Created).ToList();

                if (result.Headlines.Any())
                {
                    foreach (var h in result.Headlines)
                    {
                        h.ForumThread.UpdateLastRead(Global.AccountID, false);
                    }

                    db.SaveChanges();
                }
            }
            else
            {
                result.Headlines = new List <News>();
            }


            var accessibleThreads = db.ForumThreads.Where(x => x.RestrictedClanID == null || x.RestrictedClanID == Global.ClanID);

            accessibleThreads = accessibleThreads.Where(x => x.ForumCategory.ForumMode != ForumMode.Archive);
            if (!Global.IsAccountAuthorized)
            {
                result.NewThreads = accessibleThreads.OrderByDescending(x => x.LastPost).Take(10).Select(x => new NewThreadEntry()
                {
                    ForumThread = x
                });
            }
            else
            {
                result.NewThreads = (from t in accessibleThreads
                                     let read = t.ForumThreadLastReads.FirstOrDefault(x => x.AccountID == Global.AccountID)
                                                let readForum = t.ForumCategory.ForumLastReads.FirstOrDefault(x => x.AccountID == Global.AccountID)
                                                                where (read == null || t.LastPost > read.LastRead) && (readForum == null || t.LastPost > readForum.LastRead)
                                                                orderby t.LastPost descending
                                                                select new NewThreadEntry {
                    ForumThread = t, WasRead = read != null, WasWritten = read != null && read.LastPosted != null
                }).
                                    Take(10);
            }



            return(View("HomeIndex", result));
        }
 public LadderListManager(ZkLobbyServer zkLobbyServer)
 {
     server = zkLobbyServer;
     RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).AddTopPlayerUpdateListener(this, LadderListLength);
     TopPlayersUpdated(RatingSystems.GetRatingSystem(RatingCategory.MatchMaking).GetTopPlayers(LadderListLength)); //make sure ladderlist is never null
 }