private static void Pf_CompletedSuccessfully() { Console.WriteLine("Update completed Sucessfully."); // Set update delay and restart timer. Console.WriteLine("Updating at " + DateTime.Now.AddMilliseconds(updateIntervalAfterCompletion) + "."); pf.PagingDelay = 0; timer.Interval = updateIntervalAfterCompletion; timer.Start(); //If ladder empty do nothing if (pf.Lf.ladder.entries.Count() == 0) { return; } // Save data to file. PoeFilesControl.SaveToFile(pf.Lf); // Get different data objects for statistics/reporting. LeagueInfo data = pf.Lf; List <AccountInfo> accInfo = StatsGenerator.GetAccountsInfo(data); List <string> namesList = StatsGenerator.ListOfAccMultipleCharsAlive(accInfo); // Report owners of multiple alive characters. PTLiveReporter.ReportMultipleAliveChars(namesList); Console.WriteLine("Accounts with multiple alive characters reported to web service."); // Get classes info. List <ClassInfo> x = StatsGenerator.GetClassesInfo(data); // Sort by popularity. List <ClassInfo> orderedByPopularity = x.OrderByDescending(d => d.totalChars).ToList <ClassInfo>(); // Update ascendacy classes info PTLiveReporter.UpdateAscendancyClasses(orderedByPopularity); Console.WriteLine("Ascendancy classes info sent to server."); // Get league statistics. LeagueStats LS = StatsGenerator.GenerateLeagueStats(pf.Lf, (3600000 / updateIntervalAfterCompletion) + 2); // Send league statistics PTLiveReporter.UpdateLeagueStats(LS); Console.WriteLine("General league stats sent to server."); // Update rips counter PTLiveReporter.UpdateRipsCounter(LS.DeadCharacters); Console.WriteLine("Rips Counter updated."); // Increase Updates Counter UpdatesCount++; }
public static LeagueStats GenerateLeagueStats(LeagueInfo lf, int indexOfActivePlayersOldFile) { // Result LeagueStats result = new LeagueStats(); // Accounts Info var accsInfo = GetAccountsInfo(lf); //*** result.AccountsParticipating result.AccountsParticipating = accsInfo.Count(); //*** result.TotalCharacters result.TotalCharacters = lf.ladder.entries.Count(); foreach (var entry in lf.ladder.entries) { //*** result.DeadCharacters if (entry.dead) { result.DeadCharacters++; } //*** result.AliveCharacters if (!entry.dead) { result.AliveCharacters++; } //*** result.DeadAtLevel[1-100] if (entry.dead) { result.DeadAtLevel[entry.character.level] += 1; } //*** result.CharsAliveAboveLvl10 & result.CharsAliveAboveLvl50 if (!entry.dead && entry.character.level > 10) { result.CharsAliveAboveLvl10++; } if (!entry.dead && entry.character.level > 50) { result.CharsAliveAboveLvl50++; } //*** result.DeadBeforeLvl10 if (entry.dead && entry.character.level < 10) { result.DeadBeforeLvl10++; } } //*** result.accountableForMostDeaths // Sort by death count accsInfo. List <AccountInfo> orderedByPopularity = accsInfo.OrderByDescending(d => d.DeadCharacters).ToList <AccountInfo>(); // Add first 10 to the result.accountableForMostDeaths int count = (accsInfo.Count() >= 50) ? count = 50 : count = accsInfo.Count(); for (int i = 0; i < count; i++) { result.accountableForMostDeaths.Add(new AccountDeathsInfo(orderedByPopularity[i].accName, orderedByPopularity[i].DeadCharacters)); } //*** result.ActivePlayers // Check active players. LeagueInfo oldLInf = PoeFilesControl.GetFileByIndex(indexOfActivePlayersOldFile); //LeagueInfo oldLInf = PoeFilesControl.GetFileByIndex(1); LeagueInfo newLInfo = lf; int activePlayers = 0; foreach (var oldEntry in oldLInf.ladder.entries) { if (oldEntry.dead) { continue; } var newEntry = newLInfo.ladder.entries.Find((entr) => entr.character.name == oldEntry.character.name && entr.dead == false); if (newEntry != null) { if (oldEntry.character.experience != newEntry.character.experience) { activePlayers++; } } } result.ActivePlayers = activePlayers; return(result); }