コード例 #1
0
ファイル: Database.cs プロジェクト: skeight/RiotControl
        List <AggregatedChampionStatistics> LoadAggregatedChampionStatisticsWithTemporaryView(Summoner summoner, MapType map, GameModeType gameMode, DbConnection connection)
        {
            Profiler profiler = new Profiler(false, "LoadAggregatedChampionStatisticsWithTemporaryView", GlobalHandler);
            string   viewName = GetViewName();

            try
            {
                //Create a temporary view with a dynamically generated name to emulate the former CTE
                string temporaryString = connection.IsMySQL() ? "" : "temporary ";
                string createViewQuery = "create " + temporaryString + "view {0} as select game.map, game.game_mode, game.blue_team_id, game.purple_team_id, game.blue_team_won, player.team_id, player.summoner_id, player.champion_id, player.kills, player.deaths, player.assists, player.gold, player.minion_kills from game, player where game.blue_team_id = player.team_id or game.purple_team_id = player.team_id";
                using (var createView = Command(createViewQuery, connection, viewName))
                {
                    createView.Execute();
                    string commonWhereClause = string.Format("{0}.summoner_id = :summoner_id and {0}.map = :map and {0}.game_mode = :game_mode", viewName);
                    string selectQuery       =
                        "select statistics.champion_id, coalesce(champion_wins.wins, 0) as wins, coalesce(champion_losses.losses, 0) as losses, statistics.kills, statistics.deaths, statistics.assists, statistics.gold, statistics.minion_kills from " +
                        "(select {0}.champion_id, sum({0}.kills) as kills, sum({0}.deaths) as deaths, sum({0}.assists) as assists, sum({0}.gold) as gold, sum({0}.minion_kills) as minion_kills from {0} where {1} group by {0}.champion_id) " +
                        "as statistics " +
                        "left outer join " +
                        "(select champion_id, count(*) as wins from {0} where {1} and ((blue_team_won = 1 and blue_team_id = team_id) or (blue_team_won = 0 and purple_team_id = team_id)) group by champion_id) " +
                        "as champion_wins " +
                        "on statistics.champion_id = champion_wins.champion_id " +
                        "left outer join " +
                        "(select champion_id, count(*) as losses from {0} where {1} and ((blue_team_won = 0 and blue_team_id = team_id) or (blue_team_won = 1 and purple_team_id = team_id)) group by champion_id) " +
                        "as champion_losses " +
                        "on statistics.champion_id = champion_losses.champion_id";
                    using (var select = Command(selectQuery, connection, viewName, commonWhereClause))
                    {
                        select.Set("map", map);
                        select.Set("game_mode", gameMode);
                        select.Set("summoner_id", summoner.Id);
                        profiler.Start("ExecuteReader");
                        using (var reader = select.ExecuteReader())
                        {
                            profiler.Stop();
                            profiler.Start("AggregatedChampionStatistics/drop");
                            List <AggregatedChampionStatistics> output = new List <AggregatedChampionStatistics>();
                            while (reader.Read())
                            {
                                AggregatedChampionStatistics statistics = new AggregatedChampionStatistics(reader);
                                output.Add(statistics);
                            }
                            reader.Close();
                            using (var dropView = Command("drop view {0}", connection, viewName))
                                dropView.Execute();
                            profiler.Stop();
                            return(output);
                        }
                    }
                }
            }
            finally
            {
                ReleaseViewName(viewName);
            }
        }
コード例 #2
0
 void Start()
 {
     if (CommandProfiler != null)
     {
         CommandProfiler.Start(Query);
     }
 }
