all_seeing_eye 0.0.13 → 0.0.14
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 +1 -1
- data/all_seeing_eye.gemspec +1 -1
- data/lib/all_seeing_eye/model.rb +16 -19
- data/lib/all_seeing_eye/server/views/field.erb +1 -1
- data/lib/all_seeing_eye/server/views/layout.erb +1 -1
- data/lib/all_seeing_eye/server/views/total.erb +1 -1
- data/lib/all_seeing_eye/server.rb +4 -4
- data/test/model_test.rb +9 -3
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.14
|
data/all_seeing_eye.gemspec
CHANGED
data/lib/all_seeing_eye/model.rb
CHANGED
@@ -73,7 +73,17 @@ class AllSeeingEye::Model
|
|
73
73
|
def self.count_by_field(field, options = {})
|
74
74
|
options = {:start => '-inf', :stop => '+inf'}.merge(options)
|
75
75
|
|
76
|
-
|
76
|
+
key = if options[:value]
|
77
|
+
"allseeingeye:#{self.model_name}:fields:#{field}:#{options[:value]}:count"
|
78
|
+
else
|
79
|
+
if AllSeeingEye.redis.exists("allseeingeye:#{self.model_name}:fields:#{field}:count")
|
80
|
+
"allseeingeye:#{self.model_name}:fields:#{field}:count"
|
81
|
+
else
|
82
|
+
"allseeingeye:#{self.model_name}:fields:#{field}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
raw_list = AllSeeingEye.redis.zrangebyscore(key, options[:start], options[:stop], :with_scores => true)
|
77
87
|
list = []
|
78
88
|
raw_list.each_with_index do |value, index|
|
79
89
|
if index % 2 == 0
|
@@ -82,7 +92,7 @@ class AllSeeingEye::Model
|
|
82
92
|
list.last[1] = value.to_i
|
83
93
|
end
|
84
94
|
end
|
85
|
-
list.
|
95
|
+
list.sort{|a, b| a.first.is_a?(String) ? b.last <=> a.last : a.first <=> b.first}
|
86
96
|
end
|
87
97
|
|
88
98
|
def self.first
|
@@ -133,22 +143,6 @@ class AllSeeingEye::Model
|
|
133
143
|
tree.to_a
|
134
144
|
end
|
135
145
|
|
136
|
-
def self.created_count(start = '-inf', stop = '+inf')
|
137
|
-
start ||= Chronic.parse(start).to_i
|
138
|
-
stop ||= Chronic.parse(stop).to_i
|
139
|
-
|
140
|
-
raw_list = AllSeeingEye.redis.zrangebyscore("allseeingeye:#{self.model_name}:fields:created_at:count", start, stop, :with_scores => true)
|
141
|
-
list = []
|
142
|
-
raw_list.each_with_index do |value, index|
|
143
|
-
if index % 2 == 0
|
144
|
-
list << [value]
|
145
|
-
else
|
146
|
-
list.last[1] = value.to_i
|
147
|
-
end
|
148
|
-
end
|
149
|
-
list
|
150
|
-
end
|
151
|
-
|
152
146
|
def initialize
|
153
147
|
self.class.field_names.each do |key|
|
154
148
|
self.class.send(:attr_accessor, key.to_sym)
|
@@ -161,15 +155,18 @@ class AllSeeingEye::Model
|
|
161
155
|
end
|
162
156
|
|
163
157
|
def save
|
158
|
+
timestamp = (self.created_at.to_i / 60) * 60
|
159
|
+
|
164
160
|
AllSeeingEye.redis["allseeingeye:#{self.class.model_name}:#{id}"] = Marshal.dump(self)
|
165
161
|
AllSeeingEye.redis.sadd("allseeingeye:#{self.class.model_name}:all", id)
|
166
162
|
self.class.field_names.each do |field|
|
167
163
|
value = self.send(field.to_sym)
|
168
164
|
next if value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
169
165
|
if value.is_a?(Time) || value.is_a?(DateTime) || value.is_a?(Date)
|
166
|
+
AllSeeingEye.redis.zincrby("allseeingeye:#{self.class.model_name}:fields:#{field}:count", 1, timestamp)
|
170
167
|
AllSeeingEye.redis.zadd("allseeingeye:#{self.class.model_name}:fields:#{field}", value.to_i, id)
|
171
|
-
AllSeeingEye.redis.zincrby("allseeingeye:#{self.class.model_name}:fields:#{field}:count", 1, (value.to_i / 60) * 60)
|
172
168
|
else
|
169
|
+
AllSeeingEye.redis.zincrby("allseeingeye:#{self.class.model_name}:fields:#{field}:#{value}:count", 1, timestamp)
|
173
170
|
AllSeeingEye.redis.lpush("allseeingeye:#{self.class.model_name}:fields:#{field}:#{value}", id)
|
174
171
|
AllSeeingEye.redis.zincrby("allseeingeye:#{self.class.model_name}:fields:#{field}", 1, value)
|
175
172
|
end
|
@@ -61,7 +61,7 @@
|
|
61
61
|
|
62
62
|
$("#graph").bind("plotclick", function (event, pos, item) {
|
63
63
|
if (item) {
|
64
|
-
window.location = "
|
64
|
+
window.location = '<%= u "fields/#{CGI::escape(@field)}/" %>' + encodeURIComponent(ids[item.dataIndex])
|
65
65
|
}
|
66
66
|
});
|
67
67
|
</script>
|
@@ -21,7 +21,7 @@
|
|
21
21
|
<%= tab 'Total' %>
|
22
22
|
<%= tab 'Fields' %>
|
23
23
|
<li class='right'>
|
24
|
-
<form action='<%=u '/search' %>'
|
24
|
+
<form action='<%=u '/search' %>'>
|
25
25
|
<label>Search</label>
|
26
26
|
<input name='query' type='text'>
|
27
27
|
<input type="submit" name="submit" value="Go" >
|
@@ -18,7 +18,7 @@
|
|
18
18
|
<script type='text/javascript'>
|
19
19
|
$.plot($("#graph"),
|
20
20
|
[{
|
21
|
-
data: [ <%= @counts.collect{|
|
21
|
+
data: [ <%= @counts.collect{|count| "[#{count.first.to_i * 1000}, #{count.last.to_i}]"}.join(',') %> ],
|
22
22
|
label: 'requests'
|
23
23
|
}],
|
24
24
|
{
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'all_seeing_eye'
|
2
2
|
require 'sinatra/base'
|
3
3
|
require 'erb'
|
4
|
+
require 'cgi'
|
4
5
|
|
5
6
|
class AllSeeingEye
|
6
7
|
class Server < Sinatra::Base
|
@@ -73,11 +74,11 @@ class AllSeeingEye
|
|
73
74
|
end
|
74
75
|
|
75
76
|
get '/total' do
|
76
|
-
@counts = AllSeeingEye::Request.
|
77
|
+
@counts = AllSeeingEye::Request.count_by_field('created_at', :start => (DateTime.now - 1.month).to_i, :stop => DateTime.now.to_i)
|
77
78
|
show :total
|
78
79
|
end
|
79
80
|
|
80
|
-
|
81
|
+
get '/search' do
|
81
82
|
redirect url_path("/search/#{params[:query]}")
|
82
83
|
end
|
83
84
|
|
@@ -126,8 +127,7 @@ class AllSeeingEye
|
|
126
127
|
get %r{/fields/#{field}/(.*)$} do
|
127
128
|
@field = field
|
128
129
|
@id = params[:captures].first
|
129
|
-
@
|
130
|
-
@counts = AllSeeingEye::Request.conglomerate(@requests)
|
130
|
+
@counts = AllSeeingEye::Request.count_by_field(@field, :value => @id)
|
131
131
|
show :total
|
132
132
|
end
|
133
133
|
end
|
data/test/model_test.rb
CHANGED
@@ -189,7 +189,7 @@ context 'class methods with setup' do
|
|
189
189
|
|
190
190
|
test 'return count in a field' do
|
191
191
|
counts = AllSeeingEye::Model.count_by_field('uri')
|
192
|
-
|
192
|
+
|
193
193
|
assert_equal '/test/', counts.first.first
|
194
194
|
assert_equal 5, counts.first.last
|
195
195
|
assert_equal '/', counts.last.first
|
@@ -230,7 +230,7 @@ context 'many objects' do
|
|
230
230
|
@time = Time.now
|
231
231
|
|
232
232
|
2000.times do |n|
|
233
|
-
instance_variable_set("@obj#{n}".to_sym, AllSeeingEye::Model.create(:uri => '/', :ip => '127.0.0.1', :created_at => @time - (n * (1999 - n)) * 60))
|
233
|
+
instance_variable_set("@obj#{n}".to_sym, AllSeeingEye::Model.create(:uri => '/', :ip => n % 2 == 0 ? '127.0.0.1' : '192.168.0.1', :created_at => @time - (n * (1999 - n)) * 60))
|
234
234
|
end
|
235
235
|
end
|
236
236
|
|
@@ -244,12 +244,18 @@ context 'many objects' do
|
|
244
244
|
end
|
245
245
|
|
246
246
|
test 'get the created count' do
|
247
|
-
counts = AllSeeingEye::Model.
|
247
|
+
counts = AllSeeingEye::Model.count_by_field('created_at')
|
248
248
|
|
249
249
|
assert_equal (@obj999.created_at.to_i / 60) * 60, counts.first.first.to_i
|
250
250
|
assert_equal (@obj0.created_at.to_i / 60) * 60, counts.last.first.to_i
|
251
251
|
assert_equal 2000, counts.inject(0) {|sum, k| sum + k.last}
|
252
252
|
end
|
253
|
+
|
254
|
+
test 'get the created count for a value' do
|
255
|
+
counts = AllSeeingEye::Model.count_by_field('ip', :value => '192.168.0.1')
|
256
|
+
|
257
|
+
assert_equal 1000, counts.inject(0) {|sum, k| sum + k.last}
|
258
|
+
end
|
253
259
|
end
|
254
260
|
|
255
261
|
context 'instance methods' do
|
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:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 14
|
10
|
+
version: 0.0.14
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Josh Symonds
|