saal 0.2.24 → 0.2.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/saal_chart +49 -4
  2. data/lib/saal.rb +1 -1
  3. data/saal.gemspec +2 -2
  4. metadata +8 -8
data/bin/saal_chart CHANGED
@@ -16,7 +16,11 @@ if ARGV.size != 1
16
16
  exit (2)
17
17
  end
18
18
 
19
- SENSOR_RANGES = {:temperature=>[-15, 45], :humidity=>[0,100], :pressure=>[950,1050]}
19
+ MAX_RANGES = {:temperature=>[-10,70],
20
+ :humidity=>[0,110],
21
+ :pressure=>[900,1200]}
22
+
23
+ TYPES = {:temperature => "ºC", :humidity => "%", :pressure => "hPa"}
20
24
 
21
25
 
22
26
  SAAL::Charts.new.each do |chart|
@@ -57,9 +61,35 @@ SAAL::Charts.new.each do |chart|
57
61
  NUM_VALUES_SMALL
58
62
 
59
63
  @averages = chart.average(num_values)
64
+ @ranges = {}
65
+
66
+ # First find the smallest interval that fits all sensors for each type
67
+ @data = chart.sensors.map do |sensor|
68
+ avgs = @averages[sensor.name.to_sym]
69
+
70
+ min = avgs.select{|o| o != nil}.min
71
+ max = avgs.select{|o| o != nil}.max
72
+ if min and max
73
+ range = [(min/5).floor*5, (max/5).ceil*5]
74
+ @ranges[sensor.sensor_type] ||= range
75
+ previous = @ranges[sensor.sensor_type]
76
+ @ranges[sensor.sensor_type] = [[range[0],previous[0]].min,
77
+ [range[1],previous[1]].max]
78
+ end
79
+ end
60
80
 
81
+ # Then clip those intervals to MAX_RANGES
61
82
  @data = chart.sensors.map do |sensor|
62
- normalize_data(@averages[sensor.name.to_sym], *(SENSOR_RANGES[sensor.sensor_type]))
83
+ maxrange = MAX_RANGES[sensor.sensor_type]
84
+ @ranges[sensor.sensor_type] ||= maxrange
85
+ previous = @ranges[sensor.sensor_type]
86
+ @ranges[sensor.sensor_type] = [[maxrange[0],previous[0]].max,
87
+ [maxrange[1],previous[1]].min]
88
+ end
89
+
90
+ # Finally use those intervals to normalize the data
91
+ @data = chart.sensors.map do |sensor|
92
+ normalize_data(@averages[sensor.name.to_sym], *@ranges[sensor.sensor_type])
63
93
  end
64
94
 
65
95
  @dataurl = @data.map {|values| values.join(",")}.join('|')
@@ -74,12 +104,27 @@ SAAL::Charts.new.each do |chart|
74
104
  end
75
105
  @xincr = 100.0/@numperiods.to_f*10000.truncate.to_f/10000
76
106
 
107
+ @axes = []
108
+ @ranges.each do |type, range|
109
+ min,max = range
110
+ step = (max-min).to_f/4.0
111
+ steps = (0..4).map{|i| (min+i*step).to_i.to_s}
112
+ steps[0] = "#{min} #{TYPES[type]}"
113
+ steps[4] = "#{max} #{TYPES[type]}"
114
+ @axes << steps.join("||")
115
+ end
116
+ # Duplicate the axis if there's only one
117
+ @axes *= 2 if @axes.size == 1
118
+ # Alternate between left and right axes
119
+ @axisset = (['y','r']*@axes.size)[0..@axes.size-1].join(",")
120
+ @axes = @axes.each_with_index.map {|a,i| "#{i+1}:|#{a}"}.join("|")
121
+
77
122
  r[:chof] = "png"
78
123
  r[:chs] = "700x300"
79
124
  r[:cht] = "lc"
80
125
  r[:chco] = "00ff00,ff0000,0000ff,ff9933,800080"
81
- r[:chxt] = "x,y,y,r"
82
- 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"
126
+ r[:chxt] = "x,#{@axisset}"
127
+ r[:chxl] = "0:#{@periodnamesurl}#{@axes}"
83
128
  r[:chg] = "#{@xincr},12.5,1,5"
84
129
  r[:chd] = "t:#{@dataurl}"
85
130
 
data/lib/saal.rb CHANGED
@@ -10,7 +10,7 @@ module SAAL
10
10
  DBCONF = CONFDIR+"database.yml"
11
11
  CHARTSCONF = CONFDIR+"charts.yml"
12
12
 
13
- VERSION = '0.2.24'
13
+ VERSION = '0.2.25'
14
14
  end
15
15
 
16
16
  require File.dirname(__FILE__)+'/dbstore.rb'
data/saal.gemspec CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
6
6
  s.platform = Gem::Platform::RUBY
7
7
 
8
8
  s.name = 'saal'
9
- s.version = '0.2.24'
10
- s.date = '2013-11-23'
9
+ s.version = '0.2.25'
10
+ s.date = '2014-01-03'
11
11
 
12
12
  s.summary = "Thin abstraction layer for interfacing and recording sensors (currently onewire) and actuators (currently dinrelay)"
13
13
  s.description = <<EOF
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.24
4
+ version: 0.2.25
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-23 00:00:00.000000000 Z
12
+ date: 2014-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ownet
16
- requirement: &74238440 !ruby/object:Gem::Requirement
16
+ requirement: &85784820 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.2.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *74238440
24
+ version_requirements: *85784820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &74238180 !ruby/object:Gem::Requirement
27
+ requirement: &85784520 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *74238180
35
+ version_requirements: *85784520
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mysql
38
- requirement: &74237790 !ruby/object:Gem::Requirement
38
+ requirement: &85782840 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *74237790
46
+ version_requirements: *85782840
47
47
  description: ! "A daemon and libraries to create an abstraction layer that interfaces
48
48
  with \nsensors and actuators, recording their state, responding to requests \nfor
49
49
  current and historical values, and allowing changes of state.\n"