- import clr
- clr.AddReference("Wtvision.Sports.Tools.UefaDigitalAPIImporter")
- from Wtvision.Sports import UefaDigitalApiProxy
- from System import Array, DateTime
- import helper
- from System.Threading.Tasks import Task
- def __beforeProgram(graphicOnAirItem, momentExecution):
- graphicOnAirItem.Scene.Show("Statistics_to_Substitutes")
- graphic = GraphicTemplatesManager.GetGraphicByName("ScoreWithScorers_LineUp")
- Task.Run(action = lambda : IntelliflowController.TakeIn(graphic, OutputManager.ActiveChannelOutput, workflowType = IntelliflowController.EWorkflowType.Program))
- def __getData(graphicOnAirItem, viewBag, momentExecution):
- """_getData internal inteliflow callback
- Parameters:
- graphicOnAirItem, viewBag, momentExecution
- """
- #Graphic Data
- matches = __getTodayMatches()
- if not matches:
- momentExecution.MessageType = momentExecution.MessageType.Info
- momentExecution.Message = "No other matches found!"
- momentExecution.Cancel = True
- return
- __clearTags(viewBag)
- ## NOTE!!!!!!
- #__fillBottomInformation(viewBag, matches) ## NOT TO SHOW BOTTOM GAMES ON LINEUP ACTIVE MATCH
- viewBag.SetFloat("vBottomGames", 0) ## COMMENT THIS LINE IN CASE OF SHOW BOTTOM GAMES
- __fillTeamData(Game.HomeTeam,viewBag)
- __fillTeamData(Game.AwayTeam,viewBag)
- def __fillTeamData(team, viewBag):
- """Fill Team tags information
- Parameters:
- team: Wtvision.Sports.Team, viewBag
- Returns:
- bool:Returns true if fill all tags, false on exception
- """
- #Define if the Team is Home or Away to affect the correct Tag information
- teamType = "Home" if team == Game.HomeTeam else "Away"
- viewBag.SetTranslatedText("t{homeoraway}CoachFunction".format(homeoraway=teamType), "{{%s}}.{{LineUp}}|filter:ToUpper " % team.Coach.Function)
- viewBag.SetString("t{homeoraway}CoachFirstName".format(homeoraway=teamType), "")
- viewBag.SetString("t{homeoraway}CoachLastName".format(homeoraway=teamType), team.Coach.ShortName)
- # if the Caoch is at Risk the Card type is 1 to show the yellowcard otherwise 0 to hide the card
- viewBag.SetInt("v{homeoraway}CoachCard",1 if team.Coach.AtRisk else 0)
- players = []
- players.extend(team.InPlayByKeeperAndShirt)
- players.extend([None]*(11-len(players)))
- players.extend(team.InBenchByKeeperAndShirt)
- for enum,player in enumerate(players):
- viewBag.SetVisibility("v{homeoraway}SubstitutionVisibility{idx:02d}".format(homeoraway=teamType, idx=(enum+1)), False)
- viewBag.SetInt("v{homeoraway}Card{idx:02d}".format(homeoraway=teamType, idx=(enum+1)), 1 if player.AtRisk else 0)
- viewBag.SetString("t{homeoraway}Number{idx:02d}".format(homeoraway=teamType, idx=(enum+1)), player.Number)
- viewBag.SetString("t{homeoraway}Name{idx:02d}".format(homeoraway=teamType, idx=(enum+1)), "")
- viewBag.SetString("t{homeoraway}LastName{idx:02d}".format(homeoraway=teamType, idx=(enum+1)), player.OtherNames.upper() if player.OtherNames else player.ShortName.upper())
- def __getTodayMatches():
- """Get Today Matches
- Parameters:
- team: Wtvision.Sports.Team
- Returns:
- bool:Returns match array for Today
- """
- competitionId = Game.Competition.IdCompetition
- matchDayId = Game.Attributes["MatchDayId"]
- matches = UefaDigitalApiProxy.GetMatches(offset= "0",limit = "500",competitionId = Array[str]([Game.Competition.IdCompetition]),matchDayId = Array[str]([matchDayId]))
- matchId = Game.ExternalId
- mygame = next(iter([match for match in matches if match.Id == matchId]), None) # Get myGame
- if not mygame:
- #No Data
- return None
- matches = sorted(matches, key=lambda match: match.KickOffTime.DateTime) # No need just games for today
- return [match for match in matches if match.KickOffTime.Date == mygame.KickOffTime.Date] # JUST GAMES IN THE SAME DAY OF MY GAME
- def __fillBottomInformation(viewBag, matches):
- viewBag.SetFloat("vBottomGames", len(matches))
- for enum, match in enumerate(matches):
- viewBag.SetString("tHomeBottomTeam%02d" % (enum+1), match.HomeTeam.TeamCode.ToString().upper())
- viewBag.SetString("tAwayBottomTeam%02d" % (enum+1), match.AwayTeam.TeamCode.ToString().upper())
- status = match.Status.ToString().upper()
- if status == "FINISHED":
- if hasattr(match.Score, "Total"):
- result = "%s - %s" % (match.Score.Total.Home, match.Score.Total.Away)
- viewBag.SetString("tBottomTime%02d" % (enum+1), result)
- else:
- result = "%s - %s" % (match.Score.Regular.Home, match.Score.Regular.Away)
- viewBag.SetString("tBottomTime%02d" % (enum+1), result)
- elif status == "LIVE":
- if hasattr(match.Score, "Total"):
- result = "(%s - %s)" % (match.Score.Total.Home, match.Score.Total.Away)
- viewBag.SetString("tBottomTime%02d" % (enum+1), result)
- else:
- result = "(%s - %s)" % (match.Score.Regular.Home, match.Score.Regular.Away)
- viewBag.SetString("tBottomTime%02d" % (enum+1), result)
- elif status == "UPCOMING":
- date = match.KickOffTime.DateTime.ToLocalTime()
- hour_minute = "%sH%02d" % (date.Hour, date.Minute)
- viewBag.SetTranslatedText("tGameInfo%02d" % enum, "{{%s}}.{{AggregateSummaryResults}}" % date)
- viewBag.SetString("tBottomTime%02d" % (enum+1), "%s" % hour_minute)
- if match.Id.ToString() == Game.ExternalId.ToString():
- viewBag.SetVisibility("vHighlightVisibility", True)
- viewBag.SetFloat("vBottomHighlight", enum+1)
- viewBag.SetString("tHomeBottomTeamHighlight", match.HomeTeam.TeamCode.ToString().upper())
- viewBag.SetString("tAwayBottomTeamHighlight", match.AwayTeam.TeamCode.ToString().upper())
- status = match.Status.ToString().upper()
- if status == "FINISHED" or status == "LIVE":
- if hasattr(match.Score, "Total"):
- result = "%s - %s" % (match.Score.Total.Home, match.Score.Total.Away)
- viewBag.SetString("tBottomTimeHighlight", result)
- else:
- result = "%s - %s" % (match.Score.Regular.Home, match.Score.Regular.Away)
- viewBag.SetString("tBottomTimeHighlight", result)
- elif status == "UPCOMING":
- date = match.KickOffTime.DateTime.ToLocalTime()
- hour_minute = "%sH%02d" % (date.Hour, date.Minute)
- viewBag.SetString("tBottomTimeHighlight", "%s" % hour_minute)
- def __clearTags(viewBag):
- """Cleanup tag information
- Parameters:
- viewBag
- """
- viewBag.SetVisibility("vHighlightVisibility", False)
- for team in ["Home", "Away"]:
- viewBag.SetString("t%sCoachFunction"%team, "")
- viewBag.SetString("t%sCoachFirstName"%team, "")
- viewBag.SetString("t%sCoachLastName"%team, "")
- viewBag.SetInt("v%sCoachCard"%team, 0)
- for i in range(1,25):
- viewBag.SetString("t%sName%02d" % (team, i), "")
- viewBag.SetString("t%sLastName%02d" % (team, i), "")
- viewBag.SetString("t%sNumber%02d" % (team, i), "")
- viewBag.SetInt("v%sCard%02d" % (team, i), 0)
- viewBag.SetVisibility("v%sSubstitutionVisibility%02d" % (team, i), False)
- for tagidx in range(1,6):
- viewBag.SetString("t%sSubstitutionName%02d"%(team, tagidx), "")
- viewBag.SetString("t%sSubstitutionLastName%02d"%(team, tagidx), "")
- viewBag.SetInt("v%sSubstitutionCard%02d"%(team, tagidx), 0)
- def __beforeProgramOut(graphicOnAirItem, momentExecution):
- graphic = GraphicTemplatesManager.GetGraphicByName("ScoreWithScorers_LineUp")
- Task.Run(action = lambda: intelliflowController.TakeOut(graphic, output, workflowType = intelliflowController.EWorkflowType.Program))