public void MatchTest_ShouldMatchExact() { var whitelist = new Matchlist("imageA,imageB , *imageC, imageD* ,, ,imageE"); Assert.True(whitelist.Match("IMAGEA")); Assert.True(whitelist.Match("imageA", false)); Assert.True(whitelist.Match("*imageC")); Assert.True(whitelist.Match("imageD*")); }
public void MatchTest_ShouldMatchSuffix() { var whitelist = new Matchlist("imageD*"); Assert.True(whitelist.Match("imageDhello")); Assert.True(whitelist.Match("imageD")); Assert.False(whitelist.Match("helloimageD")); Assert.False(whitelist.Match("IMAGEDhello", false)); Assert.False(whitelist.Match("IMAGED", false)); }
public void MatchTest_ShouldMatchPrefix() { var whitelist = new Matchlist("*imageC"); Assert.True(whitelist.Match("helloimageC")); Assert.True(whitelist.Match("imageC")); Assert.False(whitelist.Match("imageChello")); Assert.False(whitelist.Match("helloIMAGEC", false)); Assert.False(whitelist.Match("IMAGEC", false)); }
public void ConstructorTest_ShouldParseInputAndIgnoreEmpty() { var whitelist = new Matchlist(" imageA,imageB , *imageC, imageD* ,, ,imageE, ").ToList(); Assert.True(whitelist.Count == 5); Assert.True(whitelist[0] == "imageA"); Assert.True(whitelist[1] == "imageB"); Assert.True(whitelist[2] == "*imageC"); Assert.True(whitelist[3] == "imageD*"); Assert.True(whitelist[4] == "imageE"); }
public void MatchTest_ShouldMatchSubstring() { var whitelist = new Matchlist("*image*"); Assert.True(whitelist.Match("1image1")); Assert.True(whitelist.Match("image")); Assert.True(whitelist.Match("imagehello")); Assert.True(whitelist.Match("helloimage")); Assert.False(whitelist.Match("mag", false)); Assert.False(whitelist.Match("helloIMAGE", false)); Assert.False(whitelist.Match("IMAGE", false)); }
public static void CheckGetQuery(Matchlist matchlist) { Assert.IsNotNull(matchlist); Assert.AreEqual(1, matchlist.TotalGames); Assert.AreEqual(0, matchlist.StartIndex); Assert.AreEqual(1, matchlist.EndIndex); Assert.IsNotNull(matchlist.Matches); long[] expected = { 2398184332L }; Assert.AreEqual(expected.Length, matchlist.Matches.Length); for (var i = 0; i < expected.Length; i++) { Assert.IsNotNull(matchlist.Matches[i]); Assert.AreEqual(expected[i], matchlist.Matches[i].GameId); } }
IEnumerator AddMoreMatches() { using (UnityWebRequest www = UnityWebRequest.Get(URLs.GetMatchlist(currentSummoner.accountId, currentIndex + 10, currentIndex))) { yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { print("Error: " + www.error); } else { Matchlist currentMatchlist = JsonConvert.DeserializeObject <Matchlist>(www.downloadHandler.text); List <GameObject> tmp = new List <GameObject>(); foreach (MatchReference match in currentMatchlist.matches) { using (UnityWebRequest wwww = UnityWebRequest.Get(URLs.GetMatch(match.gameId))) { yield return(wwww.SendWebRequest()); if (wwww.isNetworkError || wwww.isHttpError) { print("Error: " + wwww.error); } else { Match currentMatch = JsonConvert.DeserializeObject <Match>(wwww.downloadHandler.text); currentMatches.Add(currentMatch); GameObject go = Instantiate(Resources.Load <GameObject>("Prefabs/MatchPrefab"), matchlistParent); tmp.Add(go); go.name = currentMatch.gameId.ToString(); go.GetComponent <MatchPrefab>().match = currentMatch; go.GetComponent <MatchPrefab>().SetupUI(currentSummoner.accountId); go.SetActive(false); } } } foreach (GameObject go in tmp) { go.SetActive(true); } } } currentIndex += 10; }
public static void CheckGetQueryRecent(Matchlist matchlist) { Assert.IsNotNull(matchlist); Assert.IsNotNull(matchlist.Matches); //assertEquals(matchlist.totalGames, matchlist.matches.size()); const long after = 1494737245688L; //long max = 0; var timestamp = long.MaxValue; foreach (var match in matchlist.Matches) { Assert.IsNotNull(match); Assert.IsTrue(match.Timestamp >= after); // check descending Assert.IsTrue(match.Timestamp < timestamp); timestamp = match.Timestamp; } }
public void ConstructorTest_ShouldReturnFalseIfWhitelistIsEmptyOrInputIsEmpty() { var whitelist = new Matchlist(); Assert.False(whitelist.Match("haha")); Assert.False(whitelist.Match("")); Assert.False(whitelist.Match(null)); whitelist = new Matchlist(""); Assert.False(whitelist.Match("haha")); Assert.False(whitelist.Match("")); Assert.False(whitelist.Match(null)); whitelist = new Matchlist(null); Assert.False(whitelist.Match("haha")); Assert.False(whitelist.Match("")); Assert.False(whitelist.Match(null)); }
public void MatchAnyTest() { var whitelist = new Matchlist("imageA,imageB , *imageC, imageD* ,, ,imageE"); Assert.False(whitelist.MatchAny(null)); var inputs = new List <string> { }; Assert.False(whitelist.MatchAny(inputs)); inputs = new List <string> { "haha" }; Assert.False(whitelist.MatchAny(inputs)); inputs = new List <string> { "imageA" }; Assert.True(whitelist.MatchAny(inputs)); inputs = new List <string> { "imageA", "imageB" }; Assert.True(whitelist.MatchAny(inputs)); inputs = new List <string> { "image", "imageA" }; Assert.True(whitelist.MatchAny(inputs)); inputs = new List <string> { "lol", "haha", "helloimagec" }; Assert.True(whitelist.MatchAny(inputs)); inputs = new List <string> { "helloimagec", "imageDhello" }; Assert.True(whitelist.MatchAny(inputs)); }
public async Task Return_Correct_Matchlist(SummonerData summonerData) { Matchlist matchlist = await RiotAPI.Matches.GetMatchlist(summonerData.Region, summonerData.AccountId); Check.That(matchlist).IsNotNull(); }
public async Task <IActionResult> GetSummonerMatch(string name, string region, int matchesNumber) { try { Region regionEnum = Region.Get(region); var riotApi = RiotApi.NewInstance(riotApiKey); var summonerData = await riotApi.SummonerV4.GetBySummonerNameAsync(regionEnum, name); Matchlist result = riotApi.MatchV4.GetMatchlist(regionEnum, summonerData.AccountId); MatchReference[] matches = result.Matches.Take(matchesNumber).ToArray(); ArrayList machesToReturn = new ArrayList(); foreach (var match in matches) { MatchOne matchToList = new MatchOne(); matchToList.GameId = match.GameId; matchToList.Lane = match.Lane; matchToList.PlatformId = match.PlatformId; matchToList.Queue = match.Queue; matchToList.Role = match.Role; matchToList.Season = match.Season; matchToList.Timestamp = match.Timestamp; matchToList.Champion = match.Champion; matchToList.matchInfo = await GetMatchInfoFromApi(match.GameId, region); Champion champion = (Champion)match.Champion; var championName = ChampionUtils.Name(champion); matchToList.championName = championName; var matchData = riotApi.MatchV4.GetMatch(regionEnum, match.GameId); matchToList.gameDuration = matchData.GameDuration; matchToList.gameMode = matchData.GameMode; var parcipientId = 0; foreach (var participant in matchData.ParticipantIdentities) { if (participant.Player.SummonerName == name) { parcipientId = participant.ParticipantId; } } var teamId = 0; foreach (var participants in matchData.Participants) { if (participants.ParticipantId == parcipientId) { teamId = participants.TeamId; } } var winTeamOne = false; if (matchData.Teams[0].TeamId == teamId) { if (matchData.Teams[0].Win == "Win") { winTeamOne = true; } } else if (matchData.Teams[1].TeamId == teamId) { if (matchData.Teams[1].Win == "Win") { winTeamOne = true; } } matchToList.win = winTeamOne; machesToReturn.Add(matchToList); } return(Ok(machesToReturn.ToArray())); } catch (System.Exception e) { return(StatusCode(500, e)); } }
IEnumerator SetCurrentVariables() { using (UnityWebRequest www = UnityWebRequest.Get(URLs.GetSummonerFromName(searchText.text))) { yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { print("Error: " + www.error); } else { currentSummoner = JsonConvert.DeserializeObject <Summoner>(www.downloadHandler.text); } } using (UnityWebRequest www = UnityWebRequestTexture.GetTexture(URLs.GetProfileIcon(currentSummoner.profileIconId))) { yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { print("Error: " + www.error); } else { currentProfileIconTexture = ((DownloadHandlerTexture)www.downloadHandler).texture; } } currentMatches.Clear(); currentIndex = 0; using (UnityWebRequest www = UnityWebRequest.Get(URLs.GetMatchlist(currentSummoner.accountId, currentIndex + 10, currentIndex))) { yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { print("Error: " + www.error); } else { Matchlist currentMatchlist = JsonConvert.DeserializeObject <Matchlist>(www.downloadHandler.text); foreach (MatchReference match in currentMatchlist.matches) { using (UnityWebRequest wwww = UnityWebRequest.Get(URLs.GetMatch(match.gameId))) { yield return(wwww.SendWebRequest()); if (wwww.isNetworkError || wwww.isHttpError) { print("Error: " + wwww.error); } else { currentMatches.Add(JsonConvert.DeserializeObject <Match>(wwww.downloadHandler.text)); } } } } } currentIndex += 10; profileIcon.texture = currentProfileIconTexture; level.text = currentSummoner.summonerLevel.ToString(); playerName.text = currentSummoner.name; foreach (Transform match in matchlistParent) { Destroy(match.gameObject); } List <GameObject> tmp = new List <GameObject>(); foreach (Match match in currentMatches) { GameObject go = Instantiate(Resources.Load <GameObject>("Prefabs/MatchPrefab"), matchlistParent); tmp.Add(go); go.name = match.gameId.ToString(); go.GetComponent <MatchPrefab>().match = match; go.GetComponent <MatchPrefab>().SetupUI(currentSummoner.accountId); } foreach (GameObject go in tmp) { go.SetActive(true); } }
public async Task wr(params string[] names) { if (names.Length > _rapi.maxSearchWinrateNames) { await Context.User.SendMessageAsync($"Too many names entered! Limit: {_rapi.maxSearchWinrateNames}"); } else { await Context.Channel.TriggerTypingAsync(); List <EmbedFieldBuilder> content = new List <EmbedFieldBuilder>(); Summoner topSumm = null; int[] qs = { 420, 440 }; foreach (string target in names) { EmbedFieldBuilder field = new EmbedFieldBuilder(); field.Name = target; Summoner tofind = null; Matchlist mlist = null; double wins = 0, losses = 0, wr; try{ tofind = await _rapi.RAPI.SummonerV4.GetBySummonerNameAsync(Region.NA, target) ?? throw new InvalidDataException(); mlist = await _rapi.RAPI.MatchV4.GetMatchlistAsync(Region.NA, tofind.AccountId, queue : qs, endIndex : 20); if (mlist.TotalGames == 0) { throw new InvalidOperationException(); } topSumm = topSumm ?? tofind; foreach (MatchReference mref in mlist.Matches) { await CommandHandlingService.Logger(new LogMessage(LogSeverity.Debug, "winrate", $"mref: {(mref != null)}")); if (await isWin(mref.GameId, tofind)) { wins++; } else { losses++; } } wr = wins / (wins + losses); field.Value = string.Format("WR: {0:P}\nWins: {1}\nLosses:{2}\n", wr, wins, losses); } catch (InvalidDataException) { field.Value = "Does not exist"; } catch (InvalidOperationException) { field.Value = "No ranked games on record"; } catch (NullReferenceException nre) { await CommandHandlingService.Logger(new LogMessage(LogSeverity.Debug, "winrate", "Poorly Handled Exception", nre)); field.Value = "Error"; topSumm = tofind ?? tofind ?? topSumm; } content.Add(field); } await CommandHandlingService.Logger(new LogMessage(LogSeverity.Debug, "winrate command", "Building embedded message...")); EmbedBuilder embeddedMessage = new EmbedBuilder(); embeddedMessage.WithThumbnailUrl($"http://ddragon.leagueoflegends.com/cdn/{_rapi.patchNum}/img/profileicon/{(topSumm != null ? topSumm.ProfileIconId : 501)}.png"); embeddedMessage.WithColor(0xff69b4); embeddedMessage.WithTitle("Last Twenty All Ranked Queues"); embeddedMessage.WithColor(0xff69b4); embeddedMessage.WithFields(content); embeddedMessage.WithCurrentTimestamp(); embeddedMessage.WithFooter(new EmbedFooterBuilder().WithText("As of")); await ReplyAsync("", embed : embeddedMessage.Build()); } }
public ActionResult GetMatches() { int endId = 112034; int startId = 38133; for (int i = startId; i <= endId; i++) { ApplicationDbContext db = new ApplicationDbContext(); Matchlist row = (from o in db.Matchlist where o.Id == i select o).SingleOrDefault(); string region = row.region; long matid = row.matchId; int id = row.Id; try { Thread.Sleep(650); // Get all matches played by a player in patch 7.5 in RANKED SOLO when Taric is played string json = new WebClient().DownloadString("https://" + region + ".api.pvp.net/api/lol/" + region + "/v2.2/match/" + matid + "?api_key=RGAPI-bdeef08a-76db-47d5-b0e0-33fd0d9f34ff"); // Convert from JSON to object RootObject data = JsonConvert.DeserializeObject <RootObject>(json); List <Team> teams = data.teams; List <ParticipantIdentity> participantIds = data.participantIdentities; List <Participant> participants = data.participants; // Add Match to db /*MatchData m = new MatchData * { * matchId = id, * 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 * }; * * db.Match.Add(m);*/ db.Match.Add(new MatchData { matchId = id, 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 }); // Add teams to db foreach (Team t in teams) { db.Team.Add(new Team { matchid = id, 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 }); } // Add PI to db foreach (ParticipantIdentity pi in participantIds) { db.ParticipantIdentity.Add(new ParticipantId { matchid = id, participantId = pi.participantId, playerid = pi.player.summonerId, }); } // Add Part to db foreach (Participant p in participants) { db.Participant.Add(new ParticipantList { MatchId = id, 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 = id, 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 = id, runeId = runeData.runeId, rank = runeData.rank }); } foreach (Mastery masteryData in p.masteries) { db.ParticipantMasteries.Add(new ParticipantMasteries { participantid = p.participantId, matchid = id, masteryId = masteryData.masteryId, rank = masteryData.rank }); } } db.SaveChanges(); } catch { } } return(View()); }