Module: UserActivityHelper

Defined in:
app/helpers/user_activity_helper.rb

Instance Method Summary collapse

Instance Method Details

#activity_selector_week_range_for(organization = Organization.current) ⇒ Object



2
3
4
5
6
7
8
9
# File 'app/helpers/user_activity_helper.rb', line 2

def activity_selector_week_range_for(organization = Organization.current)
  start = organization.activity_start_date min_week
  (start.prev_occurring(:monday) + 1..Date.today)
      .step(7)
      .to_a
      .reverse
      .map { |it| [it, it + 7.days] }
end

#exercises_activity_statsObject



20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/user_activity_helper.rb', line 20

def exercises_activity_stats
  solved_count = {
      name: t(:solved_exercises_count, count: @activity[:exercises][:solved_count]),
      value: @activity[:exercises][:solved_count] }
  solved_percentage = {
      name: t(:solved_exercises_percentage),
      value: solved_exercises_percentage }

  @date_from ? [solved_count] : [solved_count, solved_percentage]
end

#mark_period_if_active(period_start) ⇒ Object



11
12
13
# File 'app/helpers/user_activity_helper.rb', line 11

def mark_period_if_active(period_start)
  active_period?(period_start) ? 'nav-link active' : 'nav-link'
end

#messages_activity_statsObject



31
32
33
34
35
36
37
# File 'app/helpers/user_activity_helper.rb', line 31

def messages_activity_stats
  count = @activity[:messages][:count]
  approved = @activity[:messages][:approved]

  [{name: t(:messages_pluralized, count: count), value: count},
   {name: t(:approved_messages, count: approved), value: approved}]
end

#solved_exercises_percentageObject



15
16
17
18
# File 'app/helpers/user_activity_helper.rb', line 15

def solved_exercises_percentage
  percentage = @activity[:exercises][:solved_count].to_f / @activity[:exercises][:count] * 100
  "#{percentage.ceil}%"
end