Quick and Dirty Tournament Result / List
This commit is contained in:
@@ -14,6 +14,7 @@ namespace LaDOSE.Business.Interface
|
||||
Task<ParticipantResult> AddPlayer(int tournamentId, string userName);
|
||||
|
||||
Task<List<Tournament>> GetTournaments(DateTime? start, DateTime? end);
|
||||
Task<List<Participent>> GetParticipents(int tournamentId);
|
||||
Task<List<Participent>> GetParticipents(int idTournament);
|
||||
Task<Tournament> GetTournament(int idTournament);
|
||||
}
|
||||
}
|
||||
14
LaDOSE.Src/LaDOSE.Service/Interface/ITournamentService.cs
Normal file
14
LaDOSE.Src/LaDOSE.Service/Interface/ITournamentService.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LaDOSE.Entity.Challonge;
|
||||
|
||||
namespace LaDOSE.Business.Interface
|
||||
{
|
||||
public interface ITournamentService
|
||||
{
|
||||
Task<List<Tournament>> GetTournaments(DateTime? start, DateTime? end);
|
||||
|
||||
Task<TournamentsResult> GetTournamentsResult(List<int> ids);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LaDOSE.Entity;
|
||||
using LaDOSE.Entity.Challonge;
|
||||
using LaDOSE.Entity.Wordpress;
|
||||
|
||||
namespace LaDOSE.Business.Interface
|
||||
@@ -18,6 +16,7 @@ namespace LaDOSE.Business.Interface
|
||||
|
||||
Task<string> GetLastChallonge();
|
||||
|
||||
Task<List<Tournament>> GetTournaments(DateTime? start, DateTime? end);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,21 +68,35 @@ namespace LaDOSE.Business.Provider
|
||||
return tournaments;
|
||||
}
|
||||
|
||||
public async Task<List<Participent>> GetParticipents(int tournamentId)
|
||||
public async Task<List<Participent>> GetParticipents(int idTournament)
|
||||
{
|
||||
var participentResults = new ParticipantsQuery().call(ApiCaller);
|
||||
var participentResults = await new ParticipantsQuery(){tournamentID = idTournament }.call(ApiCaller);
|
||||
|
||||
List<Participent> participants = new List<Participent>();
|
||||
participentResults.Result.ForEach(w => participants.Add(new Participent()
|
||||
participentResults.ForEach(w => participants.Add(new Participent()
|
||||
{
|
||||
Id = w.id,
|
||||
Name = w.name,
|
||||
Rank = w.final_rank,
|
||||
IsMember = false,
|
||||
IsMember = true,
|
||||
}));
|
||||
return participants;
|
||||
}
|
||||
|
||||
public async Task<Tournament> GetTournament(int idTournament)
|
||||
{
|
||||
|
||||
var tournamentResult = await new TournamentQuery(idTournament).call(ApiCaller);
|
||||
|
||||
return new Tournament()
|
||||
{
|
||||
Id = tournamentResult.id,
|
||||
Name = tournamentResult.name,
|
||||
Participents = new List<Participent>()
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public async Task<string> GetLastTournament()
|
||||
{
|
||||
string dernierTournois = null;
|
||||
|
||||
126
LaDOSE.Src/LaDOSE.Service/Service/TournamentService.cs
Normal file
126
LaDOSE.Src/LaDOSE.Service/Service/TournamentService.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LaDOSE.Business.Interface;
|
||||
using LaDOSE.Entity.Challonge;
|
||||
using LaDOSE.Entity.Context;
|
||||
using LaDOSE.Entity.Wordpress;
|
||||
using Microsoft.EntityFrameworkCore.Internal;
|
||||
|
||||
namespace LaDOSE.Business.Service
|
||||
{
|
||||
public class TournamentService : ITournamentService
|
||||
{
|
||||
private class Rules
|
||||
{
|
||||
public int PlayerMin { get; set; }
|
||||
public int PlayerMax { get; set; }
|
||||
public int FirstPoint { get; set; }
|
||||
public int SecondPoint { get; set; }
|
||||
public int ThirdFourthPoint { get; set; }
|
||||
public int Top8Point { get; set; }
|
||||
public int Top16Point { get; set; }
|
||||
|
||||
public Rules(int playerMin, int playerMax, int firstPoint, int secondPoint, int thirdFourthPoint, int top8Point, int top16Point)
|
||||
{
|
||||
PlayerMin = playerMin;
|
||||
PlayerMax = playerMax;
|
||||
FirstPoint = firstPoint;
|
||||
SecondPoint = secondPoint;
|
||||
ThirdFourthPoint = thirdFourthPoint;
|
||||
Top8Point = top8Point;
|
||||
Top16Point = top16Point;
|
||||
}
|
||||
}
|
||||
|
||||
private LaDOSEDbContext _context;
|
||||
private IChallongeProvider _challongeProvider;
|
||||
|
||||
private List<Rules> TournamentRules = new List<Rules>()
|
||||
{
|
||||
new Rules(0,8,5,3,2,0,0),
|
||||
new Rules(8,16,8,5,3,2,0),
|
||||
new Rules(16,32,12,8,5,3,2),
|
||||
new Rules(32,Int32.MaxValue,18,12,8,5,3),
|
||||
};
|
||||
|
||||
public TournamentService(LaDOSEDbContext context, IChallongeProvider challongeProvider)
|
||||
{
|
||||
this._context = context;
|
||||
this._challongeProvider = challongeProvider;
|
||||
}
|
||||
public async Task<List<Tournament>> GetTournaments(DateTime? start, DateTime? end)
|
||||
{
|
||||
List<WPUser> wpUsers = _context.WPUser.ToList();
|
||||
var tournaments = await _challongeProvider.GetTournaments(start, end);
|
||||
|
||||
foreach (var tournament in tournaments)
|
||||
{
|
||||
List<Participent> participents = await _challongeProvider.GetParticipents(tournament.Id);
|
||||
tournament.Participents = participents;
|
||||
}
|
||||
return tournaments;
|
||||
}
|
||||
|
||||
public async Task<TournamentsResult> GetTournamentsResult(List<int> ids)
|
||||
{
|
||||
TournamentsResult result = new TournamentsResult();
|
||||
result.Results = new List<Result>();
|
||||
var tournaments = new List<Tournament>();
|
||||
foreach (var idTournament in ids)
|
||||
{
|
||||
var tournament = await _challongeProvider.GetTournament(idTournament);
|
||||
tournament.Participents = await _challongeProvider.GetParticipents(tournament.Id);
|
||||
tournaments.Add(tournament);
|
||||
}
|
||||
|
||||
var games = _context.Game.ToList();
|
||||
var players = _context.WPUser.ToList();
|
||||
|
||||
var allParticipent = tournaments.SelectMany(e => e.Participents).Distinct((a, b) => a.Name == b.Name).ToList();
|
||||
foreach (var participent in allParticipent)
|
||||
{
|
||||
var player = players.FirstOrDefault(e => e.Name.Contains(participent.Name));
|
||||
if (player!=null)
|
||||
{
|
||||
participent.IsMember = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
result.Participents = allParticipent;
|
||||
|
||||
foreach (var tournament in tournaments)
|
||||
{
|
||||
var game = games.First(g => tournament.Name.Contains(g.Name));
|
||||
tournament.Game = game;
|
||||
|
||||
var playerCount = tournament.Participents.Count;
|
||||
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 >9 && p.Rank<=16).ToList();
|
||||
|
||||
result.Results.Add(new Result(first.Name,tournament.Game.Id,currentRule.FirstPoint));
|
||||
result.Results.Add(new Result(second.Name,tournament.Game.Id,currentRule.SecondPoint));
|
||||
thirdFourth.ForEach(r=> result.Results.Add(new Result(r.Name, tournament.Game.Id, currentRule.ThirdFourthPoint)));
|
||||
Top8.ForEach(r=> result.Results.Add(new Result(r.Name, tournament.Game.Id, currentRule.Top8Point)));
|
||||
Top16.ForEach(r=> result.Results.Add(new Result(r.Name, tournament.Game.Id, currentRule.Top16Point)));
|
||||
}
|
||||
|
||||
result.Games = tournaments.Select(e => e.Game).ToList();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@ using ChallongeCSharpDriver.Core.Results;
|
||||
using LaDOSE.Business.Helper;
|
||||
using LaDOSE.Business.Interface;
|
||||
using LaDOSE.Entity;
|
||||
using LaDOSE.Entity.Challonge;
|
||||
using LaDOSE.Entity.Context;
|
||||
using LaDOSE.Entity.Wordpress;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -165,19 +164,9 @@ namespace LaDOSE.Business.Service
|
||||
var lastTournament = await _challongeProvider.GetLastTournament();
|
||||
return lastTournament;
|
||||
}
|
||||
public async Task<List<Tournament>> GetTournaments(DateTime? start, DateTime? end)
|
||||
{
|
||||
var tournaments = await _challongeProvider.GetTournaments(start,end);
|
||||
|
||||
foreach (var tournament in tournaments)
|
||||
{
|
||||
List<Participent> participents = await _challongeProvider.GetParticipents(tournament.Id);
|
||||
tournament.Participents = participents;
|
||||
}
|
||||
|
||||
|
||||
return tournaments;
|
||||
}
|
||||
|
||||
private string FormatCurrentEventName(string currentEventName)
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user