code
stringlengths
1
1.73M
language
stringclasses
1 value
namespace :bilibiliranking do desc "bilibili ranking example pickup title" task :title => :environment do require 'lib/tasks/vegas_video_maker.rb' require 'lib/tasks/bili_ranking_maker.rb' include VegasVideoMaker BRM.create({:path => "#{BILI_PRO_PATH}#{ENV['pa']}\\"}) do |vvm| vvm.title(4, tru...
Ruby
namespace :bilibiliranking do desc "bilibili ranking example op" task :op => :environment do require 'lib/tasks/vegas_video_maker.rb' require 'lib/tasks/bili_ranking_maker.rb' include VegasVideoMaker BRM.create({:path => "#{BILI_PRO_PATH}#{ENV['pa']}\\"}) do |vvm| vvm.op.pics("op", 1..2, {:len...
Ruby
namespace :bilibiliranking do desc "bilibili ranking example ed" task :ed => :environment do require 'lib/tasks/vegas_video_maker.rb' require 'lib/tasks/bili_ranking_maker.rb' include VegasVideoMaker BRM.create({:path => "#{BILI_PRO_PATH}#{ENV['pa']}\\"}) do |vvm| vvm.ed_bgm do |length| ...
Ruby
namespace :bilibiliranking do desc "bilibili ranking example history" task :history => :environment do require 'lib/tasks/vegas_video_maker.rb' require 'lib/tasks/bili_ranking_maker.rb' include VegasVideoMaker BRM.create({:path => "#{BILI_PRO_PATH}#{ENV['pa']}\\"}) do |vvm| vvm.play_bgm('1.mp3...
Ruby
namespace :bilibiliranking do desc "bilibili ranking example list" task :list => :environment do require 'lib/tasks/vegas_video_maker.rb' require 'lib/tasks/bili_ranking_maker.rb' include VegasVideoMaker BRM.create({:path => "#{BILI_PRO_PATH}#{ENV['pa']}\\"}) do |vvm| vvm.play_bgm('bilibili-mu...
Ruby
#id1 前,default=0; id2 后,default=last.id; pa, 必须有except.yml namespace :bld do desc "Export to CSV" task :export_to_csv => :environment do puts time = Time.now pa = ENV['pa'] ? "#{BILI_PRO_PATH}#{ENV['pa']}\\" : nil step_index = 0 id1 = ENV['id1'].to_i id2 = ENV['id2'] || Scan.last.id except_i...
Ruby
namespace :bld do desc "Get data" task :get_acr_data => :environment do date_now = Time.now ac_types = ENV['codes'] ? AcType.find_all_by_page_code(ENV['codes'].split(',')) : AcType.find_all_by_code_type(0) pages = Scan.search ac_types puts "#{Time.now - date_now} second complete" date_now = Ti...
Ruby
module VegasVideoMaker class VVM require 'rexml/document' @project = nil @medias = [] @video_event_count = 0 @audio_event_count = 0 def self.create vvm = self.new() doc = REXML::Document.new("<?xml version=\"1.0\"?><Vegas/>") vegas = doc.root project = vegas.add_element "Project" p...
Ruby
class BiliRankingImage require 'RMagick' include Magick require 'jcode' attr_accessor :path alias :pa :path alias :pa= :path= FONT_EXE = "#{RAILS_ROOT}/public/acfun_list_font_pic.exe" TMP_FILE = 'tmp.png' @@iconv ||= Iconv.new 'GB18030', 'UTF-8//IGNORE' FONT_FZZHY_GBK = @@iconv.iconv "方正准圆_GBK" F...
Ruby
module VegasVideoMaker class BRM < VVM attr_accessor :vt, :pa, :ut, :ops #:ut => usual_time alias :vvmtime :vt alias :vvmtime= :vt= TIME_30 = VVMTime.ns(1) TIME_25 = VVMTime.nl(25) TIME_20 = VVMTime.nl(20) TIME_15 = VVMTime.nl(15) TIME_10 = VVMTime.nl(10) TIME_5 = VVMTime.nl(5) ...
Ruby
namespace :bld do desc "get data and export" task :bat => :environment do puts time = Time.now Rake::Task['bld:get_acr_data'].invoke Rake::Task['bld:get_work_info'].invoke Rake::Task['bld:ranking_work_info_fixed'].invoke Rake::Task['bld:export_to_csv'].invoke puts "#{Time.now - time} second!...
Ruby
# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person',...
Ruby
if Rails.version == '2.3.12' && Gem.available?('mongrel', Gem::Requirement.new('~>1.1.5')) && self.class.const_defined?(:Mongrel) # Pulled right from latest rack. Old looked like this in 1.1.0 version. # # def [](k) # super(@names[k] ||= @names[k.downcase]) # end # module Rack module Utils ...
Ruby
# Be sure to restart your server when you modify this file. # These settings change the behavior of Rails 2 apps and will be defaults # for Rails 3. You can remove this initializer when Rails 3 is released. if defined?(ActiveRecord) # Include Active Record class name as root for JSON serialized output. ActiveReco...
Ruby
# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone
Ruby
# Be sure to restart your server when you modify this file. # Your secret key for verifying cookie session data integrity. # If you change this key, all old sessions will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. Act...
Ruby
# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying do debug a probl...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.action_controller.consider_all_reque...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.ca...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between...
Ruby
# Be sure to restart your server when you modify this file # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.3.14' unless defined? RAILS_GEM_VERSION # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') ...
Ruby
# Don't change this file! # Configure your app in config/environment.rb and config/environments/*.rb RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) module Rails class << self def boot! unless booted? preinitialize pick_boot.run end end def booted? ...
Ruby
ActionController::Routing::Routes.draw do |map| map.logout '/logout', :controller => 'sessions', :action => 'destroy' map.login '/login', :controller => 'sessions', :action => 'new' map.register '/register', :controller => 'users', :action => 'create' map.signup '/signup', :controller => 'users', :action => 'ne...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper def img_tag file_name image_tag %[#{IMG_PATH}#{file_name}], :alt => " " end def point point point_s = point.to_s fushu = point_s.first == '-' ? true : false size = point_s.size - ( fus...
Ruby
module UsersHelper # # Use this to wrap view elements that the user can't access. # !! Note: this is an *interface*, not *security* feature !! # You need to do all access control at the controller level. # # Example: # <%= if_authorized?(:index, User) do link_to('List all users', users_path) end %> ...
Ruby
module SessionsHelper end
Ruby
module WeekliesHelper end
Ruby
module IndexHelper end
Ruby
class WeeklyResultWork < WeeklyConnect end
Ruby
class WeeklyAttr < WeeklyConnect end
Ruby
class Key < ActiveRecord::Base establish_connection :user has_many :key_users end
Ruby
class WeeklyExcept < WeeklyConnect validates_uniqueness_of :wid, :scope=>:weekly_id, :message => 'same wid' end
Ruby
class VegasVideoTime attr_accessor :h, :m, :s, :l def self.new h0=0, m0=0, s0=0, l0=0 vvm_time = super() vvm_time.h = h0; vvm_time.m = m0; vvm_time.s = s0; vvm_time.l = l0 vvm_time end def self.nl l h = l / 108000 m = l % 108000 / 1800 s = l % 108000 % 1800 / 30 l0 = l % 108000 % 1...
Ruby
class App < ActiveRecord::Base establish_connection :user end
Ruby
class BangumiType < ActiveRecord::Base has_many :bangumis has_many :hot_bangumis, :class_name => "Bangumi", :conditions => "bangumis.status = 1" validates_presence_of :name, :message => 'name is null' end
Ruby
class WeeklyResult < WeeklyConnect belongs_to :weekly belongs_to :sp_type belongs_to :weekly_result_work ['wid', 'name', 'wtype', 'author'].each do |n| unless self.column_names.include?(n) eval "attr_reader(:#{n});def #{n};@#{n} ||= weekly_result_work.#{n};end" end end def work Work.find...
Ruby
class WorkWeeklyProperty < ActiveRecord::Base end
Ruby
class Scan < ActiveRecord::Base has_many :results, :dependent => :destroy #status #nil => 旧, 0 => 新, 1 => 读取完成, 2 => 保存完成, 3 => 异常 def search ac_types url = "http://api.bilibili.tv/list?type=xml&appkey=#{Work.get_info_key}&order=default&pagesize=100" @http = Net::HTTP::Persistent.new(nil, (PROXY ? URI...
Ruby
require 'rexml/document' require 'net/http' class FlashVar < ActiveRecord::Base belongs_to :work validates_uniqueness_of :vid, :scope=>:work_id, :message => 'same' validates_presence_of :vid, :message => 'vid is null' has_many :d_results belongs_to :space_type def add_result( scan = Scan.find(:first, :orde...
Ruby
class User < ActiveRecord::Base establish_connection :user include Authentication include Authentication::ByPassword include Authentication::ByCookieToken validates_presence_of :login validates_length_of :login, :within => 3..40 validates_uniqueness_of :login validates_format_of :l...
Ruby
class KeyUser < ActiveRecord::Base establish_connection :user belongs_to :key validates_uniqueness_of :uname, :scope=>:key_id, :message => 'same' validates_presence_of :uname, :message => 'uname is null' end
Ruby
class WeeklyConnect < ActiveRecord::Base establish_connection :weekly self.abstract_class = true end
Ruby
class Weekly < WeeklyConnect has_many :weekly_results, :dependent => :destroy belongs_to :last, :foreign_key => :parent_id, :class_name => 'Weekly' def self.latest find :first, :conditions => "wid is not null", :order => '"index" desc' end def check_zero_results all :conditions => "(clicks = 0 or...
Ruby
class Author < ActiveRecord::Base has_many :works end
Ruby
class VegasVideoMaker require 'rexml/document' @project = nil @medias = [] @video_event_count = 0 @audio_event_count = 0 def self.create vvm = self.new() doc = REXML::Document.new("<?xml version=\"1.0\"?><Vegas/>") vegas = doc.root project = vegas.add_element "Project" main_video =...
Ruby
class AcType < ActiveRecord::Base has_many :works has_many :scans validates_uniqueness_of :name end
Ruby
class Work < ActiveRecord::Base belongs_to :ac_type has_many :results belongs_to :author has_many :flash_vars, :conditions => "space_type_id is not null" has_many :youku_and_tudou, :class_name => "FlashVar", :conditions => "space_type_id in (4,6)" validates_uniqueness_of :wid, :message => 'wid same' valid...
Ruby
class Bangumi < ActiveRecord::Base belongs_to :bangumi_type has_and_belongs_to_many :works, :join_table => "bangumi_works" has_many :bangumi_works validates_presence_of :name, :message => 'name is null' def check_hot_status if status.zero? works = Work.find(bangumi_works.collect(&:work_id)) ...
Ruby
class SpaceType < ActiveRecord::Base end
Ruby
class SpType < WeeklyConnect end
Ruby
#bilibili排名算法 v2.8(2012.1.6) class Results::R28 < Results::R27 def self.get_comment_revised clicks, comments, stows, ops={} return E_C if comments <= 0 if ops[:hot_bangumi] [format("%.2f", E_C.to_f * ([clicks * 1.5, 50000].min) / (clicks.to_f + comments.to_f * E_C)).to_f, E_C.to_f].min else ...
Ruby
#bilibili排名算法 v3.1(2012.9.7) #取消优酷除2 class Results::R31 < Results::R30 def space_fix @space_fix ||= 1 end end
Ruby
#bilibili排名算法 v2.5(2011.4.27) #针对『热门新番』的特殊规则 - 改 #此规则仅在周点击>200时生效 class Results::R25 < Results::R24 def is_hot_bangumi? if @is_hot_bangumi.nil? if work.ac_type_id == 25 && clicks > 200 bw = BangumiWork.first :include => :bangumi, :conditions => ["work_id = ? and bangumis.status = 1", work_id] ...
Ruby
#bilibili排名算法 v2.1(2010.11.15) #没有实质性的变化,添加一些分析用数据 class Results::R21 < Results::R20 def get_es self.get_es nil, self.scan_id end def self.get_es scan_id_from=nil, scan_id_to=nil #scan_id1和scan_id2可以是scans的id,也可以是查询后的数组 if scan_id_to.class == Array results1 = scan_id_from else ...
Ruby
#bilibili排名算法 v2.3(2011.4.5) #评论分: 评论数*(50,50*(收藏数*100/(点击数+评论数*50))).min #收藏分: 收藏数*(100,24000/收藏数 + 20).min class Results::R23 < Results::R21 def self.version self.to_s.split('::R').last.to_f / 10 end def self.get_comment_revised clicks, comments, stows if comments <= 0 E_C.to_f else [f...
Ruby
#bilibili排名算法 v2.0(2010.9) #点击分 = 点击数 * (2/(P+1)) #评论分 = 评论数 * 50*(点击分/(点击分+评论数*50)) #收藏分 = 收藏数 * 100 #总分 = 点击分 + 评论分 + 收藏分 class Results::R20 < Results::Base #评论倍值 E_C = 50 #收藏倍值 E_S = 100 @space_fix = nil def get_ranking_point clicks_point = clicks * click_revised comment_point = commen...
Ruby
#bilibili排名算法 v3.0(2012.2.20) #推荐评分计入 #按类别双算法 class Results::R30 < Results::Base #评论基础倍值 E_C = 50 #收藏基础倍值 E_S = 100 #评分基础倍值 E_T = 0.2 @space_fix = nil def self.version;self.to_s.split('::R').last.to_f / 10;end def get_ranking_point (work.is_in_rank? ? point_normal : point_bangumi).to_...
Ruby
class Results::Base < ActiveRecord::Base set_table_name :results belongs_to :work belongs_to :scan #排行总分 def get_ranking_point end def self.point_str point point_s = point.to_s fushu = point_s.first == '-' ? true : false size = point_s.size - ( fushu ? 1 : 0 ) if size <= 3 point_s ...
Ruby
#bilibili排名算法 v2.4(2011.4.20) #针对『热门新番』的特殊规则 #此规则仅在周点击>20000时生效 #评论分 = 评论数×(50,50×(50000/(点击数+评论数×50))).min #收藏分 = 收藏数×10, class Results::R24 < Results::R23 @is_hot_bangumi =nil def is_hot_bangumi? if @is_hot_bangumi.nil? if work.ac_type_id == 25 && clicks > 20000 bw = BangumiWork.first :include ...
Ruby
#bilibili排名算法 v2.2(2011.1.5) #收藏分不超过5W分 class Results::R22 < Results::R21 def get_ranking_point clicks_point = clicks * click_revised comment_point = comments * comment_revised format("%.2f", (clicks_point + comment_point + (stows > 500 ? 50000 : stows * E_S)) * space_fix).to_f end end
Ruby
class Results::R26 < Results::R25 def self.get_comment_revised clicks, comments, stows, ops={} if ops[:hot_bangumi] if comments <= 0 E_C.to_f else [format("%.2f", E_C.to_f * ([clicks * 1.5, clicks + 20000].min) / (clicks.to_f + comments.to_f * E_C)).to_f, E_C.to_f].min end el...
Ruby
#bilibili排名算法 v90.0(2010.11.15) #版本号9x.x是特殊榜单的专用版本号 #此版本专为『周刊哔哩哔哩排行榜SP』所用 class Results::R900 < Results::R20 def get_ranking_point clicks_point = clicks * click_revised comment_point = comments * comment_revised ((clicks_point + comment_point + stows * 50) * space_fix ).to_i end def space_fix sup...
Ruby
class Syn def self.cron_syn print "Syn to sqlite to postgres\n" print "vacuum...\n" Weekly.connection.execute "vacuum;" print "weekly\n" Pg::Connect.transaction do Weekly.all(:conditions => ["id > ? and wid is not null", Pg::Weekly.maximum('id') || 0]).each do |weekly| Pg::Connect.conne...
Ruby
class BangumiWork < ActiveRecord::Base belongs_to :work belongs_to :bangumi validates_presence_of :work_id, :message => 'work_id is null' validates_presence_of :index, :message => 'index is null' validates_uniqueness_of :work_id, :message => 'same' end
Ruby
class BiliRankingMaker < VegasVideoMaker attr_accessor :vt, :pa, :ut, :ops #:ut => usual_time attr_accessor :width, :height alias :vvmtime :vt alias :vvmtime= :vt= TIME_30 = VegasVideoTime.ns(1) TIME_25 = VegasVideoTime.nl(25) TIME_20 = VegasVideoTime.nl(20) TIME_15 = VegasVideoTime.nl...
Ruby
class WeeklyResultTmp < WeeklyConnect set_table_name :weekly_result_tmp end
Ruby
class WeeklyZero < WeeklyConnect end
Ruby
class Pg::WeeklyResultWork < Pg::Connect end
Ruby
class Pg::WeeklyAttr < Pg::Connect end
Ruby
class Pg::WeeklyExcept < Pg::Connect end
Ruby
class Pg::WeeklyResult < Pg::Connect belongs_to :weekly, :class_name => "Pg::Weekly" belongs_to :sp_type, :class_name => "Pg::SpType" belongs_to :weekly_result_work, :class_name => "Pg::WeeklyResultWork" ['wid', 'name', 'wtype', 'author'].each do |n| unless self.column_names.include?(n) eval "attr_re...
Ruby
class Pg::Weekly < Pg::Connect end
Ruby
class Pg::SpType < Pg::Connect end
Ruby
class Pg::Connect < ActiveRecord::Base establish_connection :pgweekly self.abstract_class = true end
Ruby
class Pg::WeeklyZero < Pg::Connect end
Ruby
class Pg::WeeklyExternal < Pg::Connect end
Ruby
class DResult < ActiveRecord::Base belongs_to :scan belongs_to :flash_var validates_uniqueness_of :flash_var_id, :scope=>:scan_id, :message => 'same' end
Ruby
class ResultTmp < ActiveRecord::Base end
Ruby
class WeeklyExternal < WeeklyConnect end
Ruby
class WeekliesController < ApplicationController before_filter :login_required layout "need_login" def edit @weekly = Weekly.find params[:id] end def index @weeklies = Weekly.all :limit => 5, :order => '"index" desc' end def update weekly = Weekly.find params[:id] weekly.update_attrib...
Ruby
class VegasController < ApplicationController caches_page :index def index end def ops if [6, 9].include?(params[:id].to_i) params[:id] = 2 end end def xml params[:width], params[:height] = case params[:fenbianlv].to_i when 1 then [512, 384] when 2 then [704, 396] ...
Ruby
class BangumiWorksController < ApplicationController skip_before_filter :verify_authenticity_token #before_filter :correct_bili_name?, :limit_bili_users #layout "need_bili_name" def index @bangumi = Bangumi.find params[:bangumi_id] @bangumi_works = BangumiWork.find_all_by_bangumi_id params[:bangumi_id]...
Ruby
class BangumiTypesController < ApplicationController skip_before_filter :verify_authenticity_token #before_filter :correct_bili_name?, :limit_bili_users #layout "need_bili_name" def new @bangumi_type = BangumiType.new render :action => :edit end def edit @bangumi_type = BangumiType.find params...
Ruby
class SessionsController < ApplicationController # render new.html.erb def new end def create logout_keeping_session! user = User.authenticate(params[:login], params[:password]) if user # Protects against session fixation attacks, causes request forgery # protection if user resubmits a...
Ruby
class DataController < ApplicationController caches_page :search def search begin if request.post? if params[:ops][:card] == '1' @html_title = "你是个好人 - 河童子" render :action =>'card', :layout => 'simple', :status => 500 else redirect_to searchget_path(params[:ops]...
Ruby
class BangumisController < ApplicationController skip_before_filter :verify_authenticity_token #before_filter :correct_bili_name?, :limit_bili_users #layout "need_bili_name" def new @bangumi = Bangumi.new :bangumi_type_id => params[:bangumi_type_id] end def edit @bangumi = Bangumi.find params[:id]...
Ruby
class WeeklyResultsController < ApplicationController caches_page :one, :top def one result = WeeklyResult.find_by_score_rank_and_weekly_id params[:rank], params[:id] work =Work.find_by_wid result.wid, :select => "wid, cdate, pic_path" last_score_rank = result.last_score_rank is_changqi = result.is_...
Ruby
# Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base #helper :all # include all helpers, all the time protect_from_forgery # See ActionController::RequestForgeryP...
Ruby
class BiliApiController < ApplicationController before_filter :login_required layout "need_login" def index @apps = App.all end def app_add App.create params[:app] redirect_to :action => :index end def app_remove App.destroy params[:id] redirect_to :action => :index end def keys...
Ruby
class IndexController < ApplicationController caches_page :qa, :hot def index unless read_fragment({}) @latest = Pg::Weekly.last @results = Pg::WeeklyResult.find_all_by_weekly_id @latest.id, :order => "score_rank", :limit => @latest.rank_from, :include => :weekly_result_work end end def hot...
Ruby
class PgWeekliesController < ApplicationController def edit @pg_weekly = Weekly.find params[:id] end def index @weeklies = Weekly.all end def search end end
Ruby
class UsersController < ApplicationController # render new.html.erb def new @user = User.new end def create logout_keeping_session! @user = User.new(params[:user]) success = @user && @user.save if success && @user.errors.empty? # Protects against session fixation attacks, causes requ...
Ruby
# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require(File.join(File.dirname(__FILE__), 'config', 'boot')) require 'rake' require 'rake/testtask' require 'rake/rdoctask' require 'tasks/rails'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/dbconsole'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../../config/boot', __FILE__) require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../../config/boot', __FILE__) require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../../config/boot', __FILE__) require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../../config/boot', __FILE__) require 'commands/performance/profiler'
Ruby