-
Notifications
You must be signed in to change notification settings - Fork 0
Fixed BaseBall Scoring and IsLive #102
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
Changes from all commits
054f001
d1e732c
bf86fc9
2f2017d
3cc61b7
6fef02b
1dd1651
af2d30e
64fbe4b
517656f
ec7266c
40574e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ query Games{ | |
| games{ | ||
| id | ||
| date | ||
| time | ||
| city | ||
| sport | ||
| team{ | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||||||||||||||||||
| package com.cornellappdev.score.util | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import android.util.Log | ||||||||||||||||||||||||||||||||
| import com.cornellappdev.score.model.GameData | ||||||||||||||||||||||||||||||||
| import com.cornellappdev.score.model.TeamBoxScore | ||||||||||||||||||||||||||||||||
| import com.cornellappdev.score.model.TeamScore | ||||||||||||||||||||||||||||||||
|
|
@@ -17,7 +18,7 @@ import com.cornellappdev.score.model.TeamScore | |||||||||||||||||||||||||||||||
| * @return a pair where the first value is a list of parsed period scores and the second is the total score (or null if invalid) | ||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||
| // TODO: ASK ABOUT OT. Other sports might be added. | ||||||||||||||||||||||||||||||||
| fun convertScores(scoreList: List<String?>?, sport: String): Pair<List<Int>, Int?> { | ||||||||||||||||||||||||||||||||
| fun convertScores(scoreList: List<String?>?, sport: String, result: String): Pair<List<Int>, Int?> { | ||||||||||||||||||||||||||||||||
| if (scoreList == null || scoreList.size < 2) return Pair(emptyList(), null) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| var scoresByPeriod = scoreList | ||||||||||||||||||||||||||||||||
|
|
@@ -31,7 +32,12 @@ fun convertScores(scoreList: List<String?>?, sport: String): Pair<List<Int>, Int | |||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (sport.lowercase() == "baseball") { | ||||||||||||||||||||||||||||||||
| scoresByPeriod = scoresByPeriod.take(9) | ||||||||||||||||||||||||||||||||
| val scoreParsed = result.split("(") | ||||||||||||||||||||||||||||||||
| scoresByPeriod = if (scoreParsed.size > 1) { | ||||||||||||||||||||||||||||||||
| scoresByPeriod.take(6) | ||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||
| scoresByPeriod.take(9) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| val totalScore = scoresByPeriod.sum() | ||||||||||||||||||||||||||||||||
| return Pair(scoresByPeriod, totalScore) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
@@ -56,14 +62,15 @@ fun toGameData( | |||||||||||||||||||||||||||||||
| scoreBreakdown: List<List<String?>?>?, | ||||||||||||||||||||||||||||||||
| team1: TeamBoxScore, | ||||||||||||||||||||||||||||||||
| team2: TeamBoxScore, | ||||||||||||||||||||||||||||||||
| sport: String | ||||||||||||||||||||||||||||||||
| sport: String, | ||||||||||||||||||||||||||||||||
| result: String, | ||||||||||||||||||||||||||||||||
| ): GameData { | ||||||||||||||||||||||||||||||||
| val (team1Scores, team1Total) = scoreBreakdown?.getOrNull(0)?.let { | ||||||||||||||||||||||||||||||||
| convertScores(it, sport) | ||||||||||||||||||||||||||||||||
| convertScores(it, sport, result) | ||||||||||||||||||||||||||||||||
| } ?: (emptyList<Int>() to null) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| val (team2Scores, team2Total) = scoreBreakdown?.getOrNull(1)?.let { | ||||||||||||||||||||||||||||||||
| convertScores(it, sport) | ||||||||||||||||||||||||||||||||
| convertScores(it, sport, result) | ||||||||||||||||||||||||||||||||
| } ?: (emptyList<Int>() to null) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| val team1Score = | ||||||||||||||||||||||||||||||||
|
|
@@ -90,11 +97,12 @@ fun parseResultScore(result: String?): Pair<Int, Int>? { | |||||||||||||||||||||||||||||||
| if (parts.size != 2) return null | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| val scorePart = parts[1].split("-") | ||||||||||||||||||||||||||||||||
| val secondScorePartEdge = scorePart[1].split("(") | ||||||||||||||||||||||||||||||||
| if (scorePart.size != 2) return null | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| val homeScore = scorePart[0].toIntOrNull() | ||||||||||||||||||||||||||||||||
| val oppScore = scorePart[1].toIntOrNull() | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| val oppScore = secondScorePartEdge[0].toIntOrNull() | ||||||||||||||||||||||||||||||||
| Log.d("HIHI", oppScore.toString()) | ||||||||||||||||||||||||||||||||
|
Comment on lines
99
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential IndexOutOfBoundsException and debug log to remove. Two issues here:
🐛 Proposed fix val scorePart = parts[1].split("-")
+ if (scorePart.size != 2) return null
+
val secondScorePartEdge = scorePart[1].split("(")
- if (scorePart.size != 2) return null
val homeScore = scorePart[0].toIntOrNull()
val oppScore = secondScorePartEdge[0].toIntOrNull()
- Log.d("HIHI", oppScore.toString())
if (homeScore != null && oppScore != null) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| if (homeScore != null && oppScore != null) { | ||||||||||||||||||||||||||||||||
| return Pair(homeScore, oppScore) | ||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded 2-hour game duration may not fit all sports.
The isLive logic assumes all games last 2 hours. However, game durations vary significantly by sport:
This could cause games to incorrectly show as "not live" while still in progress. Consider either:
🤖 Prompt for AI Agents