private void UpdateSummaryDatabase(Dictionary <string, FightDataCollection> _CachedFightDataCollections = null, List <RaidCollection_Raid> _RaidsModified = null, bool _ReplaceRaidsModified = false) { var timer = System.Diagnostics.Stopwatch.StartNew(); Logger.ConsoleWriteLine("RaidStats: Started Updating Summary Database", ConsoleColor.Green); //Caching Dictionary <string, FightDataCollection> getFightDataCollectionCache = _CachedFightDataCollections; if (getFightDataCollectionCache == null) { getFightDataCollectionCache = new Dictionary <string, FightDataCollection>(); } List <RaidCollection_Raid> raidsModified = _RaidsModified; if (raidsModified == null) { raidsModified = new List <RaidCollection_Raid>(); } Func <string, FightDataCollection> cachedGetFightDataCollectionFunc = (string _File) => { FightDataCollection db = null; if (getFightDataCollectionCache.Count > 50 && GC.GetTotalMemory(false) >= 3L * 1024L * 1024L * 1024L) { getFightDataCollectionCache = new Dictionary <string, FightDataCollection>(); GC.Collect(); } if (getFightDataCollectionCache.TryGetValue(_File, out db) == false) { db = _LoadRaidFightCollectionFile(_File); getFightDataCollectionCache.Add(_File, db); } return(db); }; //Caching if (_ReplaceRaidsModified == false) { //Default var summaryDB = VF_RDDatabase.SummaryDatabase.UpdateSummaryDatabase_New(m_RDDBFolder + "\\SummaryDatabase\\NewSummaryDatabase.dat", m_RaidCollection, raidsModified , cachedGetFightDataCollectionFunc , (_WowRealm) => { return(new RealmDB(m_RPPDatabaseHandler.GetRealmDB(_WowRealm))); }); Logger.ConsoleWriteLine("RaidStats: Done Updating Summary Database, it took " + (timer.ElapsedMilliseconds / 1000) + " seconds", ConsoleColor.Green); timer = System.Diagnostics.Stopwatch.StartNew(); VF_RDDatabase.GroupSummaryDatabase.UpdateSummaryDatabase(m_RDDBFolder, summaryDB); Logger.ConsoleWriteLine("RaidStats: Done Updating Group Summary Database, it took " + (timer.ElapsedMilliseconds / 1000) + " seconds", ConsoleColor.Green); } else { //FixBuggedSummaryDatabase VF_RDDatabase.SummaryDatabase.FixBuggedSummaryDatabase_New(m_RDDBFolder + "\\SummaryDatabase\\BaseSummaryDatabase.dat", m_RaidCollection, raidsModified , cachedGetFightDataCollectionFunc , (_WowRealm) => { return(new RealmDB(m_RPPDatabaseHandler.GetRealmDB(_WowRealm))); }); Logger.ConsoleWriteLine("RaidStats: Done Fixing " + _RaidsModified.Count + "bugged raids in Summary Database, it took " + (timer.ElapsedMilliseconds / 1000) + " seconds", ConsoleColor.Green); } }
private int AddFightsToDatabase(string _fightCollectionFile) { try { List <string> sessionDebugData = new List <string>(); int totalFightCount = 0; string filenameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(_fightCollectionFile); string fightCollectionDatName = "DataFiles\\" + DateTime.UtcNow.ToString("yyyy_MM") + "\\" + filenameWithoutExtension + ".dat"; fightCollectionDatName = VF.Utility.ConvertToUniqueFilename(fightCollectionDatName); List <DamageDataSession> dataSessions = new List <DamageDataSession>(); dataSessions = DamageDataParser.ParseFile(_fightCollectionFile, ref sessionDebugData); Console.Write("Generating Fights..."); var fights = FightDataCollection.GenerateFights(dataSessions);//, BossInformation.BossFights); Console.WriteLine("DONE"); if (fights.Fights.Count >= 1) { Logger.ConsoleWriteLine(_fightCollectionFile + " contained " + fights.Fights.Count + " fights", ConsoleColor.Yellow); List <RaidCollection_Raid> raidsModified = new List <RaidCollection_Raid>(); List <RaidCollection_Dungeon> dungeonsModified = new List <RaidCollection_Dungeon>(); m_RaidCollection.AddFightCollection(fights, fightCollectionDatName, raidsModified, dungeonsModified); //TESTING if (raidsModified.Count > 0 || dungeonsModified.Count > 0) { Logger.ConsoleWriteLine("--------------------", ConsoleColor.White); foreach (var raid in raidsModified) { var bossFights = raid.GetBossFights(fights, null); Logger.ConsoleWriteLine("Raid: " + raid.RaidInstance + "(" + raid.RaidID + ") by " + raid.RaidOwnerName, ConsoleColor.White); foreach (var bossFight in bossFights) { ++totalFightCount; bossFight.GetFightDetails(); //Trigger FightDetail request, so we get error here instead of later on the website. //Logger.ConsoleWriteLine("Fight: " + bossFight.GetBossName() + " added to RaidCollection", ConsoleColor.Green); } if (raid.RaidOwnerName.ToLower() == "unknown" || raid.RaidOwnerName == "") { try { lock (m_RPPDatabaseHandler.GetLockObject()) { var realmDB = new RealmDB(m_RPPDatabaseHandler.GetRealmDB(raid.Realm)); List <string> attendingPlayers = new List <string>(); foreach (var bossFight in bossFights) { attendingPlayers.AddRange(bossFight.GetAttendingUnits(realmDB.RD_IsPlayerFunc(bossFight))); } if (attendingPlayers.Distinct().Count() > 2) { Dictionary <string, int> guildCount = new Dictionary <string, int>(); foreach (var attendingPlayer in attendingPlayers) { string guildName = realmDB.GetPlayer(attendingPlayer).Guild.GuildName; if (guildCount.ContainsKey(guildName)) { guildCount[guildName] = guildCount[guildName] + 1; } else { guildCount.Add(guildName, 1); } } var biggestGuildCount = guildCount.OrderByDescending((_Value) => _Value.Value).First(); if (biggestGuildCount.Value >= (int)(0.7f * (float)attendingPlayers.Count)) { raid.RaidOwnerName = biggestGuildCount.Key; } else { raid.RaidOwnerName = "PUG"; } Logger.ConsoleWriteLine("Raid: Changed RaidOwnerName for " + raid.RaidInstance + "(" + raid.RaidID + ") to " + raid.RaidOwnerName, ConsoleColor.White); } else { raid.RaidOwnerName = "PUG"; } } } catch (Exception ex) { raid.RaidOwnerName = "PUG"; Logger.LogException(ex); } } } foreach (var dungeon in dungeonsModified) { var bossFights = dungeon.GetBossFights(fights); Logger.ConsoleWriteLine("Dungeon: " + dungeon.m_Dungeon + "(" + dungeon.m_UniqueDungeonID + ") by \"" + dungeon.m_GroupMembers.MergeToStringVF("\", \"") + "\"", ConsoleColor.White); foreach (var bossFight in bossFights) { ++totalFightCount; bossFight.GetFightDetails(); //Trigger FightDetail request, so we get error here instead of later on the website. //Logger.ConsoleWriteLine("Fight: " + bossFight.GetBossName() + " added to RaidCollection", ConsoleColor.Green); } } Logger.ConsoleWriteLine("--------------------", ConsoleColor.White); VF.Utility.SaveSerialize(m_RDDBFolder + fightCollectionDatName, fights); VF.Utility.BackupFile(m_RDDBFolder + "RaidCollection.dat", VF.Utility.BackupMode.Backup_Daily); VF.Utility.SaveSerialize(m_RDDBFolder + "RaidCollection.dat", m_RaidCollection, false); Logger.ConsoleWriteLine(_fightCollectionFile + " added " + totalFightCount + " fights to RaidCollection", ConsoleColor.Green); Dictionary <string, FightDataCollection> getFightDataCollectionCache = new Dictionary <string, FightDataCollection>(); getFightDataCollectionCache.Add(fightCollectionDatName, fights); UpdateSummaryDatabase(getFightDataCollectionCache, raidsModified); string debugFilePath = m_RDDBFolder + "\\DebugData\\SessionDebug\\" + DateTime.UtcNow.ToString("yyyy_MM_dd") + ".txt"; VF.Utility.AssertFilePath(debugFilePath); if (System.IO.File.Exists(debugFilePath) == true) { System.IO.File.AppendAllLines(debugFilePath, sessionDebugData); } else { System.IO.File.WriteAllLines(debugFilePath, sessionDebugData); } } else { Logger.ConsoleWriteLine(_fightCollectionFile + " already exists in RaidCollection, skipping", ConsoleColor.Green); } } return(totalFightCount); } catch (Exception ex) { Logger.LogException(ex); Logger.ConsoleWriteLine("DUE TO ERRORS WE ARE RELOADING RAIDCOLLECTION!!!", ConsoleColor.Red); //RESET m_RaidCollection!!! VF.Utility.LoadSerialize <RaidCollection>(m_RDDBFolder + "RaidCollection.dat", out m_RaidCollection); Logger.ConsoleWriteLine("RELOAD OF RAIDCOLLECTION WAS SUCCESSFULL!!!", ConsoleColor.Green); } return(0); }