forked from aeris/cryptcheck-rails
parent
a1871a22a7
commit
0a5589cfa5
@ -0,0 +1,32 @@ |
||||
class StatisticsController < ApplicationController |
||||
def index; end |
||||
|
||||
def grade |
||||
@services = Analysis.where(service: params.fetch(:service)) |
||||
|
||||
respond_to do |format| |
||||
format.html |
||||
format.json do |
||||
grades = Hash.new 0 |
||||
|
||||
@services.each do |service| |
||||
if (result = service.result) |
||||
result.each do |r| |
||||
next unless (grade = r['grade']) |
||||
grades[grade] += 1 |
||||
end |
||||
end |
||||
end |
||||
|
||||
json = { |
||||
grades: { |
||||
labels: grades.keys, |
||||
dataset: grades |
||||
} |
||||
} |
||||
|
||||
render json: json, status: :ok |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,2 @@ |
||||
module StatisticsHelper |
||||
end |
@ -0,0 +1,42 @@ |
||||
document.addEventListener("DOMContentLoaded", () => { |
||||
let gradesChart = document.getElementById('gradesChart').getContext('2d') |
||||
|
||||
let background = [ |
||||
'rgba(255, 99, 132, 1)', |
||||
'rgba(54, 162, 235, 1)', |
||||
'rgba(255, 206, 86, 1)', |
||||
'rgba(75, 192, 192, 1)', |
||||
'rgba(153, 102, 255, 1)', |
||||
'rgba(255, 159, 64, 1)' |
||||
] |
||||
|
||||
let createGradesChart = new Chart(gradesChart, { |
||||
type: 'bar' |
||||
}) |
||||
|
||||
let generateGraphs = function () { |
||||
fetch(window.location.href, { |
||||
method: "GET", |
||||
headers: { |
||||
"Accept": "application/json", |
||||
"Content-Type": "application/json", |
||||
}, |
||||
}).then((response) => { |
||||
response.json().then((data) => { |
||||
if (response.status === 200) { |
||||
let grades = data["grades"]["dataset"] |
||||
|
||||
createGradesChart.data.labels = data["grades"]["labels"] |
||||
createGradesChart.data.datasets = [{ |
||||
label: 'Count', |
||||
data: grades, |
||||
backgroundColor: background |
||||
}] |
||||
createGradesChart.update() |
||||
} |
||||
}) |
||||
}); |
||||
} |
||||
|
||||
generateGraphs() |
||||
}); |
@ -1 +1,6 @@ |
||||
import 'css/application' |
||||
|
||||
import Chart from 'chart.js/auto' |
||||
global.Chart = Chart |
||||
|
||||
import 'js/stats/grades' |
@ -0,0 +1,7 @@ |
||||
<h2>Statistiques par service</h2> |
||||
|
||||
<ul class="list-unstyled"> |
||||
<% %i[https smtp xmpp tls ssh].each do |service| %> |
||||
<li><%= link_to service, stats_grade_path(service) %> (<%= Analysis.where(service: service).count %> recherches)</li> |
||||
<% end %> |
||||
</ul> |
@ -0,0 +1,7 @@ |
||||
require "test_helper" |
||||
|
||||
class StatisticsControllerTest < ActionDispatch::IntegrationTest |
||||
# test "the truth" do |
||||
# assert true |
||||
# end |
||||
end |
Loading…
Reference in new issue