class FtcEvent::Match

Attributes

event[R]
match[R]

Public Class Methods

new(event, match) click to toggle source
# File lib/ftc_event/match.rb, line 8
def initialize(event, match)
  @event = event
  @match = match
end

Public Instance Methods

data() click to toggle source
# File lib/ftc_event/match.rb, line 26
def data
  one_row_from_table('Data', match)
end
each_team(_alliance) click to toggle source
# File lib/ftc_event/match.rb, line 58
def each_team(_alliance)
  raise 'Abstract method not implemented'
end
game_specific() click to toggle source
# File lib/ftc_event/match.rb, line 34
def game_specific
  one_row_from_table('GameSpecific', match)
end
info() click to toggle source
# File lib/ftc_event/match.rb, line 22
def info
  one_row_from_table('', match)
end
long_alliance_description(_color) click to toggle source
# File lib/ftc_event/match.rb, line 66
def long_alliance_description(_color)
  raise 'Abstract method not implemented'
end
long_alliances_description() click to toggle source
# File lib/ftc_event/match.rb, line 77
def long_alliances_description
  '%s vs. %s' % [
    long_alliance_description('red'),
    long_alliance_description('blue'),
  ]
end
long_description() click to toggle source
# File lib/ftc_event/match.rb, line 88
def long_description
  "#{long_name}: #{long_alliances_description}"
end
long_name() click to toggle source
# File lib/ftc_event/match.rb, line 46
def long_name
  raise 'Abstract method not implemented'
end
one_row_from_table(table, match) click to toggle source
# File lib/ftc_event/match.rb, line 17
def one_row_from_table(table, match)
  result = event.db.query("SELECT * FROM #{table_prefix}#{table} WHERE match = ?", [match])
  result&.first
end
other_alliance(alliance) click to toggle source
# File lib/ftc_event/match.rb, line 92
def other_alliance(alliance)
  return unless FtcEvent::ALLIANCES.include?(alliance)

  FtcEvent::ALLIANCES.reject { |x| x == alliance }.first
end
penalties_by(alliance) click to toggle source
# File lib/ftc_event/match.rb, line 98
def penalties_by(alliance)
  results["#{alliance}PenaltyCommitted"]
end
points_for(alliance) click to toggle source
# File lib/ftc_event/match.rb, line 102
def points_for(alliance)
  results["#{alliance}Score"]
end
positions() click to toggle source
# File lib/ftc_event/match.rb, line 50
def positions
  raise 'Abstract method not implemented'
end
posted() click to toggle source
# File lib/ftc_event/match.rb, line 157
def posted
  Time.at(data['postedTime'].to_f / 1000.0)
end
result() click to toggle source
# File lib/ftc_event/match.rb, line 145
def result
  "Red #{result_for('red')}, Blue #{result_for('blue')}"
end
result_for(alliance) click to toggle source
# File lib/ftc_event/match.rb, line 134
def result_for(alliance)
  return unless ALLIANCES.include?(alliance)

  from_penalties = penalties_by(other_alliance(alliance))
  '%i points [%s penalties] (%s)' % [
    score_for(alliance),
    from_penalties.zero? ? 'no' : "#{from_penalties} from",
    win_for(alliance),
  ]
end
results() click to toggle source
# File lib/ftc_event/match.rb, line 30
def results
  one_row_from_table('Results', match)
end
scheduled() click to toggle source
# File lib/ftc_event/match.rb, line 153
def scheduled
  Time.at(data['scheduleStart'].to_f / 1000.0)
end
score_for(alliance) click to toggle source
# File lib/ftc_event/match.rb, line 106
def score_for(alliance)
  points_for(alliance) + penalties_by(other_alliance(alliance))
end
short_alliance_description(_color) click to toggle source
# File lib/ftc_event/match.rb, line 62
def short_alliance_description(_color)
  raise 'Abstract method not implemented'
end
short_alliances_description() click to toggle source
# File lib/ftc_event/match.rb, line 70
def short_alliances_description
  '%s vs. %s' % [
    short_alliance_description('red'),
    short_alliance_description('blue'),
  ]
end
short_description() click to toggle source
# File lib/ftc_event/match.rb, line 84
def short_description
  "#{short_name}: #{short_alliances_description}"
end
short_identifier() click to toggle source
# File lib/ftc_event/match.rb, line 42
def short_identifier
  raise 'Abstract method not implemented'
end
short_name() click to toggle source
# File lib/ftc_event/match.rb, line 38
def short_name
  raise 'Abstract method not implemented'
end
started() click to toggle source
# File lib/ftc_event/match.rb, line 149
def started
  Time.at(data['start'].to_f / 1000.0)
end
table_prefix() click to toggle source
# File lib/ftc_event/match.rb, line 13
def table_prefix
  raise 'Abstract method not implemented'
end
teams() click to toggle source
# File lib/ftc_event/match.rb, line 54
def teams
  raise 'Abstract method not implemented'
end
win_for(alliance) click to toggle source
# File lib/ftc_event/match.rb, line 123
def win_for(alliance)
  case winner
  when 'tie'
    'tie'
  when alliance
    'win'
  when other_alliance(alliance)
    'loss'
  end
end
winner() click to toggle source
# File lib/ftc_event/match.rb, line 110
def winner
  red  = score_for('red')
  blue = score_for('blue')

  if red > blue
    'red'
  elsif blue > red
    'blue'
  else
    'tie'
  end
end