From 3a86fdbdf437873349dd06650c4c36f74f6af2fa Mon Sep 17 00:00:00 2001 From: Darkstack <1835601+darkstack@users.noreply.github.com> Date: Mon, 21 Mar 2022 01:10:48 +0100 Subject: [PATCH] Improve ranking parsing Improve Smash.gg parsing Fix useless stuff Fix --- .../LaDOSE.Api/Controllers/SmashController.cs | 6 +- LaDOSE.Src/LaDOSE.Api/Startup.cs | 3 +- LaDOSE.Src/LaDOSE.REST/RestService.cs | 4 +- .../Interface/IExternalProviderService.cs | 3 - .../ChallongProvider/ChallongeProvider.cs | 4 +- .../Provider/SmashProvider/SmashProvider.cs | 4 +- .../Provider/SmashProvider/Tournament.cs | 2 +- .../Service/ExternalProviderService.cs | 105 ++---------------- 8 files changed, 23 insertions(+), 108 deletions(-) diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/SmashController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/SmashController.cs index ab94460..8f3c8ff 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/SmashController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/SmashController.cs @@ -49,9 +49,9 @@ namespace LaDOSE.Api.Controllers { if (!String.IsNullOrEmpty(tournamentSlug)) { - var tournaments = await _service.GetSmashResult2(tournamentSlug); - - return Ok(tournaments); + //var tournaments = await _service.GetSmashResult2(tournamentSlug); + return Ok(); + //return Ok(tournaments); } return null; diff --git a/LaDOSE.Src/LaDOSE.Api/Startup.cs b/LaDOSE.Src/LaDOSE.Api/Startup.cs index e2d25e6..7560512 100644 --- a/LaDOSE.Src/LaDOSE.Api/Startup.cs +++ b/LaDOSE.Src/LaDOSE.Api/Startup.cs @@ -75,7 +75,6 @@ namespace LaDOSE.Api options => options.UseMySql($"Server={MySqlServer};Database={MySqlDatabase};User={MySqlUser};Password={MySqlPassword};", // replace with your Connection String mysqlOptions => { - mysqlOptions.ServerVersion(new Version(10, 1, 16), ServerType.MariaDb); // replace with your Server Version and Type } )); @@ -175,7 +174,7 @@ namespace LaDOSE.Api { app.UseDeveloperExceptionPage(); } - + app.UseCors(x => x //.AllowAnyOrigin() .AllowAnyMethod() diff --git a/LaDOSE.Src/LaDOSE.REST/RestService.cs b/LaDOSE.Src/LaDOSE.REST/RestService.cs index e3d3fb4..f388b44 100644 --- a/LaDOSE.Src/LaDOSE.REST/RestService.cs +++ b/LaDOSE.Src/LaDOSE.REST/RestService.cs @@ -29,9 +29,9 @@ namespace LaDOSE.REST public void Connect(Uri url, string user, string password) { Client = new RestClient(url); -#if DEBUG + Client.Timeout = 999*1000; -#endif + this.username = user; this.password = password; GetToken(user, password); diff --git a/LaDOSE.Src/LaDOSE.Service/Interface/IExternalProviderService.cs b/LaDOSE.Src/LaDOSE.Service/Interface/IExternalProviderService.cs index 5d663a4..ad7fce7 100644 --- a/LaDOSE.Src/LaDOSE.Service/Interface/IExternalProviderService.cs +++ b/LaDOSE.Src/LaDOSE.Service/Interface/IExternalProviderService.cs @@ -13,9 +13,6 @@ namespace LaDOSE.Business.Interface Task GetTournamentsResult(List ids); Task GetSmashResult(string tournamentSlug); - Task GetSmashResult2(string tournamentSlug); - - Task> GetChallongeEvents(List ids); } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Service/Provider/ChallongProvider/ChallongeProvider.cs b/LaDOSE.Src/LaDOSE.Service/Provider/ChallongProvider/ChallongeProvider.cs index ff2c7dc..a42d30b 100644 --- a/LaDOSE.Src/LaDOSE.Service/Provider/ChallongProvider/ChallongeProvider.cs +++ b/LaDOSE.Src/LaDOSE.Service/Provider/ChallongProvider/ChallongeProvider.cs @@ -204,7 +204,7 @@ namespace LaDOSE.Business.Provider.ChallongProvider return currentevent; } - private const string RegexRanking = @"Ranking #\w{3}"; + private const string RegexRanking = @"[R|r]anking.?#\w{3}"; private const string DateRanking = @"^\[(\d{2}\/\d{2}\/\d{2})\]"; private const string GameRanking = @"\-.(\w*)$"; public async Task> GetEvents(List idTournaments) @@ -223,7 +223,7 @@ namespace LaDOSE.Business.Provider.ChallongProvider } - if (tournament.Result.Name.Contains("Ranking #")) + if (tournament.Result.Name.Contains("Ranking")) { var eventName = Regex.Match(tournament.Result.Name, RegexRanking); var eventDate = Regex.Match(tournament.Result.Name, DateRanking); diff --git a/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/SmashProvider.cs b/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/SmashProvider.cs index e9b44b0..6b288b9 100644 --- a/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/SmashProvider.cs +++ b/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/SmashProvider.cs @@ -285,8 +285,8 @@ namespace LaDOSE.Business.Provider.SmashProvider Player1Id = PlayerService.GetIdBySmash(x.slots[0].entrant.participants[0]), Player2Id = PlayerService.GetIdBySmash(x.slots[1].entrant.participants[0]), - Player1Score = x.slots[0].standing.stats.score.value, - Player2Score = x.slots[1].standing.stats.score.value, + Player1Score = x.slots[0].standing.stats.score.value.HasValue ? x.slots[0].standing.stats.score.value.Value : 0, + Player2Score = x.slots[1].standing.stats.score.value.HasValue ? x.slots[1].standing.stats.score.value.Value : 0, Round = x.round ?? 0, }).ToList(); tournament.Sets = tset; diff --git a/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/Tournament.cs b/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/Tournament.cs index 9873cdb..298f5da 100644 --- a/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/Tournament.cs +++ b/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/Tournament.cs @@ -34,7 +34,7 @@ namespace LaDOSE.Business.Provider.SmashProvider public class ScoreType { public string label { get; set; } - public int value { get; set; } + public int? value { get; set; } public string displayValue { get; set; } } diff --git a/LaDOSE.Src/LaDOSE.Service/Service/ExternalProviderService.cs b/LaDOSE.Src/LaDOSE.Service/Service/ExternalProviderService.cs index 2dee64e..0145166 100644 --- a/LaDOSE.Src/LaDOSE.Service/Service/ExternalProviderService.cs +++ b/LaDOSE.Src/LaDOSE.Service/Service/ExternalProviderService.cs @@ -198,96 +198,10 @@ namespace LaDOSE.Business.Service { var parse = await this.ParseSmash(tournamentSlug); var test = await GetEventResult(parse.Id); - if (test.Results != null) - { - var test2 = test.Games.Count(); - } return test; - var tournaments = await _smashProvider.GetTournament(tournamentSlug); - var players = tournaments.Tournament.Events.Where(e => e.standings != null).SelectMany(e => e.standings.nodes.Select(e => e.player)).ToList(); - var distinctp = players.DistinctBy(e => new { e.user.id }).ToList(); - var games = _context.Game.ToList(); - - TournamentsResult result = new TournamentsResult(); - result.Results = new List(); - result.Games = new List(); - result.Participents = new List(); - distinctp.ForEach(e => - { - var x = new ChallongeParticipent() - { - Name = e.gamerTag, - ChallongeId = e.id, - Id = e.id - }; - result.Participents.Add(x); - }); - games.ForEach(e => - { - e.Id = e.SmashId ?? e.Id; - result.Games.Add(e); - }); - - foreach (var tournament in tournaments.Tournament.Events.Where(e => e.standings != null).ToList()) - { - - - var playerCount = tournament.standings.nodes.Count; - var lesSacs = tournament.standings.nodes; - var currentRule = TournamentRules.FirstOrDefault(rules => - rules.PlayerMin < playerCount && rules.PlayerMax >= playerCount - ); - if (currentRule == null) - { - throw new Exception("Unable to find rules"); - } - - var first = tournament.standings.nodes.First(p => p.placement == 1); - var second = tournament.standings.nodes.First(p => p.placement == 2); - var thirdFourth = tournament.standings.nodes.Where(p => p.placement == 3 || p.placement == 4).ToList(); - var Top8 = tournament.standings.nodes.Where(p => p.placement > 4 && p.placement < 9).ToList(); - var Top16 = tournament.standings.nodes.Where(p => p.placement > 8 && p.placement <= 16).ToList(); - - result.Results.Add(new Result(first.player.gamerTag, tournament.videogame.id, tournament.id, tournament.name, currentRule.FirstPoint, first.placement)); - lesSacs.Remove(first); - result.Results.Add(new Result(second.player.gamerTag, tournament.videogame.id, tournament.id, tournament.name, currentRule.SecondPoint, second.placement)); - lesSacs.Remove(second); - thirdFourth.ForEach(r => - result.Results.Add(new Result(r.player.gamerTag, tournament.videogame.id, tournament.id, tournament.name, - currentRule.ThirdFourthPoint, r.placement))); - thirdFourth.ForEach(p => lesSacs.Remove(p)); - if (currentRule.Top8Point != 0) - { - Top8.ForEach(r => - result.Results.Add(new Result(r.player.gamerTag, tournament.videogame.id, tournament.id, tournament.name, - currentRule.ThirdFourthPoint, r.placement))); - Top8.ForEach(p => lesSacs.Remove(p)); - } - - if (currentRule.Top16Point != 0) - { - Top16.ForEach(r => - result.Results.Add( - new Result(r.player.gamerTag, tournament.videogame.id, tournament.id, tournament.name, - currentRule.ThirdFourthPoint, r.placement))); - Top16.ForEach(p => lesSacs.Remove(p)); - } - - lesSacs.ForEach(r => - result.Results.Add(new Result(r.player.gamerTag, tournament.videogame.id, tournament.id, tournament.name, - currentRule.ThirdFourthPoint, r.placement))); - - } - - - - return await Task.FromResult(result); + } - public Task GetSmashResult2(string tournamentSlug) - { - throw new NotImplementedException(); - } public async Task> GetChallongeEvents(List ids) { @@ -384,18 +298,18 @@ namespace LaDOSE.Business.Service var Top8 = tournament.Results.Where(p => p.Rank > 4 && p.Rank < 9).ToList(); var Top16 = tournament.Results.Where(p => p.Rank > 8 && p.Rank <= 16).ToList(); - result.Results.Add(new Result(first.Player.Gamertag, tournament.Game.Id, tournament.Id, tournament.Name, currentRule.FirstPoint, first.Rank)); + result.Results.Add(new Result(first.Player.Gamertag, tournament.Game?.Id??0, tournament.Id, tournament.Name, currentRule.FirstPoint, first.Rank)); lesSacs.Remove(first.Player); - result.Results.Add(new Result(second.Player.Gamertag, tournament.Game.Id, tournament.Id, tournament.Name, currentRule.SecondPoint, second.Rank)); + result.Results.Add(new Result(second.Player.Gamertag, tournament.Game?.Id ?? 0, tournament.Id, tournament.Name, currentRule.SecondPoint, second.Rank)); lesSacs.Remove(second.Player); thirdFourth.ForEach(r => - result.Results.Add(new Result(r.Player.Gamertag, tournament.Game.Id, tournament.Id, tournament.Name, + result.Results.Add(new Result(r.Player.Gamertag, tournament.Game?.Id??0, tournament.Id, tournament.Name, currentRule.ThirdFourthPoint, r.Rank))); thirdFourth.ForEach(p => lesSacs.Remove(p.Player)); if (currentRule.Top8Point != 0) { Top8.ForEach(r => - result.Results.Add(new Result(r.Player.Gamertag, tournament.Game.Id, tournament.Id, tournament.Name, + result.Results.Add(new Result(r.Player.Gamertag, tournament.Game?.Id??0, tournament.Id, tournament.Name, currentRule.ThirdFourthPoint, r.Rank))); Top8.ForEach(p => lesSacs.Remove(p.Player)); } @@ -404,17 +318,22 @@ namespace LaDOSE.Business.Service { Top16.ForEach(r => result.Results.Add( - new Result(r.Player.Gamertag, tournament.Game.Id, tournament.Id, tournament.Name, + new Result(r.Player.Gamertag, tournament.Game?.Id??0, tournament.Id, tournament.Name, currentRule.ThirdFourthPoint, r.Rank))); Top16.ForEach(p => lesSacs.Remove(p.Player)); } lesSacs.ForEach(r => - result.Results.Add(new Result(r.Gamertag, tournament.Game.Id, tournament.Id, tournament.Name, + result.Results.Add(new Result(r.Gamertag, tournament.Game?.Id??0, tournament.Id, tournament.Name, currentRule.ThirdFourthPoint, tournament.Results.FirstOrDefault(e=>e.Player == r)?.Rank??999))); } + if (result.Results.Any(e => e.GameId == 0)) + { + result.Games.Add(new Game(){Id = 0,Name = "GAME NOT FOUND",LongName = "GAME NOT FOUND",Order = 999}); + } + System.Diagnostics.Trace.WriteLine(result.Results); return await Task.FromResult(result);