<commit_before>class Build::JsonRenderer
  def initialize
    @current_year = Date.today.year
  end

  def render(matches:, leagues:, generated:, data_generated:)
    result = {
      version: 1,
      generated: generated,
      data_generated: data_generated,
      streams: render_streams(leagues),
      matches: render_matches(matches),
      logos: render_logos
    }

    return result.to_json
  end

  def render_streams(leagues)
    leagues.reject { |league| league.streams.empty? }.map do |league|
      league.streams.map { |stream| render_stream(league: league, stream: stream) }
    end.flatten
  end

  def render_stream(league:, stream:)
    stream_url = Build::StreamUrl.new(stream['url'])

    result = {
      name: "#{league.brand_name_short(@current_year)}#{" #{stream['id']}" if stream['id']}",
      url: stream_url.url
    }

    result.merge!(league_data(league: league, year: @current_year))

    result
  end

  def league_data(league:, year:)
    {
      league: league.brand_name_short(year),
      league_long: league.brand_name(year),
      league_slug: league.slug
    }
  end

  def render_matches(matches)
    matches.sort_by { |match| match.rtime }.map do |match|
      render_match(match)
    end
  end

  def render_match(match)
    result = {
      time: match.rtime.iso8601,
      tags: render_tags(match)
    }

    result.merge!(league_data(league: match.league, year: match.rtime.year))
<commit_msg>Include match bracket in JSON output<commit_after>class Build::JsonRenderer
  def initialize
    @current_year = Date.today.year
  end

  def render(matches:, leagues:, generated:, data_generated:)
    result = {
      version: 1,
      generated: generated,
      data_generated: data_generated,
      streams: render_streams(leagues),
      matches: render_matches(matches),
      logos: render_logos
    }

    return result.to_json
  end

  def render_streams(leagues)
    leagues.reject { |league| league.streams.empty? }.map do |league|
      league.streams.map { |stream| render_stream(league: league, stream: stream) }
    end.flatten
  end

  def render_stream(league:, stream:)
    stream_url = Build::StreamUrl.new(stream['url'])

    result = {
      name: "#{league.brand_name_short(@current_year)}#{" #{stream['id']}" if stream['id']}",
      url: stream_url.url
    }

    result.merge!(league_data(league: league, year: @current_year))

    result
  end

  def league_data(league:, year:)
    {
      league: league.brand_name_short(year),
      league_long: league.brand_name(year),
      league_slug: league.slug
    }
  end

  def render_matches(matches)
    matches.sort_by { |match| match.rtime }.map do |match|
      render_match(match)
    end
  end

  def render_match(match)
    result = {
      time: match.rtime.iso8601,
      tags: render_tags(match),
      bracket: match.bracket_name
    }

    result.merge!(league_data(league: match.league, year: match.rtime.year))

{'fraction_non_alphanumeric': 0.12014976174268209, 'fraction_numerical': 0.0034036759700476512, 'mean_word_length': 3.265602322206096, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '210364', 'n_tokens_mistral': 1008, 'n_tokens_neox': 950, 'n_words': 197}