public async Task SetLadderPending(string leagueName) { var exists = await LadderExists(leagueName); if (!exists) { var ladder = new LadderModel() { Name = leagueName, Started = DateTime.MinValue, Finished = DateTime.MinValue, Ladder = new List <LadderPlayerModel>(), Running = false }; await _ladders.InsertOneAsync(ladder); } }
public async Task InitializeLadderProcess() { if (HasBuiltLadderProcess) { return; } Debug.WriteLine("Building ladder process..."); // Browsers are single-threaded so this will actually still block the UI. // See: https://github.com/aspnet/Blazor/issues/560 LadderProcess ladder = await Task.Run(() => Build.CreateLadderProcess()); Debug.WriteLine("Ladder process built."); Ladder = new LadderModel(ladder); Shopping = new ShoppingModel(ladder); ExportToAuno = new ExportToAunoModel(ladder); HasBuiltLadderProcess = true; }
public void RecomputeNow() { ladderModel = ComputeLadder(); }
public LadderCalculator() { timer = new Timer((t) => { ladderModel = ComputeLadder(); }, this, LadderRefreshMinutes * 60 * 1000, LadderRefreshMinutes * 60 * 1000); }
private LadderModel GetLadder() { LadderModel cached = (LadderModel)HttpContext.Cache.Get("ladderModel"); if (cached != null) { return(cached); } var db = new ZkDataContext(); db.CommandTimeout = 600; var options = new DataLoadOptions(); options.LoadWith <Account>(x => x.Clan); options.LoadWith <Account>(x => x.Faction); db.LoadOptions = options; var monthStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); var validAwards = db.SpringBattles.Where(x => x.StartTime >= monthStart && !x.ResourceByMapResourceID.InternalName.Contains("SpeedMetal")).SelectMany(x => x.AccountBattleAwards).GroupBy(x => x.AwardKey); var awardItems = new List <AwardItem>(); foreach (var awardsByType in validAwards) { var awardType = awardsByType.Key; var awardCounts = awardsByType.GroupBy(x => x.Account).Select(x => new { Account = x.Key, Count = x.Count() }).OrderByDescending(x => x.Count); var topCountM = awardCounts.First().Count; var topCollectorsM = new List <Account>(); foreach (var award in awardCounts) { if (award.Count == topCountM) { topCollectorsM.Add(award.Account); } else { break; } } var topScore = 0; string titleName = null; topScore = 0; var fullTitleM = ""; int topActID = 0; int topBattleID = 0; foreach (var award in awardsByType) { if (titleName == null) { titleName = award.AwardDescription.Split(',').First(); } int score; if (int.TryParse(Regex.Replace(award.AwardDescription, @"\D", String.Empty), out score)) { if (score > topScore) { topActID = award.AccountID; topBattleID = award.SpringBattleID; topScore = score; fullTitleM = string.Join(" ", award.AwardDescription.Split(',').Skip(1)); } } } var awardItem = new AwardItem { AwardType = awardType, AwardTitle = titleName, TopScoreHolderM = db.Accounts.SingleOrDefault(x => x.AccountID == topActID), TopScoreDescM = fullTitleM, TopScoreBattlePlayerM = db.SpringBattlePlayers.SingleOrDefault(x => x.AccountID == topActID && x.SpringBattleID == topBattleID), TopCollectorsM = topCollectorsM, TopCollectorCountM = topCountM, }; awardItems.Add(awardItem); } var top50Accounts = db.Accounts.Where(x => x.SpringBattlePlayers.Any(y => y.SpringBattle.StartTime > DateTime.UtcNow.AddMonths(-1)) && x.Elo1v1Weight == GlobalConst.EloWeightMax).OrderByDescending(x => x.Elo1v1). Take(50).ToList(); var top50Teams = db.Accounts.Where(x => x.SpringBattlePlayers.Any(y => y.SpringBattle.StartTime > DateTime.UtcNow.AddMonths(-1)) && x.EloWeight == GlobalConst.EloWeightMax).OrderByDescending(x => x.Elo). Take(50).ToList(); LadderModel ladder = new LadderModel { AwardItems = awardItems, Top50Accounts = top50Accounts, Top50Teams = top50Teams }; HttpContext.Cache.Add("ladderModel", ladder, null, DateTime.Now.AddHours(2), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null); return(new LadderModel { AwardItems = awardItems, Top50Accounts = top50Accounts, Top50Teams = top50Teams }); }
private LadderModel GetLadder() { LadderModel cached = (LadderModel)HttpContext.Cache.Get("ladderModel"); if (cached != null) { return cached; } var db = new ZkDataContext(); db.Database.CommandTimeout = 600; var monthStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); var validAwards = db.SpringBattles.Where(x => x.StartTime >= monthStart && !x.ResourceByMapResourceID.InternalName.Contains("SpeedMetal")).SelectMany(x => x.AccountBattleAwards).GroupBy(x => x.AwardKey); var awardItems = new List<AwardItem>(); foreach (var awardsByType in validAwards) { var awardType = awardsByType.Key; var awardCounts = awardsByType.GroupBy(x => x.Account).Select(x => new { Account = x.Key, Count = x.Count() }).OrderByDescending(x => x.Count); var topCountM = awardCounts.First().Count; var topCollectorsM = new List<Account>(); foreach (var award in awardCounts) { if (award.Count == topCountM) topCollectorsM.Add(award.Account); else break; } var topScore = 0; string titleName = null; topScore = 0; var fullTitleM = ""; int topActID = 0; int topBattleID = 0; foreach (var award in awardsByType) { if (titleName == null) titleName = award.AwardDescription.Split(',').First(); int score; if (int.TryParse(Regex.Replace(award.AwardDescription, @"\D", String.Empty), out score)) { if (score > topScore) { topActID = award.AccountID; topBattleID = award.SpringBattleID; topScore = score; fullTitleM = string.Join(" ", award.AwardDescription.Split(',').Skip(1)); } } } var awardItem = new AwardItem { AwardType = awardType, AwardTitle = titleName, TopScoreHolderM = db.Accounts.SingleOrDefault(x => x.AccountID == topActID), TopScoreDescM = fullTitleM, TopScoreBattlePlayerM = db.SpringBattlePlayers.SingleOrDefault(x => x.AccountID == topActID && x.SpringBattleID == topBattleID), TopCollectorsM = topCollectorsM, TopCollectorCountM = topCountM, }; awardItems.Add(awardItem); } var lastMonth = DateTime.UtcNow.AddMonths(-1); var top50Accounts = db.Accounts.Where(x => x.SpringBattlePlayers.Any(y => y.SpringBattle.StartTime > lastMonth)).Include(x=>x.Clan).Include(x=>x.Faction).OrderByDescending(x => x.Effective1v1Elo).WithTranslations().Take(50).ToList(); var top50Teams = db.Accounts.Where(x => x.SpringBattlePlayers.Any(y => y.SpringBattle.StartTime > lastMonth)).Include(x => x.Clan).Include(x => x.Faction).OrderByDescending(x => x.EffectiveElo).WithTranslations().Take(50).ToList(); LadderModel ladder = new LadderModel { AwardItems = awardItems, Top50Accounts = top50Accounts, Top50Teams = top50Teams }; HttpContext.Cache.Add("ladderModel", ladder, null, DateTime.Now.AddHours(2), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null); return new LadderModel { AwardItems = awardItems, Top50Accounts = top50Accounts, Top50Teams = top50Teams }; }