예제 #1
0
        private void btnGetUserStats(object sender, RoutedEventArgs e)
        {
            Console.WriteLine(((Button)sender).Tag);
            string          tag          = ((Button)sender).Tag.ToString();
            ClashClanMember detailMember = clanMembers.Find(member => member.Tag == tag);

            if (detailMember != null)
            {
                lblMemberName.Content                       = detailMember.Name;
                lblClanMemberArenaValue.Content             = detailMember.Arena.Name;
                lblClanMemberChestPointsValue.Content       = detailMember.ClanChestPoints;
                lblClanMemberDonationsRatioValue.Content    = detailMember.DonationsRatio;
                lblClanMemberDonationsReceivedValue.Content = detailMember.DonationsReceived;
                lblClanMemberDonationsValue.Content         = detailMember.Donations;
                lblClanMemberExpLevelValue.Content          = detailMember.ExpLevel;
                lblClanMemberPreviousRankValue.Content      = detailMember.PreviousClanRank;
                lblClanMemberRankValue.Content              = detailMember.ClanRank;
                lblClanMemberRoleValue.Content              = detailMember.Role;
                lblClanMemberTrophiesValue.Content          = detailMember.Trophies;

                int cardsEarned   = 0;
                int battlesPlayed = 0;
                int wins          = 0;
                int wastedAttacks = 0;
                int skipedWars    = 0;
                foreach (ClashWar log in warLogs)
                {
                    ClashWarParticipant clanWarParticipant = null;
                    clanWarParticipant = log.Participants.Find(member => member.Tag == tag);
                    if (clanWarParticipant != null)
                    {
                        cardsEarned += clanWarParticipant.CardsEarned;
                        wins        += clanWarParticipant.Wins;
                        if (clanWarParticipant.BattlesPlayed > 0)
                        {
                            battlesPlayed += clanWarParticipant.BattlesPlayed;
                        }
                        else
                        {
                            wastedAttacks++;
                        }
                    }
                    else
                    {
                        skipedWars++;
                    }
                }
                lblClanMemberBattlesPlayedValue.Content = battlesPlayed;
                lblClanMemberCardsEarnedValue.Content   = cardsEarned;
                lblClanMemberWinsValue.Content          = wins;
                lblClanMemberWastedAtacksValue.Content  = wastedAttacks;
                lblNumberOfWarsValue.Content            = warLogs.Count;
                lblClanMemberSkippedWarsValue.Content   = skipedWars;
            }
        }
예제 #2
0
        private async Task <List <ClashClanMember> > calculateWarRatio()
        {
            if (warLogs == null)
            {
                return(null);
            }
            if (clanMembers == null)
            {
                return(null);
            }

            //ClashClanMember member =null;
            List <ClashClanMember> candidates = null;

            //await Task.Run(() =>
            //{
            foreach (ClashClanMember member in clanMembers)
            {
                int wastedAttacks    = 0;
                int skipedWars       = 0;
                int participatedWars = 0;

                foreach (ClashWar log in warLogs)
                {
                    ClashWarParticipant clanWarParticipant = null;
                    clanWarParticipant = log.Participants.Find(warMember => warMember.Tag == member.Tag);
                    if (clanWarParticipant != null)
                    {
                        participatedWars++;
                        if (clanWarParticipant.BattlesPlayed == 0)
                        {
                            wastedAttacks++;
                        }
                    }
                    else
                    {
                        skipedWars++;
                    }
                }
                member.SkippedWars      = skipedWars;
                member.WastedWarAttacks = wastedAttacks;
                member.WarAtackRatio    = (participatedWars == 0)? 0 : (participatedWars - wastedAttacks) / participatedWars;
                member.ParticipatedWars = participatedWars;
            }
            candidates = clanMembers.OrderByDescending(m => m.WastedWarAttacks).ThenBy(c => c.WarAtackRatio).ThenBy(c => c.DonationsRatio).Take(3).ToList();
            return(candidates);
            //});
        }