コード例 #3
0
ファイル: Database.cs プロジェクト: skeight/RiotControl
        SummonerStatistics GetSummonerStatistics(Summoner summoner, DbConnection connection)
        {
            Profiler profiler = new Profiler(false, "GetSummonerStatistics", GlobalHandler);

            profiler.Start("GetSummonerRatings");
            List <SummonerRating> ratings = GetSummonerRatings(summoner, connection);

            profiler.Stop();
            profiler.Start("GetSummonerRankedStatistics");
            List <List <SummonerRankedStatistics> > rankedStatistics = new List <List <SummonerRankedStatistics> >();

            for (int i = 0; i < StatisticsService.Seasons; i++)
            {
                rankedStatistics.Add(GetSummonerRankedStatistics(summoner, i, connection));
            }
            profiler.Stop();
            profiler.Start("twistedTreelineStatistics");
            List <AggregatedChampionStatistics> twistedTreelineStatistics = LoadAggregatedChampionStatistics(summoner, MapType.TwistedTreeline, GameModeType.Normal, connection);

            profiler.Stop();
            profiler.Start("summonersRiftStatistics");
            List <AggregatedChampionStatistics> summonersRiftStatistics = LoadAggregatedChampionStatistics(summoner, MapType.SummonersRift, GameModeType.Normal, connection);

            profiler.Stop();
            profiler.Start("dominionStatistics");
            List <AggregatedChampionStatistics> dominionStatistics = LoadAggregatedChampionStatistics(summoner, MapType.Dominion, GameModeType.Normal, connection);

            profiler.Stop();
            profiler.Start("SummonerStatistics");
            SummonerStatistics statistics = new SummonerStatistics(ratings, rankedStatistics, twistedTreelineStatistics, summonersRiftStatistics, dominionStatistics);

            profiler.Stop();
            return(statistics);
        }
コード例 #4
0
ファイル: Handler.cs プロジェクト: skeight/RiotControl
        Reply ApiSummonerStatistics(Request request)
        {
            Profiler profiler = new Profiler(false, "ApiSummonerStatistics", GlobalHandler);

            profiler.Start("PrivilegeCheck");
            PrivilegeCheck(request);
            profiler.Stop();
            profiler.Start("GetSummoner");
            var    arguments          = request.Arguments;
            string regionAbbreviation = (string)request.Arguments[0];
            int    accountId          = (int)request.Arguments[1];
            Worker worker             = GetWorkerByAbbreviation(regionAbbreviation);
            SummonerStatisticsResult output;
            Summoner summoner = StatisticsService.GetSummoner(worker.Region, accountId);

            profiler.Stop();
            if (summoner != null)
            {
                using (var connection = GetConnection())
                {
                    profiler.Start("GetSummonerStatistics");
                    SummonerStatistics statistics = GetSummonerStatistics(summoner, connection);
                    profiler.Stop();
                    profiler.Start("SummonerStatisticsResult");
                    output = new SummonerStatisticsResult(statistics);
                    profiler.Stop();
                }
            }
            else
            {
                output = new SummonerStatisticsResult(OperationResult.NotFound);
            }
            profiler.Start("GetJSONReply");
            Reply reply = GetJSONReply(output);

            profiler.Stop();
            return(reply);
        }
コード例 #5
0
ファイル: Database.cs プロジェクト: skeight/RiotControl
 List<AggregatedChampionStatistics> LoadAggregatedChampionStatisticsWithTemporaryView(Summoner summoner, MapType map, GameModeType gameMode, DbConnection connection)
 {
     Profiler profiler = new Profiler(false, "LoadAggregatedChampionStatisticsWithTemporaryView", GlobalHandler);
     string viewName = GetViewName();
     try
     {
         //Create a temporary view with a dynamically generated name to emulate the former CTE
         string temporaryString = connection.IsMySQL() ? "" : "temporary ";
         string createViewQuery = "create " + temporaryString + "view {0} as select game.map, game.game_mode, game.blue_team_id, game.purple_team_id, game.blue_team_won, player.team_id, player.summoner_id, player.champion_id, player.kills, player.deaths, player.assists, player.gold, player.minion_kills from game, player where game.blue_team_id = player.team_id or game.purple_team_id = player.team_id";
         using (var createView = Command(createViewQuery, connection, viewName))
         {
             createView.Execute();
             string commonWhereClause = string.Format("{0}.summoner_id = :summoner_id and {0}.map = :map and {0}.game_mode = :game_mode", viewName);
             string selectQuery =
                 "select statistics.champion_id, coalesce(champion_wins.wins, 0) as wins, coalesce(champion_losses.losses, 0) as losses, statistics.kills, statistics.deaths, statistics.assists, statistics.gold, statistics.minion_kills from " +
                 "(select {0}.champion_id, sum({0}.kills) as kills, sum({0}.deaths) as deaths, sum({0}.assists) as assists, sum({0}.gold) as gold, sum({0}.minion_kills) as minion_kills from {0} where {1} group by {0}.champion_id) " +
                 "as statistics " +
                 "left outer join " +
                 "(select champion_id, count(*) as wins from {0} where {1} and ((blue_team_won = 1 and blue_team_id = team_id) or (blue_team_won = 0 and purple_team_id = team_id)) group by champion_id) " +
                 "as champion_wins " +
                 "on statistics.champion_id = champion_wins.champion_id " +
                 "left outer join " +
                 "(select champion_id, count(*) as losses from {0} where {1} and ((blue_team_won = 0 and blue_team_id = team_id) or (blue_team_won = 1 and purple_team_id = team_id)) group by champion_id) " +
                 "as champion_losses " +
                 "on statistics.champion_id = champion_losses.champion_id";
             using (var select = Command(selectQuery, connection, viewName, commonWhereClause))
             {
                 select.Set("map", map);
                 select.Set("game_mode", gameMode);
                 select.Set("summoner_id", summoner.Id);
                 profiler.Start("ExecuteReader");
                 using (var reader = select.ExecuteReader())
                 {
                     profiler.Stop();
                     profiler.Start("AggregatedChampionStatistics/drop");
                     List<AggregatedChampionStatistics> output = new List<AggregatedChampionStatistics>();
                     while (reader.Read())
                     {
                         AggregatedChampionStatistics statistics = new AggregatedChampionStatistics(reader);
                         output.Add(statistics);
                     }
                     reader.Close();
                     using (var dropView = Command("drop view {0}", connection, viewName))
                         dropView.Execute();
                     profiler.Stop();
                     return output;
                 }
             }
         }
     }
     finally
     {
         ReleaseViewName(viewName);
     }
 }
