Class: Course::ExperiencePoints::ForumDisbursement

Inherits:
Disbursement
  • Object
show all
Defined in:
app/models/course/experience_points/forum_disbursement.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#end_timeActiveSupport::TimeWithZone

End of the period to compute forum participation statistics for. If no valid end time is specified, a default end time is computed, based on the given start time, if a valid one is specified, otherwise, it defaults to the end of the Sunday that just passed.


31
32
33
34
35
36
37
38
# File 'app/models/course/experience_points/forum_disbursement.rb', line 31

def end_time
  @end_time ||
    if @start_time
      @start_time + disbursement_interval
    else
      DateTime.current.at_beginning_of_week.end_of_day.in_time_zone - 1.day
    end
end

#start_timeActiveSupport::TimeWithZone

Start of the period to compute forum participation statistics for. If no valid start time is specified, a default start time is computed, based on the given end time, if a valid one is specified, otherwise, it default to the start of last Monday.


10
11
12
13
14
15
16
17
# File 'app/models/course/experience_points/forum_disbursement.rb', line 10

def start_time
  @start_time ||
    if @end_time
      @end_time - disbursement_interval
    else
      DateTime.current.at_beginning_of_week.beginning_of_day.in_time_zone - disbursement_interval
    end
end

#weekly_capInteger

The cap on the number of experience points to give out per week for forum participation. This will be pro-rated based on the number of weeks in the period. A default of 100 is set. This can be made a setting when the needs arises.


51
52
53
# File 'app/models/course/experience_points/forum_disbursement.rb', line 51

def weekly_cap
  @weekly_cap ||= 100
end

Instance Method Details

#experience_points_recordsArray<Course::ExperiencePointsRecords>

Returns experience points records for the disbursement.


63
64
65
66
67
68
# File 'app/models/course/experience_points/forum_disbursement.rb', line 63

def experience_points_records
  preload_levels
  @experience_points_records ||= student_participation_points.map do |student, points|
    student.experience_points_records.build(points_awarded: points)
  end
end

#params_hashHash

The search parameters for the current disbursement.


91
92
93
94
95
96
97
# File 'app/models/course/experience_points/forum_disbursement.rb', line 91

def params_hash
  {
    experience_points_forum_disbursement: {
      start_time: start_time, end_time: end_time, weekly_cap: weekly_cap
    }
  }
end

#student_participation_statisticsHash<CourseUser, Hash>

Maps each student to a hash with

  1. Number of posts by the student during the given period
  2. The aggregated vote tally for the student's posts within the period
  3. An overall score that measures the student's participation for the period

76
77
78
79
80
81
82
83
84
85
86
# File 'app/models/course/experience_points/forum_disbursement.rb', line 76

def student_participation_statistics
  @student_participation_statistics ||=
    discussion_posts.group_by(&:creator).
    each_with_object({}) do |(user, posts), hash|
      post_count = posts.size
      vote_count = posts.map(&:vote_tally).reduce(&:+)
      score = post_count + vote_count
      course_user = course_users_hash[user]
      hash[course_user] = { posts: post_count, votes: vote_count, score: score }
    end
end