Skip to content

ChangeOverTimeAgent. #374

Open
wants to merge 3 commits into from

5 participants

@peter-x
peter-x commented Jun 8, 2014

New agent that computes the change of values over time. Can be combined with the TriggerAgent or the PeakDetectorAgent to fire events depending on the change of a value over time. It is especially useful if the input events do not arrive at fixed intervals.

@coveralls

Coverage Status

Coverage decreased (-0.65%) when pulling 3d4528b on peter-x:changeovertimeagent into 1512d80 on cantino:master.

@cantino cantino and 1 other commented on an outdated diff Jun 8, 2014
app/models/agents/change_over_time_agent.rb
+ {
+ 'expected_receive_period_in_days' => "2",
+ 'group_by_path' => "series",
+ 'value_path' => "value",
+ 'time_path' => "time"
+ }
+ end
+
+ def working?
+ last_receive_at && last_receive_at > options['expected_receive_period_in_days'].to_i.days.ago && !recent_error_logs?
+ end
+
+ def receive(incoming_events)
+ incoming_events.sort_by(&:created_at).each do |event|
+ data = parse event
+ log "computing1"
@cantino
Owner
cantino added a note Jun 8, 2014

You might want to either log the results, or drop this line.

@peter-x
peter-x added a note Jun 8, 2014

Thanks, forgot to remove that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@cantino
Owner
cantino commented Jun 8, 2014

Hey @peter-x, this looks super useful. Great idea!

Could you add some basic RSpecs to the new Agent?

@peter-x peter-x commented on an outdated diff Jun 8, 2014
app/models/agents/change_over_time_agent.rb
+ 'time' => time_for(event)
+ }
+ end
+
+ def factor
+ ((options['factor'].present? && options['factor'].to_f) || 1)
+ end
+
+ def compute_difference_quotient data
+ if memory['data'] && memory['data'][data['group']]
+ old_data = memory['data'][data['group']]
+ timediff = data['time'] - old_data['time']
+ if timediff != 0
+ quotient = (data['value'] - old_data['value']) / timediff
+ time = options['store_time_at_end'].to_s == 'true' ? data['time'] : ((old_data['time'] + data['time']) / 2)
+ create_event :payload => {"value" => quotient * factor, "time" => time.rfc2822.to_s}
@peter-x
peter-x added a note Jun 8, 2014

This should also contain the group name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@coveralls

Coverage Status

Coverage decreased (-0.06%) when pulling 442de4f on peter-x:changeovertimeagent into 1512d80 on cantino:master.

@alias1 alias1 added the agent label Jun 13, 2014
@cantino
Owner
cantino commented Jun 29, 2014

This looks great! Is it done?

@peter-x
peter-x commented Jun 29, 2014

Hm, I'm not quite sure yet. I think that last time I tried it, it did not work reliably.

@virtadpt

I definitely have a use for such an agent. I asked in IRC but didn't hear back from anybody about it.

@cantino
Owner
cantino commented Jul 29, 2014

@peter-x, what wasn't working when you ran it before.

@peter-x
peter-x commented Jul 30, 2014

It did not generate any events, but that could also have been my setup. It would be great if you could quickly verify it on a test installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.