saal 0.2.24 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,90 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- NUM_VALUES_SMALL = 500 # Datapoints in "small" charts
4
- NUM_VALUES_LARGE = 150 # Datapoints in "large" charts
5
- LARGE_CHART_THRESHOLD = 30*24*60*60 # Threshold for a large chart (in seconds)
6
-
7
- require File.dirname(__FILE__)+'/../lib/saal.rb'
8
-
9
- def usage
10
- $stderr.puts("Usage: saal_chart <chart dir>")
11
- end
12
-
13
- if ARGV.size != 1
14
- usage
15
- exit (2)
16
- end
17
-
18
- SENSOR_RANGES = {:temperature=>[-15, 45], :humidity=>[0,100], :pressure=>[950,1050]}
19
-
20
-
21
- SAAL::Charts.new.each do |chart|
22
- $stderr.puts "Generating chart #{chart.name}"
23
-
24
- pngfile = ARGV[0]+'/chart-'+chart.name.to_s+'.png'
25
- ymlfile = ARGV[0]+'/chart-'+chart.name.to_s+'.yml'
26
-
27
- @mins = chart.minimum
28
- @maxs = chart.maximum
29
- @avgs = chart.average
30
- @minmax = {}
31
- chart.sensors.each do |s|
32
- s = s.name.to_sym
33
- @minmax[s] = {:maximum => @maxs[s], :minimum => @mins[s], :average => @avgs[s]}
34
- end
35
-
36
- File.open(ymlfile, 'w').write(YAML::dump(@minmax))
37
-
38
- def normalize_data(data, min, max)
39
- data.map do |i|
40
- if i.nil?
41
- -1.0
42
- elsif i < min
43
- 0.0
44
- elsif i > max
45
- 100.0
46
- else
47
- (((i-min)/(max-min).to_f)*1000).round/10.0
48
- end
49
- end
50
- end
51
-
52
- @periodnames = chart.periodnames
53
- @numperiods = @periodnames.size
54
- num_values = ((chart.to-chart.from)>LARGE_CHART_THRESHOLD) ?
55
- NUM_VALUES_LARGE :
56
- NUM_VALUES_SMALL
57
-
58
- @averages = chart.average(num_values)
59
-
60
- @data = chart.sensors.map do |sensor|
61
- normalize_data(@averages[sensor.name.to_sym], *(SENSOR_RANGES[sensor.sensor_type]))
62
- end
63
-
64
- @dataurl = @data.map {|values| values.join(",")}.join('|')
65
-
66
- r = {}
67
- case chart.alignlabels
68
- when :center
69
- @periodnamesurl = "||"+@periodnames.join('||')+"||"
70
- when :left
71
- @periodnamesurl = "|"+@periodnames.join('|')+"||"
72
- r[:chxs] = "0,555555,11,-1,lt"
73
- end
74
- @xincr = 100.0/@numperiods.to_f*10000.truncate.to_f/10000
75
-
76
- r[:chof] = "png"
77
- r[:chs] = "700x300"
78
- r[:cht] = "lc"
79
- r[:chco] = "00ff00,ff0000,0000ff,ff9933,800080"
80
- r[:chxt] = "x,y,y,r"
81
- r[:chxl] = "0:#{@periodnamesurl}1:|-15ºC||0||15||30||45ºC|2:|0%|25|50|75|100%|3:|950||975||1000||1025||1050 hPa"
82
- r[:chg] = "#{@xincr},12.5,1,5"
83
- r[:chd] = "t:#{@dataurl}"
84
-
85
- @url = "http://chart.apis.google.com/chart?&"
86
- @postdata = r.map{|k,v| k.to_s+"="+v}.join("&")
87
-
88
-
89
- system "wget --quiet \"#{@url}\" --post-data=\"#{@postdata}\" -O #{pngfile}"
90
- end
@@ -1,31 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- SENSOR_INTERVAL = 60 # seconds between consecutive measurements of the sensors
4
- DBCONF = "/etc/saal/database.yml"
5
- SENSORSCONF = "/etc/saal/sensors.yml"
6
-
7
- require File.dirname(__FILE__)+'/../lib/saal.rb'
8
-
9
- def usage
10
- $stderr.puts "Usage: saal_daemon <pidfile|--foreground>"
11
- end
12
-
13
- if ARGV.size != 1
14
- usage
15
- exit 2
16
- else
17
- pidfile = ARGV[0]
18
- foreground = (ARGV[0] == '--foreground')
19
- d = SAAL::Daemon.new(:interval => SENSOR_INTERVAL,
20
- :sensorconf => SENSORSCONF,
21
- :dbconf => DBCONF,
22
- :foreground => foreground,
23
- :keep_stdin => true)
24
- pid = d.run
25
- if !foreground
26
- File.open(pidfile, 'w') do |f|
27
- f.write(pid)
28
- f.close
29
- end
30
- end
31
- end