Get the sets

This commit is contained in:
2022-03-20 13:52:05 +01:00
parent 87c9883245
commit 92b6d3e568
11 changed files with 232 additions and 17 deletions

View File

@@ -26,6 +26,7 @@ namespace LaDOSE.Entity.Context
public DbSet<Event> Event { get; set; }
public DbSet<Tournament> Tournament { get; set; }
public DbSet<Result> Result { get; set; }
public DbSet<Set> Set { get; set; }
#endregion
public DbSet<ChallongeParticipent> ChallongeParticipent { get; set; }
@@ -58,6 +59,23 @@ namespace LaDOSE.Entity.Context
.HasForeignKey(pt => pt.EventId)
;
modelBuilder.Entity<Set>()
.HasOne(e => e.Tournament)
.WithMany(e => e.Sets)
.HasForeignKey(pt => pt.TournamentId)
;
//modelBuilder.Entity<Set>()
// .HasOne(e => e.Player1)
// .WithMany(e => e.Sets)
// .HasForeignKey(pt => pt.Player1Id)
// ;
//modelBuilder.Entity<Set>()
// .HasOne(e => e.Player2)
// .WithMany(e => e.Sets)
// .HasForeignKey(pt => pt.Player2Id)
// ;
//#region SeasonGame
//modelBuilder.Entity<SeasonGame>()
// .HasKey(t => new { t.SeasonId, t.GameId });

View File

@@ -19,6 +19,7 @@ namespace LaDOSE.Entity
}
public String Name { get; set; }
public String SmashSlug { get; set; }
public int? SmashId { get; set; }
public DateTime Date { get; set; }

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Security.Cryptography.X509Certificates;
@@ -21,6 +22,7 @@ namespace LaDOSE.Entity
[NotMapped]
public Boolean IsChallonge => ChallongeId.HasValue;
//public List<Set> Sets { get; set; }
}
}

View File

@@ -0,0 +1,24 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace LaDOSE.Entity
{
public class Set : Context.Entity
{
public int TournamentId { get; set; }
public Tournament Tournament { get; set; }
public int Player1Id { get; set; }
//[ForeignKey("Player1Id")]
//public Player Player1 { get; set; }
public int Player2Id { get; set; }
//[ForeignKey("Player2Id")]
//public Player Player2 { get; set; }
public int Player1Score { get; set; }
public int Player2Score { get; set; }
public int Round { get; set; }
}
}

View File

@@ -25,7 +25,11 @@ namespace LaDOSE.Entity
public int? GameId {get;set;}
public Game Game { get; set; }
public bool Finish { get; set; }
public List<Result> Results { get; set; }
public List<Set> Sets { get; set; }

View File

@@ -5,6 +5,6 @@ namespace LaDOSE.Business.Interface
{
public interface IPlayerService : IBaseService<Player>
{
int GetBySmash(PlayerType playerUser);
int GetBySmash(ParticipantType participantUser);
}
}

View File

