<commit_before># encoding: utf-8
require 'common/format'


=begin

= TeamsController

  - version:  6.341
  - author:   <NAME>.

=end
class TeamsController < ApplicationController

  # Require authorization before invoking any of this controller's actions:
  before_action :authenticate_user!, except: [:index, :radio] # Devise HTTP log-in strategy
  # Parse parameters:
  before_action :verify_parameter, except: [:index, :closed_goggle_cup, :printout_goggle_cup]
  #-- -------------------------------------------------------------------------
  #++


  # Radiography for a specified team id: main ID card "Radiography" tab rendering.
  #
  # == Params:
  # id: the team id to be processed
  #
  def radio
    @tab_title = I18n.t('radiography.radio_tab')
    ts = TeamStats.new( @team )
    ts.retrieve_data
    @team_stats = ts.get_team_stats_dao
  end
  #-- -------------------------------------------------------------------------
  #++


  # Radiography for a specified team id: "Current Swimmers" tab rendering
  #
  # == Params:
  # id: the team id to be processed
  #
  # header_year: typically nil, it's a current date override for when checking
  #      for @swimmer badges in current season (mainly used only inside specs
  #      to test a couple of edge conditions)
  #
  def current_swimmers
    params.permit! # (No unsafe params are possible)
    @tab_title = I18n.t('radiography.team_current_swimmers_tab')
    @last_seasons = get_searched_seasons
    @affiliations = @team.team_affiliations.includes(season: :federation_type).where(season_id: @last_seasons)
    current_badges = @team.badges.where(season_id: @last_seasons).includes(:swimmer)
    @team.badges.where(season_id: @last_seasons).includes( :swimmer ) if @last_seasons && @team.badges.exists?
    @swimmers = if current_badges.nil?
      []
    else
      current_badges.map{ |badge| badge.swimmer }.uniq.sort{ |a,b| a.get_full_name <=> b.get_full_name }
    end
    @max_updated_at = find_last_updated_mir
    # Badge management entry point, only for Team Managers:
    @is_valid_team_manager = TeamManagerValidator.can_manage_team?( current_user, @team )
    @manageable_seasons_options = Season.is_not_ended
                                        .order(:description)
                                        .map { |season| [season.description, season.id] } if @is_valid_team_manager
    # Before the start of a new Season and after last Season's end, the following
    # versions can be used to allow pre-filtering & management based even on the just-ended
    # seasons: (just looks at the current year)
    #
    # @last_seasons = Season.where("INSTR(header_year, #{Date.today.year.to_s}) > 0")
    # @manageable_seasons_options = Season.where("INSTR(header_year, #{Date.today.year.to_s}) > 0")
    #                                     .order(:description)
    #                                     .map { |season| [season.description, season.id] } if @is_valid_team_manager
  end
  #-- -------------------------------------------------------------------------
  #++


  # Team Radiography - Pre-computed "Best timings" (RecordType: TTB)
  #
  # == Params:<commit_msg>Fix missing reload after badge update/insert<commit_after># encoding: utf-8
require 'common/format'


=begin

= TeamsController

  - version:  6.341
  - author:   <NAME>.

=end
class TeamsController < ApplicationController

  # Require authorization before invoking any of this controller's actions:
  before_action :authenticate_user!, except: [:index, :radio] # Devise HTTP log-in strategy
  # Parse parameters:
  before_action :verify_parameter, except: [:index, :closed_goggle_cup, :printout_goggle_cup]
  #-- -------------------------------------------------------------------------
  #++


  # Radiography for a specified team id: main ID card "Radiography" tab rendering.
  #
  # == Params:
  # id: the team id to be processed
  #
  def radio
    @tab_title = I18n.t('radiography.radio_tab')
    ts = TeamStats.new( @team )
    ts.retrieve_data
    @team_stats = ts.get_team_stats_dao
  end
  #-- -------------------------------------------------------------------------
  #++


  # Radiography for a specified team id: "Current Swimmers" tab rendering
  #
  # == Params:
  # id: the team id to be processed
  #
  # header_year: typically nil, it's a current date override for when checking
  #      for @swimmer badges in current season (mainly used only inside specs
  #      to test a couple of edge conditions)
  #
  def current_swimmers
    params.permit! # (No unsafe params are possible)
    @tab_title = I18n.t('radiography.team_current_swimmers_tab')
    @last_seasons = get_searched_seasons
    @affiliations = @team.team_affiliations.includes(season: :federation_type).where(season_id: @last_seasons)
    current_badges = @team.badges.where(season_id: @last_seasons).includes( :swimmer ) if @last_seasons && @team.badges.exists?
    @swimmers = if current_badges.nil?
      []
    else
      current_badges.map{ |badge| badge.swimmer }.uniq.sort{ |a,b| a.get_full_name <=> b.get_full_name }
    end
    @max_updated_at = @swimmers.size > 0 ? current_badges.order(updated_at: :desc).first.updated_at : 0

    # Badge management entry point, only for Team Managers:
    @is_valid_team_manager = TeamManagerValidator.can_manage_team?( current_user, @team )
    @manageable_seasons_options = Season.is_not_ended
                                        .order(:description)
                                        .map { |season| [season.description, season.id] } if @is_valid_team_manager
    # Before the start of a new Season and after last Season's end, the following
    # versions can be used to allow pre-filtering & management based even on the just-ended
    # seasons: (just looks at the current year)
    #
    # @last_seasons = Season.where("INSTR(header_year, #{Date.today.year.to_s}) > 0")
    # @manageable_seasons_options = Season.where("INSTR(header_year, #{Date.today.year.to_s}) > 0")
    #                                     .order(:description)
    #                                     .map { |season| [season.description, season.id] } if @is_valid_team_manager
  end
  #-- -------------------------------------------------------------------------
  #++


  # Team Radiography - Pre-computed "Best timings" (RecordType: TTB)
  #
  # == Params:
{'fraction_non_alphanumeric': 0.1670350489422166, 'fraction_numerical': 0.003789074834227976, 'mean_word_length': 2.3307045215562567, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '651641', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1879, 'n_words': 480}