app/controllers/swimmers_controller.rb
# Radiography for a specified swimmer id: "Trainings" tab rendering
# Swimmer training stats
# Training summary:
# Summarizes the distance and duration of trinings in significant oeriods
# FIXME
# Now uses global, last season, last month, last week and last training
# Maybe better to define swimmer-dependent significant periods such as
# macricycle, mesocycle and so on starting at a given date
#
# == Params:
# id: the swimmer id to be processed
#
Radiography for a specified swimmer id: "Trainings" tab rendering
Swimmer training stats
Training summary:
Summarizes the distance and duration of trinings in significant oeriods
FIXME
Now uses global, last season, last month, last week and last training
Maybe better to define swimmer-dependent significant periods such as
macricycle, mesocycle and so on starting at a given date

the swimmer id to be processed
Radiography for a specified swimmer id : " Trainings " tab rendering Swimmer training stats Training summary : Summarizes the distance and duration of trinings in significant oeriods FIXME Now uses global last season last month last week and last training Maybe better to define swimmer - dependent significant periods such as macricycle mesocycle and so on starting at a given date the swimmer id to be processed
def trainings
    @tab_title = I18n.t('radiography.trainings_tab')
    if @swimmer.associated_user
      current_season = Season.get_last_season_by_type( 'MASFIN' )
      @global_distance = {:distance => 0, :duration => 0, :number => 0, :avg_distance => 0, :avg_duration => 0, :avg_100_meters => 0}
      @season_distance = {:distance => 0, :duration => 0, :number => 0, :avg_distance => 0, :avg_duration => 0, :avg_100_meters => 0}
      @last_month      = {:distance => 0, :duration => 0, :number => 0, :avg_distance => 0, :avg_duration => 0, :avg_100_meters => 0}
      @last_week       = {:distance => 0, :duration => 0, :number => 0, :avg_distance => 0, :avg_duration => 0, :avg_100_meters => 0}
      @last_training   = {:distance => 0, :duration => 0, :avg_100_meters => 0}
      @global_distance[:number] = @swimmer.associated_user.user_training_stories.count
      @swimmer.associated_user.user_training_stories.each do |user_training_story|
        distance = user_training_story.user_training.total_distance
        duration = user_training_story.user_training.esteemed_total_seconds
        @global_distance[:distance] += distance
        @global_distance[:duration] += duration
        if user_training_story.swam_date >= ( Date.today - 7 )
          @last_week[:distance] += distance
          @last_week[:duration] += duration
          @last_week[:number] += 1
        end
        if user_training_story.swam_date >= ( Date.today.prev_month )
          @last_month[:distance] += distance
          @last_month[:duration] += duration
          @last_month[:number] += 1
        end
        if user_training_story.swam_date >= current_season.begin_date
          @season_distance[:distance] += distance
          @season_distance[:duration] += duration
          @season_distance[:number] += 1
        end
      end
      if @global_distance[:number] > 0
        @last_training[:distance] = @swimmer.associated_user.user_training_stories.sort_by_date.last.user_training.total_distance
        @last_training[:duration] = @swimmer.associated_user.user_training_stories.sort_by_date.last.user_training.esteemed_total_seconds
      end
      @global_distance[:avg_distance] = @global_distance[:distance] / @global_distance[:number] if @global_distance[:number].to_i > 0
      @season_distance[:avg_distance] = @season_distance[:distance] / @season_distance[:number] if @season_distance[:number].to_i > 0
      @last_month[:avg_distance]      = @last_month[:distance] / @last_month[:number] if @last_month[:number].to_i > 0
      @last_week[:avg_distance]       = @last_week[:distance] / @last_week[:number] if @last_week[:number].to_i > 0
      @global_distance[:avg_duration] = @global_distance[:duration] / @global_distance[:number] if @global_distance[:number].to_i > 0
      @season_distance[:avg_duration] = @season_distance[:duration] / @season_distance[:number] if @season_distance[:number].to_i > 0
      @last_month[:avg_duration]      = @last_month[:duration] / @last_month[:number] if @last_month[:number].to_i > 0
      @last_week[:avg_duration]       = @last_week[:duration] / @last_week[:number] if @last_week[:number].to_i > 0
      @global_distance[:avg_100_meters] = @global_distance[:avg_duration] / ( @global_distance[:avg_distance] / 100 ) if @global_distance[:avg_distance].to_i > 0
      @season_distance[:avg_100_meters] = @season_distance[:avg_duration] / ( @season_distance[:avg_distance] / 100 ) if @season_distance[:avg_distance].to_i > 0
      @last_month[:avg_100_meters]      = @last_month[:avg_duration] / ( @last_month[:avg_distance] / 100 ) if @last_month[:avg_distance].to_i > 0
      @last_week[:avg_100_meters]       = @last_week[:avg_duration] / ( @last_week[:avg_distance] / 100 ) if @last_week[:avg_distance].to_i > 0
      @last_training[:avg_100_meters]   = @last_training[:duration] / ( @last_training[:distance] / 100 ) if @last_training[:distance].to_i > 0
    else
      flash[:error] = I18n.t('swimmers.no_associated_goggler_found')
      redirect_back( fallback_location: root_path ) and return
    end
  end