@@ -11,6 +11,8 @@ namespace LaDOSE.Business.Interface
{
Task<Event> GetEvent(string slug);
Task<List<Tournament>> GetResults(ref List<Tournament> tournaments);
Task<List<Tournament>> GetSets(ref List<Tournament> tournaments);
Task<Event> ParseEvent(string slug);
Task<TournamentResponse> GetTournament(string sludge);

View File

@@ -80,11 +80,14 @@ namespace LaDOSE.Business.Provider.SmashProvider
{
Name = e.name,
SmashId = e.id,
Finish = e.state == "COMPLETED",
Game = games.FirstOrDefault(g => g.SmashId == e.videogame.id)
}).ToList();
return new Event
{
SmashSlug = slug,
Name = querySmash.Result.Tournament.Name,
SmashId = querySmash.Result.Tournament.id,
Date = querySmash.Result.Tournament.startAt,
@@ -97,7 +100,7 @@ namespace LaDOSE.Business.Provider.SmashProvider
public Task<List<Tournament>> GetResults(ref List<Tournament> tournaments)
{
foreach (var tournament in tournaments)
foreach (var tournament in tournaments.Where(t=>t.Finish).ToList())
{
var query = new GraphQLRequest
{
@@ -149,8 +152,8 @@ namespace LaDOSE.Business.Provider.SmashProvider
{
query.Variables = new
{
page = querySmash.Result.Event.standings.pageInfo.page,
eventsId = tournament.SmashId,
page = querySmash.Result.Event.standings.pageInfo.page+1,
@event = tournament.SmashId,
};
querySmash = QuerySmash<EventResponse>(query);
standings.AddRange(querySmash.Result.Event.standings.nodes);
@@ -183,6 +186,115 @@ namespace LaDOSE.Business.Provider.SmashProvider
return Task.FromResult(tournaments);
}
public Task<List<Tournament>> GetSets(ref List<Tournament> tournaments)
{
foreach (var tournament in tournaments.Where(t => t.Finish).ToList())
{
var query = new GraphQLRequest
{
Query = @"query SetsQuery($event: ID,$page:Int) {
event(id: $event){
sets(page:$page,perPage:20){
pageInfo {
total
totalPages
page
perPage
sortBy
filter
},
nodes {
id,
lPlacement,
wPlacement,
round,
slots {
id,
slotIndex,
standing{
id,
player{
id,
user{
id,
}
}
stats{
score {
label
value
displayValue
}
}
}
entrant {
id,
name,
participants{
id,
gamerTag
user {
id
},
}
},
},
phaseGroup {
id
},
identifier
},
}
}
}",
OperationName = "SetsQuery",
Variables = new
{
page = 1,
@event = tournament.SmashId,
}
};
var querySmash = QuerySmash<SetsResponse>(query);
if (querySmash.Result.Event.sets.nodes != null)
{
var sets = querySmash.Result.Event.sets.nodes;
if (querySmash.Result.Event.sets.pageInfo.totalPages > 1)
{
while (querySmash.Result.Event.sets.pageInfo.page <
querySmash.Result.Event.sets.pageInfo.totalPages)
{
query.Variables = new
{
page = querySmash.Result.Event.sets.pageInfo.page+1,
@event = tournament.SmashId,
};
querySmash = QuerySmash<SetsResponse>(query);
sets.AddRange(querySmash.Result.Event.sets.nodes);
}
}
var tset = sets.Select(x => new Set()
{
Tournament = tournament,
TournamentId = tournament.Id,
Player1Id = PlayerService.GetBySmash(x.slots[0].entrant.participants[0]),
Player2Id = PlayerService.GetBySmash(x.slots[1].entrant.participants[0]),
Player1Score = x.slots[0].standing.stats.score.value,
Player2Score = x.slots[1].standing.stats.score.value,
Round = x.round ?? 0,
}).ToList();
tournament.Sets = tset;
}
}
return Task.FromResult(tournaments);
}
public async Task<Event> ParseEvent(string slug)
{
Event e = await this.GetEvent(slug);

View File

@@ -31,16 +31,31 @@ namespace LaDOSE.Business.Provider.SmashProvider
public int id { get; set; }
public string Name { get; set; }
}
public class ScoreType
{
public string label { get; set; }
public int value { get; set; }
public string displayValue { get; set; }
}
public class StatType
{
public ScoreType score { get; set; }
}
public class StandingType
{
public int id { get; set; }
public string id { get; set; }
public int placement { get; set; }
public PlayerType player { get; set; }
public ParticipantType player { get; set; }
public StatType stats { get; set; }
}
public class PlayerType
public class ParticipantType
{
public int id { get; set; }
public string gamerTag { get; set; }
@@ -61,8 +76,37 @@ namespace LaDOSE.Business.Provider.SmashProvider
public VideoGameType videogame { get; set; }
public Node<StandingType> standings { get; set; }
public Node<SetType> sets { get; set; }
}
public class EntrantType
{
public int id { get; set; }
public string name { get; set; }
public List<ParticipantType> participants { get; set; }
}
public class SlotType
{
public string id { get; set; }
public int slotIndex { get; set; }
public StandingType standing { get; set; }
public EntrantType entrant { get; set; }
}
public class SetType
{
public string id { get; set; }
public int? lPlacement { get; set; }
public int? wPlacement { get; set; }
public int? round { get; set; }
public List<SlotType> slots { get; set; }
public string identifier { get; set; }
}
public class Node<T>
{
public PageInfoType pageInfo { get; set; }
@@ -84,7 +128,11 @@ namespace LaDOSE.Business.Provider.SmashProvider
public EventType Event { get; set; }
}
public class SetsResponse
{
public EventType Event { get; set; }
}
}

View File

@@ -18,7 +18,7 @@ namespace LaDOSE.Business.Service
public class EventService : BaseService<Event>, IEventService
{
private IChallongeProvider _challongeProvider;
private ISmashProvider _smashProvider;
#region Rules
private class Rules
{
@@ -54,7 +54,7 @@ namespace LaDOSE.Business.Service
new Rules(32, Int32.MaxValue, 18, 12, 8, 5, 3),
};
private ISmashProvider _smashProvider;
#endregion
@@ -163,7 +163,11 @@ namespace LaDOSE.Business.Service
var test = this._smashProvider.GetEvent(tournamentSlug).Result;
var testTournaments = test.Tournaments;
var getResultEvents = this._smashProvider.GetResults(ref testTournaments).Result;
this._context.Event.Add(test);
getResultEvents = this._smashProvider.GetSets(ref testTournaments).Result;
this._context.Add(test);
this._context.SaveChanges();
var tournaments = await _smashProvider.GetTournament(tournamentSlug);

View File

@@ -14,27 +14,27 @@ namespace LaDOSE.Business.Service
{
}
public int GetBySmash(PlayerType playerUser)
public int GetBySmash(ParticipantType participantUser)
{
//var p2 = _context.Player.ToList();
var p = _context.Player.FirstOrDefault(e => e.SmashId == playerUser.user.id);
var p = _context.Player.FirstOrDefault(e => e.SmashId == participantUser.user.id);
if (p == null)
{
var entity = new Player()
{
Gamertag = playerUser.gamerTag,
Name = string.IsNullOrEmpty(playerUser.user.name)? playerUser.gamerTag : playerUser.user.name,
SmashId = playerUser.user.id,
Gamertag = participantUser.gamerTag,
Name = string.IsNullOrEmpty(participantUser.user.name)? participantUser.gamerTag : participantUser.user.name,
SmashId = participantUser.user.id,
};
_context.Player.Add(entity);
_context.SaveChanges();
return entity.Id;
}
if (p.Gamertag != playerUser.gamerTag)
if (p.Gamertag != participantUser.gamerTag)
{
p.Name = playerUser.gamerTag;
p.Name = participantUser.gamerTag;
_context.SaveChanges();
}