Newer
Older
Ruby / akuma.rb
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

require 'cgi'
c = CGI.new(:accept_charset => "UTF-8")
print "Content-type: text/html; charset=UTF-8\n\n"

#<input type="text"  name="answer" maxlength="40" <br>



nendo=c["nendo"]
gakkou=c["gakkou"]
gakunen=c["gakunen"]
kurasu=c["kurasu"]
han=c["han"]
i=c["i"].to_i

name=c["name"]
var1=c["tenshi"]
var2=c["go"]
time=c["time"]


open("tenshi.csv","a:utf-8") do |tenshi|
  tenshi.printf("%d,%s,%s,%s,%d,%s,%d,%d,%d,%d\n",time,name,var1,var2,nendo,gakkou,gakunen,kurasu,han,i+1)
end

i = 0

print"<html>\n"
print"<head><title>結果</title></head>\n"
print"<body>\n"


print"<h1>#{name}さんの結果</h1>\n"


kekka=Hash.new

require'csv'
date=CSV.read("tenshi.csv", :headers=>false,  encoding: 'utf-8')
date.each do |row|
  if row[4]==nendo&&row[5]==gakkou&&row[6]==gakunen&&row[7]==kurasu&&row[8]==han
    if kekka.key?(row[1]) == false   #その人のデータがまだ代入されていなければ
      kekka[row[1]]=Array.new  #valueを配列にする
    end
    
    kekka[row[1]]<<[row[0],row[9],row[2],row[3]]  #<<で配列の末尾に右辺を追加
    i+=1
  end 
end



for gggg,akumado in kekka
  if time==row[0]&&row[9]=="1"
    printf("<p>%sさんの結果  1回目  悪魔・天使度:%d GO&STOP:%s</p>\n",gggg,akumado[0][0],akumado[0][1])
  end
  if time==row[0]&&row[9]=="2"
    printf("<p>%sさんの結果  2回目  悪魔・天使度:%d GO&STOP:%s</p>\n",gggg,akumado[1][0],akumado[1][1])
  end
  if time==row[0]&&row[9]=="3"
    printf("<p>%sさんの結果  3回目悪魔・天使度:%d GO&STOP:%s</p>\n",gggg,akumado[2][0],akumado[2][1])
  end
end


print"</body>\n"
print"</html>\n"