[refs #1861] Add downloads statistics

This commit is contained in:
santaux 2011-10-14 10:35:25 +04:00
parent f3d32273d8
commit 8103b14e15
16 changed files with 160 additions and 6 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ public/stylesheets/compiled/*
public/assets/*
config/initializers/local.rb
public/system/*
*.swp

View File

@ -52,5 +52,6 @@ gem "grit"
gem 'unicorn'
gem 'delayed_job'
gem 'paperclip', "~> 2.3"
gem 'whenever', :require => false
gem 'jammit'

View File

@ -42,6 +42,7 @@ GEM
net-ssh-gateway (>= 1.0.0)
capistrano-ext (1.2.1)
capistrano (>= 1.0.0)
chronic (0.6.4)
closure-compiler (1.1.1)
compass (0.10.6)
haml (>= 3.0.4)
@ -139,6 +140,9 @@ GEM
warden (1.0.3)
rack (>= 1.0.0)
web-app-theme (0.6.3)
whenever (0.7.0)
activesupport (>= 2.3.4)
chronic (~> 0.6.3)
will_paginate (3.0.pre2)
yui-compressor (0.9.5)
@ -166,4 +170,5 @@ DEPENDENCIES
russian
unicorn
web-app-theme (>= 0.6.2)
whenever
will_paginate (~> 3.0.pre2)

View File

@ -0,0 +1,5 @@
class DownloadsController < ApplicationController
def index
@downloads = Download.paginate :page => params[:page], :per_page => 30
end
end

View File

@ -0,0 +1,2 @@
module DownloadHelper
end

38
app/models/download.rb Normal file
View File

@ -0,0 +1,38 @@
class Download < ActiveRecord::Base
PREV_LOG_FILE = "#{ APP_CONFIG['nginx_log'] }.0"
default_scope order(:name)
class << self
def rotate_nginx_log
system("mv #{ APP_CONFIG['nginx_log'] } #{ PREV_LOG_FILE }")
system("sudo kill -USR1 `cat #{ APP_CONFIG['nginx_pid'] }`")
end
def parse_nginx_log
File.open(PREV_LOG_FILE) do |log|
while (line = log.gets)
if package = line.match( /GET \/.+\/([\w\d]+)-([\d.]+)-((\d+mdv[\d.]+)|([\d\w]+-mdv[\d.]+))\.([\w\d]+)\.rpm/ )
increase(
:name => package[1],
:version => package[2],
:distro => package[3].sub(/-/, ''),
:platform => package[6]
)
end
end
end
end
def parse_and_remove_nginx_log
parse_nginx_log
system("rm -f #{PREV_LOG_FILE}")
end
def increase(opts={})
download = find_or_initialize_by_name_and_version_and_platform_and_distro(opts)
download.counter += 1
download.save
end
end
end

View File

@ -0,0 +1,28 @@
.block
.content
%h2.title
= t("layout.downloads.title")
.inner
%table.table
%tr
%th.first= t("activerecord.attributes.download.name")
%th= t("activerecord.attributes.download.version")
%th= t("activerecord.attributes.download.distro")
%th= t("activerecord.attributes.download.platform")
%th.last= t("activerecord.attributes.download.counter")
- @downloads.each do |download|
%tr{:class => cycle("odd", "even")}
%td
= download.name
%td
= download.version
%td
= download.distro
%td
= download.platform
%td.last
= download.counter
.actions-bar.wat-cf
.actions
= will_paginate @downloads

View File

@ -20,13 +20,15 @@
%a{:href => users_path}= t("layout.menu.users")
%li{:class => controller.controller_path == 'platforms' ? 'active' : '' }
%a{:href => platforms_path}= t("layout.menu.platforms")
%li{:class => controller.controller_path == 'downloads' ? 'active' : '' }
%a{:href => downloads_path}= t("layout.menu.downloads")
#wrapper.wat-cf
= render :partial => "layouts/flashes"
#main
= yield
#footer
.block
#sidebar
= yield :sidebar

View File

@ -21,6 +21,9 @@ ru:
false_: Нет
publish: Опубликовать
downloads:
title: Статистика закачек пакетов
weekdays:
Monday: Понедельник
Tuesday: Вторник
@ -33,6 +36,7 @@ ru:
menu:
users: Пользователи
platforms: Платформы
downloads: Статистика
sessions:
sign_in_header: Вход в систему
@ -145,7 +149,7 @@ ru:
no_items_data: Данных нет
show: Просмотр
confirm_publish: Вы уверены, что хотите опубликовать контейнер?
items:
statuses:
build_error: ошибка сборки
@ -228,6 +232,7 @@ ru:
product: Продукт
build_list: Сборочный лист
build_list_item: Элемент сборочного листа
download: Статистика
attributes:
repository:
@ -244,7 +249,7 @@ ru:
build_status: Статус последней сборки
build_path: Путь к iso
created_at: Создан
updated_at: Обновлен
updated_at: Обновлен
ks: Содержимое .ks.template
counter: Содержимое .counter
build: Содержимое build
@ -322,3 +327,9 @@ ru:
level: Уровень
status: Статус
build_list: Сборочный лист
download:
name: Название
version: Версия
distro: Дистрибутив
platform: Архитектура
counter: Закачки

View File

@ -1,6 +1,8 @@
Rosa::Application.routes.draw do
devise_for :users
resources :downloads, :only => :index
resources :platforms do
member do
get 'freeze'
@ -25,7 +27,7 @@ Rosa::Application.routes.draw do
end
member do
post :publish
end
end
end
member do
@ -38,7 +40,7 @@ Rosa::Application.routes.draw do
end
resources :users
match 'build_lists/status_build', :to => "build_lists#status_build"
match 'build_lists/post_build', :to => "build_lists#post_build"
match 'build_lists/pre_build', :to => "build_lists#pre_build"

7
config/schedule.rb Normal file
View File

@ -0,0 +1,7 @@
every 1.day, :at => '0:05 am' do
runner "Download.rotate_nginx_log"
end
every 1.day, :at => '0:10 am' do
runner "Download.parse_and_remove_nginx_log"
end

View File

@ -0,0 +1,17 @@
class CreateDownloads < ActiveRecord::Migration
def self.up
create_table :downloads do |t|
t.string :name, :null => false
t.string :version
t.string :distro
t.string :platform
t.integer :counter, :default => 0
t.timestamps
end
end
def self.down
drop_table :downloads
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110428140753) do
ActiveRecord::Schema.define(:version => 20111012065448) do
create_table "arches", :force => true do |t|
t.string "name", :null => false
@ -73,6 +73,16 @@ ActiveRecord::Schema.define(:version => 20110428140753) do
add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
create_table "downloads", :force => true do |t|
t.string "name", :null => false
t.string "version"
t.string "distro"
t.string "platform"
t.integer "counter", :default => 0
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "platforms", :force => true do |t|
t.string "name"
t.string "unixname"

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe DownloadController do
end

View File

@ -0,0 +1,15 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the DownloadHelper. For example:
#
# describe DownloadHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe DownloadHelper do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe Download do
pending "add some examples to (or delete) #{__FILE__}"
end