module Spyro::ActionViewExtension::EtecHelper

Public Instance Methods

estimated_accel_from_xp(xp, earlier_xp, first_xp, date_first_xp) click to toggle source
# File lib/spyro/helpers/action_view_extension.rb, line 671
def estimated_accel_from_xp xp, earlier_xp, first_xp, date_first_xp
  current_weekly_xp = Math.log(1 + xp.to_f / 50 / 180) * 235
  earlier_weekly_xp = Math.log(1 + earlier_xp.to_f / 50 / 180) * 235
  first_weekly_xp = Math.log(1 + first_xp.to_f / 50 / 180) * 235

  ratio = (current_weekly_xp - earlier_weekly_xp) / 5
  if ratio > 0
    date1 = ((182 - current_weekly_xp) / ratio).weeks.from_now
  else
    date1 = nil
  end

  date2 = estimated_end_date_from_xp(xp, first_xp, date_first_xp)

  if (date2 - date1).weeks > 4
    1
  elsif (date2 - date1).weeks < -4
    -1
  else
    0
  end
end
estimated_end_date_from_xp(xp, first_xp, date_first_xp) click to toggle source
# File lib/spyro/helpers/action_view_extension.rb, line 645
def estimated_end_date_from_xp xp, first_xp, date_first_xp
  return Time.zone.now + 150.years if date_first_xp.nil?

  current_weekly_xp = Math.log(1 + xp.to_f / 50 / 180) * 235
  first_weekly_xp = Math.log(1 + first_xp.to_f / 50 / 180) * 235

  weeks = (Time.zone.now - date_first_xp).to_i / 1.week
  weeks = 1 if weeks == 0
  ratio = (current_weekly_xp - first_weekly_xp) / weeks
  if ratio > 0
    ((182 - current_weekly_xp) / ratio).weeks.from_now
  else
    Time.zone.now + 150.years
  end
end
user_accel_eta(user) click to toggle source
# File lib/spyro/helpers/action_view_extension.rb, line 661
def user_accel_eta user
  user_experiences = Experience.where(user_id: user.id).where(cursus_id: 1).order(:created_at)
  xp = user_experiences.sum(:experience) # nb d'XP total aujourd'hui pour l'étudiant
  earlier_xp = user_experiences.where("created_at < ?", 5.weeks.ago).sum(:experience) # nb d'XP qu'avait l'etudiant il y a 5 semaines
  first_xp = user_experiences.first.experience # la premiere entree d'XP pour un etudiant (la plus ancienne donc)
  date_first_xp = user_experiences.first.created_at # la date de cette premiere entree

  estimated_accel_from_xp(xp, earlier_xp, first_xp, date_first_xp)
end
user_eta(user) click to toggle source
# File lib/spyro/helpers/action_view_extension.rb, line 632
def user_eta user
  user_experiences = Experience.joins(:skill).where(user_id: user.id).where(cursus_id: 1).order(:created_at)

  # TROLOLO
  return Time.zone.now + 150.years if user_experiences.empty?

  xp = user_experiences.sum(:experience) # nb d'XP total aujourd'hui pour l'étudiant
  first_xp = user_experiences.first.experience # la premiere entree d'XP pour un etudiant (la plus ancienne donc)
  date_first_xp = user_experiences.first.created_at # la date de cette premiere entree

  estimated_end_date_from_xp(xp, first_xp, date_first_xp)
end