示例#1
0
        public IHttpActionResult GetPlayerDota(int PlayerID)
        {
            PlayerGame pg = db.PlayerGames.Where(x => x.IDGamer == PlayerID && x.IDGame == (int)Games.Dota).FirstOrDefault();

            if (pg == null)
            {
                return(NotFound());
            }
            DotaPlayer a = DotaAPI.GetPlayer(pg.IdAPI, pg.IDGamer).Result;

            return(Ok(a));
        }
示例#2
0
        public async Task <IHttpActionResult> GetNearPlayer(int PlayerID, float percent)
        {
            Graph <Player, Match, string> graph = new Graph <Player, Match, string>((Match e) => { return(e.Weight != 0 ? 1 / e.Weight : float.MaxValue); });

            PlayerGame currentPlayer = db.PlayerGames.Where(x => x.IDGamer == PlayerID).FirstOrDefault();

            foreach (var m in db.Matches.ToArray())
            {
                var p1 = db.PlayerGames.Where(x => x.IDGamer == m.IdPlayer1 && x.IDGame == (int)Games.Overwatch).FirstOrDefault();
                var p2 = db.PlayerGames.Where(x => x.IDGamer == m.IdPlayer2 && x.IDGame == (int)Games.Overwatch).FirstOrDefault();

                if (p1 != null && p2 != null)
                {
                    graph.AddVertice(m.Player1, p1.IdAPI);
                    graph.AddVertice(m.Player2, p2.IdAPI);
                    graph.AddAresta(p1.IdAPI, p2.IdAPI, m);
                }
            }

            DotaPlayer dotaPlayer = await DotaAPI.GetPlayer(currentPlayer.IdAPI, PlayerID);

            PlayerStats career = dotaPlayer.stats;
            float       perc   = percent / 100.0f;

            DotaFilter filter = new DotaFilter
            {
                mmr_estimate = new int[] { (int)(dotaPlayer.mmr_estimate.estimate * (1.0f - perc)), (int)(dotaPlayer.mmr_estimate.estimate * (1.0f + perc)) },
                kills        = new int[] { (int)(career.kills * (1.0f - perc)), (int)(career.kills * (1.0f + perc)) },
                xp_per_min   = new int[] { (int)(career.xp_per_min * (1.0f - perc)), (int)(career.xp_per_min * (1.0f + perc)) },
                hero_damage  = new int[] { (int)(career.hero_damage * (1.0f - perc)), (int)(career.hero_damage * (1.0f + perc)) },
                gold_per_min = new int[] { (int)(career.gold_per_min * (1.0f - perc)), (int)(career.gold_per_min * (1.0f + perc)) },
            };

            var sorted = graph.ShortPath(currentPlayer.IdAPI).OrderBy(x => x.Value).Skip(1).Take(graph.vertCount);
            List <DotaPlayer> players = new List <DotaPlayer>(sorted.Count());

            foreach (var v in sorted)
            {
                DotaPlayer pp = await DotaAPI.GetPlayer(v.Key, 0);

                if (filterDota(pp, filter))
                {
                    players.Add(pp);
                }
            }

            return(Ok(players));
        }
