You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

81 lines
3.1 KiB

<!-- <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 |service| %>
<div>
<h2>Grades for service <%= service.to_s.upcase %></h2>
<% 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="cumulative-datas">
<% left = 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] %>
<div class="cumulative-data" style="left: <%= left %>; width: <%= percent.round %>%; background-color: <%= color %>;">
<%= "#{grade}: #{percent.round}% (#{number})" %>
</div>
<% left += percent.round %>
<% end
end %>
</div>
</div>
<% end %>