Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add StatusCode to understand where we are in the game #21

Merged
merged 3 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -51,7 +51,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)
{
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about adding a Utils folder for functions like this, but I didn't want to encroach on the existing folder structure. I'm happy to put this function wherever.

return statusCode switch
{
"F" => GameStatus.Final,
"I" => GameStatus.InProgress,
"IR" => GameStatus.Delayed,
"P" => GameStatus.PreGame,
"S" => GameStatus.Scheduled,
_ => null,
};
}
}
Loading