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.
 
 
 
 
 
 

38 lines
932 B

#!./bin/rails runner
TODAY = Date.today
# general stat
stat_name = "request_per_service"
services = Analysis.group(:service).order(service: :asc).count
json = {
labels: services.keys,
dataset: services.values
}
Stat.delete_by name: stat_name, date: TODAY
Stat.create!(
name: stat_name,
date: TODAY,
dataset: json
)
# grade per service for https, smtp, tls and xmpp
%i[https smtp tls xmpp].each do |service_name|
stat_name = "grades_for_" + service_name.to_s
services = Analysis.where(service: service_name, pending: false)
grades = %w[A+ A B C D E F G].collect { |g| [g, 0] }.to_h
services.each do |service|
if (result = service.result)
result.each do |r|
next unless (grade = r['grade'])
grades[grade] += 1 if grades.has_key?(grade)
end
end
end
Stat.delete_by name: stat_name, date: TODAY
Stat.create!(
name: stat_name,
date: TODAY,
dataset: grades
)
end