単位数 その2
id:mzp:20060407で
# selvaggio 『mzp、プリントよく読むと分かるけど、単位数を数えるんであって授業数じゃないと思うよ、俺それで計算したら60%弱優だった。』
と言われたので計算しなおしてみる。
ついでに、tanni.rbは恥ずかしいので、英単語に変更してっと。
$ ruby credit.rb data.html 優 --- 47.0 良 --- 36.5 可 --- 7.5 不可 --- 0 欠席 --- 2.0 優/全体 = 47.0/93.0 = 0.505376344086022
ぎりぎりって感じだ。
require 'kconv'
Credit = Struct.new('Credit',:credit,:score)
ARGV.length != 0 or abort("usage:#$0: tanni.html")
#hash = Hash.new(0)
credits = []
open(ARGV[0]){|io|
credit = Credit.new
io.each{|line|
if line =~ %r!<TD?s+BGCOLOR="white"?s+ALIGN="RIGHT">?s+(?d?.?d+)</TD>!
credit.credit = $1.to_f
elsif line =~ %r!<TD?s+BGCOLOR="white"?s+ALIGN="CENTER">(.+)</TD>!
$1.include?(' ') and next
credit.score = $1.toutf8
credits.push credit
credit = Credit.new
end
}
}
hash = Hash.new(0)
credits.each{|credit|
hash[credit.score] += credit.credit
}
total = 0
good = 0
%w(優 良 可 不可 欠席).each{|key|
value = hash[key]
puts "#key: --- #value:"
total += value
if key == '優'
good += value
end
}
puts "?n優/全体 = #good:/#total: = #good.to_f / total:"