huginn/huginn

Extend PeakDetectorAgent to also detect instances when the values are lower than normal

Offen

#730 geöffnet am 09.03.2015

 (4 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Ruby (4.264 Forks)batch import
help wantedsuggestion

Repository-Metriken

Stars
 (49.270 Sterne)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

Hi,

My use-case is that I'm using Huginn to monitor airline tickets prices looking for deals. Currently I'm simply checking the prices and using a TriggerAgent to send me an e-mail with rules like "If there's a flight cheaper than £50". This leads to a problem that I'm getting many e-mails for routes that are usually cheaper than £50 (e.g. London to Dublin), but I'm missing deals like London to Tel Aviv for £55.

What I want is to be notified whenever a ticket is much cheaper than what it usually is (i.e. when there's some promotion).

I tried using the PeakDetectorAgent grouping by destination airport and getting the ticket values. The only problem is that I'm now detecting expensive tickets, and not cheap ones. What I want is a "ValleyDetectorAgent" of some sorts. Looking at the code, I would only need to change this:

# https://github.com/cantino/huginn/blob/master/app/models/agents/peak_detector_agent.rb#L67
if newest_value > average_value + std_multiple * standard_deviation
    memory['peaks'][group] << newest_time
    memory['peaks'][group].reject! { |p| p <= newest_time - window_duration }
    create_event :payload => { 'message' => interpolated(event)['message'], 'peak' => newest_value, 'peak_time' => newest_time, 'grouped_by' => group.to_s }
end

Maybe it would be good to refactor the PeakDetectorAgent into an AnomalyDetectorAgent that tests both if the newest_value is too high or if it's too low? There could be an option that defines if it'll trigger on values too high, too low, or both, which would allow us to keep the PeakDetectorAgent simply as a subclass of AnomalyDetectorAgent for backwards compatibility.

I'd be happy to work on it and submit a pull request, if you think it would be useful.

Thoughts?

Contributor Guide