all_seeing_eye 0.0.14 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.14
1
+ 0.0.15
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{all_seeing_eye}
8
- s.version = "0.0.14"
8
+ s.version = "0.0.15"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Josh Symonds"]
12
- s.date = %q{2011-08-11}
12
+ s.date = %q{2011-08-12}
13
13
  s.default_executable = %q{all-seeing-eye}
14
14
  s.description = %q{AllSeeingEye observes all requests, with parameters that you specify, to Redis. Then it composes them into graphs for you to see.}
15
15
  s.email = %q{veraticus@gmail.com}
@@ -44,7 +44,6 @@ Gem::Specification.new do |s|
44
44
  "lib/all_seeing_eye/server/views/layout.erb",
45
45
  "lib/all_seeing_eye/server/views/left.erb",
46
46
  "lib/all_seeing_eye/server/views/total.erb",
47
- "lib/all_seeing_eye/server/views/view.erb",
48
47
  "test/base_test.rb",
49
48
  "test/fixtures/all_seeing_eye.yml",
50
49
  "test/fixtures/redis-test.conf",
@@ -57,7 +57,7 @@ class AllSeeingEye::Model
57
57
 
58
58
  def self.find_by_field(field, options = {})
59
59
  if options[:value]
60
- all = AllSeeingEye.redis.sort("allseeingeye:#{self.model_name}:fields:#{field}:#{options[:value]}", :by => 'nosort', :get => "allseeingeye:#{self.model_name}:*").collect{|o| self.load(o)}
60
+ all = AllSeeingEye.redis.sort("allseeingeye:#{self.model_name}:fields:#{field}:#{options[:value]}", :by => 'nosort', :get => "allseeingeye:#{self.model_name}:*", :limit => options[:offset] && options[:limit] ? [options[:offset], options[:limit]] : nil).collect{|o| self.load(o)}
61
61
  all = all.find_all{|o| o.created_at > options[:start]} if options[:start]
62
62
  all = all.find_all{|o| o.created_at < options[:stop]} if options[:stop]
63
63
  all
@@ -71,19 +71,18 @@ class AllSeeingEye::Model
71
71
  end
72
72
 
73
73
  def self.count_by_field(field, options = {})
74
- options = {:start => '-inf', :stop => '+inf'}.merge(options)
74
+ options = {:start => '-inf', :stop => '+inf', :offset => nil, :limit => nil}.merge(options)
75
75
 
76
- key = if options[:value]
77
- "allseeingeye:#{self.model_name}:fields:#{field}:#{options[:value]}:count"
76
+ raw_list, needs_pruning = if options[:value]
77
+ [AllSeeingEye.redis.zrangebyscore("allseeingeye:#{self.model_name}:fields:#{field}:#{options[:value]}:count", '-inf', '+inf', :with_scores => true), true]
78
78
  else
79
79
  if AllSeeingEye.redis.exists("allseeingeye:#{self.model_name}:fields:#{field}:count")
80
- "allseeingeye:#{self.model_name}:fields:#{field}:count"
80
+ [AllSeeingEye.redis.zrangebyscore("allseeingeye:#{self.model_name}:fields:#{field}:count", '-inf', '+inf', :with_scores => true), true]
81
81
  else
82
- "allseeingeye:#{self.model_name}:fields:#{field}"
82
+ [AllSeeingEye.redis.zrangebyscore("allseeingeye:#{self.model_name}:fields:#{field}", options[:start], options[:stop], :with_scores => true), false]
83
83
  end
84
84
  end
85
85
 
86
- raw_list = AllSeeingEye.redis.zrangebyscore(key, options[:start], options[:stop], :with_scores => true)
87
86
  list = []
88
87
  raw_list.each_with_index do |value, index|
89
88
  if index % 2 == 0
@@ -92,7 +91,11 @@ class AllSeeingEye::Model
92
91
  list.last[1] = value.to_i
93
92
  end
94
93
  end