コード例 #6
0
ファイル: Database.cs プロジェクト: skeight/RiotControl
 SummonerStatistics GetSummonerStatistics(Summoner summoner, DbConnection connection)
 {
     Profiler profiler = new Profiler(false, "GetSummonerStatistics", GlobalHandler);
     profiler.Start("GetSummonerRatings");
     List<SummonerRating> ratings = GetSummonerRatings(summoner, connection);
     profiler.Stop();
     profiler.Start("GetSummonerRankedStatistics");
     List<List<SummonerRankedStatistics>> rankedStatistics = new List<List<SummonerRankedStatistics>>();
     for (int i = 0; i < StatisticsService.Seasons; i++)
         rankedStatistics.Add(GetSummonerRankedStatistics(summoner, i, connection));
     profiler.Stop();
     profiler.Start("twistedTreelineStatistics");
     List<AggregatedChampionStatistics> twistedTreelineStatistics = LoadAggregatedChampionStatistics(summoner, MapType.TwistedTreeline, GameModeType.Normal, connection);
     profiler.Stop();
     profiler.Start("summonersRiftStatistics");
     List<AggregatedChampionStatistics> summonersRiftStatistics = LoadAggregatedChampionStatistics(summoner, MapType.SummonersRift, GameModeType.Normal, connection);
     profiler.Stop();
     profiler.Start("dominionStatistics");
     List<AggregatedChampionStatistics> dominionStatistics = LoadAggregatedChampionStatistics(summoner, MapType.Dominion, GameModeType.Normal, connection);
     profiler.Stop();
     profiler.Start("SummonerStatistics");
     SummonerStatistics statistics = new SummonerStatistics(ratings, rankedStatistics, twistedTreelineStatistics, summonersRiftStatistics, dominionStatistics);
     profiler.Stop();
     return statistics;
 }
コード例 #7
0
ファイル: Handler.cs プロジェクト: skeight/RiotControl
 Reply ApiSummonerStatistics(Request request)
 {
     Profiler profiler = new Profiler(false, "ApiSummonerStatistics", GlobalHandler);
     profiler.Start("PrivilegeCheck");
     PrivilegeCheck(request);
     profiler.Stop();
     profiler.Start("GetSummoner");
     var arguments = request.Arguments;
     string regionAbbreviation = (string)request.Arguments[0];
     int accountId = (int)request.Arguments[1];
     Worker worker = GetWorkerByAbbreviation(regionAbbreviation);
     SummonerStatisticsResult output;
     Summoner summoner = StatisticsService.GetSummoner(worker.Region, accountId);
     profiler.Stop();
     if (summoner != null)
     {
         using (var connection = GetConnection())
         {
             profiler.Start("GetSummonerStatistics");
             SummonerStatistics statistics = GetSummonerStatistics(summoner, connection);
             profiler.Stop();
             profiler.Start("SummonerStatisticsResult");
             output = new SummonerStatisticsResult(statistics);
             profiler.Stop();
         }
     }
     else
         output = new SummonerStatisticsResult(OperationResult.NotFound);
     profiler.Start("GetJSONReply");
     Reply reply = GetJSONReply(output);
     profiler.Stop();
     return reply;
 }