#!ruby -Ks # -*- coding: Shift_JIS -*- # # 00:00:00.00 集計ツール 元日特別仕様 # forked from 00:00:00.00 集計ツール Ver.1.2 # # *Ver.1.0 2010/12/31 # class Zero def initialize(time) @to_i = time[0,2].to_i*360000 + time[3,2].to_i*6000 + time[6,2].to_i*100 + time[9,2].to_i @to_s = time end # 00:00:00.00までの近さ(整数) def distance_i time = @to_i if time>4320000 (time-8640000) else time end end # 00:00:00.00までの近さ(実数) def distance distance_i.to_f / 100 end # ±何秒差か def distance_s if zero? $res_mode ? "      " : " ネ申" else "%+.2f" % distance + ($res_mode ? "sec " : "") end end # 時間が前後n秒の範囲内か def in_range?(n) n*=100 @to_i>=8640000-n || @to_i<=n end def zero? distance_i.zero? end attr_reader :to_i, :to_s end def th(n) teen = n%100/10 == 1 case n%10 when 1 then teen ? "th" : "st" when 2 then teen ? "th" : "nd" when 3 then "rd" else "th" end end DEF_SERVER = "raicho.2ch.net" DEF_BOARD = "news4vip" LOG_PATH = "C:/Program Files/Live2ch/log/" range = 1 rank_max = 25 begin ### debug ### if $*.include?("-debug:dat") $*.delete("-debug:dat") raise ArgumentError, "引数が指定されていません" if $*.empty? dat = $*[0] server = $*[1] || DEF_SERVER board = $*[2] || DEF_BOARD puts "########## dat ##########" print IO.read("#{LOG_PATH}#{server}/#{board}/#{dat}.dat") #puts "#########################" exit end $res_mode = true if $*.include?("-from") && $*[$*.index("-from")+1].to_i > 0 from = $*[$*.index("-from")+1].to_i $*.delete_at($*.index("-from")+1) $*.delete("-from") else from = 0 end if $*.include?("-range") range = $*[$*.index("-range")+1].to_i $*.delete_at($*.index("-range")+1) $*.delete("-range") end if $*.include?("-max") rank_max = $*[$*.index("-max")+1].to_i $*.delete_at($*.index("-max")+1) $*.delete("-max") end raise ArgumentError, "引数が指定されていません" if $*.empty? dat_arr = $*[0].split(",") server = $*[1] || DEF_SERVER board = $*[2] || DEF_BOARD list = [] dat_arr.each_with_index do |dat, i| print "[#{i+1}] " if dat_arr.size>1 puts "http://#{server}/test/read.cgi/#{board}/#{dat}/" path = "#{LOG_PATH}#{server}/#{board}/#{dat}.dat" IO.readlines(path).each_with_index do |line, res| next if from > res+1 if line =~ /^.+?<>.*?<>.+? (\d\d:\d\d:\d\d.\d\d) (ID:[0-9a-zA-Z\/+.]{8,}).*?<>.*?<>/ time = Zero.new($1) if time.in_range?(range) list.push([res+1, time, $2, i]) #puts "#{res+1} => #{$1} #{$2} #{sprintf("%+10.2f", time.distance)}" end end end end if list.empty? puts "±#{range}秒以内のレスがありませんでした" else puts "------------------------------" # 近い順に並び替え list.sort! do |a,b| a[1].distance_i.abs <=> b[1].distance_i.abs end before = rank = nil # レス形式で出力するか if $res_mode puts <<-EOS   #{Time.now.strftime("%Y年%m月%d日")} 00:00:00.00 ランキング (#{dat_arr.size>1 ? "#{dat_arr.size}スレ合算" : "このスレのみ"})#{" (>>#{from}〜)" unless from.zero?}          ±#{range}秒以内に入った人: #{list.size} 人 EOS end list.each_with_index do |arr,i| # 順位がタイではない場合 if before == arr[1].distance_i.abs && !arr[1].zero? rank = "     " if $res_mode else break if rank_max<=i if $res_mode if arr[1].zero? rank = "ネ申." else rank = (i<9 ? ". " : "") + (i+1).to_s + "位 " end else rank = "%2d" % (i+1) + th(i+1) end before = arr[1].distance_i.abs end device = case arr[2][-1, 1] when "0" then "PC" when "O","o","Q" then "携帯" when "P" then "p2" when "I","i" then "iPhone" else "?" end puts " #{rank}#{arr[1].distance_s}#{arr[1].to_s} #{"[#{arr[3]+1}]" if dat_arr.size>1}>>#{arr[0]} " + "#{arr[2]} (#{device})#{" おめでとう!" if arr[1].zero?}" end end rescue Errno::ENOENT $stderr.puts "Error: ファイルが存在しません" rescue ArgumentError => e $stderr.puts "Error: #{e.message}" $stderr.puts "USAGE: ruby 00.00.00.00.rb [,...] [-from ] [ []]" end