Skip to content

Commit

Permalink
+ Adjustments to logic to account for error and data handling
Browse files Browse the repository at this point in the history
  • Loading branch information
KDotIV committed May 24, 2024
1 parent 687bcc6 commit f9ec06d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 9 additions & 2 deletions SengokuProvider.Library/Services/Players/PlayerIntakeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public async Task<int> IntakePlayerData(IntakePlayersByTournamentCommand command
_currentEventId = newPlayerData.Data.Id;
int playerSuccess = await ProcessPlayerData(newPlayerData);

Console.WriteLine($"Players Inserted from Registry: {_playerRegistry.Count}");
await Task.Delay(800);

Console.WriteLine("Starting Standings Processing");
var standingsSuccess = await ProcessLegendsFromNewPlayers(_playerRegistry);

Console.WriteLine($"{standingsSuccess} total standings added for player");
Expand All @@ -49,18 +53,20 @@ public async Task<int> IntakePlayerData(IntakePlayersByTournamentCommand command
throw new ApplicationException($"Unexpected Error Occurred during Player Intake: {ex.StackTrace}", ex);
}
}

private async Task<int> ProcessLegendsFromNewPlayers(ConcurrentDictionary<int, string> registeredPlayers)
{
var currentStandings = new List<PlayerStandingResult>();
if (registeredPlayers.Count == 0) throw new ApplicationException("Players must exist before new standings data is created");
foreach (var newPlayer in registeredPlayers)
{
Console.WriteLine("Querying Standings Data");
await Task.Delay(1000);
PlayerStandingResult newStanding = await _queryService.QueryPlayerStandings(new GetPlayerStandingsCommand { EventId = _currentEventId, GamerTag = newPlayer.Value, PerPage = 20 });
if (newStanding == null) { continue; }
if (newStanding == null || newStanding.Response.Contains("Failed")) { continue; }

newStanding.TournamentLinks.PlayerId = newPlayer.Key;

Check warning on line 67 in SengokuProvider.Library/Services/Players/PlayerIntakeService.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 67 in SengokuProvider.Library/Services/Players/PlayerIntakeService.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
currentStandings.Add(newStanding);
Console.WriteLine("Player Standing Data added");
}
return await IntakePlayerStandingData(currentStandings);
}
Expand Down Expand Up @@ -99,6 +105,7 @@ ON CONFLICT (entrant_id) DO UPDATE SET
if(result > 0)
{
_playerRegistry.TryRemove(data.TournamentLinks.PlayerId, out _);
totalSuccess += result;
Console.WriteLine("Player removed from registry");
}
}
Expand Down
10 changes: 6 additions & 4 deletions SengokuProvider.Library/Services/Players/PlayerQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,23 @@ public async Task<PlayerStandingResult> QueryPlayerStandings(GetPlayerStandingsC
try
{
var data = await QueryStartggStandings(command);
if (data == null) { throw new NullReferenceException(); }

var newStandingResult = MapStandingsData(data);

if(newStandingResult == null) { Console.WriteLine("No Data found for this Player"); throw new ArgumentNullException("No Data found for this Player"); }

return newStandingResult;
}
catch (Exception ex)
{
return new PlayerStandingResult { Response = $"Failed: {ex.Message} - {ex.StackTrace}" };
throw;
}
}
private PlayerStandingResult MapStandingsData(StandingGraphQLResult data)
private PlayerStandingResult? MapStandingsData(StandingGraphQLResult data)
{
var tempNode = data.Data.Entrants.Nodes.FirstOrDefault();
if (tempNode == null) return null;

var mappedResult = new PlayerStandingResult
{
Response = "Open",
Expand All @@ -51,7 +53,7 @@ private PlayerStandingResult MapStandingsData(StandingGraphQLResult data)
GamerTag = tempNode.Participants.FirstOrDefault().GamerTag,

Check warning on line 53 in SengokuProvider.Library/Services/Players/PlayerQueryService.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 53 in SengokuProvider.Library/Services/Players/PlayerQueryService.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
EventId = tempNode.Standing.Container.Tournament.Id,

Check warning on line 54 in SengokuProvider.Library/Services/Players/PlayerQueryService.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 54 in SengokuProvider.Library/Services/Players/PlayerQueryService.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
EventName = tempNode.Standing.Container.Tournament.Name,
TournamentId = tempNode.Standing.Container.Id,
TournamentId = tempNode.Standing.Container.Tournament.Id,
TournamentName = tempNode.Standing.Container.Name
},
TournamentLinks = new Links
Expand Down

0 comments on commit f9ec06d

Please sign in to comment.