Beispiel #1
0
        void UpdateSummoner(Summoner summoner, AllPublicSummonerDataDTO publicSummonerData, AggregatedStats[] aggregatedStats, PlayerLifeTimeStats lifeTimeStatistics, RecentGames recentGames, DbConnection connection)
        {
            int accountId = summoner.AccountId;

            lock (ActiveAccountIds)
            {
                // Avoid concurrent updates of the same account, it's asking for trouble and is redundant anyways
                // We might obtain outdated results in one query but that's a minor issue in comparison to corrupted database results
                if (ActiveAccountIds.Contains(accountId))
                    return;

                ActiveAccountIds.Add(accountId);
            }

            // Use a transaction because we're going to insert a fair amount of data
            using (var transaction = connection.BeginTransaction())
            {
                UpdateSummonerFields(summoner, connection, true);
                UpdateRunes(summoner, publicSummonerData, connection);

                UpdateSummonerRatings(summoner, lifeTimeStatistics, connection);
                // A season value of zero indicates the current season only
                for (int season = 0; season < aggregatedStats.Length; season++)
                    UpdateSummonerRankedStatistics(summoner, season, aggregatedStats[season], connection);
                UpdateSummonerGames(summoner, recentGames, connection);

                transaction.Commit();
            }

            lock (ActiveAccountIds)
                ActiveAccountIds.Remove(accountId);
        }
        public ChampionStatistics(int championId, AggregatedStats statistics)
        {
            ChampionId = championId;
            Statistics = statistics;

            Wins = Load("TOTAL_SESSIONS_WON");
            Losses = Load("TOTAL_SESSIONS_LOST");

            Kills = Load("TOTAL_CHAMPION_KILLS");
            Deaths = Load("TOTAL_DEATHS_PER_SESSION");
            Assists = Load("TOTAL_ASSISTS");

            MinionKills = Load("TOTAL_MINION_KILLS");

            Gold = Load("TOTAL_GOLD_EARNED");

            TurretsDestroyed = Load("TOTAL_TURRETS_KILLED");

            DamageDealt = Load("TOTAL_DAMAGE_DEALT");
            PhysicalDamageDealt = Load("TOTAL_PHYSICAL_DAMAGE_DEALT");
            MagicalDamageDealt = Load("TOTAL_MAGIC_DAMAGE_DEALT");

            DamageTaken = Load("TOTAL_DAMAGE_TAKEN");

            DoubleKills = Load("TOTAL_DOUBLE_KILLS");
            TripleKills = Load("TOTAL_TRIPLE_KILLS");
            QuadraKills = Load("TOTAL_QUADRA_KILLS");
            PentaKills = Load("TOTAL_PENTA_KILLS");

            TimeSpentDead = Load("TOTAL_TIME_SPENT_DEAD");

            MaximumKills = Load("MAX_CHAMPIONS_KILLED");
            MaximumDeaths = Load("MAX_NUM_DEATHS");
        }
 public static List<ChampionStatistics> GetChampionStatistics(AggregatedStats statistics)
 {
     Dictionary<int, ChampionStatistics> output = new Dictionary<int, ChampionStatistics>();
     foreach (var statisticsEntry in statistics.lifetimeStatistics)
     {
         int key = statisticsEntry.championId;
         if (key == 0)
             continue;
         if (output.ContainsKey(key))
             continue;
         ChampionStatistics newEntry = new ChampionStatistics(key, statistics);
         output[key] = newEntry;
     }
     return output.Values.ToList();
 }
        void UpdateSummonerRankedStatistics(SummonerDescription summoner, AggregatedStats aggregatedStatistics)
        {
            List<string> fields = new List<string>()
            {
                "summoner_id",

                "champion_id",

                "wins",
                "losses",

                "kills",
                "deaths",
                "assists",

                "minion_kills",

                "gold",

                "turrets_destroyed",

                "damage_dealt",
                "physical_damage_dealt",
                "magical_damage_dealt",

                "damage_taken",

                "double_kills",
                "triple_kills",
                "quadra_kills",
                "penta_kills",

                "time_spent_dead",

                "maximum_kills",
                "maximum_deaths",
            };

            List<ChampionStatistics> statistics = ChampionStatistics.GetChampionStatistics(aggregatedStatistics);
            foreach (var champion in statistics)
            {
                SQLCommand championUpdate = Command("update summoner_ranked_statistics set wins = :wins, losses = :losses, kills = :kills, deaths = :deaths, assists = :assists, minion_kills = :minion_kills, gold = :gold, turrets_destroyed = :turrets_destroyed, damage_dealt = :damage_dealt, physical_damage_dealt = :physical_damage_dealt, magical_damage_dealt = :magical_damage_dealt, damage_taken = :damage_taken, double_kills = :double_kills, triple_kills = :triple_kills, quadra_kills = :quadra_kills, penta_kills = :penta_kills, time_spent_dead = :time_spent_dead, maximum_kills = :maximum_kills, maximum_deaths = :maximum_deaths where summoner_id = :summoner_id and champion_id = :champion_id");
                championUpdate.SetFieldNames(fields);

                championUpdate.Set(summoner.Id);

                championUpdate.Set(champion.ChampionId);

                championUpdate.Set(champion.Wins);
                championUpdate.Set(champion.Losses);

                championUpdate.Set(champion.Kills);
                championUpdate.Set(champion.Deaths);
                championUpdate.Set(champion.Assists);

                championUpdate.Set(champion.MinionKills);

                championUpdate.Set(champion.Gold);

                championUpdate.Set(champion.TurretsDestroyed);

                championUpdate.Set(champion.DamageDealt);
                championUpdate.Set(champion.PhysicalDamageDealt);
                championUpdate.Set(champion.MagicalDamageDealt);

                championUpdate.Set(champion.DamageTaken);

                championUpdate.Set(champion.DoubleKills);
                championUpdate.Set(champion.TripleKills);
                championUpdate.Set(champion.QuadraKills);
                championUpdate.Set(champion.PentaKills);

                championUpdate.Set(champion.TimeSpentDead);

                championUpdate.Set(champion.MaximumKills);
                championUpdate.Set(champion.MaximumDeaths);

                int rowsAffected = championUpdate.Execute();

                if (rowsAffected == 0)
                {
                    //The champion entry didn't exist yet so we must create a new entry first
                    string queryFields = GetGroupString(fields);
                    string queryValues = GetPlaceholderString(fields);
                    SQLCommand championInsert = Command(string.Format("insert into summoner_ranked_statistics ({0}) values ({1})", queryFields, queryValues));
                    championInsert.CopyParameters(championUpdate);
                    championInsert.Execute();
                }
            }
        }
Beispiel #5
0
 void GetAggregatedStatistics(AggregatedStats aggregatedStatistics)
 {
     AggregatedStatistics = aggregatedStatistics;
     ProcessReply();
 }
        void UpdateSummonerRankedStatistics(Summoner summoner, int season, AggregatedStats aggregatedStatistics, DbConnection connection)
        {
            // Remove the existing ranked stats for this season
            using (var championUpdate = Command("delete from summoner_ranked_statistics where summoner_id = :summoner_id and season = :season", connection))
            {
                championUpdate.Set("summoner_id", summoner.Id);
                championUpdate.Set("season", season);
                championUpdate.Execute();
            }
            List<ChampionStatistics> statistics = ChampionStatistics.GetChampionStatistics(aggregatedStatistics);
            foreach (var champion in statistics)
            {
                using (var championUpdate = Command("update summoner_ranked_statistics set wins = :wins, losses = :losses, kills = :kills, deaths = :deaths, assists = :assists, minion_kills = :minion_kills, gold = :gold, turrets_destroyed = :turrets_destroyed, damage_dealt = :damage_dealt, physical_damage_dealt = :physical_damage_dealt, magical_damage_dealt = :magical_damage_dealt, damage_taken = :damage_taken, double_kills = :double_kills, triple_kills = :triple_kills, quadra_kills = :quadra_kills, penta_kills = :penta_kills, time_spent_dead = :time_spent_dead, maximum_kills = :maximum_kills, maximum_deaths = :maximum_deaths where summoner_id = :summoner_id and season = :season and champion_id = :champion_id", connection))
                {
                    SetSummonerRankedStatisticsParameters(championUpdate, summoner, season, champion);

                    int rowsAffected = championUpdate.Execute();

                    if (rowsAffected == 0)
                    {
                        //The champion entry didn't exist yet so we must create a new entry first
                        string query = string.Format("insert into summoner_ranked_statistics ({0}) values ({1})", GetGroupString(SummonerRankedStatisticsFields), GetPlaceholderString(SummonerRankedStatisticsFields));
                        using (var championInsert = Command(query, connection))
                        {
                            SetSummonerRankedStatisticsParameters(championInsert, summoner, season, champion);
                            championInsert.Execute();
                        }
                    }
                }
            }
        }
Beispiel #7
0
 void GetAggregatedStatistics(AggregatedStats aggregatedStatistics, int season)
 {
     AggregatedStatistics[season] = aggregatedStatistics;
     ProcessReply();
 }
Beispiel #8
0
        private void updateSummoner(PublicSummoner pSumm, PlayerLifeTimeStats summStats, AggregatedStats aggStats, AllPublicSummonerDataDTO summPages, MasteryBook masteries)
        {
            PlayerStatSummary rSolo5x5;
            PlayerStatSummary rTeam5x5;
            PlayerStatSummary normal5x5;
            List<ChampionStatistics> champStats = ChampionStatistics.GetChampionStatistics(aggStats);

            db.updateSummoner("summonerLevel", pSumm.summonerLevel.ToString(), pSumm.summonerId);
            db.updateSummoner("profileIconId", pSumm.profileIconId.ToString(), pSumm.summonerId);

            if ((rSolo5x5 = summStats.getRankedSolo5x5()) != null)
            {
                db.updateSummoner("solo5x5_elo", rSolo5x5.rating.ToString(), pSumm.summonerId);
                db.updateSummoner("solo5x5_wins", rSolo5x5.wins.ToString(), pSumm.summonerId);
                db.updateSummoner("solo5x5_losses", rSolo5x5.losses.ToString(), pSumm.summonerId);
                db.updateSummoner("solo5x5_maxElo", rSolo5x5.maxRating.ToString(), pSumm.summonerId);
            }

            if ((rTeam5x5 = summStats.getRankedTeam5x5()) != null)
            {
                db.updateSummoner("team5x5_elo", rTeam5x5.rating.ToString(), pSumm.summonerId);
                db.updateSummoner("team5x5_wins", rTeam5x5.wins.ToString(), pSumm.summonerId);
                db.updateSummoner("team5x5_losses", rTeam5x5.losses.ToString(), pSumm.summonerId);
                db.updateSummoner("team5x5_maxElo", rTeam5x5.maxRating.ToString(), pSumm.summonerId);
            }

            if ((normal5x5 = summStats.getNormal5x5()) != null)
            {
                db.updateSummoner("normal5x5_elo", normal5x5.rating.ToString(), pSumm.summonerId);
                db.updateSummoner("normal5x5_wins", normal5x5.wins.ToString(), pSumm.summonerId);
                db.updateSummoner("normal5x5_losses", normal5x5.losses.ToString(), pSumm.summonerId);
                db.updateSummoner("normal5x5_maxElo", normal5x5.maxRating.ToString(), pSumm.summonerId);
            }

            db.updateSummoner("ranked_kills", ChampionStatistics.totalRankedKills(champStats).ToString(), pSumm.summonerId);
            db.updateSummoner("ranked_assists", ChampionStatistics.totalRankedAssists(champStats).ToString(), pSumm.summonerId);
            db.updateSummoner("ranked_deaths", ChampionStatistics.totalRankedDeaths(champStats).ToString(), pSumm.summonerId);
            db.updateSummoner("ranked_pentaKills", ChampionStatistics.totalRankedPentaKills(champStats).ToString(), pSumm.summonerId);
            db.updateSummoner("ranked_quadraKills", ChampionStatistics.totalRankedQuadraKills(champStats).ToString(), pSumm.summonerId);
            db.updateSummoner("ranked_tripleKills", ChampionStatistics.totalRankedTripleKills(champStats).ToString(), pSumm.summonerId);
            db.updateSummoner("ranked_doubleKills", ChampionStatistics.totalRankedDoubleKills(champStats).ToString(), pSumm.summonerId);
            db.updateSummoner("ranked_minionKills", ChampionStatistics.totalRankedMinionKills(champStats).ToString(), pSumm.summonerId);
            db.updateSummoner("ranked_goldEarned", ChampionStatistics.totalRankedGoldEarned(champStats).ToString(), pSumm.summonerId);
            db.updateSummoner("ranked_turretsDestroyed", ChampionStatistics.totalRankedTurretsDestroyed(champStats).ToString(), pSumm.summonerId);
            db.updateSummoner("ranked_mostKills", ChampionStatistics.rankedMostKills(champStats).ToString(), pSumm.summonerId);
            db.updateSummoner("ranked_mostDeaths", ChampionStatistics.rankedMostDeaths(champStats).ToString(), pSumm.summonerId);

            /** Update Runes and Masteries */
        }