예제 #1
0
        public static ApTimeLine Mapper(MySqlDataReader reader)
        {
            var a = new ApTimeLine();

            a.MatchId    = reader.GetInt32("MatchId");
            a.PlayerId   = reader.GetInt32("ParticipantId");
            a.Rank       = reader.GetString("Rank");
            a.ChampionId = reader.GetInt32("ChampionId");
            a.Role       = reader.GetString("Role");
            a.Lane       = reader.GetString("Lane");
            a.TeamId     = reader.GetInt32("TeamId");
            a.Minute     = reader.GetInt32("Minute");
            a.TotalAp    = reader.GetInt32("TotalAP");
            a.TotalMr    = reader.GetInt32("TotalMR");
            var itemsIds = reader.GetString("ItemsIds");

            a.Patch = reader.GetString("Patch");
            a.Items = new List <Item>();
            foreach (var itemId in itemsIds.Split(new [] { '|' }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (a.Patch.Contains("5.11"))
                {
                    a.Items.Add(ItemsCache.GetItemV511(int.Parse(itemId)));
                }
                else
                {
                    a.Items.Add(ItemsCache.GetItemV514(int.Parse(itemId)));
                }
            }

            return(a);
        }
예제 #2
0
 public void EditTimeline(ApTimeLine time)
 {
     MySqlCommand cmd = new MySqlCommand("edit_timeline", connection);
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.Parameters.Add(new MySqlParameter("pMatchId", time.MatchId));
     cmd.Parameters.Add(new MySqlParameter("pParticipantId", time.PlayerId));
     cmd.Parameters.Add(new MySqlParameter("pTotalAP", time.TotalAp));
     cmd.Parameters.Add(new MySqlParameter("pMinute", time.Minute));
     var reader = cmd.ExecuteReader();
 }
예제 #3
0
 public ApTimeLine(ApTimeLine a)
 {
     MatchId     = a.MatchId;
     PlayerId    = a.PlayerId;
     TeamId      = a.TeamId;
     TotalAp     = a.TotalAp;
     TotalMr     = a.TotalMr;
     Items       = a.Items;
     Minute      = a.Minute;
     ChampionId  = a.ChampionId;
     Rank        = a.Rank;
     Role        = a.Role;
     Lane        = a.Lane;
     Patch       = a.Patch;
     CurrentGold = a.CurrentGold;
     GoldSpent   = a.GoldSpent;
     Winner      = a.Winner;
 }
예제 #4
0
 public ApTimeLine(ApTimeLine a)
 {
     MatchId = a.MatchId;
     PlayerId = a.PlayerId;
     TeamId = a.TeamId;
     TotalAp = a.TotalAp;
     TotalMr = a.TotalMr;
     Items = a.Items;
     Minute = a.Minute;
     ChampionId = a.ChampionId;
     Rank = a.Rank;
     Role = a.Role;
     Lane = a.Lane;
     Patch = a.Patch;
     CurrentGold = a.CurrentGold;
     GoldSpent = a.GoldSpent;
     Winner = a.Winner;
 }
예제 #5
0
        public static IList <ApTimeLine> GetPlayerApTimeline(Player p, string patch, int matchId, int teamId)
        {
            try
            {
                IList <ApTimeLine> timelines = new List <ApTimeLine>();
                var orderedTime = p.ItemTimeLine.OrderBy(a => a.TimeStamp).ToList();
                IDictionary <int, double> apPerMin = new Dictionary <int, double>();
                var items  = new List <Item>();
                var groups = orderedTime.GroupBy(a => (int)Math.Truncate((double)a.TimeStamp / 60000));

                var runesAp      = p.Runes.Sum(r => r.Ap);
                var runesApPerLv = p.Runes.Sum(r => r.ApPerLevel);
                var runesMr      = p.Runes.Sum(r => r.MagicResist);
                var runesMrPerLv = p.Runes.Sum(r => r.MagicResistPerLevel);
                foreach (var group in groups)
                {
                    try
                    {
                        var t = new ApTimeLine();
                        t.Minute = group.Key;
                        var lv = p.TimeLine[t.Minute].Level;
                        t.PlayerId = p.ParticipantId;
                        t.MatchId  = matchId;
                        t.TeamId   = teamId;

                        foreach (var itemTimeline in group)
                        {
                            Item item;
                            if (patch.StartsWith("5.11"))
                            {
                                item = ItemsCache.GetItemV511(itemTimeline.ItemId);
                            }
                            else
                            {
                                item = ItemsCache.GetItemV514(itemTimeline.ItemId);
                            }

                            double itemAp = 0;
                            if (itemTimeline.EventType == "ITEM_PURCHASED")
                            {
                                items.Add(item);
                            }
                            else
                            {
                                items.Remove(item);
                            }

                            double totalAp = items.Sum(i => ItemStats.GetTotalAP(i, t.Minute, p.SelectedChampion)) + runesAp + runesApPerLv * lv;
                            if (items.Any(i => i.Name == "Rabadon's Deathcap"))
                            {
                                if (patch.StartsWith("5.11"))
                                {
                                    totalAp = totalAp * 1.30;
                                }
                                else
                                {
                                    totalAp = totalAp * 1.35;
                                }
                            }

                            if (apPerMin.ContainsKey(t.Minute))
                            {
                                apPerMin[t.Minute] = totalAp;
                            }
                            else
                            {
                                apPerMin.Add(new KeyValuePair <int, double>(t.Minute, totalAp));
                            }
                        }
                        t.Items = items.ToList();

                        t.CurrentGold = p.TimeLine[t.Minute].CurrentGold;
                        t.GoldSpent   = items.Sum(i => i.GoldCost);

                        t.TotalMr = items.Sum(i => i.ItemStats.MR) + p.SelectedChampion.Stat.MagicResist + p.SelectedChampion.Stat.MagicResistPerLv * lv + runesMr + runesMrPerLv * lv;;
                        t.TotalAp = apPerMin.LastOrDefault().Value;
                        timelines.Add(t);
                    }
                    catch {
                        throw;
                    }
                }
                return(timelines);
            }
            catch {
                throw;
            }
        }
예제 #6
0
        public static ApTimeLine Mapper(MySqlDataReader reader)
        {
            var a = new ApTimeLine();
            a.MatchId = reader.GetInt32("MatchId");
            a.PlayerId = reader.GetInt32("ParticipantId");
            a.Rank = reader.GetString("Rank");
            a.ChampionId = reader.GetInt32("ChampionId");
            a.Role = reader.GetString("Role");
            a.Lane = reader.GetString("Lane");
            a.TeamId = reader.GetInt32("TeamId");
            a.Minute = reader.GetInt32("Minute");
            a.TotalAp = reader.GetInt32("TotalAP");
            a.TotalMr = reader.GetInt32("TotalMR");
            var itemsIds = reader.GetString("ItemsIds");
            a.Patch = reader.GetString("Patch");
            a.Items = new List<Item>();
            foreach (var itemId in itemsIds.Split(new []{'|'}, StringSplitOptions.RemoveEmptyEntries))
            {
                if (a.Patch.Contains("5.11"))
                    a.Items.Add(ItemsCache.GetItemV511(int.Parse(itemId)));
                else
                    a.Items.Add(ItemsCache.GetItemV514(int.Parse(itemId)));
            }

            return a;
        }
예제 #7
0
        public static IList<ApTimeLine> GetPlayerApTimeline(Player p, string patch, int matchId, int teamId)
        {
            try
            {
                IList<ApTimeLine> timelines = new List<ApTimeLine>();
                var orderedTime = p.ItemTimeLine.OrderBy(a => a.TimeStamp).ToList();
                IDictionary<int, double> apPerMin = new Dictionary<int, double>();
                var items = new List<Item>();
                var groups = orderedTime.GroupBy(a => (int)Math.Truncate((double)a.TimeStamp / 60000));

                var runesAp = p.Runes.Sum(r => r.Ap);
                var runesApPerLv = p.Runes.Sum(r => r.ApPerLevel);
                var runesMr = p.Runes.Sum(r => r.MagicResist);
                var runesMrPerLv = p.Runes.Sum(r => r.MagicResistPerLevel);
                foreach (var group in groups)
                {
                    try
                    {
                        var t = new ApTimeLine();
                        t.Minute = group.Key;
                        var lv = p.TimeLine[t.Minute].Level;
                        t.PlayerId = p.ParticipantId;
                        t.MatchId = matchId;
                        t.TeamId = teamId;

                        foreach (var itemTimeline in group)
                        {
                            Item item;
                            if (patch.StartsWith("5.11"))
                                item = ItemsCache.GetItemV511(itemTimeline.ItemId);
                            else
                                item = ItemsCache.GetItemV514(itemTimeline.ItemId);

                            double itemAp = 0;
                            if (itemTimeline.EventType == "ITEM_PURCHASED")
                            {
                                items.Add(item);
                            }
                            else
                            {
                                items.Remove(item);
                            }

                            double totalAp = items.Sum(i => ItemStats.GetTotalAP(i,t.Minute,p.SelectedChampion)) + runesAp + runesApPerLv * lv;
                            if (items.Any(i => i.Name == "Rabadon's Deathcap"))
                            {
                                if (patch.StartsWith("5.11"))
                                    totalAp = totalAp * 1.30;
                                else
                                    totalAp = totalAp * 1.35;
                            }

                            if (apPerMin.ContainsKey(t.Minute))
                            {
                                apPerMin[t.Minute] = totalAp;
                            }
                            else
                            {
                                apPerMin.Add(new KeyValuePair<int, double>(t.Minute, totalAp));
                            }

                        }
                        t.Items = items.ToList();

                        t.CurrentGold = p.TimeLine[t.Minute].CurrentGold;
                        t.GoldSpent = items.Sum(i => i.GoldCost);

                        t.TotalMr = items.Sum(i => i.ItemStats.MR) + p.SelectedChampion.Stat.MagicResist + p.SelectedChampion.Stat.MagicResistPerLv * lv + runesMr + runesMrPerLv * lv; ;
                        t.TotalAp = apPerMin.LastOrDefault().Value;
                        timelines.Add(t);
                    }
                    catch {
                        throw;
                    }
                }
                return timelines;
            }
            catch {
                throw;
            }
        }
예제 #8
0
        private static void ProcessAverages()
        {
            var champs = Data.Entidades.Caches.ChampionsCache.Get();
            foreach (var champ in champs)
            {
                IList<ApTimeLine> timelines;
                using (var data = new Data.SqlData())
                {
                    timelines = data.GetTimelines(champ.Id);
                }

                var cleanTimelines = new List<ApTimeLine>();
                var matchgroups = timelines.GroupBy(t => t.MatchId);
                int j = 0;
                foreach (var match in matchgroups)
                {
                    var participantgroups = match.OrderBy(m => m.Minute).GroupBy(m => m.PlayerId);
                    foreach (var player in participantgroups)
                    {
                        for (int i = 0; i < player.Count() - 1; i++)
                        {

                            cleanTimelines.Add(player.ElementAt(i));

                            while (player.ElementAt(i + 1).Minute > cleanTimelines.ElementAt(j).Minute + 1)
                            {
                                var newmin = new ApTimeLine(cleanTimelines.ElementAt(j));
                                newmin.Minute++;
                                cleanTimelines.Add(newmin);
                                j++;
                            }
                            j++;
                        }
                    }
                }

                var patchgroups = cleanTimelines.GroupBy(t => t.Patch);
                foreach (var patch in patchgroups)
                {
                    var rankgroups = patch.GroupBy(p => p.Rank);
                    foreach (var rank in rankgroups)
                    {
                        var rolegroups = rank.GroupBy(p => Data.Entidades.EnumHelpers.GetRealRoles(p.Role, p.Lane));
                        foreach (var role in rolegroups)
                        {
                            var minutegroups = role.OrderBy(m => m.Minute).GroupBy(t => t.Minute);
                            foreach (var minute in minutegroups)
                            {
                                var items = new List<Item>();
                                foreach (var match in minute)
                                {
                                    match.Items = Data.Entidades.Caches.ItemsCache.RemoveTrinkets(match.Items);
                                    foreach (var item in match.Items)
                                    {
                                        items.Add(item);
                                    }
                                }

                                var q = from x in items
                                        group x by x into g
                                        let count = g.Count()
                                        orderby count descending
                                        select new { Value = g.Key, Count = count };

                                var e = q.OrderByDescending(i => i.Count).Take(10);

                                var avgt = new AvgTimeLine();
                                avgt.Minute = minute.Key;
                                avgt.ChampionId = champ.Id;
                                avgt.AvgAp = minute.Average(m => m.TotalAp);
                                avgt.AvgMr = minute.Average(m => m.TotalMr);
                                avgt.Patch = patch.Key;
                                avgt.AvgGoldSpent = (int)minute.Average(m => m.GoldSpent);
                                avgt.Rank = rank.Key;
                                avgt.Role = role.Key.ToString();
                                avgt.TotalGames = minute.Count();
                                avgt.Items = string.Join("|", e.Select(i => string.Format("{0}:{1}", i.Value.Id, i.Count)));
                                using (var data = new Data.SqlData())
                                {
                                    data.SaveAvgTimeLine(avgt);
                                }
                            }
                        }
                    }
                }
            }
        }