[refs #1861] Add downloads statistics
This commit is contained in:
parent
f3d32273d8
commit
8103b14e15
|
@ -11,3 +11,4 @@ public/stylesheets/compiled/*
|
|||
public/assets/*
|
||||
config/initializers/local.rb
|
||||
public/system/*
|
||||
*.swp
|
||||
|
|
1
Gemfile
1
Gemfile
|
@ -52,5 +52,6 @@ gem "grit"
|
|||
gem 'unicorn'
|
||||
gem 'delayed_job'
|
||||
gem 'paperclip', "~> 2.3"
|
||||
gem 'whenever', :require => false
|
||||
|
||||
gem 'jammit'
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class DownloadsController < ApplicationController
|
||||
def index
|
||||
@downloads = Download.paginate :page => params[:page], :per_page => 30
|
||||
end
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module DownloadHelper
|
||||
end
|
|
@ -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
|
|
@ -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
|
||||
|
|
@ -20,6 +20,8 @@
|
|||
%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
|
||||
|
|
|
@ -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: Вход в систему
|
||||
|
@ -228,6 +232,7 @@ ru:
|
|||
product: Продукт
|
||||
build_list: Сборочный лист
|
||||
build_list_item: Элемент сборочного листа
|
||||
download: Статистика
|
||||
|
||||
attributes:
|
||||
repository:
|
||||
|
@ -322,3 +327,9 @@ ru:
|
|||
level: Уровень
|
||||
status: Статус
|
||||
build_list: Сборочный лист
|
||||
download:
|
||||
name: Название
|
||||
version: Версия
|
||||
distro: Дистрибутив
|
||||
platform: Архитектура
|
||||
counter: Закачки
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
Rosa::Application.routes.draw do
|
||||
devise_for :users
|
||||
|
||||
resources :downloads, :only => :index
|
||||
|
||||
resources :platforms do
|
||||
member do
|
||||
get 'freeze'
|
||||
|
|
|
@ -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
|
|
@ -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
|
12
db/schema.rb
12
db/schema.rb
|
@ -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"
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe DownloadController do
|
||||
|
||||
end
|
|
@ -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
|
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Download do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue