// GET: Players public ActionResult GetChallengerPlayers() { long playerCount = 0; string apiKey = DataController.GameData.apiKey; foreach (string region in DataController.GameData.gameRegions) { string json = new WebClient().DownloadString("https://" + region + ".api.pvp.net/api/lol/" + region + "/v2.5/league/challenger?type=RANKED_SOLO_5x5&api_key=" + apiKey); string JsonString = json.ToString(); JavaScriptSerializer serializer = new JavaScriptSerializer(); RootObject c = serializer.Deserialize <RootObject>(JsonString); foreach (Entry e in c.entries) { LoLPlayer p = new LoLPlayer { //playerOrTeamId = e.playerOrTeamId, //playerOrTeamName = e.playerOrTeamName, rank = "Challenger", region = region }; db.Players.Add(p); db.SaveChanges(); playerCount++; } } ViewBag.Count = playerCount; return(View()); }
// League Miner Crawler v 1.0 public ActionResult StartCrawler() { bool crawlerEnd = false; while (crawlerEnd == false) { ApplicationDbContext db = new ApplicationDbContext(); if (db.Players.Where(x => x.hasChecked == false).FirstOrDefault() != null) { // Get player who hasn't been 'crawled' LoLPlayer row = db.Players.Where(x => x.hasChecked == false).FirstOrDefault(); try { // Get matches played by that player in Ranked in patch 7.6 string jsonPlayerMatchlist = new WebClient().DownloadString("https://" + row.region + ".api.pvp.net/api/lol/" + row.region + "/v2.2/matchlist/by-summoner/" + row.playerOrTeamId + "?rankedQueues=TEAM_BUILDER_RANKED_SOLO&beginTime=1490229265895&api_key=" + DataController.GameData.apiKey); // Convert from JSON to object MatchlistQuery playerMatchilist = JsonConvert.DeserializeObject <MatchlistQuery>(jsonPlayerMatchlist); List <MatchInMatchlistQuery> matchesByPlayer = playerMatchilist.matches; // Loop through each match by a single player foreach (var match in matchesByPlayer.ToList()) { // Add matchlanes if they don't exist for this match and player if (!db.MatchLanes.Any(x => x.matchId == match.matchId && x.playerId == row.playerOrTeamId)) { db.MatchLanes.Add(new MatchLanes { matchId = match.matchId, playerId = row.playerOrTeamId, lane = match.lane, role = match.role }); } // If match doesn't exist if (!db.Matchlist.Any(x => x.matchId == match.matchId)) { // Add match data to db db.Matchlist.Add(new Matchlist { matchId = match.matchId, region = row.region, platformId = match.platformId, queue = match.queue, season = match.season, timestamp = match.timestamp }); db.SaveChanges(); Thread.Sleep(1000); // Get match data string json = new WebClient().DownloadString("https://" + row.region + ".api.pvp.net/api/lol/" + row.region + "/v2.2/match/" + match.matchId + "?api_key=" + DataController.GameData.apiKey); // Convert from JSON to object RootObject data = JsonConvert.DeserializeObject <RootObject>(json); // Add match data to db db.Match.Add(new MatchData { matchId = match.matchId, region = data.region, platformId = data.platformId, matchMode = data.matchMode, matchType = data.matchType, matchCreation = data.matchCreation, queueType = data.queueType, mapId = data.mapId, season = data.season, matchVersion = data.matchVersion }); // Get teams from query object List <Team> teams = data.teams; // Add teams to db foreach (Team t in teams) { db.Team.Add(new Team { matchid = match.matchId, teamId = t.teamId, winner = t.winner, firstBlood = t.firstBlood, firstTower = t.firstTower, firstInhibitor = t.firstInhibitor, firstBaron = t.firstBaron, firstDragon = t.firstDragon, firstRiftHerald = t.firstRiftHerald, towerKills = t.towerKills, inhibitorKills = t.inhibitorKills, baronKills = t.baronKills, dragonKills = t.dragonKills, riftHeraldKills = t.riftHeraldKills, vilemawKills = t.vilemawKills, dominionVictoryScore = t.dominionVictoryScore }); } List <ParticipantIdentity> participantIds = data.participantIdentities; List <Participant> participants = data.participants; // Add PI to db foreach (ParticipantIdentity pi in participantIds) { // Check if player exists in database or not if (!db.Players.Any(x => x.playerOrTeamId == pi.player.summonerId)) { db.Players.Add(new LoLPlayer { playerOrTeamId = pi.player.summonerId, rank = participants.Where(x => x.participantId == pi.participantId).Select(x => x.highestAchievedSeasonTier).SingleOrDefault(), region = row.region, hasChecked = false }); } db.ParticipantIdentity.Add(new ParticipantId { matchid = match.matchId, participantId = pi.participantId, playerid = pi.player.summonerId, }); } // Add Part to db foreach (Participant p in participants) { db.Participant.Add(new ParticipantList { MatchId = match.matchId, teamId = p.teamId, spell1Id = p.spell1Id, spell2Id = p.spell2Id, championId = p.championId, highestAchievedSeasonTier = p.highestAchievedSeasonTier, participantId = p.participantId }); db.ParticipantStats.Add(new ParticipantStats { participantid = p.participantId, matchid = match.matchId, winner = p.stats.winner, champLevel = p.stats.champLevel, item0 = p.stats.item0, item1 = p.stats.item1, item2 = p.stats.item2, item3 = p.stats.item3, item4 = p.stats.item4, item5 = p.stats.item5, item6 = p.stats.item6, kills = p.stats.kills, doubleKills = p.stats.doubleKills, tripleKills = p.stats.tripleKills, quadraKills = p.stats.quadraKills, pentaKills = p.stats.pentaKills, unrealKills = p.stats.unrealKills, largestKillingSpree = p.stats.largestKillingSpree, deaths = p.stats.deaths, assists = p.stats.assists, totalDamageDealt = p.stats.totalDamageDealt, totalDamageDealtToChampions = p.stats.totalDamageDealtToChampions, totalDamageTaken = p.stats.totalDamageTaken, largestCriticalStrike = p.stats.largestCriticalStrike, totalHeal = p.stats.totalHeal, minionsKilled = p.stats.minionsKilled, neutralMinionsKilled = p.stats.neutralMinionsKilled, neutralMinionsKilledTeamJungle = p.stats.neutralMinionsKilledTeamJungle, neutralMinionsKilledEnemyJungle = p.stats.neutralMinionsKilledEnemyJungle, goldEarned = p.stats.goldEarned, goldSpent = p.stats.goldSpent, combatPlayerScore = p.stats.combatPlayerScore, objectivePlayerScore = p.stats.objectivePlayerScore, totalPlayerScore = p.stats.totalPlayerScore, totalScoreRank = p.stats.totalScoreRank, magicDamageDealtToChampions = p.stats.magicDamageDealtToChampions, physicalDamageDealtToChampions = p.stats.physicalDamageDealtToChampions, trueDamageDealtToChampions = p.stats.trueDamageDealtToChampions, visionWardsBoughtInGame = p.stats.visionWardsBoughtInGame, sightWardsBoughtInGame = p.stats.sightWardsBoughtInGame, magicDamageDealt = p.stats.magicDamageDealt, physicalDamageDealt = p.stats.physicalDamageDealt, trueDamageDealt = p.stats.trueDamageDealt, magicDamageTaken = p.stats.magicDamageTaken, physicalDamageTaken = p.stats.physicalDamageTaken, trueDamageTaken = p.stats.trueDamageTaken, firstBloodKill = p.stats.firstBloodKill, firstBloodAssist = p.stats.firstBloodAssist, firstTowerKill = p.stats.firstTowerKill, firstTowerAssist = p.stats.firstTowerAssist, firstInhibitorKill = p.stats.firstInhibitorKill, firstInhibitorAssist = p.stats.firstInhibitorAssist, inhibitorKills = p.stats.inhibitorKills, towerKills = p.stats.towerKills, wardsPlaced = p.stats.wardsPlaced, wardsKilled = p.stats.wardsKilled, largestMultiKill = p.stats.largestMultiKill, killingSprees = p.stats.killingSprees, totalUnitsHealed = p.stats.totalUnitsHealed, totalTimeCrowdControlDealt = p.stats.totalTimeCrowdControlDealt }); foreach (Rune runeData in p.runes) { db.ParticipantRunes.Add(new ParticipantRunes { participantid = p.participantId, matchid = match.matchId, runeId = runeData.runeId, rank = runeData.rank }); } foreach (Mastery masteryData in p.masteries) { db.ParticipantMasteries.Add(new ParticipantMasteries { participantid = p.participantId, matchid = match.matchId, masteryId = masteryData.masteryId, rank = masteryData.rank }); } } } db.SaveChanges(); db.Dispose(); db = new ApplicationDbContext(); } row.hasChecked = true; db.SaveChanges(); db.Dispose(); } catch { // query failed } } else { crawlerEnd = true; } } return(View()); }