Created
August 14, 2013 00:30
-
-
Save izumogeiger/6227018 to your computer and use it in GitHub Desktop.
ログから線量の1時間平均と最大を出してツイートする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding:utf-8 | |
require "pp" | |
require "twitter" | |
def tweet(line) | |
Twitter.configure do |config| | |
config.consumer_key='xxxx' | |
config.consumer_secret='xxxx' | |
config.oauth_token='xxxx' | |
config.oauth_token_secret='xxxx' | |
end | |
Twitter.update(line) | |
end | |
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 | |
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 | |
end | |
cpms = lines[-3600..-1].map do |l| l.split("\t")[1].to_i end | |
total = cpms.inject(0) do |sum,i| sum + i end | |
mean = total / 3600.0 | |
mean_usv = mean / 150.0 | |
max = cpms.inject(0) do |m,i| m < i ? i : m end | |
max_usv = max / 150.0 | |
line = sprintf("GC-10(SBM-20)@島根県出雲市 1時間平均[%.2f cpm,%.3f uSv] 1時間最大[%.2f cpm,%.3f uSv] #jp_geiger",mean,mean_usv,max,max_usv) | |
tweet(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment