Browse Source

Improve colors?

stats
Norore 3 months ago
committed by aeris
parent
commit
de51a93fde
  1. 2
      app/controllers/statistics_controller.rb
  2. 22
      app/javascript/js/stats/index.js
  3. 2
      bin/stats
  4. 1
      package.json

2
app/controllers/statistics_controller.rb

@ -5,7 +5,7 @@ class StatisticsController < ApplicationController
service = params.fetch :id
respond_to do |format|
format.json do
json = Stat.where(name: "grades_for_#{service}").order(date: :desc).last.dataset
json = Stat.where(name: "grades_for_#{service}").order(date: :desc).first.dataset
render json: json, status: :ok
end
end

22
app/javascript/js/stats/index.js

@ -1,13 +1,15 @@
document.addEventListener("DOMContentLoaded", () => {
let background = [
'#5cb85c',
'#8db457',
'#beb052',
'#f0ad4e',
'#e4804e',
'#d9534f',
'#bb3d39',
'#000'
'#5cb85c', // A+
'#5cb85c', // A
'#8db457', // B+
'#8db457', // B
'#beb052', // C+
'#beb052', // C
'#6c757d', // D
'#f0ad4e', // E
'#e4804e', // F
'#d9534f' // G
]
for (const service of ["https", "smtp", "tls", "xmpp"]) {
@ -52,8 +54,8 @@ document.addEventListener("DOMContentLoaded", () => {
fetch(`/statistics/${service}.json`).then((response) => {
if (response.status === 200) {
response.json().then((data) => {
const labels = ["A+", "A", "B", "C", "D", "E", "F", "G"]
const dataset = JSON.parse(JSON.stringify(data, labels, 2))
const labels = ["A+", "A", "B+", "B", "C+", "C", "D", "E", "F", "G"]
const dataset = JSON.parse(JSON.stringify(data, labels, 0))
chart.data.labels = labels
chart.data.datasets = [{
label: 'Number of request',

2
bin/stats

@ -19,7 +19,7 @@ Stat.create!(
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
grades = %w[A+ A B+ B C+ C D E F G].collect { |g| [g, 0] }.to_h
services.each do |service|
next unless (result = service.result)
result.each do |r|

1
package.json

@ -5,6 +5,7 @@
"author": "aeris <aeris@imirhil.fr>",
"license": "AGPL-3.0-or-later",
"dependencies": {
"@popperjs/core": "^2.11.5",
"@rails/webpacker": "5.4.3",
"bootstrap": "^5.1.3",
"chart.js": "^3.7.1",

Loading…
Cancel
Save