def trainings @tab_title = I18n . t ( 'radiography.trainings_tab' ) if @swimmer . associated_user current_season = Season . get_last_season_by_type ( 'MASFIN' ) @global_distance = { :distance => 0 , :duration => 0 , :number => 0 , :avg_distance => 0 , :avg_duration => 0 , :avg_100_meters => 0 } @season_distance = { :distance => 0 , :duration => 0 , :number => 0 , :avg_distance => 0 , :avg_duration => 0 , :avg_100_meters => 0 } @last_month = { :distance => 0 , :duration => 0 , :number => 0 , :avg_distance => 0 , :avg_duration => 0 , :avg_100_meters => 0 } @last_week = { :distance => 0 , :duration => 0 , :number => 0 , :avg_distance => 0 , :avg_duration => 0 , :avg_100_meters => 0 } @last_training = { :distance => 0 , :duration => 0 , :avg_100_meters => 0 } @global_distance [ :number ] = @swimmer . associated_user . user_training_stories . count @swimmer . associated_user . user_training_stories . each do | user_training_story | distance = user_training_story . user_training . total_distance duration = user_training_story . user_training . esteemed_total_seconds @global_distance [ :distance ] += distance @global_distance [ :duration ] += duration if user_training_story . swam_date >= ( Date . today - 7 ) @last_week [ :distance ] += distance @last_week [ :duration ] += duration @last_week [ :number ] += 1 end if user_training_story . swam_date >= ( Date . today . prev_month ) @last_month [ :distance ] += distance @last_month [ :duration ] += duration @last_month [ :number ] += 1 end if user_training_story . swam_date >= current_season . begin_date @season_distance [ :distance ] += distance @season_distance [ :duration ] += duration @season_distance [ :number ] += 1 end end if @global_distance [ :number ] > 0 @last_training [ :distance ] = @swimmer . associated_user . user_training_stories . sort_by_date . last . user_training . total_distance @last_training [ :duration ] = @swimmer . associated_user . user_training_stories . sort_by_date . last . user_training . esteemed_total_seconds end @global_distance [ :avg_distance ] = @global_distance [ :distance ] / @global_distance [ :number ] if @global_distance [ :number ] . to_i > 0 @season_distance [ :avg_distance ] = @season_distance [ :distance ] / @season_distance [ :number ] if @season_distance [ :number ] . to_i > 0 @last_month [ :avg_distance ] = @last_month [ :distance ] / @last_month [ :number ] if @last_month [ :number ] . to_i > 0 @last_week [ :avg_distance ] = @last_week [ :distance ] / @last_week [ :number ] if @last_week [ :number ] . to_i > 0 @global_distance [ :avg_duration ] = @global_distance [ :duration ] / @global_distance [ :number ] if @global_distance [ :number ] . to_i > 0 @season_distance [ :avg_duration ] = @season_distance [ :duration ] / @season_distance [ :number ] if @season_distance [ :number ] . to_i > 0 @last_month [ :avg_duration ] = @last_month [ :duration ] / @last_month [ :number ] if @last_month [ :number ] . to_i > 0 @last_week [ :avg_duration ] = @last_week [ :duration ] / @last_week [ :number ] if @last_week [ :number ] . to_i > 0 @global_distance [ :avg_100_meters ] = @global_distance [ :avg_duration ] / ( @global_distance [ :avg_distance ] / 100 ) if @global_distance [ :avg_distance ] . to_i > 0 @season_distance [ :avg_100_meters ] = @season_distance [ :avg_duration ] / ( @season_distance [ :avg_distance ] / 100 ) if @season_distance [ :avg_distance ] . to_i > 0 @last_month [ :avg_100_meters ] = @last_month [ :avg_duration ] / ( @last_month [ :avg_distance ] / 100 ) if @last_month [ :avg_distance ] . to_i > 0 @last_week [ :avg_100_meters ] = @last_week [ :avg_duration ] / ( @last_week [ :avg_distance ] / 100 ) if @last_week [ :avg_distance ] . to_i > 0 @last_training [ :avg_100_meters ] = @last_training [ :duration ] / ( @last_training [ :distance ] / 100 ) if @last_training [ :distance ] . to_i > 0 else flash [ :error ] = I18n . t ( 'swimmers.no_associated_goggler_found' ) redirect_back ( fallback_location : root_path ) and return end end
Radiography for a specified swimmer id: "Trainings" tab rendering
Swimmer training stats
Training summary:
Summarizes the distance and duration of trinings in significant oeriods
FIXME
Now uses global, last season, last month, last week and last training
Maybe better to define swimmer-dependent significant periods such as
macricycle, mesocycle and so on starting at a given date
Radiography for a specified swimmer id : " Trainings " tab rendering Swimmer training stats Training summary : Summarizes the distance and duration of trinings in significant oeriods FIXME Now uses global last season last month last week and last training Maybe better to define swimmer - dependent significant periods such as macricycle mesocycle and so on starting at a given date
# FIXME [Steve] DISABLE the tab even before doing a redirect on the action # FIXME # Needs to be a full goggler (swimmer associated with a user) # Needs to be a the user associated swimmer or a buddy with training sharing # Compute total training distances # FIXME # Maybe better show akways from last Monday # FIXME # Maybe better show akways from the first day of current month # Compute average distance per training # Compute average duration per training # Compute average 100 meters performance