Skip to content

Instantly share code, notes, and snippets.

@yswallow
Created March 22, 2019 00:32
Show Gist options
  • Select an option

  • Save yswallow/26f0e63ee3093f9130d39fcedc0b7c25 to your computer and use it in GitHub Desktop.

Select an option

Save yswallow/26f0e63ee3093f9130d39fcedc0b7c25 to your computer and use it in GitHub Desktop.
開設学類別のGPAを計算する
str = File.read("SIRS201519198.csv")
def hyoka2gp(c)
case c
when 'A+'
4.3
when 'A'
4
when 'B'
3
when 'C'
2
when ?D
0
else
-1
end
end
a = str.each_line.to_a
a.shift
kamoku = Struct.new("Kamoku", :bango, :tanisu, :hyoka)
gp = Struct.new("GP", :sum_gp, :sum_tanisu)
kamokus = []
a.each do |l|
la = l.chomp.split('","')
kamokus << kamoku.new(la[2],la[4].to_f,hyoka2gp(la[7]))
end
shizen = gp.new(0,0)
joho = gp.new(0,0)
sonota = gp.new(0,0)
kamokus.each do |k|
if k.hyoka >= 0
case k.bango
when /^[FE]/ #旧自然学群科目
shizen.sum_tanisu += k.tanisu
shizen.sum_gp += k.tanisu*k.hyoka
when /^G/ #情報学群科目
joho.sum_tanisu += k.tanisu
joho.sum_gp += k.tanisu*k.hyoka
else
sonota.sum_tanisu += k.tanisu
sonota.sum_gp += k.tanisu*k.hyoka
end
end
end
puts "旧自然学群GPA: #{shizen.sum_gp/shizen.sum_tanisu}"
puts "情報学群GPA: #{joho.sum_gp/joho.sum_tanisu}"
puts "その他GPA: #{sonota.sum_gp/sonota.sum_tanisu}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment