Skip to content

Instantly share code, notes, and snippets.

@izumogeiger
Created August 2, 2013 08:43
Show Gist options
  • Save izumogeiger/6138396 to your computer and use it in GitHub Desktop.
Save izumogeiger/6138396 to your computer and use it in GitHub Desktop.
# coding:utf-8
require "pp"
require "fileutils"
now = Time.now
dir = File.join(ENV["HOME"],"gc10",now.strftime("%Y"),now.strftime("%m"))
file = File.join(dir,now.strftime("%d")+".txt")
lines = File.read(file).split("\n")
if lines.size < 3600*3
now -= 3600*24
dir = File.join(ENV["HOME"],"gc10",now.strftime("%Y"),now.strftime("%m"))
file = File.join(dir,now.strftime("%d")+".txt")
nlines = File.read(file).split("\n")
lines = nlines + lines
return if lines.size < 3600*3
end
cpms = lines[-3600*3..-1].map do |l| l.split("\t")[1] end
datafile = "/tmp/data.txt"
File.open(datafile,"w") do |io|
(60*3).times do |i|
win = cpms[i*60...(i+1)*60]
total = win.inject(0) do |sum,i| sum + i.to_i end
cpm = total/60.0
io.printf("%d\t%.2f\n",i-180,cpm)
end
end
pngdir = File.join(ENV["HOME"],"gc10","graph",
now.strftime("%Y"),
now.strftime("%m"),
now.strftime("%d"))
png = File.join(pngdir,now.strftime("%H")+".png")
FileUtils.mkdir_p(pngdir)
cmd = <<-EOS
set title "GC-10(SBM-20) Radiation"
set xl "minutes"
set yl "cpm"
set terminal png
set out "#{png}"
plot "#{datafile}"
EOS
cmdfile = "/tmp/cmd.txt"
File.open(cmdfile,"w") do |io| io.puts cmd end
`gnuplot #{cmdfile}`
FileUtils.rm_f(datafile)
FileUtils.rm_f(cmdfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment