示例#1
0
        public PlayerChampionStats BuildPlayerChampionStats(long summonerId, int championId, List <Match> matches)
        {
            int   wins = 0, losses = 0;
            float totalKills = 0, totalDeaths = 0, totalAssists = 0;
            float totalCs = 0, totalWardsPlaced = 0, totalWardsKilled = 0;
            long  totalGameTime = 0;

            foreach (Match match in matches)
            {
                int participantId = 0;
                foreach (ParticipantIdentity participantIdentity in match.participantIdentities)
                {
                    if (participantIdentity.player.summonerId == summonerId)
                    {
                        participantId = participantIdentity.ParticipantId;
                        break;
                    }
                }
                totalKills      += match.participants[participantId - 1].stats.kills;
                totalDeaths     += match.participants[participantId - 1].stats.deaths;
                totalAssists    += match.participants[participantId - 1].stats.assists;
                totalCs         += match.participants[participantId - 1].stats.neutralMinionsKilled + match.participants[participantId - 1].stats.totalMinionsKilled;
                totalWardsPlaced = match.participants[participantId - 1].stats.wardsPlaced;
                totalWardsKilled = match.participants[participantId - 1].stats.wardsKilled;
                if ((participantId < 6 && match.teams[0].win == "Win") || (participantId >= 6 && match.teams[0].win == "Fail"))
                {
                    wins++;
                }
                else
                {
                    losses++;
                }
                totalGameTime += match.gameDuration;
            }
            PlayerChampionStats playerChampionStats = new PlayerChampionStats()
            {
                championId           = championId,
                csPerMinute          = totalCs / (totalGameTime / 60),
                kda                  = (totalKills + totalAssists) / (totalDeaths),
                wardsPlacedPerMinute = totalWardsPlaced / (totalGameTime / 60),
                wardsKilledPerMinute = totalWardsKilled / (totalGameTime / 60),
                summonerId           = summonerId,
                wins                 = wins,
                losses               = losses
            };

            return(playerChampionStats);
        }
示例#2
0
        public void WritePlayerChampionStats(PlayerChampionStats playerChampionStats)
        {
            _sqlConnection.Open();
            string insertPlayerChampionStatsSQL = "INSERT INTO playerChampionStats(summonerId, championId, wins, losses, kda, csPerMin, wardsPlacedPerMinute, wardsKilledPerMinute) " +
                                                  "VALUES (" + playerChampionStats.summonerId + "," + playerChampionStats.championId + "," + playerChampionStats.wins + "," + playerChampionStats.losses + ","
                                                  + playerChampionStats.kda + "," + playerChampionStats.csPerMinute + "," + playerChampionStats.wardsPlacedPerMinute + "," + playerChampionStats.wardsKilledPerMinute + ");";

            try
            {
                new SQLiteCommand(insertPlayerChampionStatsSQL, _sqlConnection).ExecuteNonQuery();
            }
            catch
            {
            }
            _sqlConnection.Close();
        }