示例#3
0
        bool filterDota(DotaPlayer p, DotaFilter filter)
        {
            bool ret = true;

            //assists
            if (!ret)
            {
                return(false);
            }
            if (filter.assists != null)
            {
                if (filter.assists.Length > 1)
                {
                    if (filter.assists[1] == -1)
                    {
                        ret = p.stats.assists > filter.assists[0];
                    }
                    else if (filter.assists[1] > -1 && filter.assists[0] > -1)
                    {
                        ret = (p.stats.assists > filter.assists[0] && p.stats.assists < filter.assists[1]);
                    }
                    else if (filter.assists[0] == -1)
                    {
                        ret = p.stats.assists < filter.assists[1];
                    }
                }
                else
                {
                    ret = p.stats.assists == filter.assists[0];
                }
            }

            //competitive_rank
            if (!ret)
            {
                return(false);
            }
            if (filter.competitive_rank != null)
            {
                if (filter.competitive_rank.Length > 1)
                {
                    if (filter.competitive_rank[1] == -1)
                    {
                        ret = p.competitive_rank > filter.competitive_rank[0];
                    }
                    else if (filter.competitive_rank[1] > -1 && filter.competitive_rank[0] > -1)
                    {
                        ret = (p.competitive_rank > filter.competitive_rank[0] && p.competitive_rank < filter.competitive_rank[1]);
                    }
                    else if (filter.competitive_rank[0] == -1)
                    {
                        ret = p.competitive_rank < filter.competitive_rank[1];
                    }
                }
                else
                {
                    ret = p.competitive_rank == filter.competitive_rank[0];
                }
            }

            //deaths
            if (!ret)
            {
                return(false);
            }
            if (filter.deaths != null)
            {
                if (filter.deaths.Length > 1)
                {
                    if (filter.deaths[1] == -1)
                    {
                        ret = p.stats.deaths > filter.deaths[0];
                    }
                    else if (filter.deaths[1] > -1 && filter.deaths[0] > -1)
                    {
                        ret = (p.stats.deaths > filter.deaths[0] && p.stats.deaths < filter.deaths[1]);
                    }
                    else if (filter.deaths[0] == -1)
                    {
                        ret = p.stats.deaths < filter.deaths[1];
                    }
                }
                else
                {
                    ret = p.stats.deaths == filter.deaths[0];
                }
            }

            //gold_per_min
            if (!ret)
            {
                return(false);
            }
            if (filter.gold_per_min != null)
            {
                if (filter.gold_per_min.Length > 1)
                {
                    if (filter.gold_per_min[1] == -1)
                    {
                        ret = p.stats.gold_per_min > filter.gold_per_min[0];
                    }
                    else if (filter.gold_per_min[1] > -1 && filter.gold_per_min[0] > -1)
                    {
                        ret = (p.stats.gold_per_min > filter.gold_per_min[0] && p.stats.gold_per_min < filter.gold_per_min[1]);
                    }
                    else if (filter.gold_per_min[0] == -1)
                    {
                        ret = p.stats.gold_per_min < filter.gold_per_min[1];
                    }
                }
                else
                {
                    ret = p.stats.gold_per_min == filter.gold_per_min[0];
                }
            }

            //hero damage
            if (!ret)
            {
                return(false);
            }
            if (filter.hero_damage != null)
            {
                if (filter.hero_damage.Length > 1)
                {
                    if (filter.hero_damage[1] == -1)
                    {
                        ret = p.stats.hero_damage > filter.hero_damage[0];
                    }
                    else if (filter.hero_damage[1] > -1 && filter.hero_damage[0] > -1)
                    {
                        ret = (p.stats.hero_damage > filter.hero_damage[0] && p.stats.hero_damage < filter.hero_damage[1]);
                    }
                    else if (filter.hero_damage[0] == -1)
                    {
                        ret = p.stats.hero_damage < filter.hero_damage[1];
                    }
                }
                else
                {
                    ret = p.stats.hero_damage == filter.hero_damage[0];
                }
            }

            //hero healing
            if (!ret)
            {
                return(false);
            }
            if (filter.hero_healing != null)
            {
                if (filter.hero_healing.Length > 1)
                {
                    if (filter.hero_healing[1] == -1)
                    {
                        ret = p.stats.hero_healing > filter.hero_healing[0];
                    }
                    else if (filter.hero_healing[1] > -1 && filter.hero_healing[0] > -1)
                    {
                        ret = (p.stats.hero_healing > filter.hero_healing[0] && p.stats.hero_healing < filter.hero_healing[1]);
                    }
                    else if (filter.hero_healing[0] == -1)
                    {
                        ret = p.stats.hero_healing < filter.hero_healing[1];
                    }
                }
                else
                {
                    ret = p.stats.hero_healing == filter.hero_healing[0];
                }
            }

            //kills
            if (!ret)
            {
                return(false);
            }
            if (filter.kills != null)
            {
                if (filter.kills.Length > 1)
                {
                    if (filter.kills[1] == -1)
                    {
                        ret = p.stats.kills > filter.kills[0];
                    }
                    else if (filter.kills[1] > -1 && filter.kills[0] > -1)
                    {
                        ret = (p.stats.kills > filter.kills[0] && p.stats.kills < filter.kills[1]);
                    }
                    else if (filter.kills[0] == -1)
                    {
                        ret = p.stats.kills < filter.kills[1];
                    }
                }
                else
                {
                    ret = p.stats.kills == filter.kills[0];
                }
            }

            //last_hits
            if (!ret)
            {
                return(false);
            }
            if (filter.last_hits != null)
            {
                if (filter.last_hits.Length > 1)
                {
                    if (filter.last_hits[1] == -1)
                    {
                        ret = p.stats.last_hits > filter.last_hits[0];
                    }
                    else if (filter.last_hits[1] > -1 && filter.last_hits[0] > -1)
                    {
                        ret = (p.stats.last_hits > filter.last_hits[0] && p.stats.last_hits < filter.last_hits[1]);
                    }
                    else if (filter.last_hits[0] == -1)
                    {
                        ret = p.stats.last_hits < filter.last_hits[1];
                    }
                }
                else
                {
                    ret = p.stats.last_hits == filter.last_hits[0];
                }
            }

            //mmr_estimate
            if (!ret)
            {
                return(false);
            }
            if (filter.mmr_estimate != null)
            {
                if (filter.mmr_estimate.Length > 1)
                {
                    if (filter.mmr_estimate[1] == -1)
                    {
                        ret = p.mmr_estimate.estimate > filter.mmr_estimate[0];
                    }
                    else if (filter.mmr_estimate[1] > -1 && filter.mmr_estimate[0] > -1)
                    {
                        ret = (p.mmr_estimate.estimate > filter.mmr_estimate[0] && p.mmr_estimate.estimate < filter.mmr_estimate[1]);
                    }
                    else if (filter.mmr_estimate[0] == -1)
                    {
                        ret = p.mmr_estimate.estimate < filter.mmr_estimate[1];
                    }
                }
                else
                {
                    ret = p.mmr_estimate.estimate == filter.mmr_estimate[0];
                }
            }

            //rank_tier
            if (!ret)
            {
                return(false);
            }
            if (filter.rank_tier != null)
            {
                if (filter.rank_tier.Length > 1)
                {
                    if (filter.rank_tier[1] == -1)
                    {
                        ret = p.rank_tier > filter.rank_tier[0];
                    }
                    else if (filter.rank_tier[1] > -1 && filter.rank_tier[0] > -1)
                    {
                        ret = (p.rank_tier > filter.rank_tier[0] && p.rank_tier < filter.rank_tier[1]);
                    }
                    else if (filter.rank_tier[0] == -1)
                    {
                        ret = p.rank_tier < filter.rank_tier[1];
                    }
                }
                else
                {
                    ret = p.rank_tier == filter.rank_tier[0];
                }
            }

            //tower_damage
            if (!ret)
            {
                return(false);
            }
            if (filter.tower_damage != null)
            {
                if (filter.tower_damage.Length > 1)
                {
                    if (filter.tower_damage[1] == -1)
                    {
                        ret = p.stats.tower_damage > filter.tower_damage[0];
                    }
                    else if (filter.tower_damage[1] > -1 && filter.tower_damage[0] > -1)
                    {
                        ret = (p.stats.tower_damage > filter.tower_damage[0] && p.stats.tower_damage < filter.tower_damage[1]);
                    }
                    else if (filter.tower_damage[0] == -1)
                    {
                        ret = p.stats.tower_damage < filter.tower_damage[1];
                    }
                }
                else
                {
                    ret = p.stats.tower_damage == filter.tower_damage[0];
                }
            }

            //xp_per_min
            if (!ret)
            {
                return(false);
            }
            if (filter.xp_per_min != null)
            {
                if (filter.xp_per_min.Length > 1)
                {
                    if (filter.xp_per_min[1] == -1)
                    {
                        ret = p.stats.xp_per_min > filter.xp_per_min[0];
                    }
                    else if (filter.xp_per_min[1] > -1 && filter.xp_per_min[0] > -1)
                    {
                        ret = (p.stats.xp_per_min > filter.xp_per_min[0] && p.stats.xp_per_min < filter.xp_per_min[1]);
                    }
                    else if (filter.xp_per_min[0] == -1)
                    {
                        ret = p.stats.xp_per_min < filter.xp_per_min[1];
                    }
                }
                else
                {
                    ret = p.stats.xp_per_min == filter.xp_per_min[0];
                }
            }


            return(ret);
        }