Game Options and StateInfo
The options and state info objects contains timing state of the liveblog. This is only relevant for sports games with timing features. While options
contains general settings, state_info
will contain the current time. Both are needed to properly calcualte timing information
Options
Tik::Model::Options::TimedGameOptions
"options: {
"_type": "Tik::Model::Options::TimedGameOptions"
"timing_type": "aud", // Time of game clock used
"regular_phase_length": 45, // Length of a regular game phase in minutes
"num_regular_phases": 2, // Number or regular game phases (valid numbers are 1-4)
"overtime_phase_length": 15, // Length of an overtime phase in minutes
"num_overtime_phases": 2 // Number of possible overtime phases
}
Example: Phaes of a soccer game
gamestate = 0 : Pregame
gamestate = 1 : Game running
recurrence = 1, is_break = false : Half 1
recurrence = 1, is_break = true : Break half 1
recurrence = 2, is_break = false : Half 2
recurrence = 2, is_break = true : Break half 2
recurrence = 3, is_break = false : Overtime 1
recurrence = 3, is_break = true : Break Overtime 1
recurrence = 4, is_break = false : Overtime 2
recurrence = 4, is_break = true : Break Overtime 2
gamestate = 2 : Shootout
gamestate = 31 : Postgame
Timing Type
The timing_type
field describes the type of game clock used. Possible values are:
u
: Clock counts up from 0:00 toregular_phase_time
and resets back to 0:00 each phased
: Clock counts down fromregular_phase_time
and resets each pahseau
: Clock counts up from 0:00 toregular_phase_time
but does not reset (second phase starts atregular_phase_time + 1
)aui
: Clock counts up from 0:00 toregular_phase_time
, does not reset and allows for injury time added at the end (second phase still starts atregular_phase_time + 1
)
State
Tik::Model::GameMetaInfo::TimeBasedGameStateInfo
"state_info": {
"_type": "Tik::Model::GameStateInfo::TimeBasedGameStateInfo",
"timeout": false // Indicates whether game timing control is paused
"check_time": 1578920400, // unix timestamp event occured in seconds
"check_seconds": 0, // seconds from beginning of current phase
"is_break": false,
"recurrence": 1, // phase of current game state
"gamestate": 1 // current game state
// Deprected and unused fields
"minute": 0, // DEPRECATED use check_time and check_seconds instead
}
How to get the current game minute
Let’s assume the following options and state info:
"options": {
"_type": "Tik::Model::Options::TimedGameOptions"
"timing_type": "aud",
"regular_phase_length": 45,
"num_regular_phases": 2,
"overtime_phase_length": 15,
"num_overtime_phases": 2
},
"state_info": {
"_type": "Tik::Model::GameStateInfo::TimeBasedGameStateInfo",
"check_time": 1578920400,
"check_seconds": 660,
"is_break": false,
"recurrence": 2,
"gamestate": 1
}
Calculate the time current game time:
// gamestate = 1 indictes the game is running, recurrenc = 2 indicates the second half
// Assuming the current unix time is
const CurrentTimestamp = 1578920700
// Caluclate how many seconds have already been played in the current phase
const SecondInPhase = state_info.check_seconds + (CurrentTimestamp - state_info.check_time)
// => 960
// Since timing_type = 'aud':
// we have to caluclate the start offset of the current phase in seconds first
const StartOfCurrentPhase = (state_info.recurrence - 1) * options.regular_phase_length * 60
// => 2700
// Now combine the two to get the current overall seconds played
const SecondsPlayed = StartOfCurrentPhase + SecondInPhase
// => 3660
// To get a soccer style "X. Min" divide by 60 and add 1:
const MinuteOfPlay = (SecondsPlayed / 60) + 1
// => 61