Skip to content

Commit

Permalink
Merge pull request #21 from faskowbn/bfaskowitz/add_schedule_status
Browse files Browse the repository at this point in the history
Add StatusCode to understand where we are in the game
  • Loading branch information
markjamesm authored May 18, 2024
2 parents 06a941b + c1e79e5 commit c3fb730
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/Enums/StatusCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace BaseballSharp.Enums;
/// <summary>
/// Represents the status of the game using predefined status codes. Note that there may be more codes than these --
/// these are the status codes observed manually.
/// </summary>
public enum GameStatus
{
Final, // "F"
InProgress, // "I"
Delayed, // "IR"
PreGame, // "P"
Scheduled // "S"
}
3 changes: 2 additions & 1 deletion src/MLBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public async Task<IEnumerable<Schedule>> GetScheduleAsync(DateTime date)
gameID = game.gamePk,
AwayTeam = game.teams?.away?.team?.name,
HomeTeam = game.teams?.home?.team?.name,
ScheduledInnings = game.scheduledInnings
ScheduledInnings = game.scheduledInnings,
StatusCode = Schedule.GetStatusCode(game.status?.statusCode)
});
}
}
Expand Down
28 changes: 27 additions & 1 deletion src/Models/Schedule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace BaseballSharp.Models;
using BaseballSharp.Enums;

namespace BaseballSharp.Models;

public class Schedule
{
Expand All @@ -15,4 +17,28 @@ public class Schedule
/// The number of innings scheduled for the game.
/// </summary>
public int? ScheduledInnings { get; set; }

/// <summary>
/// The status of the game. A few possible codes are "F" for Final, "I" for In Progress,
/// "IR" for Delayed, "P" for Pre-game, and "S" for Sceduled.
/// </summary>
public GameStatus? StatusCode { get; set; }

/// <summary>
/// Gets the GameStatus enum value based on the provided status code string.
/// </summary>
/// <param name="statusCode">The status code string.</param>
/// <returns>The corresponding GameStatus enum value, or null if the status code is unknown.</returns>
public static GameStatus? GetStatusCode(string? statusCode)
{
return statusCode switch
{
"F" => GameStatus.Final,
"I" => GameStatus.InProgress,
"IR" => GameStatus.Delayed,
"P" => GameStatus.PreGame,
"S" => GameStatus.Scheduled,
_ => null,
};
}
}

0 comments on commit c3fb730

Please sign in to comment.