95
- list.sort{|a, b| a.first.is_a?(String) ? b.last <=> a.last : a.first <=> b.first}
94
+ if needs_pruning
95
+ list = list.find_all{|i| i.first.to_i > options[:start]} if options[:start] && options[:start] != '-inf'
96
+ list = list.find_all{|i| i.first.to_i < options[:stop]} if options[:stop] && options[:stop] != '+inf'
97
+ end
98
+ list.sort{|a, b| a.first.to_i == 0 ? b.last <=> a.last : a.first <=> b.first}
96
99
  end
97
100
 
98
101
  def self.first
@@ -105,15 +108,19 @@ class AllSeeingEye::Model
105
108
 
106
109
  def self.search(query, options = {})
107
110
  if query =~ /^[\sa-zA-Z0-9,-]*? to [\sa-zA-Z0-9,-]*?$/
108
- start = Chronic.parse(query.split(' to ').first, :context => :past)
109
- stop = Chronic.parse(query.split(' to ').last, :context => :past)
110
- AllSeeingEye.redis.zrangebyscore("allseeingeye:#{self.model_name}:fields:created_at", start.to_i, stop.to_i, :with_scores => false).collect{|id| self.find(id)}
111
+ start = Chronic.parse(query.split(' to ').first, :context => :past).to_i
112
+ stop = Chronic.parse(query.split(' to ').last, :context => :past).to_i
113
+ if options[:count]
114
+ return self.count_by_field('created_at', :start => start, :stop => stop)
115
+ else
116
+ return AllSeeingEye.redis.zrangebyscore("allseeingeye:#{self.model_name}:fields:created_at", start, stop, :with_scores => false).collect{|id| self.find(id)}
117
+ end
111
118
  elsif query =~ /^(#{self.field_names.join('|')}):(.*)$/
112
- self.find_by_field($1, :value => $2)
113
- else
114
- results = []
115
- self.field_names.each {|f| results << self.find_by_field(f, :value => query)}
116
- results.flatten.uniq
119
+ if options[:count]
120
+ self.count_by_field($1, :value => $2)
121
+ else
122
+ self.find_by_field($1, :value => $2)
123
+ end
117
124
  end
118
125
  end
119
126
 
@@ -66,6 +66,7 @@ class AllSeeingEye
66
66
 
67
67
  def show(page, layout = true)
68
68
  response["Cache-Control"] = "max-age=0, private, must-revalidate"
69
+ @page = params[:page].blank? ? 1 : params[:page].to_i if page == :field || page == 'field'
69
70
  erb page.to_sym, {:layout => layout}
70
71
  end
71
72
 
@@ -85,8 +86,7 @@ class AllSeeingEye
85
86
  get '/search/:id' do
86
87
  @field = 'total'
87
88
  @query = params[:id]
88
- @requests = AllSeeingEye::Request.search(@query)
89
- @counts = AllSeeingEye::Request.conglomerate(@requests)
89
+ @requests = AllSeeingEye::Request.search(@query, :count => true)
90
90
  show :total
91
91
  end
92
92
 
@@ -117,10 +117,10 @@ class AllSeeingEye
117
117
  @id = params[:captures].first
118
118
  @view = f
119
119
  @requests = AllSeeingEye::Request.find_by_field(@field, :value => @id)
120
- @counts = Hash.new(0)
121
- @requests.each {|r| next if r.send(@view.to_sym).nil?; @counts[r.send(@view.to_sym)] += 1}
122
- @counts = @counts.sort {|a, b| b.last <=> a.last}
123
- show :view
120
+ counts = Hash.new(0)
121
+ @requests.each {|r| next if r.send(@view.to_sym).nil?; counts[r.send(@view.to_sym)] += 1}
122
+ @requests = counts.sort {|a, b| b.last <=> a.last}
123
+ show :field
124
124
  end
125
125
  end
126
126
 
@@ -228,4 +228,9 @@ tr:last-child td.last {
228
228
  }
229
229
  #page #graph {
230
230
  width: 98%; height: 500px; margin: 0 10px;
231
- }
231
+ }
232
+ #page #pager {
233
+ width: 95%; height: 30px; margin: 10px 0; padding: 0 10px;
234
+ }
235
+ #pager #previous {float: left;}
236
+ #pager #next {float: right;}
@@ -1,23 +1,32 @@
1
1
  <%= partial(:left) %>
2
2
 
3
+ <% paged_requests = @requests[((@page - 1) * 10)..(@page * 10)] %>
4
+
3
5
  <div id='right'>
4
6
  <% if @query %>
5
7
  <h1>Search &raquo; <%= humanize @query %> &raquo; <%= humanize @field %></h1>
8
+ <% elsif @view %>
9
+ <h1><a href='/fields/<%= @field %>'><%= humanize @field %></a> &raquo; <%= humanize @id %> &raquo; <%= humanize @view %></h1>
6
10
  <% else %>
7
11
  <h1><%= humanize @field %></h1>
8
12
  <% end %>
9
13
 
10
- <% if @requests.empty? %>
14
+ <% if paged_requests.nil? || paged_requests.empty? %>
11
15
  <h2>No requests found.</h2>
12
16
  <% else %>
13
17
  <div id='graph'></div>
18
+
19
+ <div id='pager'>
20
+ <% if @page != 1 %><a href='<%= u "#{current_page}?page=#{@page - 1}"%>' id='previous'>&laquo; previous</a><% end %>
21
+ <% if @requests.count > @page * 10 %><a href='<%= u "#{current_page}?page=#{@page + 1}"%>' id='next'>next &raquo;</a><% end %>
22
+ </div>
14
23
 
15
24
  <script type='text/javascript'>
16
- var ids = [ <%= @requests[0..10].collect{|r| "'#{r.first}'"}.join(',') %>]
25
+ var ids = [ <%= paged_requests.collect{|r| "'#{r.first}'"}.join(',') %>]
17
26
 
