Skip to content

Commit

Permalink
patch: fixed some errors handling incomplete JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
plaberge committed Sep 15, 2024
1 parent 517ba17 commit 82c16b6
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 10 deletions.
71 changes: 65 additions & 6 deletions NHLStats/NHLStats/GameEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,37 @@ public GameEvent(string gameId, JToken json)
// 525 - takeaway (unique details: playerId)
// 535 - delayed-penalty (no unique details)

JToken tokenCheck;


this.gameId = gameId;
eventId = json.SelectToken("eventId").ToString();
periodNumber = json.SelectToken("periodDescriptor.number").ToString();
periodType = json.SelectToken("periodDescriptor.periodType").ToString();
timeInPeriod = json.SelectToken("timeInPeriod").ToString();
timeRemaining = json.SelectToken("timeRemaining").ToString();
situationCode = json.SelectToken("situationCode").ToString();
homeTeamDefendingSide = json.SelectToken("homeTeamDefendingSide").ToString();

tokenCheck = json.SelectToken("situationCode");
if (tokenCheck != null)
{
situationCode = json.SelectToken("situationCode").ToString();
}
else
{
situationCode = "0";
}


tokenCheck = json.SelectToken("homeTeamDefendingSide");
if (tokenCheck != null)
{
homeTeamDefendingSide = json.SelectToken("homeTeamDefendingSide").ToString();
}
else
{
homeTeamDefendingSide = "N/A";
}

typeCode = json.SelectToken("typeCode").ToString();
typeDescKey = json.SelectToken("typeDescKey").ToString();
sortOrder = json.SelectToken("sortOrder").ToString();
Expand Down Expand Up @@ -146,9 +168,36 @@ public GameEvent(string gameId, JToken json)
}
else if (typeCode == "506") // Shot-on-goal event
{
xCoordinate = json.SelectToken("details.xCoord").ToString();
yCoordinate = json.SelectToken("details.yCoord").ToString();
zoneCode = json.SelectToken("details.zoneCode").ToString();
tokenCheck = json.SelectToken("details.xCoord");
if (tokenCheck != null)
{
xCoordinate = json.SelectToken("details.xCoord").ToString();
}
else
{
xCoordinate = "0";
}

tokenCheck = json.SelectToken("details.yCoord");
if (tokenCheck != null)
{
yCoordinate = json.SelectToken("details.yCoord").ToString();
}
else
{
xCoordinate = "0";
}


tokenCheck = json.SelectToken("details.zoneCode");
if (tokenCheck != null)
{
xCoordinate = json.SelectToken("details.zoneCode").ToString();
}
else
{
zoneCode = "N/A";
}
shotType = json.SelectToken("details.shotType").ToString();
shootingPlayerId = json.SelectToken("details.shootingPlayerId").ToString();
goalieInNetId = json.SelectToken("details.goalieInNetId").ToString();
Expand All @@ -175,7 +224,17 @@ public GameEvent(string gameId, JToken json)
zoneCode = json.SelectToken("details.zoneCode").ToString();
blockingPlayerId = json.SelectToken("details.blockingPlayerId").ToString();
shootingPlayerId = json.SelectToken("details.shootingPlayerId").ToString();
reason = json.SelectToken("details.reason").ToString();

tokenCheck = json.SelectToken("details.reason");
if (tokenCheck != null)
{
reason = json.SelectToken("details.reason").ToString();
}
else
{
reason = "N/A";
}

eventOwnerTeamId = json.SelectToken("details.eventOwnerTeamId").ToString();
}
else if (typeCode == "509") // Penalty event
Expand Down
17 changes: 17 additions & 0 deletions NHLStats/NHLStats/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ public static int GetCurrentAge(string birthDate)
return age;
}

public static string SafeOutput (string dataInput, string desiredOutputType)
{
if (dataInput == null || dataInput.ToString() == "" || dataInput.ToString() == " ")
{
if (desiredOutputType == "string")
return "NULL";
else if (desiredOutputType == "time")
return "00:00";
else if (desiredOutputType == "number")
return "0";
else
return "0";
}
else
return dataInput;
}


}
}
Binary file modified NHLStats/NHLStats/bin/Debug/net6.0/NHLStats.dll
Binary file not shown.
Binary file modified NHLStats/NHLStats/bin/Debug/net6.0/NHLStats.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[assembly: System.Reflection.AssemblyCompanyAttribute("NHLStats")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+641d59829a1d4b8e87280c0797902ad2a92b7778")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+517ba174c19da199baf4a598e3973caaab5b1dc0")]
[assembly: System.Reflection.AssemblyProductAttribute("NHLStats")]
[assembly: System.Reflection.AssemblyTitleAttribute("NHLStats")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f92183c79216b69bda1feacc9360e2746b00526199122938cd2d5d13ceff8995
2799e66329e3e11dca9bba7d85418493170fe71773fb00fe1e09421fd83f1e9d
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0c3bedc4867389446583c44138e4ac104033dffbbaa232b412bdb2bc7658d452
ca48906584f9074fff12e2191ebd707fb13747882f2bd7108288c7c0a6c3a5af
Binary file modified NHLStats/NHLStats/obj/Debug/net6.0/NHLStats.dll
Binary file not shown.
Binary file modified NHLStats/NHLStats/obj/Debug/net6.0/NHLStats.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documents":{"C:\\Users\\plaberge\\source\\repos\\plaberge\\nhlstats\\*":"https://raw.githubusercontent.com/plaberge/nhlstats/de0a105499768c5503b4b1a13d5a23206712b5f9/*"}}
{"documents":{"C:\\Users\\plaberge\\source\\repos\\plaberge\\nhlstats\\*":"https://raw.githubusercontent.com/plaberge/nhlstats/517ba174c19da199baf4a598e3973caaab5b1dc0/*"}}
Binary file modified NHLStats/NHLStats/obj/Debug/net6.0/ref/NHLStats.dll
Binary file not shown.
Binary file modified NHLStats/NHLStats/obj/Debug/net6.0/refint/NHLStats.dll
Binary file not shown.

0 comments on commit 82c16b6

Please sign in to comment.