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

Update: Test Cricket #1175

Merged
merged 1 commit into from
Mar 2, 2023
Merged
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
Version 1.2
- Added Team Innings to scoreboard and changed font
- Show 'need' not 'trail' when in the 4th innings
- Only use mobileName if it exists
  • Loading branch information
M0ntyP committed Mar 1, 2023
commit b1bd36bd5275232ebae1797501a45b530a688b31
59 changes: 45 additions & 14 deletions apps/testcricket/test_cricket.star
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ Description: This app takes the selected team and displays the current match sit
Author: M0ntyP

v1.0 - Original app published
v1.1 - A few updates...

v1.1
Team score formatting when total is < 10 and < 100 so it lines up with batsmen scores properly
Using "mobile" names for batsmen & bowlers with names longer than 10 chars
Status message updates - removed last bowler bowling figures from the long breaks
Combined "scheduled" and "pre" match states
Added Zimbabwe, Afghanistan and Ireland as teams you can select

v1.2
- Added Team Innings to scoreboard
- Show 'need' not 'trail' in the 4th innings
- Only use mobileName if it exists

Future ideas
- Remove "Rem Overs" if all out
- Update Description?
"""

load("cache.star", "cache")
Expand Down Expand Up @@ -74,6 +84,7 @@ def main(config):
if Playing == True:
MatchID = str(MatchID)
Match_URL = "https://hs-consumer-api.espncricinfo.com/v1/pages/match/details?lang=en&seriesId=" + MatchID + "&matchId=" + MatchID + "&latest=true"
#print(Match_URL)

# cache specific match data for 1 minute
MatchData = get_cachable_data(Match_URL, MATCH_CACHE)
Expand All @@ -88,6 +99,12 @@ def main(config):
Wickets = Match_JSON["scorecard"]["innings"][Innings]["wickets"]
Runs = Match_JSON["scorecard"]["innings"][Innings]["runs"]

# What inning for the batting side
if Innings == 0 or Innings == 1:
TeamInn = "1st"
else:
TeamInn = "2nd"

# In front or behind? And how much?
Lead_or_Trail = Match_JSON["scorecard"]["innings"][Innings]["lead"]

Expand All @@ -96,6 +113,10 @@ def main(config):
else:
trail = False

# if 4th innings of the match, show what they need to win
if Innings == 3:
Lead_or_Trail = Lead_or_Trail + 1

Lead_or_Trail = math.fabs(Lead_or_Trail)
Lead_or_Trail = humanize.ftoa(Lead_or_Trail)

Expand All @@ -104,9 +125,13 @@ def main(config):
else:
Lead = " trail " + Lead_or_Trail

# if 4th innings of the match, show what they need to win
if Innings == 3:
Lead = " need " + Lead_or_Trail

# How many overs bowled in this innings
Overs = Match_JSON["scorecard"]["innings"][Innings]["overs"]
Overs = str(Overs)
#Overs = Match_JSON["scorecard"]["innings"][Innings]["overs"]
#Overs = str(Overs)

# How many overs left in the day
RemOvers = Match_JSON["match"]["liveOversPending"]
Expand All @@ -126,8 +151,9 @@ def main(config):

# On strike batsman details
Batsman1 = Match_JSON["livePerformance"]["batsmen"][0]["player"]["fieldingName"]
if len(Batsman1) > 10:
Batsman1 = Match_JSON["livePerformance"]["batsmen"][0]["player"]["mobileName"]
if len(Batsman1) > 11:
if len(Match_JSON["livePerformance"]["batsmen"][0]["player"]["mobileName"]) > 1:
Batsman1 = Match_JSON["livePerformance"]["batsmen"][0]["player"]["mobileName"]
Batsman1_Runs = Match_JSON["livePerformance"]["batsmen"][0]["runs"]

# Partnership details
Expand All @@ -142,15 +168,20 @@ def main(config):
WicketsInt = int(Wickets)
if WicketsInt > 0:
LastOut_Name = Match_JSON["scorecard"]["innings"][Innings]["inningWickets"][WicketsInt - 1]["player"]["fieldingName"]
if len(LastOut_Name) > 11:
if len(Match_JSON["scorecard"]["innings"][Innings]["inningWickets"][WicketsInt - 1]["player"]["mobileName"]) > 1:
LastOut_Name = Match_JSON["scorecard"]["innings"][Innings]["inningWickets"][WicketsInt - 1]["player"]["mobileName"]

LastOut_Runs = Match_JSON["scorecard"]["innings"][Innings]["inningWickets"][WicketsInt - 1]["runs"]

# check if there is a second batsmen out there, this applies at fall of wicket & end of innings
Batsmen = len(Match_JSON["livePerformance"]["batsmen"])

if Batsmen == 2:
Batsman2 = Match_JSON["livePerformance"]["batsmen"][1]["player"]["fieldingName"]
if len(Batsman2) > 10:
Batsman2 = Match_JSON["livePerformance"]["batsmen"][1]["player"]["mobileName"]
if len(Batsman2) > 11:
if len(Match_JSON["livePerformance"]["batsmen"][1]["player"]["mobileName"]) > 1:
Batsman2 = Match_JSON["livePerformance"]["batsmen"][1]["player"]["mobileName"]
Batsman2_Runs = Match_JSON["livePerformance"]["batsmen"][1]["runs"]
Batsman2_Runs_Str = str(Batsman2_Runs)

Expand Down Expand Up @@ -306,39 +337,39 @@ def main(config):
children = [
render.Column(
children = [
TeamScore(BattingTeam, BattingTeamColor, Wickets, Runs),
TeamScore(BattingTeam, BattingTeamColor, TeamInn, Wickets, Runs),
BatsmanScore(Batsman1, Batsman1_Runs_Str, BatsmanColor),
BatsmanScore(Batsman2, Batsman2_Runs_Str, Batsman2Color),
StatusRow(Status, StatusColor),
],
),
render.Column(
children = [
TeamScore(BattingTeam, BattingTeamColor, Wickets, Runs),
TeamScore(BattingTeam, BattingTeamColor, TeamInn, Wickets, Runs),
BatsmanScore(Batsman1, Batsman1_Runs_Str, BatsmanColor),
BatsmanScore(Batsman2, Batsman2_Runs_Str, Batsman2Color),
StatusRow(Status2, Status2Color),
],
),
render.Column(
children = [
TeamScore(BattingTeam, BattingTeamColor, Wickets, Runs),
TeamScore(BattingTeam, BattingTeamColor, TeamInn, Wickets, Runs),
BatsmanScore(Batsman1, Batsman1_Runs_Str, BatsmanColor),
BatsmanScore(Batsman2, Batsman2_Runs_Str, Batsman2Color),
StatusRow(Status3, Status3Color),
],
),
render.Column(
children = [
TeamScore(BattingTeam, BattingTeamColor, Wickets, Runs),
TeamScore(BattingTeam, BattingTeamColor, TeamInn, Wickets, Runs),
BatsmanScore(Batsman1, Batsman1_Runs_Str, BatsmanColor),
BatsmanScore(Batsman2, Batsman2_Runs_Str, Batsman2Color),
StatusRow(Status4, Status4Color),
],
),
render.Column(
children = [
TeamScore(BattingTeam, BattingTeamColor, Wickets, Runs),
TeamScore(BattingTeam, BattingTeamColor, TeamInn, Wickets, Runs),
BatsmanScore(Batsman1, Batsman1_Runs_Str, BatsmanColor),
BatsmanScore(Batsman2, Batsman2_Runs_Str, Batsman2Color),
StatusRow(Status5, Status5Color),
Expand Down Expand Up @@ -540,7 +571,7 @@ def main(config):
# should never get here but lint wanted it
return None

def TeamScore(BattingTeam, BattingTeamColor, Wickets, Runs):
def TeamScore(BattingTeam, BattingTeamColor, TeamInn, Wickets, Runs):
# if all out
if Wickets != "10":
Wickets = Wickets + "/"
Expand All @@ -561,7 +592,7 @@ def TeamScore(BattingTeam, BattingTeamColor, Wickets, Runs):
pad = (2, 1, 0, 0),
child = render.Marquee(
width = 40,
child = render.Text(content = BattingTeam, color = BattingTeamColor, font = "CG-pixel-3x5-mono", offset = 0),
child = render.Text(content = BattingTeam + " " + TeamInn, color = BattingTeamColor, font = "CG-pixel-4x5-mono", offset = 0),
),
)),
render.Box(width = 24, height = 8, child = render.Text(content = Wickets + Runs, color = BattingTeamColor, font = "CG-pixel-3x5-mono")),
Expand Down