Esempio n. 1
0
        public static void Main()
        {
            var items      = ItemDb.LoadItems();
            var warlockMax = items.Max(i => i.WarlockLootValue);
            var mageMax    = items.Max(i => i.MageLootValue);

            PrintItems(items, warlockMax, mageMax);

            var nDaysAgo = DateTime.Today - TimeSpan.FromDays(150);
            IEnumerable <Player> players = PlayerDb.LoadPlayers(nDaysAgo, nDaysAgo, RaidTierDates[RaidTier.AhnQiraj])
                                           .Where(p => p.Characters.Any(c => c.IsMain && (c.Class == CharacterClass.Warlock || c.Class == CharacterClass.Mage)))
                                           .OrderByDescending(p => p.LootPriority);

            PrintPlayersLoot(players, mageMax, warlockMax);
            PrintPlayers(players);

            Console.ReadKey();
        }
Esempio n. 2
0
        public static List <Player> LoadPlayers(DateTime?attendanceFromDate = null, DateTime?lootFromDate = null, DateTime?performanceFromDate = null)
        {
            var players = new Dictionary <int, Player>();
            var lines   = File.ReadAllLines(PlayersFile).Skip(1);

            foreach (string line in lines)
            {
                var l = CsvReader.ReadFromText(line, new CsvOptions()
                {
                    HeaderMode = HeaderMode.HeaderAbsent
                }).ToArray()[0];
                int playerId  = int.Parse(l.Values[0]);
                var character = new Character
                {
                    Name   = l.Values[1],
                    Class  = (CharacterClass)Enum.Parse(typeof(CharacterClass), l.Values[2]),
                    IsMain = bool.Parse(l.Values[3]),
                };
                if (players.ContainsKey(playerId))
                {
                    players[playerId].Characters.Add(character);
                }
                else
                {
                    players.Add(playerId, new Player
                    {
                        Id         = playerId,
                        Characters = new List <Character> {
                            character
                        },
                        Attitude = l.Values.Length > 4 ? double.Parse(l.Values[4]) : 1,
                    });
                }
            }

            var lootByCharacter = new Dictionary <string, List <Loot> >();

            foreach (var loot in LootDb.LoadLoot().Where(l => l.DateTime >= lootFromDate))
            {
                if (lootByCharacter.ContainsKey(loot.Character))
                {
                    lootByCharacter[loot.Character].Add(loot);
                }
                else
                {
                    lootByCharacter.Add(loot.Character, new List <Loot> {
                        loot
                    });
                }
            }
            var items      = ItemDb.LoadItems().ToDictionary(i => i.Id, i => i);
            var mageMax    = items.Values.Max(i => i.MageLootValue);
            var warlockMax = items.Values.Max(i => i.WarlockLootValue);

            var logs = WarcraftLogDb.LoadWarcraftLogs();

            foreach (var player in players.Values)
            {
                player.Attendance = logs
                                    .Where(l => l.Date >= attendanceFromDate || attendanceFromDate == null)
                                    .Select(l => l.Parses.Any(p => player.Characters.Any(c => c.Name == p.Key)) ? 1 : 0)
                                    .Average();
                var performances = logs
                                   .Where(l => l.Date >= performanceFromDate && (l.Date >= Program.RaidTierDates[l.RaidTier] && l.Date < Program.RaidTierDates[(RaidTier)((int)l.RaidTier + 1)]))
                                   .Select(l => l.Parses.Any(p => p.Key == player.Main.Name) ? l.Parses.First(p => p.Key == player.Main.Name).Value : -1)
                                   .Where(p => p >= 0)
                                   .ToList();
                player.Performance = performances.Any() ? performances.Average() : 0;
                player.Loot        = lootByCharacter.ContainsKey(player.Main.Name) ? lootByCharacter[player.Main.Name]
                                     .Where(l => items.ContainsKey(l.ItemId))
                                     .Select(l => new Tuple <Loot, Item>(l, items[l.ItemId]))
                                     .ToList()
                    : new List <Tuple <Loot, Item> >();
            }

            return(players.Values.ToList());
        }