-
Notifications
You must be signed in to change notification settings - Fork 41
Add point views #483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add point views #483
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/ConditionalAssignment: Use the return of the conditional for variable assignment and comparison. |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout/EndAlignment: end at 32, 0 is not aligned with module at 2, 1. |
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<% require 'portable_csv' %> | ||
<%= PortableCSV.generate(:force_quotes => true) do |csv| | ||
arr = ["Username"] | ||
arr += @user_fields.map(&:label) if @user_fields | ||
arr += @exercises.map{ |exercise| [exercise[:name]] + (exercise.available_points.length > 1 ? [nil] * (exercise.available_points.length-1) : []) }.flatten | ||
csv << arr | ||
|
||
arr = [nil] | ||
arr += [nil] * @user_fields.length if @user_fields | ||
arr += @exercises.map{|exercise| exercise.available_points.sort.map{|point| point.name }}.flatten | ||
csv << arr | ||
|
||
@users.each do |user, index| | ||
user_points = @users_to_points[user.login] | ||
arr = [user.login] | ||
if @user_fields | ||
@user_fields.each do |field| | ||
value = user.user_field_values.find { |o| o.field_name == field.name } | ||
arr += [value.value] if value | ||
end | ||
end | ||
@exercises.each do |exercise| | ||
exercise.available_points.sort.each do |p| | ||
arr += user_points.include?(p.name) ? [1] : [0] | ||
end | ||
end | ||
csv << arr | ||
end | ||
end.html_safe %> |
+2 −2 | misc/Makefile | |
+7 −14 | uml/Makefile | |
+224 −287 | uml/busybox/busybox-config | |
+13 −30 | uml/kernel/kernel-config.amd64 | |
+7 −10 | uml/rootfs/multistrap.conf.in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/IndentationWidth: Use 2 (not 1) spaces for indentation.