5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-05-18 13:40:49 +00:00

estadísticas básicas

This commit is contained in:
f 2019-08-01 21:20:42 -03:00
parent cc94a76567
commit aebe5b6764
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
13 changed files with 92 additions and 1 deletions

View file

@ -40,6 +40,7 @@ Metrics/BlockLength:
- 'config/environments/production.rb'
- 'config/initializers/devise.rb'
- 'db/schema.rb'
- 'config/routes.rb'
Metrics/ClassLength:
Exclude:

View 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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
View file

@ -0,0 +1,3 @@
# frozen_string_literal: true
SiteStat = Struct.new(:site)

View 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

View 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

View file

@ -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'

View file

@ -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'

View file

@ -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

View file

@ -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