Dcompdver='$Id: dcomp.rb,v 1.8 2004-03-03 22:18:11+09 waka Exp waka $'.split(" ")[2] # http://www.double-red.net/ =begin ndiary.conf に以下を定義すると勲章の変更ができる。 #( ) 内は defalut値 #高いコンプリート率(60)設定、表示() DCOMP_GSTAR_R='100' DCOMP_GSTAR='' #まあまあ高いコンプリート率設定(50)、表示() DCOMP_SSTAR_R='70' DCOMP_SSTAR='' #がんばったコンプリート率設定(40)、表示() DCOMP_BSTAR_R='50' DCOMP_BSTAR='' =end def my_parsedate(d) #yyyy-mm-dd y,m,d = d.split("-") return [y.to_i,m.to_i,d.to_i] end def diary_span(start,last) start_y , start_m , start_d = my_parsedate(start) last_y , last_m , last_d = my_parsedate(last) start_date = Date.new(start_y , start_m , start_d) last_date = Date.new(last_y , last_m , last_d) arry = [start_date.to_s , last_date.to_s , (last_date - start_date).to_i] return arry end def month_days(y , m) day = (28..31).to_a.delete_if { |d| begin !Date::valid_date?(y , m , d) rescue NameError !Date::exist?(y , m , d) end } return day.last end def month_complete(year , month , diary_num) complete = sprintf("%3.2f" , (diary_num.to_f / month_days(year , month.to_f) * 100)) return complete end def plug(opt) require 'date' begin require 'find' rescue LoadError puts "#{$!}" puts "warning or error.(this is dcomp plug-in\'s message.)" end dir = @logDirectory gStar = '' sStar = '' bStar = '' gStar_r = 60 sStar_r = 50 bStar_r = 40 gStar = @diary.config['DCOMP_GSTAR'].to_s unless @diary.config['DCOMP_GSTAR'].to_s.empty? sStar = @diary.config['DCOMP_SSTAR'].to_s unless @diary.config['DCOMP_SSTAR'].to_s.empty? bStar = @diary.config['DCOMP_BSTAR'].to_s unless @diary.config['DCOMP_BSTAR'].to_s.empty? gStar_r = @diary.config['DCOMP_GSTAR_R'].to_s unless @diary.config['DCOMP_GSTAR_R'].to_s.empty? sStar_r = @diary.config['DCOMP_SSTAR_R'].to_s unless @diary.config['DCOMP_SSTAR_R'].to_s.empty? bStar_r = @diary.config['DCOMP_BSTAR_R'].to_s unless @diary.config['DCOMP_BSTAR_R'].to_s.empty? diary_files = Array.new year_array = Array.new begin Find.find(dir) {|file| f = File.basename(file) if /^\d{8}\.diary$/i =~ f then diary_files << f end } rescue puts "#{$!}" puts "warning or error.(this is dcomp plug-in\'s message.)" end start_yyyymmdd = diary_files.min.gsub(/^(\d{4})(\d\d)(\d\d).+$/,"\\1-\\2-\\3") last_yyyymmdd = diary_files.max.gsub(/^(\d{4})(\d\d)(\d\d).+$/,"\\1-\\2-\\3") diary_num = diary_files.size start_y, =my_parsedate(start_yyyymmdd) last_y, =my_parsedate(last_yyyymmdd) each_month = Array.new (start_y..last_y).each{|y| (01..12).each{|m| cnt = 0 begin # Dir.new(dir + File::Separator + y.to_s + File::Separator + sprintf("%02d",m)).entries.each{|diary| diary_files.each{|diary| if /#{y}#{sprintf("%02d",m)}\d\d\.diary$/i =~ diary then cnt += 1 end } rescue puts "#{$!}" puts "warning or error.(this is dcomp plug-in\'s message.)" # end unless cnt == 0 then each_month << [y,m,cnt] end } } pre = nil star = "" aa = Array.new aa << "年" (1..12).each{|i| aa << "#{i}月" } str = '' each_month_complete = Array.new total_diary_cnt = 0 each_month.each{|i| y = i[0] m = i[1] c = i[2] m_c = month_complete(y,m,c) if y != pre #&& i != each_month.last then str << "\n \n \n \n " aa.fill("-") aa[0] = y pre = y end if m_c.to_i >= gStar_r then star = gStar elsif m_c.to_i >= sStar_r then star = sStar elsif m_c.to_i >= bStar_r then star = bStar else star = "" end aa[m] = "#{star}#{m_c}" if i == each_month.last then str << "\n \n \n \n " end each_month_complete << [y,m,c,m_c,month_days(y,m)] total_diary_cnt += c } str << "\n
" << aa.join("").to_s << "
" << aa.join("").to_s << "
\n" startD,lastD,span = diary_span(start_yyyymmdd,last_yyyymmdd) #comp_ratio = sprintf("%3.3f",(diary_num.to_f / span.to_f) * 100) #str << sprintf("Total (%s - %s) %s %% (%d/%d)", startD , lastD , comp_ratio , diary_num,span) comp_ratio = sprintf("%3.3f",(total_diary_cnt.to_f / span.to_f) * 100) str << sprintf("Total (%s - %s) %s %% (%d/%d)",startD,lastD,comp_ratio,total_diary_cnt,span) str << "" return str end