Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute Difference Agent #1572

Merged
merged 1 commit into from Jul 9, 2016
Merged

Conversation

lloydpick
Copy link
Contributor

Hi,

I wanted to have the ability to enrich an event with a comparison of events, e.g. the last received value was X, what is the integer/decimal difference or percentage change when compared to the new event value Y.

Wrote this agent because I couldn't really find one that did what I wanted. I'm not sure if I could have achieved the the same outcome with some agent that already exists? I've not been using Huginn for too long, but decided to write this anyway, it let me learn how to write agents.

Code and passing tests are attached.

Cheers

@cantino
Copy link
Member

cantino commented Jul 1, 2016

Awesome @lloydpick, this looks like a useful addition to Huginn. Thanks, and welcome!


private

def handle(opts, event = nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably don't need the = nil part, since the attribute is always provided.

@lloydpick
Copy link
Contributor Author

Changes made


def handle(opts, event)
attribute = opts['attribute']
attribute_value = event.payload[attribute].nil? ? 0 : event.payload[attribute]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be an option to use either JSONPath or Liquid to access the attribute?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, i'll need to go find an example of that, but sure.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I just noticed you are already calling interpolated(event) in receive, so using liquid to modify the attribute based on the incoming event would already work, but one could not access values nested in the received event object.
You could change the attribute option key to value and directly use that interpolated result, this would allow the user to set it to {{data.value}}, interpolated({data: {value: 6}}) would then return {value: "6"}.

@lloydpick
Copy link
Contributor Author

ok, JSON path support has been added. I've also taken out the BigDecimal stuff after running into some weird edge cases, just gone back to floats and rounding which can be customised.

@dsander
Copy link
Collaborator

dsander commented Jul 4, 2016

That looks like a neat combination of both worlds to me, maybe you could note that all configuration options will be liquid interpolated based on the incoming event?

@cantino
Copy link
Member

cantino commented Jul 6, 2016

Looks great!

@lloydpick
Copy link
Contributor Author

Note added

@cantino cantino merged commit 8c0a10f into huginn:master Jul 9, 2016
@cantino
Copy link
Member

cantino commented Jul 9, 2016

Awesome, thanks @lloydpick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants