Module: Spyro::ActionViewExtension::EtecHelper
- Included in:
- ApplicationHelper
- Defined in:
- lib/spyro/helpers/action_view_extension.rb
Instance Method Summary collapse
- #estimated_accel_from_xp(xp, earlier_xp, first_xp, date_first_xp) ⇒ Object
- #estimated_end_date_from_xp(xp, first_xp, date_first_xp) ⇒ Object
- #user_accel_eta(user) ⇒ Object
- #user_eta(user) ⇒ Object
Instance Method Details
#estimated_accel_from_xp(xp, earlier_xp, first_xp, date_first_xp) ⇒ Object
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
# 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) ⇒ Object
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 |
# 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) ⇒ Object
661 662 663 664 665 666 667 668 669 |
# 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) ⇒ Object
632 633 634 635 636 637 638 639 640 641 642 643 |
# 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 |