18
27
  $.plot($("#graph"),
19
28
  [{
20
- data: [ <%= @requests[0..10].enum_for(:each_with_index).collect {|f, i| "[#{i}, #{f.last}]"}.join(',') %> ],
29
+ data: [ <%= paged_requests.enum_for(:each_with_index).collect {|f, i| "[#{i}, #{f.last}]"}.join(',') %> ],
21
30
  label: 'requests'
22
31
  }],
23
32
  {
@@ -27,7 +36,7 @@
27
36
  grid: { hoverable: true, clickable: true },
28
37
  xaxis: {
29
38
  autoscaleMargin: 0.05,
30
- ticks: [ <%= @requests[0..10].enum_for(:each_with_index).collect {|f, i| "[#{i}, '#{f.first.split(' ').join('\n').gsub('/','/\n')}']"}.join(',') %> ]
39
+ ticks: [ <%= paged_requests.enum_for(:each_with_index).collect {|f, i| "[#{i}, '#{f.first.split(' ').join('\n').gsub('/','/\n')}']"}.join(',') %> ]
31
40
  },
32
41
  yaxis: {
33
42
  autoscaleMargin: 0.01
data/test/model_test.rb CHANGED
@@ -163,6 +163,10 @@ context 'class methods with setup' do
163
163
  assert results.collect(&:id).include?(@obj4.id)
164
164
  end
165
165
 
166
+ test 'find model objects with a limit and offset' do
167
+
168
+ end
169
+
166
170
  test 'find model objects by a date field' do
167
171
  results = AllSeeingEye::Model.find_by_field('created_at', :start => @obj1.created_at, :stop => @obj4.created_at)
168
172
 
@@ -215,12 +219,11 @@ context 'class methods with setup' do
215
219
  assert results.collect(&:id).include?(@obj6.id)
216
220
  end
217
221
 
218
- test 'search without a specific field' do
219
- results = AllSeeingEye::Model.search('192.168.0.1')
222
+ test 'search for a count on a specific field' do
223
+ results = AllSeeingEye::Model.search('uri:/test/', :count => true)
220
224
 
221
- assert_equal 2, results.count
222
- assert results.collect(&:id).include?(@obj4.id)
223
- assert results.collect(&:id).include?(@obj6.id)
225
+ assert_equal 4, results.count
226
+ assert_equal results.last, [((@obj6.created_at.to_i / 60) * 60).to_s, 2]
224
227
  end
225
228
  end
226
229
 
@@ -246,6 +249,7 @@ context 'many objects' do
246
249
  test 'get the created count' do
247
250
  counts = AllSeeingEye::Model.count_by_field('created_at')
248
251
 
252
+ assert_equal counts, AllSeeingEye::Model.search('ten years ago to one year from now', :count => true)
249
253
  assert_equal (@obj999.created_at.to_i / 60) * 60, counts.first.first.to_i
250
254
  assert_equal (@obj0.created_at.to_i / 60) * 60, counts.last.first.to_i
251
255
  assert_equal 2000, counts.inject(0) {|sum, k| sum + k.last}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: all_seeing_eye
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 14
10
- version: 0.0.14
9
+ - 15
10
+ version: 0.0.15
11
11
  platform: ruby
12
12
  authors:
13
13
  - Josh Symonds
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-11 00:00:00 -05:00
18
+ date: 2011-08-12 00:00:00 -05:00
19
19
  default_executable: all-seeing-eye
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -199,7 +199,6 @@ files:
199
199
  - lib/all_seeing_eye/server/views/layout.erb
200
200
  - lib/all_seeing_eye/server/views/left.erb
201
201
  - lib/all_seeing_eye/server/views/total.erb
202
- - lib/all_seeing_eye/server/views/view.erb
203
202
  - test/base_test.rb
204
203
  - test/fixtures/all_seeing_eye.yml
205
204
  - test/fixtures/redis-test.conf
@@ -1,63 +0,0 @@
1
- <%= partial(:left) %>
2
-
3
- <div id='right'>
4
- <h1><a href='/fields/<%= @field %>'><%= humanize @field %></a> &raquo; <%= humanize @id %> &raquo; <%= humanize @view %></h1>
5
-
6
- <% if @counts.flatten.empty? %>
7
- <h2>No requests found.</h2>
8
- <% else %>
9
- <div id='graph'></div>
10
-
11
- <script type='text/javascript'>
12
- $.plot($("#graph"),
13
- [{
14
- data: [ <%= @counts.enum_for(:each_with_index).collect {|f, i| "[#{i}, #{f.last}]"}.join(',') %> ],
15
- label: 'requests'
16
- }],
17
- {
18
- series: {
19
- bars: { show: true, align: "center", barWidth: 0.9}
20
- },
21
- grid: { hoverable: true, clickable: true },
22
- xaxis: {
23
- autoscaleMargin: 0.05,
24
- ticks: [ <%= @counts.reverse.enum_for(:each_with_index).collect {|f, i| "[#{i}, '#{f.first.to_s.split(' ').join('\n').gsub('/','/\n')}']"}.join(',') %> ]
25
- },
26
- yaxis: {
27
- autoscaleMargin: 0.01
28
- },
29
- legend: {
30
- show: false
31
- },
32
- colors: ["#6bc2f6", "#d18b2c", "#dba255", "#919733"]
33
- });
34
-
35
- var previousPoint = null;
36
-
37
- $("#graph").bind("plothover", function (event, pos, item) {
38
- if (item) {
39
- if (previousPoint != item.dataIndex) {
40
- previousPoint = item.dataIndex;
41
-
42
- $("#tooltip").remove();
43
- var x = item.datapoint[0].toFixed(2),
44
- y = item.datapoint[1].toFixed(2);
45
-
46
- showTooltip(item.pageX, item.pageY,
47
- Math.round(y) + ' ' + item.series.label + ' for ' + item.series.xaxis.ticks[item.dataIndex].label );
48
- }
49
- }
50
- else {
51
- $("#tooltip").remove();
52
- previousPoint = null;
53
- }
54
- });
55
-
56
- $("#graph").bind("plotclick", function (event, pos, item) {
57
- if (item) {
58
- window.location = "/fields/<%= @field %>/" + encodeURIComponent(ids[item.dataIndex])
59
- }
60
- });
61
- </script>
62
- <% end %>
63
- </div>