5 changed files with 77 additions and 13 deletions
@ -1,15 +1,79 @@ |
|||
<div class="row"> |
|||
<!-- <div class="col-4">--> |
|||
<!-- <h2>Requests per service</h2>--> |
|||
|
|||
<!-- <canvas id="servicesChart" aria-label="Pie chart for number of requests per service" role="img"></canvas>--> |
|||
<!-- </div>--> |
|||
<% colors = { |
|||
"A+" => '#5cb85c', |
|||
"A" => '#5cb85c', |
|||
"B+" => '#8db457', |
|||
"B" => '#8db457', |
|||
"C+" => '#beb052', |
|||
"C" => '#beb052', |
|||
"D" => '#6c757d', |
|||
"E" => '#f0ad4e', |
|||
"F" => '#e4804e', |
|||
"G" => '#d9534f' } %> |
|||
|
|||
<% %i[https smtp tls xmpp].each do |s| %> |
|||
<div class="col-6"> |
|||
<h2>Grades for service <%= s.to_s.upcase %></h2> |
|||
<% %i[https smtp tls xmpp].each do |service| %> |
|||
<div> |
|||
<h2>Grades for service <%= service.to_s.upcase %></h2> |
|||
|
|||
<canvas id="<%= "grades" + s.to_s.upcase_first + "Chart" %>" aria-label="Bar chart for number of grades for service <%= s.to_s.upcase %>" role="img"></canvas> |
|||
|
|||
<% grades = Stat.where(name: "grades_for_#{service}").order(date: :desc).first |
|||
total = grades.data.collect { _2 }.sum %> |
|||
|
|||
Over <%= total %> URL tested with a grade.<br> |
|||
|
|||
<!-- SVG solution --> |
|||
<em>SVG solution</em> |
|||
<div class="row"> |
|||
<svg width="100%" height="45" role="img" xmlns="http://www.w3.org/2000/svg" aria-labelledby="<%= "title-grades-#{service} description-grades-#{service}" %>"> |
|||
<title id="<%= "title-grades-#{service}" %>">Last grades for service <%= service %></title> |
|||
<description id="<%= "description-grades-#{service}" %>"> |
|||
This graphic represents the percentage of different grades obtained for the last analysis of |
|||
service <%= service %> requested. The obtained grades are: |
|||
<% grades.data.sort_by(&:first).each do |grade, number| %> |
|||
<% unless %w(T V).include?(grade) |
|||
percent = (number.to_f / total.to_f) * 100.0 %> |
|||
<%= "#{grade}: #{percent.round(2)} (#{number} requests)" %>; |
|||
<% end |
|||
end %> |
|||
Exotic grades like T or V are excluded from this graphic. |
|||
</description> |
|||
<% y = 0 |
|||
x = 0 |
|||
grades.data.sort_by(&:first).each do |grade, number| |
|||
%> |
|||
<% unless %w(T V).include?(grade) %> |
|||
<% percent = (number.to_f / total.to_f) * 100.0 |
|||
color = colors[grade] %> |
|||
<rect x="<%= x %>%" y="<%= y %>" width="<%= "#{percent.round}%" %>" |
|||
height="40" style="<%= "fill:#{color};" %>" |
|||
data-service="<%= service %>" |
|||
data-grade="<%= grade %>" |
|||
data-percent="<%= "#{percent}%" %>" |
|||
data-number="<%= number %>" |
|||
/> |
|||
<text x="<%= x + 0.4 %>%" y="25" style="fill:black;"><%= "#{grade}: #{percent.round}% (#{number})" %></text> |
|||
<% x += percent.round %> |
|||
<% end |
|||
end %> |
|||
</svg> |
|||
</div> |
|||
|
|||
<!-- DIV solution --> |
|||
<em>DIV solution</em> |
|||
<div class="row"> |
|||
<% grades.data.sort_by(&:first).each do |grade, number| %> |
|||
<% unless %w(T V).include?(grade) |
|||
percent = (number.to_f / total.to_f) * 100.0 |
|||
color = colors[grade] %> |
|||
<div style="width: <%= percent.round %>%; height: 2rem; line-height: 2rem; display: inline-block; background-color: <%= color %>; white-space: nowrap; text-overflow: ellipsis; margin-right: 2px"> |
|||
<%= "#{grade}: #{percent.round}% (#{number})" %> |
|||
</div> |
|||
<% end |
|||
end %> |
|||
</div> |
|||
<% end %> |
|||
</div> |
|||
</div> |
|||
<% end %> |
Loading…
Reference in new issue