From 0150402ca6b5c0310f483528b2c7c7e7034b0897 Mon Sep 17 00:00:00 2001 From: Darkstack <1835601+darkstack@users.noreply.github.com> Date: Tue, 22 Mar 2022 00:14:46 +0100 Subject: [PATCH] Rework the UI Fix Score Add Kiouze CSS Rework the tournaments API --- .../LaDOSE.Api/Controllers/EventController.cs | 3 +- .../LaDOSE.Api/Controllers/SmashController.cs | 62 ---- .../LaDOSE.Api/Controllers/TestController.cs | 82 ++--- .../Controllers/TournamentController.cs | 34 +- LaDOSE.Src/LaDOSE.Api/Startup.cs | 2 + LaDOSE.Src/LaDOSE.DTO/EventDTO.cs | 8 + .../LaDOSE.DesktopApp.csproj | 3 + .../LaDOSE.DesktopApp/Resources/css.css | 343 ++++++++++++++++++ .../ViewModels/TournamentResultViewModel.cs | 119 +++++- .../Views/TournamentResultView.xaml | 187 ++++++---- LaDOSE.Src/LaDOSE.REST/RestService.cs | 20 +- .../Interface/IChallongeProvider.cs | 4 +- .../Interface/IExternalProviderService.cs | 8 +- .../ChallongProvider/ChallongeProvider.cs | 2 +- .../Provider/SmashProvider/SmashProvider.cs | 8 +- .../Provider/SmashProvider/Tournament.cs | 5 +- .../Service/ExternalProviderService.cs | 280 +++++++++----- 17 files changed, 890 insertions(+), 280 deletions(-) delete mode 100644 LaDOSE.Src/LaDOSE.Api/Controllers/SmashController.cs create mode 100644 LaDOSE.Src/LaDOSE.DTO/EventDTO.cs create mode 100644 LaDOSE.Src/LaDOSE.DesktopApp/Resources/css.css diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/EventController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/EventController.cs index d7db738..a2aae4b 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/EventController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/EventController.cs @@ -11,7 +11,8 @@ using Microsoft.AspNetCore.Mvc; namespace LaDOSE.Api.Controllers { - [Authorize] + [AllowAnonymous] + //[Authorize] [Produces("application/json")] [Route("api/[controller]")] public class EventController : GenericController diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/SmashController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/SmashController.cs deleted file mode 100644 index 8f3c8ff..0000000 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/SmashController.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using AutoMapper; -using LaDOSE.Business.Interface; -using LaDOSE.DTO; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -namespace LaDOSE.Api.Controllers -{ -#if DEBUG - [AllowAnonymous] -#endif - [Produces("application/json")] - [Route("api/[controller]")] - public class SmashController : Controller - { - - private IExternalProviderService _service; - - private IMapper _mapper; - - // GET - public SmashController(IMapper mapper, IExternalProviderService service) - { - _mapper = mapper; - _service = service; - } - //This may be a get , but i dont know what the RFC State for Get request with Body - //As i don't like to populate GET request with body this will be a post (and i think - //it will be easier to proxy. - [HttpGet("GetTournament/{tournamentSlug}")] - public async Task GetSmashTournament(string tournamentSlug) - { - if (!String.IsNullOrEmpty(tournamentSlug)) - { - - var tournaments = await _service.GetSmashResult(tournamentSlug); - - return Ok(tournaments); - } - - return null; - } - [HttpGet("AddTournament/{tournamentSlug}")] - public async Task AddSmashTournament(string tournamentSlug) - { - if (!String.IsNullOrEmpty(tournamentSlug)) - { - //var tournaments = await _service.GetSmashResult2(tournamentSlug); - return Ok(); - //return Ok(tournaments); - } - - return null; - } - - - } -} diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/TestController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/TestController.cs index 2815d0e..c253b7c 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/TestController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/TestController.cs @@ -1,50 +1,50 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using AutoMapper; -using LaDOSE.Business.Interface; -using LaDOSE.DTO; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using System.Threading.Tasks; +//using AutoMapper; +//using LaDOSE.Business.Interface; +//using LaDOSE.DTO; +//using Microsoft.AspNetCore.Authorization; +//using Microsoft.AspNetCore.Mvc; -namespace LaDOSE.Api.Controllers -{ -#if DEBUG - [AllowAnonymous] -#endif - [Produces("application/json")] - [Route("api/[controller]")] - public class TestController : Controller - { +//namespace LaDOSE.Api.Controllers +//{ +//#if DEBUG +// [AllowAnonymous] +//#endif +// [Produces("application/json")] +// [Route("api/[controller]")] +// public class TestController : Controller +// { - private IExternalProviderService _service; +// private IExternalProviderService _service; - private IMapper _mapper; +// private IMapper _mapper; - // GET - public TestController(IMapper mapper, IExternalProviderService service) - { - _mapper = mapper; - _service = service; - } - //This may be a get , but i dont know what the RFC State for Get request with Body - //As i don't like to populate GET request with body this will be a post (and i think - //it will be easier to proxy. - [HttpGet("Test/{tournamentSlug}")] - public async Task GetSmashTournament(string tournamentSlug) - { - if (!String.IsNullOrEmpty(tournamentSlug)) - { - var tournaments = await _service.GetSmashResult(tournamentSlug); +// // GET +// public TestController(IMapper mapper, IExternalProviderService service) +// { +// _mapper = mapper; +// _service = service; +// } +// //This may be a get , but i dont know what the RFC State for Get request with Body +// //As i don't like to populate GET request with body this will be a post (and i think +// //it will be easier to proxy. +// [HttpGet("Test/{tournamentSlug}")] +// public async Task GetSmashTournament(string tournamentSlug) +// { +// if (!String.IsNullOrEmpty(tournamentSlug)) +// { +// var tournaments = await _service.GetSmashResult(tournamentSlug); - return Ok(tournaments); - } +// return Ok(tournaments); +// } - return null; - } +// return null; +// } - } -} +// } +//} diff --git a/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs b/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs index a3bd887..38ae090 100644 --- a/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs +++ b/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs @@ -25,9 +25,11 @@ namespace LaDOSE.Api.Controllers _mapper = mapper; _service = service; } + //This may be a get , but i dont know what the RFC State for Get request with Body //As i don't like to populate GET request with body this will be a post (and i think //it will be easier to proxy. + [HttpPost("GetTournaments")] public async Task> GetChallonges([FromBody] TimeRangeDTO dto) { @@ -48,14 +50,36 @@ namespace LaDOSE.Api.Controllers throw new Exception("Invalid arguments"); } - var test = await _service.GetChallongeEvents(ids); - - //var tournamentsResult = await _service.GetTournamentsResult(ids); - - return _mapper.Map(new TournamentsResultDTO()); + var test = await _service.GetEventsResult(ids); + return _mapper.Map(test); } + [HttpGet("ParseSmash/{tournamentSlug}")] + public async Task AddSmashTournament(string tournamentSlug) + { + if (!String.IsNullOrEmpty(tournamentSlug)) + { + var smash = await _service.ParseSmash(tournamentSlug); + //var tournaments = await _service.GetSmashResult2(tournamentSlug); + return smash != null; + //return Ok(tournaments); + } + + return false; + } + [HttpPost("ParseChallonge")] + public async Task ParseChallonge([FromBody] List ids) + { + if (ids != null) + { + var tournaments = await _service.ParseChallonge(ids); + return tournaments.Count>0; + } + return false; + } + + } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Api/Startup.cs b/LaDOSE.Src/LaDOSE.Api/Startup.cs index 7560512..84a6698 100644 --- a/LaDOSE.Src/LaDOSE.Api/Startup.cs +++ b/LaDOSE.Src/LaDOSE.Api/Startup.cs @@ -122,6 +122,8 @@ namespace LaDOSE.Api cfg.CreateMap(); cfg.CreateMap(); cfg.CreateMap(); + cfg.CreateMap(); + cfg.CreateMap(); cfg.CreateMap(); cfg.CreateMap(); diff --git a/LaDOSE.Src/LaDOSE.DTO/EventDTO.cs b/LaDOSE.Src/LaDOSE.DTO/EventDTO.cs new file mode 100644 index 0000000..8cd29a0 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DTO/EventDTO.cs @@ -0,0 +1,8 @@ +namespace LaDOSE.DTO +{ + public class EventDTO + { + public int Id { get; set; } + public string Name { get; set; } + }; +} \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj b/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj index e9dfe24..27b38c2 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj +++ b/LaDOSE.Src/LaDOSE.DesktopApp/LaDOSE.DesktopApp.csproj @@ -240,6 +240,9 @@ + + + diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Resources/css.css b/LaDOSE.Src/LaDOSE.DesktopApp/Resources/css.css new file mode 100644 index 0000000..8504a92 --- /dev/null +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Resources/css.css @@ -0,0 +1,343 @@ +body { + color: #efefef; + background-color: #141415; +} + + + +:root { + --breakpoint-xs: 0; + --breakpoint-sm: 576px; + --breakpoint-md: 768px; + --breakpoint-lg: 992px; + --breakpoint-xl: 1200px; +} + +.table { + width: 100%; + margin-bottom: 1rem; + background-color: transparent; +} + + .table th, + .table td { + padding: 0.75rem; + vertical-align: top; + border-top: 1px solid #dee2e6; + } + + .table thead th { + vertical-align: bottom; + border-bottom: 2px solid #dee2e6; + } + + .table tbody + tbody { + border-top: 2px solid #dee2e6; + } + + .table .table { + background-color: #fff; + } + +.table-sm th, +.table-sm td { + padding: 0.3rem; +} + +.table-bordered { + border: 1px solid #dee2e6; +} + + .table-bordered th, + .table-bordered td { + border: 1px solid #dee2e6; + } + + .table-bordered thead th, + .table-bordered thead td { + border-bottom-width: 2px; + } + +.table-borderless th, +.table-borderless td, +.table-borderless thead th, +.table-borderless tbody + tbody { + border: 0; +} + +.table-striped tbody tr:nth-of-type(odd) { + background-color: rgba(0, 0, 0, 0.05); +} + +.table-hover tbody tr:hover { + background-color: rgba(0, 0, 0, 0.075); +} + +.table-primary, +.table-primary > th, +.table-primary > td { + background-color: #b8daff; +} + +.table-hover .table-primary:hover { + background-color: #9fcdff; +} + + .table-hover .table-primary:hover > td, + .table-hover .table-primary:hover > th { + background-color: #9fcdff; + } + +.table-secondary, +.table-secondary > th, +.table-secondary > td { + background-color: #d6d8db; +} + +.table-hover .table-secondary:hover { + background-color: #c8cbcf; +} + + .table-hover .table-secondary:hover > td, + .table-hover .table-secondary:hover > th { + background-color: #c8cbcf; + } + +.table-success, +.table-success > th, +.table-success > td { + background-color: #c3e6cb; +} + +.table-hover .table-success:hover { + background-color: #b1dfbb; +} + + .table-hover .table-success:hover > td, + .table-hover .table-success:hover > th { + background-color: #b1dfbb; + } + +.table-info, +.table-info > th, +.table-info > td { + background-color: #bee5eb; +} + +.table-hover .table-info:hover { + background-color: #abdde5; +} + + .table-hover .table-info:hover > td, + .table-hover .table-info:hover > th { + background-color: #abdde5; + } + +.table-warning, +.table-warning > th, +.table-warning > td { + background-color: #ffeeba; +} + +.table-hover .table-warning:hover { + background-color: #ffe8a1; +} + + .table-hover .table-warning:hover > td, + .table-hover .table-warning:hover > th { + background-color: #ffe8a1; + } + +.table-danger, +.table-danger > th, +.table-danger > td { + background-color: #f5c6cb; +} + +.table-hover .table-danger:hover { + background-color: #f1b0b7; +} + + .table-hover .table-danger:hover > td, + .table-hover .table-danger:hover > th { + background-color: #f1b0b7; + } + +.table-light, +.table-light > th, +.table-light > td { + background-color: #fdfdfe; +} + +.table-hover .table-light:hover { + background-color: #ececf6; +} + + .table-hover .table-light:hover > td, + .table-hover .table-light:hover > th { + background-color: #ececf6; + } + +.table-dark, +.table-dark > th, +.table-dark > td { + background-color: #c6c8ca; +} + +.table-hover .table-dark:hover { + background-color: #b9bbbe; +} + + .table-hover .table-dark:hover > td, + .table-hover .table-dark:hover > th { + background-color: #b9bbbe; + } + +.table-active, +.table-active > th, +.table-active > td { + background-color: rgba(0, 0, 0, 0.075); +} + +.table-hover .table-active:hover { + background-color: rgba(0, 0, 0, 0.075); +} + + .table-hover .table-active:hover > td, + .table-hover .table-active:hover > th { + background-color: rgba(0, 0, 0, 0.075); + } + +.table .thead-dark th { + color: #fff; + background-color: #212529; + border-color: #32383e; +} + +.table .thead-light th { + color: #495057; + background-color: #e9ecef; + border-color: #dee2e6; +} + +.table-dark { + color: #fff; + background-color: #212529; +} + + .table-dark th, + .table-dark td, + .table-dark thead th { + border-color: #32383e; + } + + .table-dark.table-bordered { + border: 0; + } + + .table-dark.table-striped tbody tr:nth-of-type(odd) { + background-color: rgba(255, 255, 255, 0.05); + } + + .table-dark.table-hover tbody tr:hover { + background-color: rgba(255, 255, 255, 0.075); + } + +@media (max-width: 575.98px) { + .table-responsive-sm { + display: block; + width: 100%; + overflow-x: auto; + -webkit-overflow-scrolling: touch; + -ms-overflow-style: -ms-autohiding-scrollbar; + } + + .table-responsive-sm > .table-bordered { + border: 0; + } +} + +@media (max-width: 767.98px) { + .table-responsive-md { + display: block; + width: 100%; + overflow-x: auto; + -webkit-overflow-scrolling: touch; + -ms-overflow-style: -ms-autohiding-scrollbar; + } + + .table-responsive-md > .table-bordered { + border: 0; + } +} + +@media (max-width: 991.98px) { + .table-responsive-lg { + display: block; + width: 100%; + overflow-x: auto; + -webkit-overflow-scrolling: touch; + -ms-overflow-style: -ms-autohiding-scrollbar; + } + + .table-responsive-lg > .table-bordered { + border: 0; + } +} + +@media (max-width: 1199.98px) { + .table-responsive-xl { + display: block; + width: 100%; + overflow-x: auto; + -webkit-overflow-scrolling: touch; + -ms-overflow-style: -ms-autohiding-scrollbar; + } + + .table-responsive-xl > .table-bordered { + border: 0; + } +} + +.table-responsive { + display: block; + width: 100%; + overflow-x: auto; + -webkit-overflow-scrolling: touch; + -ms-overflow-style: -ms-autohiding-scrollbar; +} + + .table-responsive > .table-bordered { + border: 0; + } + +.table { + border-collapse: collapse !important; +} + + .table td, + .table th { + /*background-color: #fff !important;*/ + } + +.table-bordered th, +.table-bordered td { + border: 1px solid #dee2e6 !important; +} + +.table-dark { + color: #fff; + background-color: #212529 +} + + .table-dark th, + .table-dark td, + .table-dark thead th, + .table-dark tbody + tbody { + border-color: #dee2e6; + } + +.table .thead-dark th { + color: inherit; + border-color: #dee2e6; +} diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/TournamentResultViewModel.cs b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/TournamentResultViewModel.cs index 3c57181..3df1ac3 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/TournamentResultViewModel.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/TournamentResultViewModel.cs @@ -5,6 +5,7 @@ using System.Collections.ObjectModel; using System.Data; using System.IO; using System.Linq; +using System.Reflection; using System.Text; using System.Text.RegularExpressions; using System.Windows.Controls; @@ -26,12 +27,14 @@ namespace LaDOSE.DesktopApp.ViewModels #region Properties - private string css = "strong { font-weight: 700;} " + - "a { color: #ff9024;}"+ - "body { color: #efefef;background-color: #141415; }" + - ""+ - "a:hover, .entry-meta span a:hover, .comments-link a:hover, body.coldisplay2 #front-columns a:active {color: #cb5920;}"+ - "tr td { border: 1px dashed #3D3D3D;} "; + private string css = string.Empty; + + //"strong { font-weight: 700;} ". + + // "a { color: #ff9024;}"+ + // "body { color: #efefef;background-color: #141415; }" + + // ""+ + // "a:hover, .entry-meta span a:hover, .comments-link a:hover, body.coldisplay2 #front-columns a:active {color: #cb5920;}"+ + // "tr td { border: 1px dashed #3D3D3D;} "; private String _selectRegex; public String SelectRegex @@ -44,6 +47,17 @@ namespace LaDOSE.DesktopApp.ViewModels } } + private String _selectEventRegex; + + public String SelectEventRegex + { + get { return _selectEventRegex; } + set + { + _selectEventRegex = value; + NotifyOfPropertyChange(() => SelectEventRegex); + } + } private string _slug; public String Slug { @@ -108,6 +122,8 @@ namespace LaDOSE.DesktopApp.ViewModels private TournamentsResultDTO _results; public List Tournaments { get; set; } + public List Events { get; set; } + public TournamentsResultDTO Results { get => _results; @@ -118,6 +134,18 @@ namespace LaDOSE.DesktopApp.ViewModels } } + private ObservableCollection _selectedEvents; + + public ObservableCollection SelectedEvents + { + get { return _selectedEvents; } + set + { + _selectedEvents = value; + NotifyOfPropertyChange(() => SelectedEvents); + } + } + private ObservableCollection _selectedTournaments; public ObservableCollection SelectedTournaments @@ -178,18 +206,28 @@ namespace LaDOSE.DesktopApp.ViewModels { this.RestService = restService; _selectedTournaments = new ObservableCollection(); + _selectedEvents = new ObservableCollection(); Tournaments = new List(); + Events = new List(); } protected override void OnInitialize() { + var manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("LaDOSE.DesktopApp.Resources.css.css"); + using (var sr = new StreamReader(manifestResourceStream)) + { + this.css = sr.ReadToEnd(); + } + + this.To = DateTime.Now; this.From = DateTime.Now.AddMonths(-1); this.SelectRegex = "Ranking"; this.Slug = "ranking-1001"; LoadTournaments(); + LoadEvents(); base.OnInitialize(); } @@ -205,6 +243,18 @@ namespace LaDOSE.DesktopApp.ViewModels }); } + public void LoadEvents() + { + WpfUtil.Await(() => + { + var eventsDtos = this.RestService + .GetAllEvents().ToList(); + this.Events = eventsDtos; + + NotifyOfPropertyChange("Events"); + }); + } + public DataTable GridDataTable { get => _gridDataTable; @@ -219,7 +269,7 @@ namespace LaDOSE.DesktopApp.ViewModels { WpfUtil.Await(() => { - var tournamentsIds = SelectedTournaments.Select(e => e.ChallongeId).ToList(); + var tournamentsIds = SelectedEvents.Select(e => e.Id).ToList(); var resultsDto = this.RestService.GetResults(tournamentsIds); this.Results = resultsDto; ComputeDataGrid(); @@ -231,12 +281,30 @@ namespace LaDOSE.DesktopApp.ViewModels WpfUtil.Await(() => { - var resultsDto = this.RestService.GetSmashResults(Slug); - this.Results = resultsDto; - ComputeDataGrid(); - ComputeHtml(); + var resultsDto = this.RestService.ParseSmash(Slug); + if (!resultsDto) + { + MessageBox.Show("Fail"); + } }); } + public void GetChallonge() + { + WpfUtil.Await(() => + { + var ids = SelectedTournaments.Select(e => e.ChallongeId).ToList(); + var resultsDto = this.RestService.ParseChallonge(ids); + if (!resultsDto) + { + MessageBox.Show("Fail"); + } + }); + } + + public void UpdateEvent() + { + LoadEvents(); + } public void SelectYear() { @@ -257,6 +325,13 @@ namespace LaDOSE.DesktopApp.ViewModels if (selectedTournaments.Count > 0) selectedTournaments.ForEach(e => this.SelectedTournaments.AddUI(e)); } + public void SelectEvent() + { + var selectedEvents = this.Events.Where(e => Regex.IsMatch(e.Name, this.SelectEventRegex)).ToList(); + this.SelectedEvents.Clear(); + if (selectedEvents.Count > 0) + selectedEvents.ForEach(e => this.SelectedEvents.AddUI(e)); + } //This could be simplified the Dictionary was for a previous usage, but i m too lazy to rewrite it. private void ComputeDataGrid() { @@ -344,7 +419,11 @@ namespace LaDOSE.DesktopApp.ViewModels sb.Append(""); int columns = 0; - foreach (var game in Results.Games) + + var distinct = Results.Results.Select(e => e.GameId).Distinct(); + + var gamePlayed = Results.Games.Where(e=> distinct.Contains(e.Id)); + foreach (var game in gamePlayed) { List enumerable = Results.Results.Where(r => r.GameId == game.Id).ToList(); List top3 = enumerable.OrderBy(e => e.Rank).Take(3).Select(e => e.Player).ToList(); @@ -358,7 +437,15 @@ namespace LaDOSE.DesktopApp.ViewModels sb.Append(""); } columns++; - sb.Append(""); + //https://challonge.com/fr/{enumerable.First().TournamentUrl} + var url = enumerable.FirstOrDefault().TournamentUrl; + url = url.Replace(" ", "-"); + url = url.Replace(".", "-"); + sb.AppendLine($"Voir le Bracket

"); } diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Views/TournamentResultView.xaml b/LaDOSE.Src/LaDOSE.DesktopApp/Views/TournamentResultView.xaml index 05d3896..31a1313 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Views/TournamentResultView.xaml +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Views/TournamentResultView.xaml @@ -14,71 +14,136 @@ d:DesignHeight="450" d:DesignWidth="800"> - - + + - - - - - - - - + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - @@ -93,13 +158,13 @@ - + + @@ -165,20 +230,16 @@ - - - + + + - + - - Slug : - - - + \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.REST/RestService.cs b/LaDOSE.Src/LaDOSE.REST/RestService.cs index f388b44..f1ca01f 100644 --- a/LaDOSE.Src/LaDOSE.REST/RestService.cs +++ b/LaDOSE.Src/LaDOSE.REST/RestService.cs @@ -281,15 +281,29 @@ namespace LaDOSE.REST } - public TournamentsResultDTO GetSmashResults(string slug) + + public bool ParseSmash(string slug) { CheckToken(); - var restRequest = new RestRequest($"Api/Smash/GetTournament/{slug}", Method.GET); - var restResponse = Client.Get(restRequest); + var restRequest = new RestRequest($"Api/Tournament/ParseSmash/{slug}", Method.GET); + var restResponse = Client.Get(restRequest); return restResponse.Data; } + + public bool ParseChallonge(List ids) + { + CheckToken(); + return Post, bool>("Api/Tournament/ParseChallonge", ids); + } #endregion + public List GetAllEvents() + { + CheckToken(); + var restRequest = new RestRequest("/api/Event", Method.GET); + var restResponse = Client.Get>(restRequest); + return restResponse.Data; + } } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Service/Interface/IChallongeProvider.cs b/LaDOSE.Src/LaDOSE.Service/Interface/IChallongeProvider.cs index e8744fd..7b890e1 100644 --- a/LaDOSE.Src/LaDOSE.Service/Interface/IChallongeProvider.cs +++ b/LaDOSE.Src/LaDOSE.Service/Interface/IChallongeProvider.cs @@ -19,7 +19,9 @@ namespace LaDOSE.Business.Interface Task GetTournament(int idTournament); Task GetTournament(string urlTournament); - Task> GetEvents(List idTournaments); + Task> ParseEvent(List idTournaments); + + } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Service/Interface/IExternalProviderService.cs b/LaDOSE.Src/LaDOSE.Service/Interface/IExternalProviderService.cs index ad7fce7..016a269 100644 --- a/LaDOSE.Src/LaDOSE.Service/Interface/IExternalProviderService.cs +++ b/LaDOSE.Src/LaDOSE.Service/Interface/IExternalProviderService.cs @@ -9,10 +9,14 @@ namespace LaDOSE.Business.Interface public interface IExternalProviderService { Task> GetTournaments(DateTime? start, DateTime? end); + Task ParseSmash(string tournamentSlug); + Task> ParseChallonge(List ids); - Task GetTournamentsResult(List ids); - Task GetSmashResult(string tournamentSlug); + //Task GetChallongeTournamentsResult(List ids); + //Task GetSmashResult(string tournamentSlug); Task> GetChallongeEvents(List ids); + + Task GetEventsResult(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 a42d30b..cc4c194 100644 --- a/LaDOSE.Src/LaDOSE.Service/Provider/ChallongProvider/ChallongeProvider.cs +++ b/LaDOSE.Src/LaDOSE.Service/Provider/ChallongProvider/ChallongeProvider.cs @@ -207,7 +207,7 @@ namespace LaDOSE.Business.Provider.ChallongProvider 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) + public async Task> ParseEvent(List idTournaments) { var result = new List(); foreach (var idTournament in idTournaments) diff --git a/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/SmashProvider.cs b/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/SmashProvider.cs index 6b288b9..4e7dd58 100644 --- a/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/SmashProvider.cs +++ b/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/SmashProvider.cs @@ -128,6 +128,10 @@ namespace LaDOSE.Business.Provider.SmashProvider id } } + }, + entrant { + id, + isDisqualified } placement } @@ -161,11 +165,11 @@ namespace LaDOSE.Business.Provider.SmashProvider } } - var res= standings.Select(x => new Result() + var res= standings.Where(s=>s.entrant.isDisqualified != true).Select(x => new Result() { Tournament = tournament, TournamentId = tournament.Id, - + PlayerId = PlayerService.GetIdBySmash(x.player), Rank = x.placement }).ToList(); diff --git a/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/Tournament.cs b/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/Tournament.cs index 298f5da..8feccce 100644 --- a/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/Tournament.cs +++ b/LaDOSE.Src/LaDOSE.Service/Provider/SmashProvider/Tournament.cs @@ -53,6 +53,8 @@ namespace LaDOSE.Business.Provider.SmashProvider public StatType stats { get; set; } + public EntrantType entrant { get; set; } + } public class ParticipantType @@ -67,6 +69,7 @@ namespace LaDOSE.Business.Provider.SmashProvider public string name { get; set; } } + public class EventType { public int id { get; set; } @@ -83,7 +86,7 @@ namespace LaDOSE.Business.Provider.SmashProvider { public int id { get; set; } public string name { get; set; } - + public bool? isDisqualified { get; set; } public List participants { get; set; } } diff --git a/LaDOSE.Src/LaDOSE.Service/Service/ExternalProviderService.cs b/LaDOSE.Src/LaDOSE.Service/Service/ExternalProviderService.cs index 0145166..6643bf1 100644 --- a/LaDOSE.Src/LaDOSE.Service/Service/ExternalProviderService.cs +++ b/LaDOSE.Src/LaDOSE.Service/Service/ExternalProviderService.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; +using System.Reactive.Subjects; using System.Threading.Tasks; using LaDOSE.Business.Helper; using LaDOSE.Business.Interface; @@ -75,87 +77,87 @@ namespace LaDOSE.Business.Service //} } - public async Task GetTournamentsResult(List ids) - { - TournamentsResult result = new TournamentsResult(); - result.Results = new List(); - var players = _context.WPUser.ToList(); - var games = _context.Game.ToList(); - var tournaments = await GetChallongeTournaments(ids, games); + //public async Task GetChallongeTournamentsResult(List ids) + //{ + // TournamentsResult result = new TournamentsResult(); + // result.Results = new List(); + // var players = _context.WPUser.ToList(); + // var games = _context.Game.ToList(); + // var tournaments = await GetChallongeTournaments(ids, games); - var allParticipent = tournaments.SelectMany(e => e.Participents).Distinct((a, b) => a.Name == b.Name) - .ToList(); + // var allParticipent = tournaments.SelectMany(e => e.Participents).Distinct((a, b) => a.Name == b.Name) + // .ToList(); - allParticipent.RemoveAll(e => e.Name.StartsWith("[FORFAIT]")); - //USELESS - //foreach (var participent in allParticipent) - //{ - // var player = players.FirstOrDefault(e => e.Name.Contains(participent.Name)); - // if (player != null) - // { - // participent.IsMember = true; - // } - //} + // allParticipent.RemoveAll(e => e.Name.StartsWith("[FORFAIT]")); + // //USELESS + // //foreach (var participent in allParticipent) + // //{ + // // var player = players.FirstOrDefault(e => e.Name.Contains(participent.Name)); + // // if (player != null) + // // { + // // participent.IsMember = true; + // // } + // //} - result.Participents = allParticipent; + // result.Participents = allParticipent; - foreach (var tournament in tournaments) - { + // foreach (var tournament in tournaments) + // { - var playerCount = tournament.Participents.Count; - var lesSacs = tournament.Participents; - var currentRule = TournamentRules.FirstOrDefault(rules => - rules.PlayerMin < playerCount && rules.PlayerMax >= playerCount - ); - if (currentRule == null) - { - throw new Exception("Unable to find rules"); - } + // var playerCount = tournament.Participents.Count; + // var lesSacs = tournament.Participents; + // var currentRule = TournamentRules.FirstOrDefault(rules => + // rules.PlayerMin < playerCount && rules.PlayerMax >= playerCount + // ); + // if (currentRule == null) + // { + // throw new Exception("Unable to find rules"); + // } - var first = tournament.Participents.First(p => p.Rank == 1); - var second = tournament.Participents.First(p => p.Rank == 2); - var thirdFourth = tournament.Participents.Where(p => p.Rank == 3 || p.Rank == 4).ToList(); - var Top8 = tournament.Participents.Where(p => p.Rank > 4 && p.Rank < 9).ToList(); - var Top16 = tournament.Participents.Where(p => p.Rank > 8 && p.Rank <= 16).ToList(); + // var first = tournament.Participents.First(p => p.Rank == 1); + // var second = tournament.Participents.First(p => p.Rank == 2); + // var thirdFourth = tournament.Participents.Where(p => p.Rank == 3 || p.Rank == 4).ToList(); + // var Top8 = tournament.Participents.Where(p => p.Rank > 4 && p.Rank < 9).ToList(); + // var Top16 = tournament.Participents.Where(p => p.Rank > 8 && p.Rank <= 16).ToList(); - result.Results.Add(new Result(first.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url, currentRule.FirstPoint, first.Rank ?? 0)); - lesSacs.Remove(first); - result.Results.Add(new Result(second.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url, currentRule.SecondPoint, second.Rank ?? 0)); - lesSacs.Remove(second); - thirdFourth.ForEach(r => - result.Results.Add(new Result(r.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url, - currentRule.ThirdFourthPoint, r.Rank ?? 0))); - thirdFourth.ForEach(p => lesSacs.Remove(p)); - if (currentRule.Top8Point != 0) - { - Top8.ForEach(r => - result.Results.Add(new Result(r.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url, currentRule.Top8Point, r.Rank ?? 0))); - Top8.ForEach(p => lesSacs.Remove(p)); - } + // result.Results.Add(new Result(first.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url, currentRule.FirstPoint, first.Rank ?? 0)); + // lesSacs.Remove(first); + // result.Results.Add(new Result(second.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url, currentRule.SecondPoint, second.Rank ?? 0)); + // lesSacs.Remove(second); + // thirdFourth.ForEach(r => + // result.Results.Add(new Result(r.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url, + // currentRule.ThirdFourthPoint, r.Rank ?? 0))); + // thirdFourth.ForEach(p => lesSacs.Remove(p)); + // if (currentRule.Top8Point != 0) + // { + // Top8.ForEach(r => + // result.Results.Add(new Result(r.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url, currentRule.Top8Point, r.Rank ?? 0))); + // Top8.ForEach(p => lesSacs.Remove(p)); + // } - if (currentRule.Top16Point != 0) - { - Top16.ForEach(r => - result.Results.Add( - new Result(r.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url, currentRule.Top16Point, r.Rank ?? 0))); - Top16.ForEach(p => lesSacs.Remove(p)); - } + // if (currentRule.Top16Point != 0) + // { + // Top16.ForEach(r => + // result.Results.Add( + // new Result(r.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url, currentRule.Top16Point, r.Rank ?? 0))); + // Top16.ForEach(p => lesSacs.Remove(p)); + // } - lesSacs.ForEach(r => - result.Results.Add(new Result(r.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url, - currentRule.Participation, r.Rank ?? 0))); - } + // lesSacs.ForEach(r => + // result.Results.Add(new Result(r.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url, + // currentRule.Participation, r.Rank ?? 0))); + // } - result.Games = tournaments.Select(e => e.Game).Distinct((game, game1) => game.Name == game1.Name).Where(e => e != null).ToList(); - if (result.Games == null) - { - result.Games = new List(); - } - result.Games.Add(new Game() { Id = 0, Order = 9999, Name = "UNKNOW" }); - return result; - } + // result.Games = tournaments.Select(e => e.Game).Distinct((game, game1) => game.Name == game1.Name).Where(e => e != null).ToList(); + // if (result.Games == null) + // { + // result.Games = new List(); + // } + // result.Games.Add(new Game() { Id = 0, Order = 9999, Name = "UNKNOW" }); + // return result; + //} public async Task ParseSmash(string tournamentSlug) @@ -189,23 +191,33 @@ namespace LaDOSE.Business.Service } + public Task> ParseChallonge(List ids) + { + return _challongeProvider.ParseEvent(ids); + } + private Event GetBySlug(string tournamentSlug) { return _context.Event.FirstOrDefault(e => e.SmashSlug == tournamentSlug); } - public async Task GetSmashResult(string tournamentSlug) - { - var parse = await this.ParseSmash(tournamentSlug); - var test = await GetEventResult(parse.Id); - return test; + //public async Task GetSmashResult(string tournamentSlug) + //{ + // var parse = await this.ParseSmash(tournamentSlug); + // var test = await GetEventResult(parse.Id); + // return test; - } + //} + //public async Task GetEventsResult(List events) + //{ + // var test = await GetEventsResult(events); + // return test; + //} public async Task> GetChallongeEvents(List ids) { - var events = await this._challongeProvider.GetEvents(ids); + var events = await this._challongeProvider.ParseEvent(ids); this._context.Event.AddRange(events); return events; } @@ -251,6 +263,108 @@ namespace LaDOSE.Business.Service return this._context.ChallongeTournament.Any(e => e.ChallongeId == idTournament); } + /// + /// Get Events Result + /// + /// + /// + public async Task GetEventsResult(List id) + { + var cevent = new Event(); + cevent.Tournaments = new List(); + List players = new List(); + foreach (var eventId in id) + { + Event e = _context.Event.Include(e => e.Tournaments).ThenInclude(t => t.Results).ThenInclude(e => e.Player).FirstOrDefault(e => e.Id == eventId); + players = players.Concat(e.Tournaments.SelectMany(e => e.Results.Select(e => e.Player)).Distinct().ToList()).ToList(); + cevent.Tournaments = cevent.Tournaments.Concat(e.Tournaments).ToList(); + } + + var games = _context.Game.ToList(); + + TournamentsResult result = new TournamentsResult(); + result.Results = new List(); + result.Games = new List(); + result.Participents = new List(); + players.ForEach(e => + { + var x = new ChallongeParticipent() + { + Name = e.Gamertag, + ChallongeId = e.Id, + Id = e.Id + }; + result.Participents.Add(x); + }); + + foreach (var tournament in cevent.Tournaments.Where(e => e.Results != null && e.Results.Any()).ToList()) + { + + var tplayer = tournament.Results.Select(e => e.Player).ToList(); + var playerCount = tplayer.Count(); + var lesSacs = tplayer; + var currentRule = TournamentRules.FirstOrDefault(rules => + rules.PlayerMin < playerCount && rules.PlayerMax >= playerCount + ); + if (currentRule == null) + { + throw new Exception("Unable to find rules"); + } + + var first = tournament.Results.First(p => p.Rank == 1); + var second = tournament.Results.First(p => p.Rank == 2); + var thirdFourth = tournament.Results.Where(p => p.Rank == 3 || p.Rank == 4).ToList(); + 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 ?? 0, tournament.Id, tournament.Name, currentRule.FirstPoint, first.Rank)); + lesSacs.Remove(first.Player); + 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 ?? 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 ?? 0, tournament.Id, tournament.Name, + currentRule.Top8Point, r.Rank))); + Top8.ForEach(p => lesSacs.Remove(p.Player)); + } + + if (currentRule.Top16Point != 0) + { + Top16.ForEach(r => + result.Results.Add( + new Result(r.Player.Gamertag, tournament.Game?.Id ?? 0, tournament.Id, tournament.Name, + currentRule.Top16Point, r.Rank))); + Top16.ForEach(p => lesSacs.Remove(p.Player)); + } + + lesSacs.ForEach(r => + result.Results.Add(new Result(r.Gamertag, tournament.Game?.Id ?? 0, tournament.Id, tournament.Name, + currentRule.Participation, 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 }); + } + + var enumerable = result.Results.Select(e => e.GameId).Distinct(); + result.Games = _context.Game.Where(g => enumerable.Contains(g.Id)).ToList(); + + System.Diagnostics.Trace.WriteLine(result.Results); + + return await Task.FromResult(result); + } + /// + /// Get Result For one Event + /// + /// + /// public async Task GetEventResult(int id) { @@ -272,11 +386,6 @@ namespace LaDOSE.Business.Service }; result.Participents.Add(x); }); - games.ForEach(e => - { - e.Id = e.SmashId ?? e.Id; - result.Games.Add(e); - }); foreach (var tournament in cevent.Tournaments.Where(e => e.Results != null && e.Results.Any()).ToList()) { @@ -310,7 +419,7 @@ namespace LaDOSE.Business.Service { Top8.ForEach(r => result.Results.Add(new Result(r.Player.Gamertag, tournament.Game?.Id??0, tournament.Id, tournament.Name, - currentRule.ThirdFourthPoint, r.Rank))); + currentRule.Top8Point, r.Rank))); Top8.ForEach(p => lesSacs.Remove(p.Player)); } @@ -319,13 +428,13 @@ namespace LaDOSE.Business.Service Top16.ForEach(r => result.Results.Add( new Result(r.Player.Gamertag, tournament.Game?.Id??0, tournament.Id, tournament.Name, - currentRule.ThirdFourthPoint, r.Rank))); + currentRule.Top16Point, r.Rank))); Top16.ForEach(p => lesSacs.Remove(p.Player)); } lesSacs.ForEach(r => 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))); + currentRule.Participation, tournament.Results.FirstOrDefault(e=>e.Player == r)?.Rank??999))); } @@ -334,6 +443,9 @@ namespace LaDOSE.Business.Service result.Games.Add(new Game(){Id = 0,Name = "GAME NOT FOUND",LongName = "GAME NOT FOUND",Order = 999}); } + var enumerable = result.Results.Select(e => e.GameId).Distinct(); + result.Games = _context.Game.Where(g => enumerable.Contains(g.Id)).ToList(); + System.Diagnostics.Trace.WriteLine(result.Results); return await Task.FromResult(result);
" + + var span = 1; + if (columns == gamePlayed.Count()) + { + if (columns % 2 != 0) + { + span = 2; + } + } + sb.Append($"" + "" + $"{game.LongName} ({Results.Results.Count(e => e.GameId == game.Id)} participants) :" + ""); @@ -366,7 +453,11 @@ namespace LaDOSE.DesktopApp.ViewModels if (top3.Count >= 3) { sb.AppendLine($"
1/ {top3[0]}
2/ {top3[1]}
3/ {top3[2]}
"); - sb.AppendLine($"https://challonge.com/fr/{enumerable.First().TournamentUrl}