public void UpdateDatabase(RPPDatabase _Database, DateTime _EarliestDateTime)
        {
            var realmDBs = _Database.GetRealms();

            foreach (var realmDB in realmDBs)
            {
                foreach (var playerHistory in realmDB.Value.PlayersHistory)
                {
                    try
                    {
                        if (playerHistory.Value.GuildHistory.Count < 1)
                        {
                            continue;
                        }

                        if (playerHistory.Value.GuildHistory.Last().Uploader.GetTime() >= _EarliestDateTime)
                        {
                            List <string> guildsAffected = new List <string>();
                            for (int i = playerHistory.Value.GuildHistory.Count - 1; i >= 0; --i)
                            {
                                if (playerHistory.Value.GuildHistory[i].Uploader.GetTime() < _EarliestDateTime)
                                {
                                    break;
                                }

                                string guildName = playerHistory.Value.GuildHistory[i].Data.GuildName;
                                if (guildsAffected.Contains(guildName) == false)
                                {
                                    guildsAffected.Add(guildName);
                                }
                            }
                            foreach (string guildName in guildsAffected)
                            {
                                if (guildName == "nil" || guildName == "None")
                                {
                                    continue;
                                }
                                if (GetGuildSummary(realmDB.Value.Realm, guildName) == null)
                                {
                                    var newGuildSummary = new GuildSummary(guildName, realmDB.Value.Realm);
                                    newGuildSummary.InitCache();
                                    AddGuildSummary(newGuildSummary);
                                }
                            }
                            foreach (var guild in m_Guilds)
                            {
                                if (guild.Value.Realm == realmDB.Value.Realm)
                                {
                                    guild.Value.Update(playerHistory.Key, playerHistory.Value, _EarliestDateTime);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        VF_RealmPlayersDatabase.Logger.LogException(ex);
                    }
                }
            }
        }
        public PlayerSummaryDatabase(RPPDatabase _Database)
        {
            var realmDBs = _Database.GetRealms();

            foreach (var realmDB in realmDBs)
            {
                UpdateRealm(realmDB.Value);
            }
        }
Beispiel #3
0
        public static void Thread_GenerateData(RPPDatabase _Database)
        {
            Logger.ConsoleWriteLine("TODO: Fix this!!!!!");
            for (int i = 0; i < 5; ++i)
            {
                var generatedContributorStatisticData = new Dictionary <WowRealm, Dictionary <int, ContributorStatisticItem> >();
                try
                {
                    ContributorStatisticItem lastUsedCSI = new ContributorStatisticItem();
                    foreach (var realm in _Database.GetRealms())
                    {
                        realm.Value.WaitForLoad(RealmDatabase.LoadStatus.EverythingLoaded);

                        if (generatedContributorStatisticData.ContainsKey(realm.Key) == false)
                        {
                            generatedContributorStatisticData.Add(realm.Key, new Dictionary <int, ContributorStatisticItem>());
                        }
                        var realmCSD = generatedContributorStatisticData[realm.Key];

                        foreach (var playerHistory in realm.Value.PlayersHistory)
                        {
                            var playerUpdates = playerHistory.Value.GetUpdates();
                            foreach (var playerUpdate in playerUpdates)
                            {
                                var currContributorID = playerUpdate.GetContributorID();
                                if (lastUsedCSI.m_ContributorID != currContributorID)
                                {
                                    if (realmCSD.ContainsKey(currContributorID) == false)
                                    {
                                        realmCSD.Add(currContributorID, new ContributorStatisticItem(currContributorID));
                                    }
                                    lastUsedCSI = realmCSD[currContributorID];
                                }
                                lastUsedCSI.AddInspectData(playerHistory.Key, playerUpdate.GetTime());
                            }
                        }
                    }
                    sm_ContributorStatisticData = generatedContributorStatisticData;
                    break;
                }
                catch (Exception ex)
                {
                    Logger.LogException(ex);
                    System.Threading.Thread.Sleep(500);
                    Logger.ConsoleWriteLine("Thread_GenerateData() Trying again!");
                }
            }
        }
        public void UpdateDatabase(RPPDatabase _Database, DateTime _EarliestDateTime)
        {
            List <string> failedMountItemNames     = new List <string>();
            List <string> failedCompanionItemNames = new List <string>();

            var realmDBs = _Database.GetRealms();

            foreach (var realmDB in realmDBs)
            {
                realmDB.Value.WaitForLoad(VF_RealmPlayersDatabase.RealmDatabase.LoadStatus.PlayersHistoryLoaded);
                foreach (var playerHistory in realmDB.Value.PlayersHistory)
                {
                    try
                    {
                        if (playerHistory.Value.GearHistory.Count < 1 || playerHistory.Value.GearHistory.Last().Uploader.GetTime() < _EarliestDateTime)
                        {
                            continue;
                        }

                        UInt64 playerID = GetEntityID(realmDB.Value.Realm, playerHistory.Key);

                        foreach (var gearHistory in playerHistory.Value.GearHistory)
                        {
                            if (gearHistory.Uploader.GetTime() < _EarliestDateTime)
                            {
                                continue;
                            }

                            foreach (var item in gearHistory.Data.Items)
                            {
                                var itemSummary  = GetItemSummary(item.Value);
                                var optionalSlot = item.Value.Slot;
                                if (item.Value.Slot == ItemSlot.Finger_1)
                                {
                                    optionalSlot = ItemSlot.Finger_2;
                                }
                                else if (item.Value.Slot == ItemSlot.Finger_2)
                                {
                                    optionalSlot = ItemSlot.Finger_1;
                                }
                                else if (item.Value.Slot == ItemSlot.Trinket_1)
                                {
                                    optionalSlot = ItemSlot.Trinket_2;
                                }
                                else if (item.Value.Slot == ItemSlot.Trinket_2)
                                {
                                    optionalSlot = ItemSlot.Trinket_1;
                                }
                                else if (item.Value.Slot == ItemSlot.Main_Hand)
                                {
                                    optionalSlot = ItemSlot.Off_Hand;
                                }
                                else if (item.Value.Slot == ItemSlot.Off_Hand)
                                {
                                    optionalSlot = ItemSlot.Main_Hand;
                                }

                                if (item.Value.Slot != optionalSlot)
                                {
                                    ItemInfo optionalItemInfo;
                                    if (gearHistory.Data.Items.TryGetValue(optionalSlot, out optionalItemInfo) == true)
                                    {
                                        //Possible duplicate, check it out
                                        if (optionalItemInfo.ItemID == item.Value.ItemID &&
                                            optionalItemInfo.SuffixID == item.Value.SuffixID)
                                        {
                                            //Add duplicate
                                            itemSummary.AddOwner(playerID, gearHistory.Uploader.GetTime(), true);
                                        }
                                        else
                                        {
                                            //No duplicates
                                            itemSummary.AddOwner(playerID, gearHistory.Uploader.GetTime());
                                        }
                                    }
                                    else
                                    {
                                        //No duplicates
                                        itemSummary.AddOwner(playerID, gearHistory.Uploader.GetTime());
                                    }
                                }
                                else
                                {
                                    //No duplicates
                                    itemSummary.AddOwner(playerID, gearHistory.Uploader.GetTime());
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        VF_RealmPlayersDatabase.Logger.LogException(ex);
                    }
                }
                foreach (var playerExtraData in realmDB.Value.PlayersExtraData)
                {
                    try
                    {
                        UInt64 playerID = GetEntityID(realmDB.Value.Realm, playerExtraData.Key);

                        foreach (var mount in playerExtraData.Value.Mounts)
                        {
                            int mountID = VF.ItemTranslations.FindItemID(mount.Mount);
                            if (mountID > 0)
                            {
                                var itemSummary = GetItemSummary(mountID, 0);
                                itemSummary.AddOwner(playerID, mount.GetEarliestUpload().GetTime());
                            }
                            else
                            {
                                failedMountItemNames.AddUnique(mount.Mount);
                            }
                        }

                        foreach (var companion in playerExtraData.Value.Companions)
                        {
                            int companionID = VF.ItemTranslations.FindItemID(companion.Name);
                            if (companionID > 0)
                            {
                                var itemSummary = GetItemSummary(companionID, 0);
                                itemSummary.AddOwner(playerID, companion.GetEarliestUpload().GetTime());
                            }
                            else
                            {
                                failedCompanionItemNames.AddUnique(companion.Name);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        VF_RealmPlayersDatabase.Logger.LogException(ex);
                    }
                }
            }
            VF_RealmPlayersDatabase.Logger.ConsoleWriteLine("Failed to add Mounts with names: " + String.Join("\", \"", failedMountItemNames.ToArray()) + "\"");
            VF_RealmPlayersDatabase.Logger.ConsoleWriteLine("Failed to add Companions with names: " + String.Join("\", \"", failedCompanionItemNames.ToArray()) + "\"");
        }