Add configurable search_url #1552

This commit is contained in:
Aleksey Ivanov 2017-05-22 22:34:20 +03:00
parent 13e5ebc3ef
commit eccb449dfd
3 changed files with 11 additions and 3 deletions

View file

@ -14,6 +14,8 @@ module Agents
You may set `window_duration_in_days` to change the default memory window length of `14` days, `min_peak_spacing_in_days` to change the default minimum peak spacing of `2` days (peaks closer together will be ignored), and `std_multiple` to change the default standard deviation threshold multiple of `3`.
You may set `min_events` for the minimal number of accumulated events before the agent starts detecting.
You may set `search_url` to point to something else than Twitter search.
MD
event_description <<-MD
@ -28,7 +30,7 @@ module Agents
MD
def validate_options
unless options['expected_receive_period_in_days'].present? && options['message'].present? && options['value_path'].present? && options['min_events'].present?
unless options['expected_receive_period_in_days'].present? && options['message'].present? && options['value_path'].present? && options['min_events'].present? && options['search_url'].present?
errors.add(:base, "expected_receive_period_in_days, value_path, min_events and message are required")
end
end
@ -40,6 +42,7 @@ module Agents
'value_path' => "count",
'message' => "A peak of {{count}} was found in {{filter}}",
'min_events' => '4',
'search_url' => 'https://twitter.com/search?q=%{q}'
}
end

View file

@ -1,12 +1,11 @@
<% content_for :head do %>
<%= javascript_include_tag "graphing" %>
<% end %>
<% if @agent.memory[:data] && @agent.memory[:data].length > 0 %>
<h3>Recent Trends</h3>
<% @agent.memory[:data].each.with_index do |(group_name, data), index| %>
<div class="filter-group counts">
<div class='filter'><%= link_to group_name.to_s, "https://twitter.com/search?q=#{CGI::escape group_name.to_s}", :target => "blank" %></div>
<div class='filter'><%= link_to group_name.to_s, format(@agent.options[:search_url], q: CGI::escape(group_name.to_s)), :target => "blank" %></div>
<div class="chart-container group-<%= index.to_s %>">
<div class="y-axis"></div>

View file

@ -10,6 +10,7 @@ describe Agents::PeakDetectorAgent do
'value_path' => "count",
'message' => "A peak was found",
'min_events' => "4",
'search_url' => "https://twitter.com/search?q=%{q}"
}
}
@ -90,6 +91,11 @@ describe Agents::PeakDetectorAgent do
expect(@agent).not_to be_valid
end
it "should validate presence of search_url" do
@agent.options['search_url'] = nil
expect(@agent).not_to be_valid
end
it "should validate presence of expected_receive_period_in_days" do
@agent.options['expected_receive_period_in_days'] = ""
expect(@agent).not_to be_valid