Skip to content

Instantly share code, notes, and snippets.

@izumogeiger
Created August 7, 2013 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izumogeiger/6170090 to your computer and use it in GitHub Desktop.
Save izumogeiger/6170090 to your computer and use it in GitHub Desktop.
# coding:utf-8
require "pp"
require "fileutils"
require 'pony'
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|
win = []
(60*3).times do |i|
m = cpms[i*60...(i+1)*60]
total = m.inject(0) do |sum,i| sum + i.to_i end
cpm = total/60.0
win << cpm
win.shift if win.size > 5
wp = win.inject(0) do |sum,i| sum + i.to_i end
wp /= win.size if wp != 0
io.printf("%d\t%.2f\t%.2f\n",i-180,cpm,wp)
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)
title = "GC-10(SBM-20) Radiation #{Time.now}"
cmd = <<-EOS
set title "#{title}"
set xl "minutes"
set yl "cpm"
set yrange [0:50]
set style line 1
set grid
set terminal png
set out "#{png}"
plot "#{datafile}" u 1:2 title "cpm", "" u 1:3 w l lw 2 lc rgb "green" title "smoothed cpm (5minutes)"
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)
Pony.mail({
:to => 'mogemoge@blogger.com',
:via => :smtp,
:via_options => {
:address => 'smtp.gmail.com',
:port => '587',
:enable_starttls_auto => true,
:user_name => 'user',
:password => 'password',
:authentication => :plain, # :plain, :login, :cram_md5, no auth by default
:domain => "localhost.localdomain"
},
:subject => title,
:body => title,
:attachments => { File.basename(png) => File.read(png)}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment