Skip to content

Commit 76ad367

Browse files
committed
Soft deadline support for weekly points
1 parent 22a71fc commit 76ad367

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

app/models/course.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,7 @@ def exercise_group_completion_by_user
501501
end
502502

503503
# Returns a hash of exercise group => {
504-
# :available_points => number of available points,
505-
# :points_by_user => {user_id => number_of_points}
504+
# { awarded: double, late: double }
506505
# }
507506
def exercise_group_completion_ratio_for_user(user)
508507
# TODO: clean up exercise group discovery
@@ -515,16 +514,19 @@ def exercise_group_completion_ratio_for_user(user)
515514
next if available_points.empty?
516515

517516
sql = <<-EOS
518-
SELECT COUNT(*)
517+
SELECT awarded_after_soft_deadline, COUNT(*)
519518
FROM awarded_points
520519
WHERE course_id = #{conn.quote(id)} AND
521520
name IN (#{available_points.map { |ap| conn.quote(ap) }.join(',')}) AND
522521
user_id = #{conn.quote(user.id)}
523-
GROUP BY user_id
522+
GROUP BY awarded_after_soft_deadline
524523
EOS
525524

526-
res = conn.select_rows(sql)
527-
result[group] = res.empty? ? 0 : res[0][0].to_f / available_points.length
525+
res = conn.execute(sql).values.to_h
526+
result[group] = {
527+
awarded: res["f"].nil? ? 0 : res["f"].to_i,
528+
late: res["t"].nil? ? 0 : res["t"].to_i,
529+
}
528530
end
529531
end
530532

app/views/participants/show.html.erb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@
4747
</div>
4848
</div>
4949
<% if @group_completion_ratios[course.id] %>
50-
<% @group_completion_ratios[course.id].each do |group, ratio| %>
50+
<% @group_completion_ratios[course.id].each do |group, ratios| %>
5151
<br>
5252
<span class="progress-label">Awarded points for <%= group %></span>
5353
<div class="progress course-points-progress">
54-
<% unless ratio.zero? %>
55-
<div class="progress-bar bg-info" role="progressbar" style="width: <%= ratio * 100 %>%" aria-valuenow="<%= ratio * 100 %>" aria-valuemin="0" aria-valuemax="100">
56-
<%= sprintf("%.0f", ratio * 100) %>%
54+
<% unless (ratios[:awarded] + ratios[:late]).zero? %>
55+
<% calculated_ratio = ratios[:awarded] + ratios[:late] * course.soft_deadline_point_multiplier %>
56+
<div class="progress-bar bg-info" role="progressbar" style="width: <%= calculated_ratio * 100 %>%" aria-valuenow="<%= calculated_ratio * 100 %>" aria-valuemin="0" aria-valuemax="100">
57+
<%= sprintf("%.0f", calculated_ratio * 100) %>%
5758
</div>
5859
<% end %>
5960
</div>

0 commit comments

Comments
 (0)