mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-25 03:56:22 +00:00
estadísticas básicas
This commit is contained in:
parent
cc94a76567
commit
aebe5b6764
13 changed files with 92 additions and 1 deletions
|
@ -40,6 +40,7 @@ Metrics/BlockLength:
|
|||
- 'config/environments/production.rb'
|
||||
- 'config/initializers/devise.rb'
|
||||
- 'db/schema.rb'
|
||||
- 'config/routes.rb'
|
||||
|
||||
Metrics/ClassLength:
|
||||
Exclude:
|
||||
|
|
18
app/controllers/stats_controller.rb
Normal file
18
app/controllers/stats_controller.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Estadísticas del sitio
|
||||
class StatsController < ApplicationController
|
||||
include Pundit
|
||||
before_action :authenticate_usuarie!
|
||||
|
||||
def index
|
||||
@site = find_site
|
||||
authorize SiteStat.new(@site)
|
||||
|
||||
# Solo queremos el promedio de tiempo de compilación, no de
|
||||
# instalación de dependencias.
|
||||
stats = @site.build_stats.jekyll
|
||||
@build_avg = stats.average(:seconds).to_f.round(2)
|
||||
@build_max = stats.maximum(:seconds).to_f.round(2)
|
||||
end
|
||||
end
|
|
@ -22,6 +22,14 @@ module ApplicationHelper
|
|||
"#{f.first}[#{f.last}]"
|
||||
end
|
||||
|
||||
def distance_of_time_in_words_if_more_than_a_minute(seconds)
|
||||
if seconds > 60
|
||||
distance_of_time_in_words seconds
|
||||
else
|
||||
I18n.t('seconds', seconds: seconds)
|
||||
end
|
||||
end
|
||||
|
||||
def sanitize_markdown(text, options = {})
|
||||
sanitize(CommonMarker.render_html(text), options)
|
||||
end
|
||||
|
|
|
@ -3,4 +3,6 @@
|
|||
# Recolecta estadísticas durante la generación del sitio
|
||||
class BuildStat < ApplicationRecord
|
||||
belongs_to :deploy
|
||||
|
||||
scope :jekyll, -> { where(action: 'bundle_exec_jekyll_build') }
|
||||
end
|
||||
|
|
|
@ -42,7 +42,7 @@ class Deploy < ApplicationRecord
|
|||
# XXX: prestar atención a la concurrencia de sqlite3, se podría
|
||||
# enviar los datos directamente a una API para que se manejen desde
|
||||
# el proceso principal de rails y evitar problemas.
|
||||
stat = build_stats.build action: cmd.split('-', 2).first.tr(' ', '_')
|
||||
stat = build_stats.build action: cmd.split(' -', 2).first.tr(' ', '_')
|
||||
r = nil
|
||||
|
||||
time_start
|
||||
|
|
|
@ -18,6 +18,7 @@ class Site < ApplicationRecord
|
|||
belongs_to :licencia
|
||||
|
||||
has_many :deploys
|
||||
has_many :build_stats, through: :deploys
|
||||
has_many :roles
|
||||
has_many :usuaries, -> { where('roles.rol = ?', 'usuarie') },
|
||||
through: :roles
|
||||
|
|
3
app/models/site_stat.rb
Normal file
3
app/models/site_stat.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
SiteStat = Struct.new(:site)
|
15
app/policies/site_stat_policy.rb
Normal file
15
app/policies/site_stat_policy.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Política de acceso a las estadísticas
|
||||
class SiteStatPolicy
|
||||
attr_reader :site_stat, :usuarie
|
||||
|
||||
def initialize(usuarie, site_stat)
|
||||
@usuarie = usuarie
|
||||
@site_stat = site_stat
|
||||
end
|
||||
|
||||
def index?
|
||||
site_stat.site.usuarie? usuarie
|
||||
end
|
||||
end
|
18
app/views/stats/index.haml
Normal file
18
app/views/stats/index.haml
Normal file
|
@ -0,0 +1,18 @@
|
|||
.row
|
||||
.col
|
||||
= render 'layouts/breadcrumb',
|
||||
crumbs: [link_to(t('sites.index'), sites_path),
|
||||
link_to(@site.name, site_path(@site)), t('.title')]
|
||||
.row
|
||||
.col
|
||||
%h1= t('.title')
|
||||
%p.lead= t('.help')
|
||||
|
||||
%table.table.table-striped.table-condensed
|
||||
%tbody
|
||||
%tr
|
||||
%td= t('.build.average')
|
||||
%td= distance_of_time_in_words_if_more_than_a_minute @build_avg
|
||||
%tr
|
||||
%td= t('.build.maximum')
|
||||
%td= distance_of_time_in_words_if_more_than_a_minute @build_max
|
|
@ -1,4 +1,5 @@
|
|||
en:
|
||||
seconds: '%{seconds} seconds'
|
||||
deploy_mailer:
|
||||
deployed:
|
||||
subject: "[Sutty] The site %{site} has been built"
|
||||
|
@ -184,6 +185,15 @@ en:
|
|||
It also helps with site archival for historical purposes :)
|
||||
|
||||
ejemplo: 'example'
|
||||
stats:
|
||||
index:
|
||||
title: Statistics
|
||||
help: |
|
||||
Statistics show information about how your site is generated and
|
||||
how many resources it uses.
|
||||
build:
|
||||
average: 'Average building time'
|
||||
maximum: 'Maximum building time'
|
||||
sites:
|
||||
repository:
|
||||
config: 'Changes in config'
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
es:
|
||||
seconds: '%{seconds} segundos'
|
||||
deploy_mailer:
|
||||
deployed:
|
||||
subject: "[Sutty] El sitio %{site} ha sido generado"
|
||||
|
@ -195,6 +196,15 @@ es:
|
|||
|
||||
También sirve para archivo histórico :)
|
||||
ejemplo: 'ejemplo'
|
||||
stats:
|
||||
index:
|
||||
title: Estadísticas
|
||||
help: |
|
||||
Las estadísticas visibilizan información sobre cómo se genera y
|
||||
cuántos recursos utiliza tu sitio.
|
||||
build:
|
||||
average: 'Tiempo promedio de generación'
|
||||
maximum: 'Tiempo máximo de generación'
|
||||
sites:
|
||||
repository:
|
||||
config: 'Cambios en la configuración'
|
||||
|
|
|
@ -42,5 +42,7 @@ Rails.application.routes.draw do
|
|||
# Compilar el sitio
|
||||
post 'enqueue', to: 'sites#enqueue'
|
||||
post 'reorder_posts', to: 'sites#reorder_posts'
|
||||
|
||||
resources :stats, only: [:index]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -217,6 +217,9 @@ tengamos tiempo de hacerlo realmente.
|
|||
# TODO
|
||||
|
||||
* ver las estadisticas de compilación en lugar del log (el log también)
|
||||
|
||||
agrupar los build stats para poder ver todos los pasos de una
|
||||
compilación juntos
|
||||
* comitear en git los articulos (igual no es de esta rama...)
|
||||
* link a visitar sitio
|
||||
* editor de opciones
|
||||
|
|
Loading…
Reference in a new issue