5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 05:36:21 +00:00

Merge branch 'blazer' into panel.sutty.nl

This commit is contained in:
f 2022-04-30 20:45:21 -03:00
commit 034a9d4aee
3 changed files with 43 additions and 18 deletions

View file

@ -34,7 +34,14 @@ class StatsController < ApplicationController
def index def index
breadcrumb I18n.t('stats.index.title'), '' breadcrumb I18n.t('stats.index.title'), ''
@chart_params = { interval: interval } params.with_defaults! default_url_options
@chart_params = {
interval: interval,
period_start: params[:period_start],
period_end: params[:period_end]
}
hostnames hostnames
last_stat last_stat
chart_options chart_options
@ -46,7 +53,7 @@ class StatsController < ApplicationController
Stat::COLUMNS.each do |column| Stat::COLUMNS.each do |column|
@columns[column] = @columns[column] =
Rails.cache.fetch("stats/#{column}/#{site.id}", expires_in: expires_in) do Rails.cache.fetch("stats/#{column}/#{site.id}", expires_in: expires_in) do
Rollup.where(interval: interval, name: "host|#{column}") rollup_scope.where(interval: interval, name: "host|#{column}")
.where_dimensions(host: hostnames) .where_dimensions(host: hostnames)
.group("dimensions->>'#{column}'") .group("dimensions->>'#{column}'")
.sum(:value) .sum(:value)

View file

@ -11,8 +11,6 @@
# Los hostnames de un sitio van a poder obtenerse a partir de # Los hostnames de un sitio van a poder obtenerse a partir de
# Site#hostnames con la garantía de que son únicos. # Site#hostnames con la garantía de que son únicos.
class UriCollectionJob < PeriodicJob class UriCollectionJob < PeriodicJob
include RecursiveRollup
# Ignoramos imágenes porque suelen ser demasiadas y no aportan a las # Ignoramos imágenes porque suelen ser demasiadas y no aportan a las
# estadísticas. # estadísticas.
IMAGES = %w[.png .jpg .jpeg .gif .webp .jfif].freeze IMAGES = %w[.png .jpg .jpeg .gif .webp .jfif].freeze
@ -76,13 +74,29 @@ class UriCollectionJob < PeriodicJob
# @param :dimensions [Hash] # @param :dimensions [Hash]
# @param :filter [Hash] # @param :filter [Hash]
# @return [nil] # @return [nil]
def rollup(name:, dimensions:, filter: nil) def rollup(name:, dimensions:, interval: starting_interval, filter: nil)
AccessLog.where(**(filter || dimensions)) AccessLog.where(**(filter || dimensions))
.where('created_at >= ?', beginning_of_interval) .where('created_at >= ?', beginning_of_interval)
.completed_requests .completed_requests
.non_robots .non_robots
.group(*dimensions.keys) .group(*dimensions.keys)
.rollup(name, interval: starting_interval, update: true) .rollup(name, interval: interval, update: true)
end
# Generar rollups con el resto de la información
#
# @param :name [String]
# @param :dimensions [Hash]
# @param :filter [Hash]
# @return [nil]
def reduce_rollup(name:, dimensions:, filter: nil)
Stat::INTERVALS.reduce do |_previous, current|
rollup(name: name, dimensions: dimensions, filter: filter, interval: current)
current
end
nil
end end
def stat_name def stat_name

View file

@ -9,9 +9,13 @@
%time{ datetime: @last_stat.updated_at } %time{ datetime: @last_stat.updated_at }
#{time_ago_in_words @last_stat.updated_at}. #{time_ago_in_words @last_stat.updated_at}.
.mb-5 %form.mb-5.form-inline{ method: 'get' }
- Stat::INTERVALS.each do |interval| - Stat::INTERVALS.each do |interval|
= link_to t(".#{interval}"), site_stats_path(interval: interval, urls: params[:urls]), class: "btn #{'btn-primary active' if @interval == interval}" = link_to t(".#{interval}"), site_stats_path(interval: interval, urls: params[:urls], period_start: params[:period_start].to_date.try(:"beginning_of_#{interval}").to_date, period_end: params[:period_end]), class: "mb-0 btn #{'btn-primary active' if @interval == interval}"
%input.form-control{ type: 'date', name: :period_start, value: params[:period_start] }
%input.form-control{ type: 'date', name: :period_end, value: params[:period_end] }
%button.btn.mb-0{ type: 'submit' }= t('.filter')
.mb-5 .mb-5
%h2= t('.host.title', count: @hostnames.size) %h2= t('.host.title', count: @hostnames.size)