-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use PointVisualisation concern to add required variables
- Loading branch information
Irene
committed
Apr 23, 2018
1 parent
0ff4a72
commit 1354c78
Showing
7 changed files
with
111 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true. | ||
module PointVisualisation | ||
extend ActiveSupport::Concern | ||
|
||
def define_point_stats(user) | ||
# TODO: bit ugly | ||
@awarded_points = Hash[AwardedPoint.where(id: AwardedPoint.all_awarded(user)).to_a.sort!.group_by(&:course_id).map { |k, v| [k, v.map(&:name)] }] | ||
@courses = [] | ||
@missing_points = {} | ||
@percent_completed = {} | ||
@group_completion_ratios = {} | ||
@awarded_points.keys.each do |course_id| | ||
course = Course.find(course_id) | ||
next if course.hide_submissions? | ||
@courses << course | ||
|
||
awarded = @awarded_points[course.id] | ||
missing = AvailablePoint.course_points(course).order!.map(&:name) - awarded | ||
@missing_points[course_id] = missing | ||
|
||
@percent_completed[course_id] = | ||
if (awarded.size + missing.size).positive? | ||
100 * (awarded.size.to_f / (awarded.size + missing.size)) | ||
else | ||
0 | ||
end | ||
@group_completion_ratios[course_id] = course.exercise_group_completion_ratio_for_user(user) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<section> | ||
<br> | ||
<h2><%= title %></h2> | ||
<br> | ||
<% for course in courses %> | ||
<% if course && @percent_completed[course.id] %> | ||
<div class="card"> | ||
<div class="card-body"> | ||
<% if show_course_name %> | ||
<h3 class="card-title"> | ||
<% if can? :read, course %> | ||
<%= link_to course.title, organization_course_path(course.organization, course) %> | ||
<% else %> | ||
<%= course.title %> | ||
<% end %> | ||
</h3> | ||
<br> | ||
<% end %> | ||
<% if can? :see_points, course%> | ||
<span class="progress-label">Awarded points</span> | ||
<div class="progress course-points-progress"> | ||
<div class="progress-bar" role="progressbar" style="width: <%= @percent_completed[course.id] %>%" aria-valuenow="<%= @percent_completed[course.id] %>" aria-valuemin="0" aria-valuemax="100"> | ||
<%= sprintf("%.0f", @percent_completed[course.id]) %>% | ||
</div> | ||
</div> | ||
<% if @group_completion_ratios[course.id] %> | ||
<% @group_completion_ratios[course.id].each do |group, ratio| %> | ||
<br> | ||
<span class="progress-label">Awarded points for <%= group %></span> | ||
<div class="progress course-points-progress"> | ||
<% unless ratio.zero? %> | ||
<div class="progress-bar bg-info" role="progressbar" style="width: <%= ratio * 100 %>%" aria-valuenow="<%= ratio * 100 %>" aria-valuemin="0" aria-valuemax="100"> | ||
<%= sprintf("%.0f", ratio * 100) %>% | ||
</div> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
<br> | ||
<% end %> | ||
<br> | ||
<table class="table table-hover"> | ||
<thead class=""> | ||
<tr> | ||
<th></th> | ||
<th>Point names</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<th scope="row">Awarded points</td> | ||
<td><%= points_list(@awarded_points[course.id]) %></td> | ||
</tr> | ||
<tr> | ||
<th scope="row">Missing points</td> | ||
<td><%= points_list(@missing_points[course.id]) %></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<% else %> | ||
For this course points are not visible. | ||
<% end %> | ||
</div> | ||
</div> | ||
<%else%> | ||
You don't have any points for this course | ||
<br> | ||
<% end %> | ||
<br> | ||
<% end %> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters