Improve ranking parsing
Improve Smash.gg parsing Fix useless stuff Fix
This commit is contained in:
@@ -49,9 +49,9 @@ namespace LaDOSE.Api.Controllers
|
|||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(tournamentSlug))
|
if (!String.IsNullOrEmpty(tournamentSlug))
|
||||||
{
|
{
|
||||||
var tournaments = await _service.GetSmashResult2(tournamentSlug);
|
//var tournaments = await _service.GetSmashResult2(tournamentSlug);
|
||||||
|
return Ok();
|
||||||
return Ok(tournaments);
|
//return Ok(tournaments);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -75,7 +75,6 @@ namespace LaDOSE.Api
|
|||||||
options => options.UseMySql($"Server={MySqlServer};Database={MySqlDatabase};User={MySqlUser};Password={MySqlPassword};", // replace with your Connection String
|
options => options.UseMySql($"Server={MySqlServer};Database={MySqlDatabase};User={MySqlUser};Password={MySqlPassword};", // replace with your Connection String
|
||||||
mysqlOptions =>
|
mysqlOptions =>
|
||||||
{
|
{
|
||||||
|
|
||||||
mysqlOptions.ServerVersion(new Version(10, 1, 16), ServerType.MariaDb); // replace with your Server Version and Type
|
mysqlOptions.ServerVersion(new Version(10, 1, 16), ServerType.MariaDb); // replace with your Server Version and Type
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ namespace LaDOSE.REST
|
|||||||
public void Connect(Uri url, string user, string password)
|
public void Connect(Uri url, string user, string password)
|
||||||
{
|
{
|
||||||
Client = new RestClient(url);
|
Client = new RestClient(url);
|
||||||
#if DEBUG
|
|
||||||
Client.Timeout = 999*1000;
|
Client.Timeout = 999*1000;
|
||||||
#endif
|
|
||||||
this.username = user;
|
this.username = user;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
GetToken(user, password);
|
GetToken(user, password);
|
||||||
|
|||||||
@@ -13,9 +13,6 @@ namespace LaDOSE.Business.Interface
|
|||||||
Task<TournamentsResult> GetTournamentsResult(List<int> ids);
|
Task<TournamentsResult> GetTournamentsResult(List<int> ids);
|
||||||
Task<TournamentsResult> GetSmashResult(string tournamentSlug);
|
Task<TournamentsResult> GetSmashResult(string tournamentSlug);
|
||||||
|
|
||||||
Task<TournamentsResult> GetSmashResult2(string tournamentSlug);
|
|
||||||
|
|
||||||
|
|
||||||
Task<List<Event>> GetChallongeEvents(List<int> ids);
|
Task<List<Event>> GetChallongeEvents(List<int> ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,7 +204,7 @@ namespace LaDOSE.Business.Provider.ChallongProvider
|
|||||||
return currentevent;
|
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 DateRanking = @"^\[(\d{2}\/\d{2}\/\d{2})\]";
|
||||||
private const string GameRanking = @"\-.(\w*)$";
|
private const string GameRanking = @"\-.(\w*)$";
|
||||||
public async Task<List<Event>> GetEvents(List<int> idTournaments)
|
public async Task<List<Event>> GetEvents(List<int> 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 eventName = Regex.Match(tournament.Result.Name, RegexRanking);
|
||||||
var eventDate = Regex.Match(tournament.Result.Name, DateRanking);
|
var eventDate = Regex.Match(tournament.Result.Name, DateRanking);
|
||||||
|
|||||||
@@ -285,8 +285,8 @@ namespace LaDOSE.Business.Provider.SmashProvider
|
|||||||
|
|
||||||
Player1Id = PlayerService.GetIdBySmash(x.slots[0].entrant.participants[0]),
|
Player1Id = PlayerService.GetIdBySmash(x.slots[0].entrant.participants[0]),
|
||||||
Player2Id = PlayerService.GetIdBySmash(x.slots[1].entrant.participants[0]),
|
Player2Id = PlayerService.GetIdBySmash(x.slots[1].entrant.participants[0]),
|
||||||
Player1Score = x.slots[0].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,
|
Player2Score = x.slots[1].standing.stats.score.value.HasValue ? x.slots[1].standing.stats.score.value.Value : 0,
|
||||||
Round = x.round ?? 0,
|
Round = x.round ?? 0,
|
||||||
}).ToList();
|
}).ToList();
|
||||||
tournament.Sets = tset;
|
tournament.Sets = tset;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace LaDOSE.Business.Provider.SmashProvider
|
|||||||
public class ScoreType
|
public class ScoreType
|
||||||
{
|
{
|
||||||
public string label { get; set; }
|
public string label { get; set; }
|
||||||
public int value { get; set; }
|
public int? value { get; set; }
|
||||||
public string displayValue { get; set; }
|
public string displayValue { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,97 +198,11 @@ namespace LaDOSE.Business.Service
|
|||||||
{
|
{
|
||||||
var parse = await this.ParseSmash(tournamentSlug);
|
var parse = await this.ParseSmash(tournamentSlug);
|
||||||
var test = await GetEventResult(parse.Id);
|
var test = await GetEventResult(parse.Id);
|
||||||
if (test.Results != null)
|
|
||||||
{
|
|
||||||
var test2 = test.Games.Count();
|
|
||||||
}
|
|
||||||
return test;
|
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>();
|
|
||||||
result.Games = new List<Game>();
|
|
||||||
result.Participents = new List<ChallongeParticipent>();
|
|
||||||
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<TournamentsResult> GetSmashResult2(string tournamentSlug)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<List<Event>> GetChallongeEvents(List<int> ids)
|
public async Task<List<Event>> GetChallongeEvents(List<int> ids)
|
||||||
{
|
{
|
||||||
var events = await this._challongeProvider.GetEvents(ids);
|
var events = await this._challongeProvider.GetEvents(ids);
|
||||||
@@ -384,18 +298,18 @@ namespace LaDOSE.Business.Service
|
|||||||
var Top8 = tournament.Results.Where(p => p.Rank > 4 && p.Rank < 9).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();
|
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);
|
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);
|
lesSacs.Remove(second.Player);
|
||||||
thirdFourth.ForEach(r =>
|
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)));
|
currentRule.ThirdFourthPoint, r.Rank)));
|
||||||
thirdFourth.ForEach(p => lesSacs.Remove(p.Player));
|
thirdFourth.ForEach(p => lesSacs.Remove(p.Player));
|
||||||
if (currentRule.Top8Point != 0)
|
if (currentRule.Top8Point != 0)
|
||||||
{
|
{
|
||||||
Top8.ForEach(r =>
|
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)));
|
currentRule.ThirdFourthPoint, r.Rank)));
|
||||||
Top8.ForEach(p => lesSacs.Remove(p.Player));
|
Top8.ForEach(p => lesSacs.Remove(p.Player));
|
||||||
}
|
}
|
||||||
@@ -404,17 +318,22 @@ namespace LaDOSE.Business.Service
|
|||||||
{
|
{
|
||||||
Top16.ForEach(r =>
|
Top16.ForEach(r =>
|
||||||
result.Results.Add(
|
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)));
|
currentRule.ThirdFourthPoint, r.Rank)));
|
||||||
Top16.ForEach(p => lesSacs.Remove(p.Player));
|
Top16.ForEach(p => lesSacs.Remove(p.Player));
|
||||||
}
|
}
|
||||||
|
|
||||||
lesSacs.ForEach(r =>
|
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)));
|
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);
|
System.Diagnostics.Trace.WriteLine(result.Results);
|
||||||
|
|
||||||
return await Task.FromResult(result);
|
return await Task.FromResult(result);
|
||||||
|
|||||||
Reference in New Issue
Block a user