Example #1
0
        public GuildData(string guid, IEnumerable <LogData> logs, IEnumerable <LogPlayer> logMembers)
        {
            Guid = guid;
            Logs = logs.ToArray();

            var accountList   = new List <GuildMember>();
            var characterList = new List <GuildCharacter>();

            var members  = logMembers.ToArray();
            var accounts = members.GroupBy(x => x.AccountName);

            foreach (var accountGrouping in accounts)
            {
                string accountName = accountGrouping.Key;

                var accountLogs = Logs
                                  .Where(l => l.Players.Any(p => p.AccountName == accountName && p.GuildGuid == guid))
                                  .Distinct()
                                  .ToArray();
                var account = new GuildMember(accountName, accountLogs);

                var accountCharacters = new List <GuildCharacter>();

                var characters = accountGrouping.GroupBy(x => (x.Name, x.Profession));
                foreach (var characterGrouping in characters)
                {
                    (string characterName, var profession) = characterGrouping.Key;

                    var characterLogs = accountLogs
                                        .Where(l => l.Players.Any(p => p.Name == characterName && p.GuildGuid == guid))
                                        .Distinct();
                    var character = new GuildCharacter(account, profession, characterName, characterLogs);
                    accountCharacters.Add(character);
                }

                account.Characters = accountCharacters;

                accountList.Add(account);
                characterList.AddRange(account.Characters);
            }

            Accounts   = accountList.OrderByDescending(x => x.Logs.Count).ToArray();
            Characters = characterList.OrderByDescending(x => x.Logs.Count).ToArray();
        }
Example #2
0
        public GuildData(string guid, IEnumerable <LogData> logs, IEnumerable <LogPlayer> logMembers)
        {
            Guid = guid;
            Logs = logs.ToArray();

            var accountList   = new List <GuildMember>();
            var characterList = new List <GuildCharacter>();

            var members         = logMembers.ToArray();
            var accounts        = members.GroupBy(x => x.AccountName);
            var logsByAccount   = new Dictionary <string, List <LogData> >();
            var logsByCharacter = new Dictionary <string, List <LogData> >();

            foreach (var log in Logs)
            {
                foreach (var player in log.Players)
                {
                    if (!logsByAccount.TryGetValue(player.AccountName, out var accountLogs))
                    {
                        var newAccountList = new List <LogData>();
                        logsByAccount[player.AccountName] = newAccountList;
                        accountLogs = newAccountList;
                    }

                    accountLogs.Add(log);

                    if (!logsByCharacter.TryGetValue(player.Name, out var characterLogs))
                    {
                        var newCharacterList = new List <LogData>();
                        logsByCharacter[player.Name] = newCharacterList;
                        characterLogs = newCharacterList;
                    }

                    characterLogs.Add(log);
                }
            }

            foreach (var accountGrouping in accounts)
            {
                string accountName = accountGrouping.Key;

                var accountLogs = logsByAccount[accountName];
                var account     = new GuildMember(accountName, accountLogs);

                var accountCharacters = new List <GuildCharacter>();

                var characters = accountGrouping.GroupBy(x => (x.Name, x.Profession));
                foreach (var characterGrouping in characters)
                {
                    (string characterName, var profession) = characterGrouping.Key;

                    var characterLogs = logsByCharacter[characterName];
                    var character     = new GuildCharacter(account, profession, characterName, characterLogs);
                    accountCharacters.Add(character);
                }

                account.Characters = accountCharacters;

                accountList.Add(account);
                characterList.AddRange(account.Characters);
            }

            Accounts   = accountList.OrderByDescending(x => x.Logs.Count).ToArray();
            Characters = characterList.OrderByDescending(x => x.Logs.Count).ToArray();
        }