Class: Cmd::All
Instance Method Summary
collapse
#all_sensors, #all_sensors_table, #fail!, #with_redis, #with_safe_restore_of
#assert_array!, #assert_positive_integer!, #assert_ranged_float!, #camelize, #camelize_keys, #constantize, #each_subset, #subsets_of, #symbolize_keys, #titleize, #uniqid
Instance Method Details
#create(name, type) ⇒ Object
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/cmd.rb', line 93
def create(name, type)
with_redis do
klass = constantize("PulseMeter::Sensor::Timelined::#{type}")
puts "PulseMeter::Sensor::Timelined::#{type}"
fail! "Unknown sensor type #{type}" unless klass
sensor = klass.new(name, options.dup)
puts "Sensor created"
puts all_sensors_table
end
end
|
#create_simple(name, type) ⇒ Object
124
125
126
127
128
129
130
131
132
|
# File 'lib/cmd.rb', line 124
def create_simple(name, type)
with_redis do
klass = constantize("PulseMeter::Sensor::#{type}")
fail! "Unknown sensor type #{type}" unless klass
sensor = klass.new(name, options.dup)
puts "Sensor created"
puts all_sensors_table
end
end
|
#delete(name) ⇒ Object
85
86
87
88
|
# File 'lib/cmd.rb', line 85
def delete(name)
with_safe_restore_of(name) {|sensor| sensor.cleanup}
puts "Sensor #{name} deleted"
end
|
#drop(name, from, to) ⇒ Object
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/cmd.rb', line 144
def drop(name, from, to)
time_from, time_to = [from, to].map do |str|
str.match(/\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})\z/) do |m|
Time.gm(*m.captures.map(&:to_i))
end
end
fail! "DATE_FROM is not a valid timestamp" unless time_from.is_a?(Time)
fail! "DATE_TO is not a valid timestamp" unless time_to.is_a?(Time)
with_safe_restore_of(name) do |sensor|
fail! "Sensor #{name} has no drop_within method" unless sensor.respond_to?(:drop_within)
sensor.drop_within(time_from, time_to)
end
end
|
#event(name, value) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/cmd.rb', line 52
def event(name, value)
if "json" == options[:format]
value = JSON.parse(value)
end
with_safe_restore_of(name) {|sensor| sensor.event(value)}
end
|
#reduce ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/cmd.rb', line 40
def reduce
with_redis do
puts 'Registered sensors to be reduced'
puts all_sensors_table
PulseMeter::Sensor::Timeline.reduce_all_raw
puts "DONE"
end
end
|
#sensors ⇒ Object
34
35
36
|
# File 'lib/cmd.rb', line 34
def sensors
with_redis {puts all_sensors_table(options[:format])}
end
|
#timeline(name, seconds) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/cmd.rb', line 62
def timeline(name, seconds)
with_safe_restore_of(name) do |sensor|
puts sensor.
timeline(seconds).
map {|data| [data.start_time, data.value || '']}.
to_table(options[:format])
end
end
|
#timeline_within(name, from, till) ⇒ Object
74
75
76
77
78
79
80
81
|
# File 'lib/cmd.rb', line 74
def timeline_within(name, from, till)
with_safe_restore_of(name) do |sensor|
puts sensor.
timeline_within(Time.parse(from), Time.parse(till)).
map {|data| [data.start_time, data.value || '']}.
to_table(options[:format])
end
end
|
#update(name) ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/cmd.rb', line 107
def update(name)
with_safe_restore_of(name) do |sensor|
opts = options.dup
[:ttl, :interval, :reduce_delay, :raw_data_ttl, :annotation].each do |attr|
opts[attr] ||= sensor.send(attr)
end
klass = sensor.class
new_sensor = klass.new(name, opts)
new_sensor.dump!(false)
puts "Sensor updated"
puts all_sensors_table
end
end
|
#value(name) ⇒ Object
135
136
137
138
139
140
|
# File 'lib/cmd.rb', line 135
def value(name)
with_safe_restore_of(name) do |sensor|
fail! "Sensor #{name} has no value method" unless sensor.respond_to?(:value)
puts "Value: #{sensor.value}"
end
end
|